584B.md (1709B)
1 Source: https://codeforces.com/problemset/problem/584/B 2 3 B. Kolya and Tanya 4 5 time limit per test 6 7 1 second 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 Kolya loves putting gnomes at the circle table and giving them coins, and Tanya loves studying triplets of gnomes, sitting in the vertexes of an equilateral triangle. 22 23 More formally, there are 3*n* gnomes sitting in a circle. Each gnome can have from 1 to 3 coins. Let's number the places in the order they occur in the circle by numbers from 0 to 3*n* - 1, let the gnome sitting on the *i*-th place have *a**i* coins. If there is an integer *i* (0 ≤ *i* < *n*) such that *a**i* + *a**i* + *n* + *a**i* + 2*n* ≠ 6, then Tanya is satisfied. 24 25 Count the number of ways to choose *a**i* so that Tanya is satisfied. As there can be many ways of distributing coins, print the remainder of this number modulo 109 + 7. Two ways, *a* and *b*, are considered distinct if there is index *i* (0 ≤ *i* < 3*n*), such that *a**i* ≠ *b**i* (that is, some gnome got different number of coins in these two ways). 26 27 Input 28 29 A single line contains number *n* (1 ≤ *n* ≤ 105) — the number of the gnomes divided by three. 30 31 Output 32 33 Print a single number — the remainder of the number of variants of distributing coins that satisfy Tanya modulo 109 + 7. 34 35 Examples 36 37 Input 38 39 ``` 40 1 41 ``` 42 43 Output 44 45 ``` 46 20 47 ``` 48 49 Input 50 51 ``` 52 2 53 ``` 54 55 Output 56 57 ``` 58 680 59 ``` 60 61 Note 62 63 20 ways for *n* = 1 (gnome with index 0 sits on the top of the triangle, gnome 1 on the right vertex, gnome 2 on the left vertex): 