else
{
SAM *q=p->son[c];
if(p->len+1==q->len) np->pre=q;
else
{
SAM *nq=&que[tot++];
*nq=*q;
nq->len=p->len+1;
np->pre=q->pre=nq;
while(p&&p->son[c]==q) p->son[c]=nq,p=p->pre;
}
}
tail=np;
}
bool cmp(int x,int y)
{
return que[x].len
int len,c[N];
int slove()
{
mem(c,0);
for(int i=0;i
root->sum=0;
int ans=0;
for(int i=0;i
SAM *p=b[i];
{
if(i==0&&j==0) continue;
if(p->son[j])
{
SAM *q=p->son[j];
q->cnt=(q->cnt+p->cnt)%MOD;
q->sum=(q->sum+p->sum*10+p->cnt*j)%MOD;
}
}
ans=(ans+p->sum)%MOD;
}
return ans;
}
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
tot=0;
root=tail=&que[tot++];
len=1;
while(n--)
{
scanf("%s",str);
for(int i=0;str[i];i++) add(str[i]-'0',len++);
add(10,len++); www.2cto.com
}
printf("%d\n",slove());
for(int i=0;i
return 0;
}