MOD = 10**9 + 7 N = gets.to_i c = [0] + gets.split.map(&:to_i) fact = [1] (1 .. N).each do |i| fact[i] = fact[i - 1] * i % MOD end perm_all = fact[N] * ((1 .. 9).map { |d| fact[c[d]] }.inject(:*) % MOD).pow(MOD - 2, MOD) % MOD n_inv = N.pow(MOD - 2, MOD) perm = [0] + (1 .. 9).map { |d| perm_all * c[d] * n_inv % MOD } ones = (10.pow(N, MOD) - 1) * 9.pow(MOD - 2, MOD) % MOD sum = (1 .. 9).sum { |d| ones * d * perm[d] % MOD } % MOD puts sum