#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
char s[3005];
char t[3005];
const ll mods=192608179773;
const ll x=203;
ll res[9000009];
int cnt;
int main()
{
scanf("%d%s%s",&n,s+1,t+1);
for(int i=1;i<=n;i++)
{
int pos=1;
ll num=0;
for(int j=i;j<=n;j++)
{
while(pos<=n&&s[pos]!=t[j]) pos++;
if(pos>n) break;
pos++;
num=((ll)num*x+(ll)(t[j]-'a')+1)%mods;
res[++cnt]=num;
}
}
sort(res+1,res+1+cnt);
printf("%d",unique(res+1,res+1+cnt)-res-1);
return 0;
}