#include #include #include #include #include #include #include #include #include #include #include #include #include #define getchar getchar_unlocked #define putchar putchar_unlocked #define _rep(_1, _2, _3, _4, name, ...) name #define rep2(i, n) rep3(i, 0, n) #define rep3(i, a, b) rep4(i, a, b, 1) #define rep4(i, a, b, c) for (int i = int(a); i < int(b); i += int(c)) #define rep(...) _rep(__VA_ARGS__, rep4, rep3, rep2, _)(__VA_ARGS__) using namespace std; using i64 = long long; using u8 = unsigned char; using u32 = unsigned; using u64 = unsigned long long; using f80 = long double; int get_int() { int c, n; while ((c = getchar()) < '0'); n = c - '0'; while ((c = getchar()) >= '0') n = n * 10 + (c - '0'); return n; } namespace Poly { using poly = vector; vector tmp64; int mod; i64 lmod; int mul_mod(int a, int b) { return i64(a) * b % mod; } i64 add_mod64(i64 a, i64 b) { return (a += b - lmod) < 0 ? a + lmod : a; } i64 sub_mod64(i64 a, i64 b) { return (a -= b) < 0 ? a + lmod : a; } int fixed(int a) { return (a %= mod) < 0 ? a + mod : a; } void set_mod(int m) { mod = m; lmod = i64(mod) << 32; } poly poly_mul(const poly& f, const poly& g) { int s1 = f.size(), s2 = g.size(), s = s1 + s2 - 1; tmp64.assign(s, 0); rep(i, s1) if (f[i]) rep(j, s2) { tmp64[i + j] = add_mod64(tmp64[i + j], i64(f[i]) * int(g[j])); } poly ret(s); rep(i, s) ret[i] = tmp64[i] % mod; return ret; } poly poly_rem(const poly& f, const poly& g) { int s1 = f.size(), s2 = g.size(); if (s1 < s2) return f; assert(g[0] == 1); tmp64.resize(s1); copy(f.begin(), f.end(), tmp64.begin()); rep(i, s1 - s2 + 1) { int c = tmp64[i] % mod; if (c) rep(j, 1, s2) tmp64[i + j] = sub_mod64(tmp64[i + j], i64(c) * int(g[j])); tmp64[i] = c; } poly ret(s2 - 1); rep(i, s2 - 1) ret[i] = tmp64[s1 - s2 + 1 + i] % mod; return ret; } poly x_pow_mod(i64 e, const poly& f) { if (e == 0) return poly(1, 1); poly ret = poly_rem(poly({1, 0}), f); for (i64 mask = (i64(1) << __lg(e)) >> 1; mask; mask >>= 1) { ret = poly_mul(ret, ret); if (e & mask) ret.push_back(0); ret = poly_rem(ret, f); } return ret; } int nth_term(i64 e, poly f, poly terms, const int mod) { if (mod == 1) return 0; assert(f.size() <= terms.size() + 1); set_mod(mod); rep(i, f.size()) f[i] = fixed(f[i]); rep(i, terms.size()) terms[i] = fixed(terms[i]); auto rem = x_pow_mod(e, f); reverse(rem.begin(), rem.end()); i64 ret = 0; rep(i, rem.size()) ret = add_mod64(ret, i64(rem[i]) * terms[i]); return ret % mod; } } // Poly void solve() { using namespace Poly; auto f = poly({1, -16, 102, -342, 685, -884, 753, -386, 62, 56, -39, 4, 4}); auto g = poly({32, 316, 2292, 14422, 84744, 479004, 2638328, 14258574, 75940592, 399782668, 84795558, 786749020, 442043859, 352536615, 76576421, 744912747, 420315017, 25759333}); i64 N; while (~scanf("%lld", &N)) { printf("%d\n", nth_term(N - 1, f, g, 1e9 + 7)); } } int main() { clock_t beg = clock(); solve(); clock_t end = clock(); fprintf(stderr, "%.3f sec\n", double(end - beg) / CLOCKS_PER_SEC); return 0; }