Fibonacci's Nightmare

아직 제출이 없습니다시간 제한2초메모리 제한256 MB

문제

Define a random linear recursive sequence (RLRS) as a sequence of random variables a_0,a_1,a\_0, a\_1, \ldots which is generated as follows. First, a_0=1a\_0 = 1. Then, for every nn starting from 11, choose integers ii and jj independently and equiprobably from \[0;n1]\[0; n-1], and set a_n=a_i+a_ja\_n = a\_i + a\_j (note that at this moment, the values of a_0a\_0, \ldots, a_n1a\_{n - 1} are already determined).

For example, a_1=a_0+a_0=2a\_1 = a\_0 + a\_0 = 2, and a_2a\_2 is equally likely to be a_0+a_0a\_0 + a\_0, a_0+a_1a\_0 + a\_1, a_1+a_0a\_1 + a\_0 and a_1+a_1a\_1 + a\_1, thus it has 25% probability to be 22, 50% to be 33 and 25% to be 44. After that, a_3a\_3 is equiprobably chosen from a_0+a_0a\_0 + a\_0, a_0+a_1a\_0 + a\_1, a_0+a_2a\_0 + a\_2, a_1+a_0a\_1 + a\_0, a_1+a_1a\_1 + a\_1, a_1+a_2a\_1 + a\_2, a_2+a_0a\_2 + a\_0, a_2+a_1a\_2 + a\_1, a_2+a_2a\_2 + a\_2; and so on.

You are to determine the variance of nn-th term of RLRS.

The variance of a random variable XX is defined as Var(X)=E(XE(X))2\mathbf{Var}(X) = \mathbf{E}(X - \mathbf{E}(X))^2 (here E(X)\mathbf{E}(X) means expectation or mean value of the random variable XX).

입력

The first line of input contains the integer nn (0n1060 \leq n \leq 10^6).

출력

Let the variance of a_na\_n be a rational number equal to U/VU/V when cancelled to lowest terms (that is, UU and VV are integers, V>0V > 0 and the greatest common divisor of UU and VV is 11). Output the number X=(UV1)mod(109+7)X = (U \cdot V^{-1}) \bmod (10^9 + 7). That is, XX should satisfy the congruence VXUVX \equiv U modulo (109+7)(10^9 + 7). It is guaranteed that such XX exists and is the only root of this equation with 0X<109+70 \leq X < 10^9 + 7.

힌트

a_1a\_1 is always equal to 22, so Var(a_1)=0\mathbf{Var}(a\_1) = 0.

Var(a_2)=12\mathbf{Var}(a\_2) = \frac{1}{2}.

Var(a_5)=26336\mathbf{Var}(a\_5) = \frac{263}{36}.