import std.stdio, std.array, std.string, std.conv, std.algorithm; import std.typecons, std.range, std.random, std.math, std.container; import std.numeric, std.bigint, core.bitop; void main() { auto N = readln.chomp.to!int; auto A = 0 ~ readln.split.map!(to!long).array; immutable long MOD = 10^^9 + 7; long mx = 0; foreach (a; A) mx = max(mx, a); if (mx == A.sum) { long ans = ((powmod(10, N, MOD) - 1 + MOD) % MOD) * powmod(9, MOD-2, MOD) % MOD; foreach (i; 1..10) if (A[i]) ans = ans * i % MOD; ans.writeln; return; } bool all_even = iota(1, 10, 2).map!(i => A[i] == 0).all; long sm = 0; foreach (i; 1..10) sm += A[i] * i; if (sm % 9 == 0) { writeln(9); } else if (sm % 3 == 0) { if (all_even) { writeln(6); } else { writeln(3); } } else { writeln(1); } } long powmod(long a, long x, long m) { long ret = 1; while (x) { if (x % 2) ret = ret * a % m; a = a * a % m; x /= 2; } return ret; }