#include #if __has_include() #include using namespace atcoder; #endif using namespace std; #define rep(i, n) for (decltype(n) i = 0, i##_len = (n); i < i##_len; ++i) #define reps(i, n) for (decltype(n) i = 1, i##_len = (n); i <= i##_len; ++i) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(x) ((int)(x).size()) #define pl(s) cout << (s) << "\n"; #define plx(s) {cout << (s) << "\n"; exit(0);} #define yes(s) cout << ((s)?"Yes":"No") << "\n"; #define bit(n) (1LL << ((int)(n))) #define get1bit(x,n) (((x) >> (int)(n)) & 1) #define pcnt(x) __builtin_popcountll(x) #define flog(x) (63 - __builtin_clzll(x)) #define clog(x) (((x)==1)?0:(64-__builtin_clzll((x)-1))) #define cdiv(x,y) (((x)+(y)-1)/(y)) #define lb(a,x) distance((a).begin(),lower_bound((a).begin(),(a).end(),(x))) #define ub(a,x) distance((a).begin(),upper_bound((a).begin(),(a).end(),(x))) #ifdef __LOCAL #include #define dump(...) DUMPOUT << " " << string(#__VA_ARGS__) << ": " << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl << " ", dump_func(__VA_ARGS__) #else #define dump(...) #endif using ll = long long; using ld = long double; template using V = vector; template inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;} template inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;} template istream &operator>>(istream &is, complex &v) {T x, y; is >> x >> y; v.real(x); v.imag(y); return is;} template istream &operator>>(istream &is, V &v) {for (auto&& e : v) is >> e;return is;} template istream &operator>>(istream &is, pair &v) {is >> v.first >> v.second;return is;} template istream &operator>>(istream &is, array &v) {for (auto&& e : v) is >> e;return is;} template inline string join(const T& v, string sep = " ") {if (v.size() == 0) return "" ;stringstream ss;for (auto&& e : v) ss << sep << e;return ss.str().substr(1);} template inline void uniq(T& a, bool presort = true){if (presort) sort(all(a));a.erase(unique(all(a)),a.end());} template vector compress(vector &x){auto ret = x; uniq(ret); rep(i,sz(x)) x[i] = lb(ret, x[i]); return ret;} template constexpr bool between(T a, T x, T b) {return (a <= x && x < b);} template constexpr bool intersect(T l1, T r1, T l2, T r2) {return max(l1,l2) <= min(r1,r2);} template V make_vec(size_t n, T a) {return V(n, a);} template auto make_vec(size_t n, Ts... ts) {return V(n, make_vec(ts...));} template inline V CUM(V &a) {int n = sz(a); V ret(n+1); rep(i,n) ret[i+1] = a[i] + ret[i]; return ret;} template inline V DIF(V &a) {int n = sz(a)-1; V ret(n); rep(i,n) ret[i] = a[i+1] - a[i]; return ret;} template void chooseKFromN(const int n, const int k, T f) {int x, y; for (int i = bit(k) - 1; i < bit(n); x = i & -i, y = i + x, i = (((i & ~y) / x) >> 1) | y) f(i);} template void chooseFromS(const int n, int s, T f) {for (int i = bit(n)-1; i >= 0; --i) {i&=s; f(i);}} template void chooseContainS(const int n, int s, T f) {for (int i = s; i < bit(n); i=(++i)|s) f(i);} template void chooseFromMBit(const int n, const int m, T f) { V powm(n+1, 1); for (int i = 0; i < n; ++i) powm[i+1] = m * powm[i]; for (int i = 0; i < powm[n]; ++i) {V bits(n);for (int j = 0; j < n; ++j) bits[j] = (i / powm[j]) % m;f(bits);} } template void choosePermutation(const int n, T f) {V ord(n); iota(all(ord), 0);do{f(ord);} while (next_permutation(all(ord)));} constexpr ll TEN(int n) {return (n == 0) ? 1 : 10 * TEN(n - 1);} constexpr ll POW(ll x, ll n) {ll ret = 1;while (n > 0) {if (n & 1) ret *= x;x *= x;n >>= 1;}return ret;} constexpr ll MODPOW(ll x, ll n, ll m) {ll ret = 1;while (n > 0) {if (n&1) ret = ret * x % m;x = x * x % m;n >>= 1;}return ret;} constexpr ll nC2(ll n) {assert(between(ll(0),n,ll(3037000501)));return n * (n-1)/2;} constexpr ll NSUM(ll n) {assert(between(ll(0),n,ll(3037000500)));return n * (n+1)/2;} constexpr ll pos1d(ll y, ll x, ll h, ll w) {assert(between(ll(0),y,h));assert(between(ll(0),x,w));return y*w + x;} constexpr pair pos2d(ll p, ll h, ll w) {ll y = p/w, x = p - y*w;assert(between(ll(0),y,h));assert(between(ll(0),x,w));return {y, x};} V> buildComb(int n = 60) {V> v(n+1, V(n+1));rep(i,sz(v)) {v[i][0] = 1; v[i][i] = 1;}for (int j = 1; j < sz(v); ++j) for (int k = 1; k < j; ++k) v[j][k] = v[j-1][k-1] + v[j-1][k];return v;} inline bool palindrome(const string& s){return equal(all(s), s.rbegin());} inline string upper(string s) {for(auto&& e: s) e = between('a',e,(char)('z'+1)) ? e - ('a'-'A') : e;return s;} inline string lower(string s) {for(auto&& e: s) e = between('A',e,(char)('Z'+1)) ? e + ('a'-'A') : e;return s;} inline string replace(string s, map &from, V &to) {for (auto&& e: s) e = '0' + (char)(to[from[e]]);return s;} struct IOS {IOS() {cin.tie(nullptr); ios::sync_with_stdio(false); dump("");}} IO; constexpr int INF = (1 << 30) - 1; constexpr ll INFL = 1LL << 60; using mint = modint1000000007; std::istream& operator>>(std::istream& is, mint& a) { int tmp; is >> tmp; a = tmp; return is; } std::ostream& operator<<(std::ostream& os, const mint& a) {return os << a.val();} mint arithmetic_sum(ll a, ll l, ll n) { mint m = n; m *= a+l; m /= 2; return m; } mint natural_sum(ll n) { return arithmetic_sum(1,n,n); } struct Factorial { V fact, ifact, fsum; Factorial(ll n):fact(n+1),ifact(n+1),fsum(n+1) { fact[0] = 1; for (ll i = 1; i <= n; ++i) fact[i] = fact[i-1]*i; ifact[n] = fact[n].inv(); for (ll i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i; fsum[0] = 1; for (ll i = 1; i <= n; ++i) { if (i&1) fsum[i] = fsum[i-1] - ifact[i]; else fsum[i] = fsum[i-1] + ifact[i]; } } mint binom(ll n, ll k) { if (k < 0 || k > n) return 0; return fact[n]*ifact[k]*ifact[n-k]; } mint perm(ll n, ll k) { if (k < 0 || n < k) return 0; return fact[n]*ifact[n-k]; } mint h(ll n, ll k) { return binom(n+k-1, n); } mint s(ll n, ll k) { mint ret = 0; for (ll i = 0; i <= k; ++i) { mint tmp = mint(i).pow(n); tmp *= binom(k,i); if ((k-i)&1) ret -= tmp; else ret += tmp; } ret *= ifact[k]; return ret; } mint bell(ll n, ll k) { mint ret = 0; for (ll i = 0; i <= k; ++i) { mint tmp = mint(i).pow(n); tmp *= ifact[i]; tmp *= fsum[k-i]; ret += tmp; } return ret; } V> part(ll n, ll k) { V> p(n+1, V(k+1)); p[0][0] = 1; rep(i,n+1) reps(j,k) { p[i][j] = p[i][j-1]; if (i-j >= 0) p[i][j] += p[i-j][j]; } return p; } } f(1000005); struct Solver { V> G; V memo; void solve() { int n; cin >> n; V c(9); cin >> c; int m = 0; rep(i,9) if (c[i]) ++m; mint ans = 0, base = 1, p = f.perm(m-1, m-1); rep(i,n) { rep(j,9) { mint tmp = (j+1); tmp *= p; tmp *= c[j]; tmp *= base; dump(tmp); ans += tmp; } base *= 10; } pl(ans) } } solver; signed main(void) {solver.solve();return 0;}