#include<bits/stdc++.h>
using namespace std;
#define __MY_TEST__ 0
#define int long long
const int mod1=1e9+7,mod2=998244353;
signed main(){
#if __MY_TEST__
freopen(".in","r",stdin);
freopen(".out","w",stdout);
#endif
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int n,ans=0;
string s,t;
cin>>n>>s>>t;
set<int>st1,st2;
for(int i=0;i<n;i++)
{
int p=0,hash1=0,hash2=0;
for(int j=i;j<n;j++)
{
while(p<n&&s[p]!=t[j])
{
p++;
}
if(p>=n) break;
p++;
ans++;
hash1=hash1*27+t[j]-'a'+1;
hash1%=mod1;
hash2=hash2*27+t[j]-'a'+1;
hash2%=mod2;
if(st1.count(hash1)&&st2.count(hash2))
{
ans--;
}
st1.insert(hash1);
st2.insert(hash2);
}
}
cout<<ans<<endl;
#if __MY_TEST__
fclose(stdin);
fclose(stdout);
#endif
}