Problem:
Score : 1500 points

Problem Statement

The currency used in Takahashi Kingdom is Myon.
There are 1-, 10-, 100-, 1000- and 10000-Myon coins, and so forth. Formally, there are 10^n-Myon coins for any non-negative integer n.

There are N items being sold at Ex Store.
The price of the i-th (1≦i≦N) item is A_i Myon.

Takahashi is going to buy some, at least one, possibly all, of these N items.
He hates receiving change, so he wants to bring coins to the store so that he can pay the total price without receiving change, no matter what items he chooses to buy.
Also, since coins are heavy, he wants to bring as few coins as possible.

Find the minimum number of coins he must bring to the store. It can be assumed that he has an infinite supply of coins.

Constraints

1≦N≦20,000

1≦A_i≦10^{12}

Input

The input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the minimum number of coins Takahashi must bring to the store, so that he can pay the total price without receiving change, no matter what items he chooses to buy.

Sample Input 1

3
43 24 37

Sample Output 1

16

There are seven possible total prices: 24, 37, 43, 61, 67, 80, and 104.
With seven 1-Myon coins, eight 10-Myon coins and one 100-Myon coin, Takahashi can pay any of these without receiving change.

Sample Input 2

5
49735011221 970534221705 411566391637 760836201000 563515091165

Sample Output 2

105

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include<stdio.h>
#include<algorithm>
using namespace std;
typedef long long ll;
ll a[20010];
int n;
struct pr{
	ll l,r;
	pr(ll l=0,ll r=0):l(l),r(r){}
}p[30],q[30];
bool operator<(pr a,pr b){return a.l==b.l?a.r<b.r:a.l<b.l;}
int M;
bool gao(){
	int i,C;
	ll l,r;
	for(i=1;i<=M;i++){
		if(!p[i].l||p[i].l>p[i].r)return 1;
	}
	sort(p+1,p+M+1);
	C=0;
	l=p[1].l;
	r=p[1].r;
	for(i=2;i<=M;i++){
		if(r<p[i].l-1){
			q[++C]=pr(l,r);
			l=p[i].l;
			r=p[i].r;
		}else
			r=max(r,p[i].r);
	}
	q[++C]=pr(l,r);
	for(i=1;i<=C;i++)p[i]=q[i];
	M=C;
	return 0;
}
bool check(ll pw,int t){//S%(10*pw) in [t*pw,(t+1)*pw)
	int i,j;
	p[M=1]=pr(t*pw,(t+1)*pw-1);
	pw*=10;
	for(i=1;i<=n;i++){
		for(j=1;j<=M;j++)p[M+j]=pr((p[j].l-a[i]%pw+pw)%pw,(p[j].r-a[i]%pw+pw)%pw);
		M*=2;
		if(gao())return 1;
	}
	return 0;
}
int main(){
	int i,j,s;
	ll pw;
	scanf("%d",&n);
	for(i=1;i<=n;i++)scanf("%lld",a+i);
	pw=1;
	s=0;
	for(i=0;i<17;i++,pw*=10){
		for(j=9;j>0;j--){
			if(check(pw,j)){
				s+=j;
				break;
			}
		}
	}
	printf("%d",s);
}