Recently, Norge found a string s=s1s2…sns=s1s2…sn consisting of nn lowercase Latin letters. As an exercise to improve his typing speed, he decided to type all substrings of the string ss. Yes, all n(n+1)2n(n+1)2 of them!

A substring of ss is a non-empty string x=s[a…b]=sasa+1…sbx=s[a…b]=sasa+1…sb (1≤a≤b≤n1≤a≤b≤n). For example, "auto" and "ton" are substrings of "automaton".

Shortly after the start of the exercise, Norge realized that his keyboard was broken, namely, he could use only kk Latin letters c1,c2,…,ckc1,c2,…,ck out of 2626.

After that, Norge became interested in how many substrings of the string ss he could still type using his broken keyboard. Help him to find this number.

Input

The first line contains two space-separated integers nn and kk (1≤n≤2⋅1051≤n≤2⋅105, 1≤k≤261≤k≤26) — the length of the string ss and the number of Latin letters still available on the keyboard.

The second line contains the string ss consisting of exactly nn lowercase Latin letters.

The third line contains kk space-separated distinct lowercase Latin letters c1,c2,…,ckc1,c2,…,ck — the letters still available on the keyboard.

Output

Print a single number — the number of substrings of ss that can be typed using only available letters c1,c2,…,ckc1,c2,…,ck.

Examples
input
7 2
abacaba
a b
output
12
input
10 3
sadfaasdda
f a d
output
21
input
7 1
aaaaaaa
b
output
0
Note

In the first example Norge can print substrings s[1…2]s[1…2], s[2…3]s[2…3], s[1…3]s[1…3], s[1…1]s[1…1], s[2…2]s[2…2], s[3…3]s[3…3], s[5…6]s[5…6], s[6…7]s[6…7], s[5…7]s[5…7], s[5…5]s[5…5], s[6…6]s[6…6], s[7…7]s[7…7].


题倒是简单但是s=200000这样的数据用int就中招了

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <numeric>
#include <cmath>
#define LL long long
using namespace std; int main()
{
int n, k;
cin >> n >> k;
string s;
cin >> s;
set<char> all;
for (int i = ; i < k; i++)
{
char t;
cin >> t;
all.insert(t);
}
LL cnt=,sum=;
for (int i = ; i < s.size(); i++)
{
if (all.find(s[i]) != all.end())
{
cnt++;
}
else
{
sum += cnt*(cnt + ) / ;
cnt = ;
}
if(i==s.size()- && all.find(s[i]) != all.end())
sum += cnt*(cnt + ) / ;
}
cout << sum;
//system("pause");
return ;
}

CF1272C的更多相关文章

随机推荐

  1. mybatis一级缓存和二级缓存(二)

    注意事项与示例配置 一级缓存 Mybatis对缓存提供支持,但是在没有配置的默认情况下,它只开启一级缓存,一级缓存只是相对于同一个SqlSession而言.所以在参数和SQL完全一样的情况下,我们使用 ...

  2. Redis 数据总结(1 数据导入)

    理论基础部分:http://www.redis.cn/topics/mass-insert.html 几百上千万的数据建议使用pipe来完成导入. 1.windows 下数据导入命令: type ou ...

  3. PP: A multi-horizon quantile recurrent forecaster

    2017 NIPS, time series workshop traditional methods: ARIMA. Seq2Seq quantile forecast; RELATED WORK ...

  4. PHP实现导出CSV文件

    在做导出一个信息表为excel文件这个功能完成之后,自己用得好好的,但是到HR那边就告诉我导出的文件无法用她电脑上的office打开,心想,兼容没做好,想问下她的版本号,结果半天没回复消息.我老大来了 ...

  5. Laravel通过用户名和密码查询

    一.如果要检查要验证的用户数据是否正确,可以使用: if (Auth::validate($credentials)) { // } 二.但是如果您想通过用户和密码从数据库中获取用户,您可以使用: / ...

  6. MySQL用B+树做索引

    索引这个词,相信大多数人已经相当熟悉了,很多人都知道MySQL的索引主要以B+树为主,但是要问到为什么用B+树,恐怕很少有人能把前因后果讲述的很完整.本文就来从头到尾介绍下数据库的索引. 索引是一种数 ...

  7. 给IDEA添加右键打开功能

    添加文件夹右键程序打开 开始运行regedit 找到 HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell 1.右键shell目录新建项Idea 2. ...

  8. SpringBoot学习- 7、问题Could not autowire. No beans of 'xxxx' type found处理

    SpringBoot学习足迹 这个问题网上有好多同学都提到这个问题,代码可以运行,但是就是有红线,强迫症不能忍 自己试验下 1.增加一个final编译一下,再删掉就不会出红线了 public clas ...

  9. opencv 实现人脸检测(harr特征)

    我这里用的是已经训练好的haar级联分类器. 眼睛检测 haarcascade_eye_tree_eyeglasses.xml 人脸检测 haarcascade_frontalface_alt2.xm ...

  10. 【翻译】浅析为何使用融合CDN是大趋势

    使用传统CDN的用户遇到的新问题 随着云计算时代的快速发展,尤其是流媒体大视频时代的到来,用户在是使用过往CDN节点资源调配将面临很多问题: 问题1: 流媒体时代不局限于静态内容分发,直播点播等视频服 ...