166E.md (1445B)
1 Source: https://codeforces.com/problemset/problem/166/E 2 3 E. Tetrahedron 4 5 time limit per test 6 7 2 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 stdin 16 17 output 18 19 stdout 20 21 You are given a tetrahedron. Let's mark its vertices with letters *A*, *B*, *C* and *D* correspondingly. 22 23  24 25 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. 26 27 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 (109 + 7). 28 29 Input 30 31 The first line contains the only integer *n* (1 ≤ *n* ≤ 107) — the required length of the cyclic path. 32 33 Output 34 35 Print the only integer — the required number of ways modulo 1000000007 (109 + 7). 36 37 Examples 38 39 Input 40 41 ``` 42 2 43 ``` 44 45 Output 46 47 ``` 48 3 49 ``` 50 51 Input 52 53 ``` 54 4 55 ``` 56 57 Output 58 59 ``` 60 21 61 ``` 62 63 Note 64 65 The required paths in the first sample are: 66 67 * *D* - *A* - *D* 68 * *D* - *B* - *D* 69 * *D* - *C* - *D*