eolymp
bolt
Try our new interface for solving problems
Problems

Fibonacci sequence

Fibonacci sequence

\{\textbf{F_k}\}\textbf{^\{∞\}_\{k=-∞\}} - infinite sequence of integers, which satisfies the Fibonacci \textbf{F_k} = \textbf{F_\{k-1\}} + \textbf{F_\{k-2\}} (for any integer \textbf{k}). Are also given \textbf{i}, \textbf{F_i}, \textbf{j}, \textbf{F_j}, \textbf{n} (\textbf{i} ≠ \textbf{j}). Find \textbf{F_n}. Example of sequence: \InputFile In the first line are the numbers \textbf{i}, \textbf{F_i}, \textbf{j}, \textbf{F_j}, \textbf{n}. \textbf{-1000} ≤ \textbf{i}, \textbf{j}, \textbf{n} ≤ \textbf{1000}, \textbf{-2000000000} ≤ \textbf{F_k} ≤ \textbf{2000000000} (\textbf{k} = \textbf{min}(\textbf{i}, \textbf{j}, \textbf{n}) \textbf{...} \textbf{max}(\textbf{i}, \textbf{j}, \textbf{n})). \OutputFile Derive a single number \textbf{F_n.}
Time limit 1 second
Memory limit 64 MiB
Input example #1
3 5 -1 4 5
Output example #1
12