#include <iostream>
#include <algorithm>
#define llint long long
#define mod 1000000007

using namespace std;

llint fact[1005], fact_inv[1005];

llint modpow(llint a, llint n)
{
	if(n == 0) return 1;
	if(n % 2){
		return ((a%mod) * (modpow(a, n-1)%mod)) % mod;
	}
	else{
		return modpow((a*a)%mod, n/2) % mod;
	}
}

void make_fact()
{
	llint val = 1;
	fact[0] = 1;
	for(int i = 1; i < 1005; i++){
		val *= i;
		val %= mod;
		fact[i] = val;
	}
	for(int i = 0; i < 1005; i++){
		fact_inv[i] = modpow(fact[i], mod-2);
	}
}

llint comb(llint n, llint k)
{
	llint ret = 1;
	ret *= fact[n];
	ret *= fact_inv[k], ret %= mod;
	ret *= fact_inv[n-k], ret %= mod;
	return ret;
}

llint n;
llint a[205];
llint keta[205];
llint beki[1005];
llint num[205];
llint cnt[6];
llint dp[6][205][1005];

llint calc2(int x)
{
	cnt[x]--; n--;
	
	for(int i = 0; i <= 5; i++){
		for(int j = 0; j <= n; j++){
			for(int k = 0; k < 1005; k++){
				dp[i][j][k] = 0;
			}
		}
	}
	dp[0][0][0] = 1;
	
	for(int i = 0; i < 5; i++){
		for(int j = 0; j <= n; j++){
			for(int k = 0; k < 1005; k++){
				for(int l = 0; l <= cnt[i+1]; l++){
					if(j+l <= n && k+l*(i+1) < 1005){
						dp[i+1][j+l][k+l*(i+1)] += dp[i][j][k] * comb(cnt[i+1], l) % mod;
						dp[i+1][j+l][k+l*(i+1)] %= mod;
					}
				}
			}
		}
	}
	
	llint ret = 0;
	for(int j = 0; j <= n; j++){
		for(int k = 0; k < 1005; k++){
			llint tmp = dp[5][j][k] * fact[j] % mod;
			tmp *= num[n-j], tmp %= mod;
			tmp *= beki[k], tmp %= mod;
			ret += tmp, ret %= mod;
		}
	}
	cnt[x]++; n++;
	
	return ret;
}

llint calc()
{
	for(int i = 1; i <= 5; i++) cnt[i] = 0;
	for(int i = 1; i <= n; i++) cnt[keta[i]]++;
	
	llint ret = 0;
	for(int i = 1; i <= 5; i++){
		llint tmp = calc2(i);
		for(int j = 1; j <= n; j++){
			if(keta[j] == i){
				ret += tmp * a[j] % mod;
				ret %= mod;
			}
		}
	}
	return ret;
}

llint getketa(llint x)
{
	if(x == 0) return 1;
	llint ret = 0;
	for(;x;x/=10) ret++;
	return ret;
}

int main(void)
{
	make_fact();
	
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	sort(a+1, a+n+1);
	reverse(a+1, a+n+1);
	
	if(n == 1){
		cout << a[1] << endl;
		return 0;
	}
	
	beki[0] = 1;
	for(int i = 1; i < 1005; i++) beki[i] = beki[i-1]*10%mod;
	for(int i = 1; i <= n; i++) keta[i] = getketa(a[i]);
	for(int i = 0; i <= n; i++){
		for(int j = 0; j <= i; j++){
			num[i] += comb(i, j) * fact[j] % mod;
			num[i] %= mod;
		}
	}
	
	llint ans = calc(), zcnt = 0;
	for(int i = 1; i <= n; i++) if(a[i] == 0) zcnt++;
	n--;
	ans += mod - zcnt*calc()%mod;
	ans %= mod;
	cout << ans << endl;
	
	return 0;
}

### Prompt

Generate a CPP solution to the following problem:

Now I have a card with n numbers on it. Consider arranging some or all of these appropriately to make numbers. Find the number obtained by adding all the numbers created at this time.

For example, if you have 1 and 2, you will get 4 numbers 1, 2, 12, 21 so the total number is 36. Even if the same numbers are produced as a result of arranging them, if they are arranged differently, they are added separately. For example, if you have a card called 1 and a card called 11, there are two ways to arrange them so that they are 111, but add them as different ones. There are no leading zero cards among the cards, and we do not accept numbers that lead to zero reading. Output the answer divided by 1,000,000,007.



Input

The input is given in the form:

> n
> a1
> a2
> ...
> an
>

The first line contains n (1 ≤ n ≤ 200), which represents the number of cards, and the next n lines contain the number ai (0 ≤ ai <10000) on each card. Also, the same number is never written on multiple cards.

Output

Output the sum of all the numbers you can make divided by 1,000,000,007 on one line.

Examples

Input

2
1
2


Output

36


Input

2
1
11


Output

234


Input

4
0
4
7
8


Output

135299

### Response

```cpp
#include <iostream>
#include <algorithm>
#define llint long long
#define mod 1000000007

using namespace std;

llint fact[1005], fact_inv[1005];

llint modpow(llint a, llint n)
{
	if(n == 0) return 1;
	if(n % 2){
		return ((a%mod) * (modpow(a, n-1)%mod)) % mod;
	}
	else{
		return modpow((a*a)%mod, n/2) % mod;
	}
}

void make_fact()
{
	llint val = 1;
	fact[0] = 1;
	for(int i = 1; i < 1005; i++){
		val *= i;
		val %= mod;
		fact[i] = val;
	}
	for(int i = 0; i < 1005; i++){
		fact_inv[i] = modpow(fact[i], mod-2);
	}
}

llint comb(llint n, llint k)
{
	llint ret = 1;
	ret *= fact[n];
	ret *= fact_inv[k], ret %= mod;
	ret *= fact_inv[n-k], ret %= mod;
	return ret;
}

llint n;
llint a[205];
llint keta[205];
llint beki[1005];
llint num[205];
llint cnt[6];
llint dp[6][205][1005];

llint calc2(int x)
{
	cnt[x]--; n--;
	
	for(int i = 0; i <= 5; i++){
		for(int j = 0; j <= n; j++){
			for(int k = 0; k < 1005; k++){
				dp[i][j][k] = 0;
			}
		}
	}
	dp[0][0][0] = 1;
	
	for(int i = 0; i < 5; i++){
		for(int j = 0; j <= n; j++){
			for(int k = 0; k < 1005; k++){
				for(int l = 0; l <= cnt[i+1]; l++){
					if(j+l <= n && k+l*(i+1) < 1005){
						dp[i+1][j+l][k+l*(i+1)] += dp[i][j][k] * comb(cnt[i+1], l) % mod;
						dp[i+1][j+l][k+l*(i+1)] %= mod;
					}
				}
			}
		}
	}
	
	llint ret = 0;
	for(int j = 0; j <= n; j++){
		for(int k = 0; k < 1005; k++){
			llint tmp = dp[5][j][k] * fact[j] % mod;
			tmp *= num[n-j], tmp %= mod;
			tmp *= beki[k], tmp %= mod;
			ret += tmp, ret %= mod;
		}
	}
	cnt[x]++; n++;
	
	return ret;
}

llint calc()
{
	for(int i = 1; i <= 5; i++) cnt[i] = 0;
	for(int i = 1; i <= n; i++) cnt[keta[i]]++;
	
	llint ret = 0;
	for(int i = 1; i <= 5; i++){
		llint tmp = calc2(i);
		for(int j = 1; j <= n; j++){
			if(keta[j] == i){
				ret += tmp * a[j] % mod;
				ret %= mod;
			}
		}
	}
	return ret;
}

llint getketa(llint x)
{
	if(x == 0) return 1;
	llint ret = 0;
	for(;x;x/=10) ret++;
	return ret;
}

int main(void)
{
	make_fact();
	
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	sort(a+1, a+n+1);
	reverse(a+1, a+n+1);
	
	if(n == 1){
		cout << a[1] << endl;
		return 0;
	}
	
	beki[0] = 1;
	for(int i = 1; i < 1005; i++) beki[i] = beki[i-1]*10%mod;
	for(int i = 1; i <= n; i++) keta[i] = getketa(a[i]);
	for(int i = 0; i <= n; i++){
		for(int j = 0; j <= i; j++){
			num[i] += comb(i, j) * fact[j] % mod;
			num[i] %= mod;
		}
	}
	
	llint ans = calc(), zcnt = 0;
	for(int i = 1; i <= n; i++) if(a[i] == 0) zcnt++;
	n--;
	ans += mod - zcnt*calc()%mod;
	ans %= mod;
	cout << ans << endl;
	
	return 0;
}

```