#include <iostream>
#include <bits/stdc++.h>
#include <unordered_map>
#define int long long
#define mk make_pair
#define gcd __gcd
using namespace std;
const double eps = 1e-10;
const int mod = 1e9+7;
const int N = 1e6+1;
int n,m,k,t = 1,cas = 1;
int a[N],b[N];
int res[N];
signed main(){
//cin>>t;
while(t--){
cin>>n>>m;
string s;
cin>>s;
map<char,int> mp;
for(int i = 0 ; i < m ; i ++){
char x;
cin>>x;
mp[x] = 1;
}
int res = 0;
for(int i = 0 ; i < s.size() ; i ++){
int tmp = 0;
while(i < s.size() && mp[s[i]]){
tmp ++;
i ++;
}
res += tmp*(tmp+1)/2;
}
cout<<res<<endl;
}
return 0;
}
#include <iostream>
#include <bits/stdc++.h>
#include <unordered_map>
#define int long long
#define mk make_pair
#define gcd __gcd
using namespace std;
const double eps = 1e-10;
const int mod = 1e9+7;
const int N = 1e6+1;
int n,m,k,t = 1,cas = 1;
int a[N],b[N];
int res[N];
int dp[N][2];
signed main(){
//cin>>t;
while(t--){
cin>>n;
for(int i = 0 ; i < n ; i ++){
cin>>a[i];
}
dp[0][0] = 1;
for(int i = 1 ; i < n ; i ++){
if(a[i] > a[i-1]){
dp[i][0] = dp[i-1][0]+1;
}else{
dp[i][0] = 1;
}
}
dp[n-1][1] = 1;
for(int i = n-2 ; i >= 0 ; i --){
if(a[i] < a[i+1]){
dp[i][1] = dp[i+1][1] +1;
}else{
dp[i][1] = 1;
}
}
int res = 1;
a[n] = -1;
for(int i = 0 ; i < n-1 ; i ++){
if(a[i] < a[i+1]){
res = max(res,dp[i][0]+dp[i+1][1]);
}
if(a[i] < a[i+2]){
res = max(res,dp[i][0]+dp[i+2][1]);
}
}
cout<<res<<endl;
}
return 0;
}
#include <iostream>
#include <bits/stdc++.h>
#include <unordered_map>
#define int long long
#define mk make_pair
#define gcd __gcd
using namespace std;
const double eps = 1e-10;
const int mod = 1e9+7;
const int N = 1e6+1;
int n,m,k,t = 1,cas = 1;
int a[N],b[N];
int res[N];
vector<int> edge[N];
struct node{
int pos;
int step;
node(int x,int y){
pos = x;
step = y;
}
};
queue<node> que;
int mark[N];
int vis[N];
bool check(int x,int y){
return (a[x]%2) != (a[y]%2);
}
signed main(){
//cin>>t;
while(t--){
cin>>n;
for(int i = 0 ; i < n ; i ++){
cin>>a[i];
}
for(int i = 0 ; i < n ; i ++){
int l = i-a[i];
int r = i+a[i];
int flag = 0;
if(r < n ){
if(check(i,r)) flag = 1;
edge[r].push_back(i);
}
if(l >= 0){
if(check(i,l)) flag = 1;
edge[l].push_back(i);
}
if(flag){
mark[i] = 1;
que.push(node(i,1));
}
}
while(!que.empty()){
node now = que.front();que.pop();
int pos = now.pos;
for(int i = 0 ; i < edge[pos].size() ; i ++){
int to = edge[pos][i];
if(mark[to] == 0){
mark[to] = mark[pos]+1;
que.push(node(to,now.step+1));
}
}
}
for(int i = 0 ; i < n ; i ++){
if(!mark[i]) cout<<-1<<" ";
else cout<<mark[i]<<" ";
}
cout<<endl;
}
return 0;
}