#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
inline void add(int &x, int v) { x += v; if (x >= MOD) x -= MOD; }
inline int mul(int x, int y) { return (1LL*x*y)%MOD; }

int N;
int fact[201];
int A[200], C[200];
int T[5][801][201];
int nCr[201][201];
int R[201];
int num[5];

void solve(int type) {
  if (num[type] == 0) return;
  auto &dp = T[type];
  rep(i, 801) rep(j, 201) dp[i][j] = 0;
  num[type]--;
  dp[0][0] = 1;
  for (int x=1; x<=4; x++) rep(_, num[x]) {
    for (int j=800-x; j>=0; j--) {
      for (int k=199; k>=0; k--) {
        add(dp[j+x][k+1], dp[j][k]);
      }
    }
  }
  num[type]++;
}
int f() {
  for (int i=1; i<=4; i++) solve(i);
  int sum = 0;
  rep(i, N) {
    int p = A[i];
    rep(s, 801) {
      rep(k, N) {
        if (T[C[i]][s][k] == 0) continue;
        add(sum, mul(mul(mul(fact[k], T[C[i]][s][k]), p), R[N-1-k]));
      }
      p = (10LL*p)%MOD;
    }
  }
  return sum;
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N;
  rep(i, N) cin >> A[i];
  sort(A, A+N, greater<int>());

  fact[0] = 1;
  for (int i=1; i<=200; i++) fact[i] = (1LL*i*fact[i-1]) % MOD;
  nCr[0][0] = 1;
  for (int i=1; i<=200; i++) {
    nCr[i][0] = 1;
    for (int j=1; j<=200; j++) nCr[i][j] = (nCr[i-1][j-1] + nCr[i-1][j]) % MOD;
  }
  rep(i, N+1) {
    rep(j, i+1) add(R[i], mul(nCr[i][j], fact[j]));
  }

  bool has_zero = false;
  rep(i, N) {
    int x = A[i];
    if (x == 0) {
      C[i] = 1;
      has_zero = true;
    }
    while (x) C[i]++, x/=10;
    num[C[i]]++;
  }
  int sum = f();
  if (has_zero) {
    N--;
    num[1]--;
    add(sum, (MOD-f())%MOD);
  }
  cout << sum << "\n";
  return 0;
}