60. Fibonacci (hard version)

Time Limit: 2 seconds

Memory Limit: 1024 MB

Rating: 1600

Problem Statement

Output the $N$-th number in the Fibonacci sequence modulo $10^9+7$, where term $0$ is $0$ and term $1$ is $1$. $(0 \le N \le 10^{18})$

Input

The first line has integer $N$.

Output

Output the answer.

Sample Cases
Sample Input 1:
0

Sample Output 1:
0


Sample Input 2:
1000

Sample Output 2:
517691607
Explanation

https://en.wikipedia.org/wiki/Fibonacci_sequence

Sources

IanOJ Contest #1 (Div. 3) > Problem E2

Submit | Back