#include<cstdio>
#include<cstring>
using namespace std;
const int nMax = 111111;
int num[nMax];
char s[nMax];
int sa[nMax], rank[nMax], height[nMax];
int wa[nMax], wb[nMax], wv[nMax], wd[nMax];
int cmp(int *r, int a, int b, int l){
return r[a] == r[b] && r[a+l] == r[b+l];
}
int min(int a,int b){return a<b ? a:b;}
void da(int *r, int n, int m){
int i, j, p, *x = wa, *y = wb, *t;
for(i = 0; i < m; i ++) wd[i] = 0;
for(i = 0; i < n; i ++) wd[x[i]=r[i]] ++;
for(i = 1; i < m; i ++) wd[i] += wd[i-1];
for(i = n-1; i >= 0; i --) sa[-- wd[x[i]]] = i;
for(j = 1, p = 1; p < n; j *= 2, m = p){
for(p = 0, i = n-j; i < n; i ++) y[p ++] = i;
for(i = 0; i < n; i ++) if(sa[i] >= j) y[p ++] = sa[i] - j;
for(i = 0; i < n; i ++) wv[i] = x[y[i]];
for(i = 0; i < m; i ++) wd[i] = 0;
for(i = 0; i < n; i ++) wd[wv[i]] ++;
for(i = 1; i < m; i ++) wd[i] += wd[i-1];
for(i = n-1; i >= 0; i --) sa[-- wd[wv[i]]] = y[i];
for(t = x, x = y, y = t, p = 1, x[sa[0]] = 0, i = 1; i < n; i ++){
x[sa[i]] = cmp(y, sa[i-1], sa[i], j) ? p - 1: p ++;
}
}
}
void calHeight(int *r, int n){
int i, j, k = 0;
for(i = 1; i <= n; i ++) rank[sa[i]] = i;
for(i = 0; i < n; height[rank[i ++]] = k){
for(k ? k -- : 0, j = sa[rank[i]-1]; r[i+k] == r[j+k]; k ++);
}
}
int pow10[nMax];//pow10数组维护10的幂指数
int sum10[nMax];//sum10数组维护形如110,1110,11110的数
void init(){
pow10[0]=sum10[0]=1;
pow10[1]=sum10[1]=10;
for(int i=2;i<=100000;i++){
pow10[i]=pow10[i-1]*10%2012;
sum10[i]=(sum10[i-1]+pow10[i])%2012;
}
//for(int i=1;i<10;i++) printf("%d %d\n",pow10[i],sum10[i]);
}
int loc[nMax],flag[nMax];//loc数组维护s数组中每一个位置对应的字符串标号
//flag数组维护每一个标号的字符串的结束位置
int v[nMax];//v数组维护原字符串的值
int sum[nMax],sumsum[nMax];//sum数组维护v数组的前缀和,sumsum数组维护sum数组的前缀和
int get(int i){return i<0? 0:sum[i];}
int main(){
int n;
init();
while(scanf("%d",&n)!=EOF){
int cnt1,cnt2,len;
cnt1=0;
for(int kase=1;kase<=n;kase++){
scanf("%s",s+cnt1);
len=(int)strlen(s);
s[len++]='$';
for(int i=cnt1;i<=len;i++){
num[i]=s[i];
loc[i]=kase;
}
flag[kase]=len;
cnt1=len;
}
num[cnt1]=0;
//puts(s);
//for(int i=0;i<cnt1;i++) printf("%d ",loc[i]);
//printf("\n");
//for(int kase=1;kase<=n;kase++) printf("%d ",flag[kase]);
//printf("\n");
cnt2=0;
for(int i=0;i<cnt1;i++){
if(s[i]>='0'&&s[i]<='9'){
v[cnt2++]=s[i]-'0';
}
}
//for(int i=0;i<cnt2;i++) printf("%d",v[i]);
//printf("\n");
//build sum
sum[0]=sumsum[0]=v[0];
for(int i=1;i<cnt2;i++){
sum[i]=(sum[i-1]*10+v[i])%2012;
sumsum[i]=(sumsum[i-1]+sum[i])%2012;
}
//for(int i=0;i<cnt2;i++) printf("%d ",sum[i]);
//printf("\n");
//for(int i=0;i<cnt2;i++) printf("%d ",sumsum[i]);
//printf("\n");
//solve
int tloc,ans=0,start1,start2,end,tem;
//for(int i=0;i<=cnt1;i++) printf("%d ",num[i]);
//printf("\n");
da(num,cnt1+1,150);
calHeight(num,cnt1);
for(int i=1;i<=cnt1;i++){
tloc=sa[i];
//printf("%d\n",tloc);
if(s[tloc]=='0'||s[tloc]<'0'||s[tloc]>'9') continue;
//对字符串中前导‘0’以及非数字字符不进行处理
tloc=tloc+1-loc[tloc];
//printf("%d\n",tloc);
start1=tloc;
start2=start1+height[i];
end=flag[loc[sa[i]]]-loc[sa[i]];
//printf("%d\n",end);
//printf("%d\n",start2);
if(start2>=end) continue;
tem=(get(start2-1)-get(start1-1)*pow10[height[i]])%2012;
tem=(tem*sum10[end-start2])%2012;
//printf("%d\n",tem);
ans=(ans+tem)%2012;
ans=(ans+sumsum[end-1]-sumsum[start2-1]-get(start2-1)*sum10[end-start2])%2012;
//printf("%d %d\n",sumsum[end-1],get(start2-1));
//printf("%d\n",ans);
}
if(ans<0) ans+=2012;
printf("%d\n",ans%2012);
}
return 0;
}