// yukicoder: No.147 試験監督(2) // 2019.4.11 bal4u #include #include //// 高速入力 #if 1 #define gc() getchar_unlocked() #else #define gc() getchar() #endif long long in() { int c = gc(); long long n = 0; do n = 10 * n + (c & 0xf), c = gc(); while (c >= '0'); return n; } int ins(char *s) // 文字列の入力 スペース以下の文字で入力終了 { char *p = s; do *s = gc(); while (*s++ > ' '); *--s = 0; return s - p; } #define MOD 1000000007 //// fibonacci数の高速計算 void multiply(int F[2][2], int M[2][2]) { int x = ((long long)F[0][0] * M[0][0] + (long long)F[0][1] * M[1][0]) % MOD; int y = ((long long)F[0][0] * M[0][1] + (long long)F[0][1] * M[1][1]) % MOD; int z = ((long long)F[1][0] * M[0][0] + (long long)F[1][1] * M[1][0]) % MOD; int w = ((long long)F[1][0] * M[0][1] + (long long)F[1][1] * M[1][1]) % MOD; F[0][0] = x; F[0][1] = y; F[1][0] = z; F[1][1] = w; } void power(int F[2][2], long long n) { int M[2][2] = { {1,1},{1,0} }; if (n == 0 || n == 1) return; power(F, n >> 1); multiply(F, F); if (n & 1) multiply(F, M); } int fib(long long n) { int F[2][2] = { {1,1},{1,0} }; if (n == 0) return 0; power(F, n - 1); return F[0][0]; } //// 多倍長整数 #define N 1000000000 int num[50]; int qq[50], rr[2]; void mpStr2Num(int *num, int len, char *str) { char *ss = str + len; int k, x, *nn; x = 0, k = 1, nn = num; do { x += (*--ss - '0') * k; k *= 10; if (k == N || ss == str) *++nn = x, x = 0, k = 1; } while (ss != str); *num = nn - num; } void mpDiv(int *q, int *r, int *za, int zb) { int i; int *aa, *qq; int ca; long long x; *r = 0, *q = *za; for (ca = 0, aa = za + *za, qq = q + *q, i = *za; i > 0; i--) { x = (long long)N * ca + *aa--; *qq-- = (int)(x / zb), ca = (int)(x % zb); } if (*(q + *q) == 0) (*q)--; if (ca > 0) *r++ = 1, *r = ca; else *r = 0; } // calc b^p (mod m) int big_mod(int b, int p) { long long d, s = 1; if (b == 0) return 0; d = b % MOD; while (p) { if (p & 1) s = (s * d) % MOD; p >>= 1; d = (d * d) % MOD; } return (int)s; } char d[220]; int main() { int n, c, w; long long ans; n = (int)in(); ans = 1; while (n--) { c = fib(in() + 2); w = ins(d); mpStr2Num(num, w, d); mpDiv(qq, rr, num, MOD-1); ans = (ans * big_mod(c, rr[1])) % MOD; } printf("%d\n", (int)ans); return 0; }