#include <bits/stdc++.h>
using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define F first
#define S second
const long long MOD = 1e9+7;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef pair<int,int> pii;
typedef long long ll;
// Mod int
// const int MOD = 1000000007;
struct mint{
  ll x;
  mint():x(0){}
  mint(ll x):x((x%MOD+MOD)%MOD){}
  mint operator+=(const mint& a){ if((x+=a.x)>=MOD) x-=MOD; return *this;}
  mint operator-=(const mint& a){ if((x+=MOD-a.x)>=MOD) x-=MOD; return *this;}
  mint operator*=(const mint& a){ (x*=a.x)%=MOD; return *this;}
  mint operator+(const mint& a)const{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
mint powmod(mint x,ll y){
	mint a(1);
	while(y){
		if(y&1) a=a*x;
		x=x*x;
		y/=2;
	}
	return a;
}
vector<vector<mint>> dp[5];
int main(){
	int n;
	cin>>n;
	vector<pii> v(n);
	bool zero=false;
	rep(i,n) cin>>v[i].F;
	rep(i,n){
		if(v[i].F==0){
			zero=true;
			v[i].S=1;
		}
		else{
			int cnt=0;
			int t=v[i].F;
			while(t){
				t/=10;
				cnt++;
			}
			v[i].S=cnt;
		}
	}
	vint w(5,0);
	rep(i,n){
		w[v[i].S]+=v[i].F;
	}
	int cc[5]={};
	rep(i,n){
		cc[v[i].S]++;
	}
	mint ans[2];
	rep(i,2) ans[i].x=0;
	vector<mint> fun(210,mint(0LL));
	vector<mint> fun_sum(210,mint(0LL));
	fun[0]+=mint(1);
	reep(i,1,210){
		fun[i]=mint(i)*fun[i-1];
	}
	mint combi[210][210];
	rep(i,210) rep(j,210) combi[i][j].x=0LL;
	rep(i,210){
		combi[i][0]=combi[i][i]=mint(1);
		reep(j,1,i){
			combi[i][j]=combi[i-1][j]+combi[i-1][j-1];
		}
	}
	rep(i,210){
		if(i==0){
			fun_sum[0]=mint(1);
			continue;
		}
		rep(j,i+1){
			fun_sum[i]+=combi[i][j]*fun[j];
		}
	}
	rep(o,2){
		if(o){
			if(!zero) continue;
			else cc[1]--;
		}
		rep(i,5) dp[i]=vector<vector<mint>>(1000,vector<mint>(210));
		rep(i,5){
			dp[i][0][0].x=1;
			if(!cc[i]) continue;
			cc[i]--;
			rep(j,5){
				rep(k,cc[j]){
					vector<vector<mint>> tmp=dp[i];
					for(int p=999;p>=0;p--){
						for(int q=209;q>=0;q--){
							if(!tmp[p][q].x) continue;
							dp[i][p+j][q+1]+=tmp[p][q];
						}
					}
				}
			}
			cc[i]++;
		}
		rep(i,5){
			rep(j,1000){
				ll t=0;
				rep(k,210){
					t+=(dp[i][j][k]*fun[k]*fun_sum[n-o-k-1]).x;
				}
				ans[o]+=mint(w[i])*powmod(mint(10),j)*mint(t);
			}
		}
	}
	cout<<(ans[0]-ans[1]).x<<endl;
}