The Tribonacci sequence is a sequence in which every next element is made by the sum of the previous three elements from the sequence.
Write a computer program that finds the Nth element of the Tribonacci sequence, if you are given the first three elements of the sequence and the number N. Mathematically said: with given T1, T2 and T3 – you must find Tn.
Read from the standard input
The values of the first three Tribonacci elements will be given on the first three input lines.
The number N will be on the fourth line. This is the number of the consecutive element of the sequence that must be found by your program.
The input data will always be valid and in the format described. There is no need to check it explicitly.
Print to the standard output
At the only output line you must print the Nth element of the given Tribonacci sequence.
- The values of the first three elements of the sequence will be integers between -2 000 000 000 and 2 000 000 000.
The number N will be a positive integer between 1 and 15 000, inclusive.