#include #include #include #include #include using namespace std; using ll = long long; using ull = unsigned long long; #define rep(i,n) for(int i=0; i<(n); i++) using mll = atcoder::static_modint<1000000007>; int GCD(int a, int b){ return b ? GCD(b,a%b) : a; } int main(){ int N; cin >> N; int C[9]; rep(i,9) cin >> C[i]; set X; rep(i,9) if(C[i]) X.insert(i+1); if(X.size() == 1){ int x = *X.begin(); mll ans = 0; rep(i,N) ans = ans * 10 + x; cout << ans.val() << "\n"; } int g = 8*7*5*9; for(int x : X) g = GCD(g,x); ll sum = 0; rep(d,9) sum += ll(C[d]) * (d+1); if(sum % 3 == 0) g = g / GCD(g,3) * 3; if(sum % 9 == 0) g = g / GCD(g,9) * 9; cout << g << "\n"; return 0; } struct ios_do_not_sync{ ios_do_not_sync(){ ios::sync_with_stdio(false); cin.tie(nullptr); } } ios_do_not_sync_instance;