for(t=x,x=y,y=t,p=1,x[sa[0]]=0,i=1;i
}
return;
}
int sa[maxn],Rank[maxn],height[maxn];
//求height数组
void calheight(const char *r,int *sa,int n){
int i,j,k=0;
for(i=1;i<=n;i++) Rank[sa[i]]=i;
for(i=0;i
return;
}
char str[maxn],ch[maxn];
int k;
int s[maxn][2];
LL tot,top;
int main(){
while(scanf("%d",&k)!=EOF&&k){
int l1,l2;
scanf("%s%s",str,ch);
l1=strlen(str);l2=strlen(ch);
str[l1]='@';
for(int i=l1+1;i<=l1+l2;i++)
str[i]=ch[i-l1-1];
int n=l1+l2+1;
str[n]='\0';
da(str,sa,n+1,130);
calheight(str,sa,n);
tot=top=0;
for(int i=1;i<=n;i++){
if(height[i]
int cnt=0;
if(sa[i-1]
top--;
tot-=s[top][1]*(s[top][0]-height[i]);
cnt+=s[top][1];
}
s[top][0]=height[i];s[top++][1]=cnt;
if(sa[i]>l1) sum+=tot;
}
}
tot=top=0;
for(int i=1;i<=n;i++){
if(height[i]
int cnt=0;
if(sa[i-1]>l1) cnt++,tot+=height[i]-k+1;
while(top>0&&height[i]<=s[top-1][0]){
top--;
tot-=s[top][1]*(s[top][0]-height[i]);
cnt+=s[top][1];
}
s[top][0]=height[i];s[top++][1]=cnt;
if(sa[i]
}
printf("%I64d\n",sum);
}
return 0;
}