eolymp
bolt
Try our new interface for solving problems
Problems

Sequence (2)

Sequence (2)

Each member of the sequence of decimal digits \textbf{d_1}, \textbf{d_2}, \textbf{d_3}, ..., starting from the fourth, the last digit is the sum of the previous three. On the set \textbf{d_1}, \textbf{d_2}, \textbf{d_3} find the \textbf{N}-th term of the sequence. \InputFile In the first row are the numbers \textbf{d_1}, \textbf{d_2}, \textbf{d_3}, separated by spaces, in the second - the number \textbf{N}. \textbf{1} ≤ \textbf{N} ≤ \textbf{10^15}. \OutputFile Print a single digit - \textbf{d_N}.
Time limit 1 second
Memory limit 64 MiB
Input example #1
1 4 8
4
Output example #1
3