#include <bits/stdc++.h>
using namespace std;

int mod = 1000000007;

long long modpow(long long a,long long b,long long m) {
    long long ans = 1;
    while(b) {
        if(b & 1) {
            (ans *= a) %= m;
        }
        (a *= a) %= m;
        b /= 2;
    }
    return ans;
}

long long modinv(long long a, long long m) {
    long long b = m,u = 1,v = 0;
    while (b) {
        long long t = a/b;
        a -= t*b;
        u -= t*v;
        swap(a,b);
        swap(u,v);
    }
    u %= m;
    if (u < 0) {
        u += m;
    }
    return u;
}

int main() {
    int N;
    cin >> N;
    vector<long long>tmp(9);
    for(int i = 0; i < 9; i++) {
        cin >> tmp[i];
    }
    int g = -1;
    for(int i = 0; i < 9; i++) {
        for(int j = i+1; j < 9; j++) {
            if(tmp[i] && tmp[j]) {
                if(g == -1) {
                    g = abs((i+1)*10+(j+1)-((j+1)*10+i+1));
                }
                else {
                    g = gcd(g,abs((i+1)*10+(j+1)-((j+1)*10+i+1)));
                }
                g = gcd(g,abs((j+1)*10+(i+1)-((i+1)*10+j+1)));
            }
        }
    }
    if(g == -1) {
        for(int i = 0; i < 9; i++) {
            if(tmp[i]) {
                cout << (modpow(10,tmp[i]-1,mod)+modpow(10,0,mod))*modinv(2,mod)%mod*tmp[i]%mod*(i+1)%mod << endl;
            }
        }
        return 0;
    }
    int cnt = 0;
    long long sum = 0;
    for(int i = 0; i < 9; i++) {
        cnt += tmp[i];
        long long tmp2 = (modpow(10,cnt-1,g)+modpow(10,cnt-tmp[i],g))%g*tmp[i]%g*modinv(2,g)%g;
        sum += tmp2*(i+1)%g;
        sum %= g;
    }
    g = gcd(g,sum);
    cout << g << endl;
}