#include #include using namespace std; using namespace atcoder; #define rep(i,n)for (int i = 0; i < int(n); ++i) #define rrep(i,n)for (int i = int(n)-1; i >= 0; --i) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() template void chmax(T& a, const T& b) {a = max(a, b);} template void chmin(T& a, const T& b) {a = min(a, b);} using ll = long long; using P = pair; using VI = vector; using VVI = vector; using VL = vector; using VVL = vector; using mint = modint1000000007; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; int c[11] = {}; rep(i, 9) cin >> c[i + 1]; int cs = 0; rep(i, 10) cs += c[i] > 0; if (cs == 1) { rep(i, 10) if (c[i]) { cout << ((mint(10).pow(n) - 1) / 9 * i).val() << endl; } return 0; } if (n <= 10) { ll g = 0; string s; rep(i, 10) s.append(c[i], '0' + i); do { g = gcd(g, stoll(s)); } while(next_permutation(all(s))); cout << g << endl; return 0; } int r9 = 0; rep(i, 10) r9 = (r9 + (ll)i * c[i]) % 9; bool b2 = true, b4 = true, b8 = true, b5 = true, b7 = true; rep(i, 10) { if (i % 2) b2 = false; if (i % 4) b4 = false; if (i % 8) b8 = false; if (i % 5) b5 = false; if (i % 7) b7 = false; } int g = 1; if (r9 % 3 == 0) g *= 3; if (r9 % 9 == 0) g *= 3; if (b2) g *= 2; if (b4) g *= 2; if (b8) g *= 2; if (b5) g *= 5; if (b7) g *= 7; cout << g << endl; }