import std.conv, std.functional, std.stdio, std.string; import std.algorithm, std.array, std.bigint, std.container, std.math, std.numeric, std.range, std.regex, std.typecons; import core.bitop; class EOFException : Throwable { this() { super("EOF"); } } string[] tokens; string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; } int readInt() { return readToken.to!int; } long readLong() { return readToken.to!long; } real readReal() { return readToken.to!real; } bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } } bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } } int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; } int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); } int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); } // a^-1 (mod m) long modInv(long a, long m) in { assert(m > 0, "modInv: m > 0 must hold"); } do { long b = m, x = 1, y = 0, t; for (; ; ) { t = a / b; a -= t * b; if (a == 0) { assert(b == 1 || b == -1, "modInv: gcd(a, m) != 1"); if (b == -1) { y = -y; } return (y < 0) ? (y + m) : y; } x -= t * y; t = b / a; b -= t * a; if (b == 0) { assert(a == 1 || a == -1, "modInv: gcd(a, m) != 1"); if (a == -1) { x = -x; } return (x < 0) ? (x + m) : x; } y -= t * x; } } /* P = 10^9 + 7 (5 / P) = (P / 5) = (2 / 5) = -1 r = T, s = 1 - T in F_P[T] / (T^2 - T - 1) f(k) = (r^k - s^k) / (r - s) f(m) + f(2 m) + ... + f(n m) = (r^m (r^(n m) - 1) / (r^m - 1) - s^m (s^(n m) - 1) / (s^m - 1)) / (r - s) (a + b T)^-1 = (-(a + b) / (b^2 - a b - a^2), b / (b^2 - a b - a^2)) */ enum MO = 10L^^9 + 7; long[2] sub(in long[2] a, in long[2] b) { return [(a[0] - b[0]) % MO, (a[1] - b[1]) % MO]; } long[2] mul(in long[2] a, in long[2] b) { return [(a[0] * b[0] + a[1] * b[1]) % MO, (a[0] * b[1] + a[1] * b[0] + a[1] * b[1]) % MO]; } long[2] inv(in long[2] a) { const c = modInv(a[1]^^2 - a[0] * a[1] - a[0]^^2, MO); return [(-(a[0] + a[1]) * c) % MO, (a[1] * c) % MO]; } long[2] power(in long[2] a, long e) { long[2] b = a.dup, c = [1, 0]; for (; e; e >>= 1) { if (e & 1) { c = mul(c, b); } b = mul(b, b); } return c; } void main() { try { for (; ; ) { const N = readLong(); const M = readLong(); const long[2] one = [1L, 0L], r = [0L, 1L], s = [1L, -1L]; const rm = power(r, M), sm = power(s, M); const rnm = power(r, N * M), snm = power(s, N * M); const ans = mul(sub( mul(mul(rm, sub(rnm, one)), inv(sub(rm, one))), mul(mul(sm, sub(snm, one)), inv(sub(sm, one))) ), inv(sub(r, s))); assert(ans[1] == 0); writeln((ans[0] % MO + MO) % MO); } } catch (EOFException e) { } }