#include #define rep(i,a,b) for(int i=a;i= mod ? x - mod : x; } template int add(int x, T... y) { return add(x, add(y...)); } int mul(int x, int y) { return 1LL * x * y % mod; } template int mul(int x, T... y) { return mul(x, mul(y...)); } int sub(int x, int y) { return add(x, mod - y); } int modpow(int a, long long b) { int ret = 1; while (b > 0) { if (b & 1) ret = 1LL * ret * a % mod; a = 1LL * a * a % mod; b >>= 1; } return ret; } int modinv(int a) { return modpow(a, mod - 2); } typedef vector Vec; typedef vector Mat; Vec mulMatVec(Mat a, Vec b) { int n = b.size(); Vec ret(n, 0); rep(i, 0, n) rep(j, 0, n) ret[i] = add(ret[i], mul(a[i][j], b[j])); return ret; } Mat mulMatMat(Mat a, Mat b) { int n = a.size(); Mat ret(n, Vec(n, 0)); rep(i, 0, n) rep(j, 0, n) rep(k, 0, n) ret[i][j] = add(ret[i][j], mul(a[i][k], b[k][j])); return ret; } Mat fastpow(Mat x, ll n) { Mat ret(x.size(), Vec(x.size(), 0)); rep(i, 0, x.size()) ret[i][i] = 1; while (0 < n) { if ((n % 2) == 0) { x = mulMatMat(x, x); n >>= 1; } else { ret = mulMatMat(ret, x); --n; } } return ret; } void printVec(Vec a) { cout << "[\t"; rep(i, 0, a.size()) cout << a[i] << "\t"; cout << "]" << endl; } void printMat(Mat a) { rep(i, 0, a.size()) printVec(a[i]); } /*---------------------------------------------------------------------------------------------------             ∧_∧       ∧_∧  (´<_` )  Welcome to My Coding Space!      ( ´_ゝ`) /  ⌒i     /   \    | |     /   / ̄ ̄ ̄ ̄/  |   __(__ニつ/  _/ .| .|____      \/____/ (u ⊃ ---------------------------------------------------------------------------------------------------*/ string M[10] = { "1000000000", // 0. 初期状態(どこもつながってない) "1111110000", // 1. (1,2) "1111010000", // 2. (1,3) "1111011000", // 3. (1,4) "1100110010", // 4. (2,3) "1111111100", // 5. (2,4) "1001011010", // 6. (3,4) "1000101100", // 7. (1,2)(3,4) "0000010010", // 8. (1,4)(2,3) "0111111011" // 9. 受理状態(単純閉路ができてる) }; string Vinit = "1000000000"; ll N; //--------------------------------------------------------------------------------------------------- void _main() { while (cin >> N) { Mat m(10, Vec(10, 0)); rep(y, 0, 10) rep(x, 0, 10) m[y][x] = M[y][x] - '0'; Vec v(10, 0); rep(x, 0, 10) v[x] = Vinit[x] - '0'; m = fastpow(m, N + 1); v = mulMatVec(m, v); cout << v[9] << endl; } }