#include #include #include #include #include #include #include #include #define rep(i, n) for (int i = 0; i < (n); i++) #define rrep(i, n) for (int i = (n)-1; i >= 0; i--) using namespace std; typedef long long int lli; lli MOD = 1000000007; struct Matrix { vector a; lli n; lli mod = 1e9 + 7; Matrix(lli n) : n(n) { a.assign(n * n, 0); }; Matrix operator*(const Matrix r) const { Matrix v(n); rep(i, n) rep(j, n) rep(k, n) { v.a[i * n + j] += a[i * n + k] * r.a[k * n + j]; v.a[i * n + j] %= mod; } return v; } Matrix operator+(const Matrix r) const { Matrix v(n); rep(i, n) rep(j, n) { v.a[i * n + j] = (a[i * n + j] + r.a[i * n + j]) % mod; } return v; } void set(int b, int d, int c) { a[b * n + d] = c; } void operator*=(const Matrix r) { Matrix v(n); rep(i, n) rep(j, n) rep(k, n) { v.a[i * n + j] += a[i * n + k] * r.a[k * n + j]; v.a[i * n + j] %= mod; } *this = v; } void show() { rep(i, n) rep(j, n) { cerr << a[i * n + j] << ' '; if (j == n - 1) cerr << endl; } } }; Matrix idn(lli n) { Matrix a(n); rep(i, n) { a.a[i * n + i] = 1; } return a; } Matrix pow_mat(Matrix a, lli n) { Matrix an = idn(a.n); while (n > 0) { if (n & 1) an *= a; a *= a; n /= 2; } return an; } Matrix parseStr2Matrix(int n, vector s) { Matrix g(10); rep(i, n) { rep(j, n) g.set(i, j, s[i][j] - '0'); } return g; } int main() { vector s = { "1000000000", "1111000010", "1111110000", "1111111100", "1011110000", "1011111000", "1001011010", "1100001100", "0001000010", "0111111011", }; auto m = parseStr2Matrix(10, s); lli n; cin >> n; auto g = pow_mat(m, n + 1); g.show(); cout << g.a[9 * 10 + 0] << endl; }