rt,七重哈希,因为不明原因常熟过大((((
/*writer:菜鸡houpingze*/
/*
Note:
*/
#include<bits/stdc++.h>
#define reg register int
#define INF (1<<30)
using namespace std;
int read(){
int res=0,fs=1; char c=getchar();
while(!(c>='0' && c<='9')){ if(c=='-')fs=-1; c=getchar(); }
while(c>='0' && c<='9')res=res*10+c-'0',c=getchar();
return res*fs;
}
void print(int x){
if(x<0) { putchar('-'); x=-x;}
if(x>9) print(x/10);
putchar(x%10+'0');
}
int n,cnt,m,a[5010],ans,t[101001],tmp;
string x,y;
map<string,bool>xx;
unordered_map<int,bool>h1,h2,h3,h4,h5,h6;
int m1=23333333;
int m2=19190810;
int m3=20081121;
bool hashx[1000005],hashy[1010100];
int m4=20200401;
int m5=100007;
int m6=10000007;
//map<string,bool>xx;
//int h1[3000*3000+5],h2[3000*3000+5],h3[3000*3000+5],h4[3000*3000+5],h5[3000*3000+5],h6[3000*3000+5];
bool pd(string v){
int j=0;
for(int i=0;i<x.size();i++){
if(x[i]==v[j]){
j++;
if(j==v.size()) return 1;
}
}
return 0;
}
int ton[513];
int main() {
cin>>n;
cin>>x>>y;
for(int i=1;i<n;i++){
if(!(x[i]==y[i]&&x[i]==x[i-1])){
tmp=1;
break;
}
}
for(int i=0;i<n;i++){
// srand((int)(time(0)));
if(y[i]%4>=2)
hashx[i]=1;
// cout<<hashx[i]<<" ";
}
for(int i=0;i<n;i++){
if(x[i]%100>50){
hashy[i]=1;
}
}
if(tmp==0){
cout<<n;
return 0;
}
for(int i=0;i<x.size();i++){
t[x[i]]++;
}
// for(int i=1;)
for(int i=0;i<y.size();i++){
memset(ton,0,sizeof(ton));
string v="";
string sl="";
long long hx=0,hy=0,hz=1,ha=0,hb=0,hc=1;
int nowy=0;
int fl=0;
for(int j=i;j<y.size();j++){
while(x[nowy]!=y[j]){
nowy++;
if(nowy==x.size()+1){
fl=1;
break;
}
}
nowy++;
if(fl==1) break;
if(sl.size()<=300) sl+=y[j];
if((j-i+1)%2==0) hx+=y[j];
else hx-=y[j];
if((j-i+1)%2==1) hy+=y[j];
else hy-=y[j];
hz*=y[j];
hz%=m3;
if(hashx[j-i+1]) ha+=y[j];
else ha-=y[j];
if(hashy[j-i+1]) hb+=y[j];
else hb-=y[j];
if(hashx[j-i+1]) hc*=y[j];
else hc/=y[j];
if(hc==0) hc=1;
v+=y[j];
if(t[y[j]]==0) break;
ton[y[j]]++;
if(t[y[j]]<ton[y[j]]) break;
// string sl=v.substr(0,70);
// cout<<v<<' ';
if(h1[hx%m1]==0||h2[hy%m2]==0||h3[hz%m3]==0||h4[ha%m4]==0||h5[hb%m5]==0||xx[sl]==0||h6[hc%m6]==0){
// xx[v]=1;
// cout<<"OK\n";
xx[sl]=1;
ans++;
h1[hx%m1]=1;
h2[hy%m2]=1;
h3[hz%m3]=1;
h4[ha%m4]=1;
h5[hb%m5]=1;
h6[hc%m6]=1;
}
}
}
cout<<ans;
return 0;
}