Codeforces Round 113 (Div. 2)
E
Tetrahedron
Codeforces
1500
原题
← D→
翻译中…

You are given a tetrahedron. Let's mark its vertices with letters $*A*$, $*B*$, $*C*$ and $*D*$ correspondingly.

翻译中…

image

翻译中…

An ant is standing in the vertex $*D*$ of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each moment of time he makes a step from one vertex to another one along some edge of the tetrahedron. The ant just can't stand on one place.

翻译中…

You do not have to do much to solve the problem: your task is to count the number of ways in which the ant can go from the initial vertex $*D*$ to itself in exactly $*n*$ steps. In other words, you are asked to find out the number of different cyclic paths with the length of $*n*$ from vertex $*D*$ to itself. As the number can be quite large, you should print it modulo $1000000007$ ($10^{9} + 7$).

翻译中…

Input

翻译中…

The first line contains the only integer $*n*$ ($1 ≤ *n* ≤ 10^{7}$) — the required length of the cyclic path.

翻译中…

Output

翻译中…

Print the only integer — the required number of ways modulo $1000000007$ ($10^{9} + 7$).

翻译中…

Note

翻译中…

The required paths in the first sample are:

翻译中…
  • $*D* - *A* - *D*$
  • $*D* - *B* - *D*$
  • $*D* - *C* - *D*$
翻译中…

样例

Input #1
2
Output #1
3
InputCopy OutputCopy
Input #2
4
Output #2
21
InputCopy OutputCopy
题目信息
题号
166E
时间限制
2 s
内存限制
256 MB
标签
动态规划
数学
矩阵

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。