#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>; ll GCD(ll a, ll b){ return b ? GCD(b,a%b) : a; } int main(){ ll N; cin >> N; ll C[9]; rep(i,9) cin >> C[i]; set X; rep(i,9) if(C[i]) X.insert(i+1); if(X.size() == 1){ ll x = *X.begin(); mll ans = (mll(10).pow(N) - 1) / 9; ans = ans * x; cout << ans.val() << "\n"; return 0; } ll mult = 8*7*5*9; for(ll x : X) mult = GCD(mult,x); ll sum = 0; rep(d,9) sum += ll(C[d]) * (d+1); sum = GCD(sum,9); cout << (mult * sum) << "\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;