#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <valarray>
#include <iterator>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) container.begin(), container.end()
#define RALL(container) container.rbegin(), container.rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int n;
ll dp[5][201][1001];
int calced[5];
ll P[1001];
ll P2[1001];
ll P3[1001];

ll solve(vector<string> &a, int t){
	int dig = a[t].size();
	int r = atoi(a[t].c_str());
	if(!calced[dig]){
		calced[dig] = 1;
		dp[dig][0][0] = 1;
		REP(i, a.size()){
			if(i == t) continue;
			RREP(j, i+1)RREP(k, (i+1)*4){
				dp[dig][j+1][k+a[i].size()] += dp[dig][j][k];
				if(dp[dig][j+1][k+a[i].size()] > MOD) dp[dig][j+1][k+a[i].size()]-=MOD;
			}
		}
	}
	ll sum=0;
	ll tenp = 1;
	REP(j, 800){
		REP(i, a.size()){
			sum += (tenp*dp[dig][i][j])%MOD * P3[i];
			if(sum > MOD) sum %= MOD;
		}
		tenp *= 10;
		if(tenp > MOD) tenp %= MOD;
	}
	return (r*sum)%MOD;
}

ll C[1010][1010];
void make_C(){
    memset(C, 0, (int)sizeof(C));    
    REP(i, 1000){
        C[i][0] = C[i][i] = 1;
        for(int j = 1; j < i; j++) C[i][j] = (C[i-1][j-1] + C[i-1][j]) % MOD;
    }
    REP(i, 1000)for(int j = 0; j <= i; j++) P2[i] = (P2[i] + C[i][j]*P[i-j]) % MOD;
}

main(){
	P[0] = 1;
	REP(i, 1000) P[i+1] = (P[i] * (i+1))%MOD;
	make_C();
	while(cin >> n){
		memset(calced, 0, sizeof(calced));
		memset(dp, 0, sizeof(dp));
		vector<string> a(n);
		REP(i, n) cin >> a[i];
		sort(RALL(a));
		ll sum = 0;
		REP(i, a.size()) P3[i] = (P2[n-1-i] * P[i])%MOD;
		REP(i, n) sum += solve(a, i);
		if(a.back() == "0"){
			memset(calced, 0, sizeof(calced));
			memset(dp, 0, sizeof(dp));
			a.resize(a.size()-1);
			REP(i, a.size()) P3[i] = (P2[a.size()-1-i] * P[i])%MOD;
			REP(i, a.size()) sum -= solve(a, i);
		}
		cout << (sum%MOD+MOD)%MOD << endl;
	}
	return 0;
}

Measured memory_bytes: 17092