#include using namespace std; template struct modint{ long long val; modint(): val(0) {} modint(long long x){ if(x < 0) val = x % MOD + MOD; else val = x % MOD; } modint(const modint &t){ val = t.val; } modint& operator =(const modint m){ val = m.val; return *this; } modint operator -(){ return modint(-val); } modint& operator-=(const modint &m){ val -= m.val; if(val < 0) val += MOD; return *this; } modint& operator+=(const modint &m){ val += m.val; if(val >= MOD) val -= MOD; return *this; } modint& operator*=(const modint &m){ val *= m.val; val %= MOD; return *this; } modint& operator/=(modint m){ *this *= m.inv(); return *this; } modint inv(){ long long x = 1, y = 0; long long a = val, b = MOD; while(b != 0){ long long t = a / b; a -= t * b; x -= t * y; swap(a, b); swap(x, y); } x %= MOD; if(x < 0) x += MOD; return modint(x); } modint pow(long long k){ long long res = 1; long long v = val; while(k > 0){ if(k & 1) res = res * v % MOD; v = v * v % MOD; k >>= 1; } return modint(res); } bool operator==(const modint &m){ return val == m.val; } modint operator+(const modint &m){ return modint(*this) += m; } modint operator-(const modint &m){ return modint(*this) -= m; } modint operator*(const modint &m){ return modint(*this) *= m; } modint operator/(const modint &m){ return modint(*this) /= m; } bool operator!=(const modint &m){ return modint(*this).val != m.val; } bool operator!=(const int &m){ return modint(*this).val != m; } }; const int MOD = 1000000007; using mint = modint; int main(){ int N; cin >> N; vector c(9); for(int i = 0; i < 9; i++) cin >> c[i]; for(int i = 0; i < 9; i++){ if(c[i] == N){ mint ten = 10; mint ans = 0; ans = (ten.pow(N) - 1) / 9 * (i + 1); cout << ans.val << endl; return 0; } } bool f = true; long long sum = 0; for(long long i = 0; i < 9; i++){ if(i % 2 == 0 && c[i] > 0) f = false; sum += c[i] * (i + 1); } int ans = 1; if(f) ans *= 2; if(c[3] + c[7] == N){ ans = 4; } if(sum % 9 == 0){ cout << 9 * ans << endl; } else if(sum % 3 == 0){ cout << 3 * ans << endl; } else cout << ans << endl; }