import std.algorithm, std.conv, std.range, std.stdio, std.string; const mod = 10^^9+7; alias mint = FactorRing!mod; const r = 3; void main() { auto stats = makeStats(), ns = stats.length.to!int; int[int] mi; foreach (int i, stat; stats) mi[stat] = i; auto m = new mint[][](ns, ns); foreach (si; stats) foreach (sj; canMoves(si)) m[mi[sj]][mi[si]] = 1; auto u = new mint[][](ns, ns); foreach (i; 0..ns) u[i][i] = 1; auto n = readln.chomp.to!long; auto mp = repeatedSquare!(mint[][], matMul)(m, n, u); auto ans = mint(0); foreach (si; stats) if (!(si>>r)) ans += mp[mi[si]][mi[(1< !i.bitTest(j) && i.bitTest(r+j)) || iota(r-1).any!(j => !i.bitTest(j) && !i.bitTest(j+1)))) stats ~= i; return stats; } auto canMoves(int prevStat) { auto stat = (prevStat>>r); int[] canMoves(int stat, int j) { if (j == r) return [stat]; if (stat.bitTest(j)) return canMoves(stat, j+1); int[] stats; if (prevStat.bitTest(j) && (j == 0 || stat.bitTest(j-1))) stats ~= canMoves(stat, j+1); if (!stat.bitTest(j)) stats ~= canMoves(stat.bitSet(j).bitSet(r+j), j+1); if (j < r-1 && !stat.bitTest(j) && !stat.bitTest(j+1)) stats ~= canMoves(stat.bitSet(j).bitSet(j+1), j+2); return stats; } return canMoves(stat, 0); } pragma(inline) { pure bool bitTest(T)(T n, size_t i) { return (n & (T(1) << i)) != 0; } pure T bitSet(T)(T n, size_t i) { return n | (T(1) << i); } pure T bitReset(T)(T n, size_t i) { return n & ~(T(1) << i); } pure T bitComp(T)(T n, size_t i) { return n ^ (T(1) << i); } import core.bitop; pure int bsf(T)(T n) { return core.bitop.bsf(ulong(n)); } pure int bsr(T)(T n) { return core.bitop.bsr(ulong(n)); } pure int popcnt(T)(T n) { return core.bitop.popcnt(ulong(n)); } } pure T repeatedSquare(T, alias pred = "a * b", U)(T a, U n) { return repeatedSquare(a, n, T(1)); } pure T repeatedSquare(T, alias pred = "a * b", U)(T a, U n, T init) { import std.functional; alias predFun = binaryFun!pred; if (n == 0) return init; auto r = init; while (n > 0) { if ((n & 1) == 1) r = predFun(r, a); a = predFun(a, a); n >>= 1; } return r; } T[][] matMul(T)(const T[][] a, const T[][] b) { auto l = b.length, m = a.length, n = b[0].length; auto c = new T[][](m, n); foreach (i; 0..m) { static if (T.init != 0) c[i][] = 0; foreach (j; 0..n) foreach (k; 0..l) c[i][j] += a[i][k] * b[k][j]; } return c; } struct FactorRing(int m, bool pos = false) { version(BigEndian) { union { long vl; struct { int vi2; int vi; } } } else { union { long vl; int vi; } } static init() { return FactorRing!(m, pos)(0); } @property int toInt() { return vi; } alias toInt this; this(int v) { vi = v; } this(int v, bool runMod) { vi = runMod ? mod(v) : v; } this(long v) { vi = mod(v); } ref FactorRing!(m, pos) opAssign(int v) { vi = v; return this; } pure auto mod(int v) const { static if (pos) return v % m; else return (v % m + m) % m; } pure auto mod(long v) const { static if (pos) return cast(int)(v % m); else return cast(int)((v % m + m) % m); } static if (!pos) { pure auto opUnary(string op: "-")() const { return FactorRing!(m, pos)(mod(-vi)); } } static if (m < int.max / 2) { pure auto opBinary(string op: "+")(int rhs) const { return FactorRing!(m, pos)(mod(vi + rhs)); } pure auto opBinary(string op: "-")(int rhs) const { return FactorRing!(m, pos)(mod(vi - rhs)); } } else { pure auto opBinary(string op: "+")(int rhs) const { return FactorRing!(m, pos)(mod(vl + rhs)); } pure auto opBinary(string op: "-")(int rhs) const { return FactorRing!(m, pos)(mod(vl - rhs)); } } pure auto opBinary(string op: "*")(int rhs) const { return FactorRing!(m, pos)(mod(vl * rhs)); } pure auto opBinary(string op)(FactorRing!(m, pos) rhs) const if (op == "+" || op == "-" || op == "*") { return opBinary!op(rhs.vi); } static if (m < int.max / 2) { auto opOpAssign(string op: "+")(int rhs) { vi = mod(vi + rhs); } auto opOpAssign(string op: "-")(int rhs) { vi = mod(vi - rhs); } } else { auto opOpAssign(string op: "+")(int rhs) { vi = mod(vl + rhs); } auto opOpAssign(string op: "-")(int rhs) { vi = mod(vl - rhs); } } auto opOpAssign(string op: "*")(int rhs) { vi = mod(vl * rhs); } auto opOpAssign(string op)(FactorRing!(m, pos) rhs) if (op == "+" || op == "-" || op == "*") { return opOpAssign!op(rhs.vi); } }