#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,cnt;
string a,b;
map<int,int>mp;
signed main(){
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin >> n >> a >> b;
a = " " + a;
b = " " + b;
for(int i = 1 ; i <= n ; i ++){
int x = 1,hs = 0;
for(int j = i ; j <= n ; j ++){
while(x <= n && a[x] != b[j]){
x ++;
}
if(x > n)break;
x ++;
hs = hs * 131 + b[j];
if(hs > 0 && !mp[hs]){
mp[hs] = 1;
cnt ++;
}
}
}
cout << cnt;
return 0;
}