malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int pos[1 << 12], num[1 << 12];   int p[1 << 12], q[1 << 12];   void maintain(int x, int y) {     for (;;) {       int t = pos[q[x] ^ num[x]];       if (t == x)         return;       else if (t == y) {         swap(p[x], p[y]);         swap(pos[p[x]], pos[p[y]]);         return;       }       swap(q[y], q[t]);       swap(p[x], p[y]);       swap(pos[p[x]], pos[p[y]]);       swap(p[x], p[t]);       swap(pos[p[x]], pos[p[t]]);       x = t;     }   }   int fir[1 << 12];   int main() {     int n;     scanf( %d , &n);     int s = 0;     for (int i = 0; i < (1 << n); i++) {       scanf( %d , &fir[i]);       s ^= fir[i];     }     if (s) {       puts( Fou );       return 0;     }     for (int i = 0; i < (1 << n); i++) p[i] = q[i] = pos[i] = i;     for (int i = 0; i < (1 << n) - 1; i++) {       num[i + 1] ^= (num[i] ^ fir[i]);       num[i] = fir[i];       maintain(i, i + 1);     }     puts( Shi );     for (int i = 0; i < (1 << n); i++) printf( %d  , p[i]);     printf(  n );     for (int i = 0; i < (1 << n); i++) printf( %d  , q[i]);     printf(  n );     return 0;   }
#include <bits/stdc++.h>   template <typename T>   bool chkmax(T &x, T y) {     return x < y ? x = y, true : false;   }   template <typename T>   bool chkmin(T &x, T y) {     return x > y ? x = y, true : false;   }   using namespace std;   long long ksm(long long a, long long b) {     if (!b) return 1;     long long ns = ksm(a, b >> 1);     ns = ns * ns % 998244353;     if (b & 1) ns = ns * a % 998244353;     return ns;   }   int pl[5500];   struct th {     int sz;     int l, r;     vector<int> pls;     th *ch[2];     vector<vector<int> > id;   } p[200005], *rt[70];   int cal(th *a, int l, int r) {     int p1 = lower_bound(a->pls.begin(), a->pls.end(), l) - a->pls.begin();     int p2 =         lower_bound(a->pls.begin(), a->pls.end(), r + 1) - a->pls.begin() - 1;     if (p1 > p2) return 0;     return a->id[p1][p2];   }   int cnt = 0;   vector<pair<int, int> > g;   int mer(int x, int y) {     if (!x) return y;     if (!y) return x;     cnt++;     g.push_back(make_pair(x, y));     return cnt;   }   int stcnt = 0;   void bdtree(th *a, int l, int r) {     a->l = l, a->r = r;     for (int i = l; i <= r; i++) a->pls.push_back(pl[i]);     int sz = r - l + 1;     sort(a->pls.begin(), a->pls.end());     a->id.resize(sz);     for (int j = 0; j < sz; j++) a->id[j].resize(sz);     if (sz == 1)       a->id[0][0] = a->pls[0];     else {       int mid = (l + r) >> 1;       a->ch[0] = &p[stcnt++], a->ch[1] = &p[stcnt++];       bdtree(a->ch[0], l, mid);       bdtree(a->ch[1], mid + 1, r);       for (int i = 0; i < sz; i++)         for (int j = i; j < sz; j++)           a->id[i][j] = mer(cal(a->ch[0], a->pls[i], a->pls[j]),                             cal(a->ch[1], a->pls[i], a->pls[j]));     }   }   int re[100005];   int main() {     int n, qs;     scanf( %d%d , &n, &qs);     cnt = n;     for (int i = 1; i <= n; i++) {       int a;       scanf( %d , &a), pl[a] = i;     }     vector<th *> q;     int nr = 1;     while (nr <= n) {       th *n1 = &p[stcnt++];       int ur = min(n, nr + 200);       bdtree(n1, nr, ur);       q.push_back(n1);       nr = ur + 1;     }     for (int i = 1; i <= qs; i++) {       int pr = 0;       int l, r;       scanf( %d%d , &l, &r);       for (auto m : q) pr = mer(pr, cal(m, l, r));       re[i] = pr;     }     cout << cnt << endl;     for (auto h : g) printf( %d %d n , h.first, h.second);     for (int i = 1; i <= qs; i++) printf( %d  , re[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long arr[n];       for (long long i = 0; i < n; i++) cin >> arr[i];       long long p = 0;       while (p < n) {         if (arr[p] < p) break;         p++;       }       --p;       long long s = n - 1;       while (s >= 0) {         if (arr[s] < n - s - 1) break;         s--;       }       ++s;       if (s <= p || (s == p + 1 && arr[s] != arr[p]))         cout <<  Yes ;       else         cout <<  No ;       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 5;   struct aa {     int x, y;   } s[maxn];   int vis1[maxn], vis2[maxn], vis3[maxn];   bool judge(int i) {     if (vis2[s[i].x] + 1 > (vis1[s[i].x]) / 2 ||         vis2[s[i].y] + 1 > (vis1[s[i].y]) / 2)       return false;     else       return true;   }   bool cmp(aa a, aa b) {     if (a.x == b.x)       return a.x < b.x;     else       return a.y > b.y;   }   int main() {     int n, m, cnt, res;     scanf( %d%d , &n, &m);     cnt = m;     res = (n + m + 1) / 2;     for (int i = 0; i < m; i++) {       scanf( %d%d , &s[i].x, &s[i].y);       if (s[i].x < s[i].y) swap(s[i].x, s[i].y);       vis1[s[i].x]++;       vis1[s[i].y]++;     }     random_shuffle(s, s + m);     for (int i = 0; i < m && cnt > res; i++) {       if (judge(i)) {         vis2[s[i].x]++;         vis2[s[i].y]++;         vis3[i] = 1;         cnt--;       }     }     printf( %d n , cnt);     for (int i = 0; i < m; i++) {       if (!vis3[i]) {         printf( %d %d n , s[i].x, s[i].y);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   std::vector<int> G[100005];   int color[100005];   void DFS(int s, int co) {     color[s] = co;     for (int i = 0; i < G[s].size(); i++) {       int to = G[s][i];       if (color[to] == 0) {         DFS(to, -1 * co);       }     }   }   int main(int argc, char const *argv[]) {     scanf( %d , &n);     for (int i = 0; i < n - 1; i++) {       int u, v;       scanf( %d%d , &u, &v);       G[u].push_back(v);       G[v].push_back(u);     }     int s1 = 0;     long long ans = 0;     DFS(1, 1);     for (int i = 1; i <= n; i++)       if (color[i] == -1) s1++;     printf( %lld n , 1LL * (n - s1) * s1 - 1LL * n + 1LL);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int SIZE = int(101);   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     string s;     cin >> s;     int i = 0;     int a;     string m[5];     while (1) {       i++;       if (s.size() % i == 0) {         a = s.size() / i;       } else {         a = int(s.size() / i) + 1;       }       if (a <= 20) {         break;       }     }     int d;     if (s.size() % a == 0) {       d = s.size() / a;       cout << s.size() / a;     } else {       d = int(s.size() / a) + 1;       cout << int(s.size() / a) + 1;     }     cout <<     << a;     for (int j = 0; j < d; j++) {       if (s.size() % d != 0 && s.size() % d == abs(j - d)) {         i = 0;         int k = 0;         while (j != 0) {           j--;           while (m[i].size() < a - 1) {             m[i] += s[k];             k++;           }           m[i] +=  * ;           i++;         }         while (i < d) {           while (m[i].size() < a) {             m[i] += s[k];             k++;           }           i++;         }         break;       } else {         if (s.size() % d == 0) {           i = 0;           int k = 0;           while (i < d) {             while (m[i].size() < a) {               m[i] += s[k];               k++;             }             i++;           }           break;         }       }     }     cout <<   n ;     for (int j = 0; j < d; j++) {       cout << m[j] <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5005;   int n, m, ans[N];   pair<int, int> p[N];   vector<pair<int, int> > g[N];   void dfs(int v, int pr = -1) {     for (auto it : g[v]) {       int to = it.first;       if (to != pr) {         p[to] = make_pair(v, it.second);         dfs(to, v);       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (int i = 1; i < n; i++) {       int x, y;       cin >> x >> y;       g[x].push_back(make_pair(y, i));       g[y].push_back(make_pair(x, i));     }     cin >> m;     vector<pair<int, pair<int, int> > > e;     for (int i = 1; i <= m; i++) {       int x, y, z;       cin >> x >> y >> z;       e.push_back(make_pair(z, make_pair(x, y)));     }     sort(e.begin(), e.end());     for (auto it : e) {       int x = it.second.first, y = it.second.second, val = it.first;       dfs(x);       while (y != x) {         ans[p[y].second] = it.first;         y = p[y].first;       }     }     for (auto it : e) {       int x = it.second.first, y = it.second.second, val = it.first;       dfs(x);       int mn = 1e9;       while (y != x) {         mn = min(mn, ans[p[y].second]);         y = p[y].first;       }       if (mn != val) {         return cout <<  -1 , 0;       }     }     for (int i = 1; i < n; i++) {       cout << (ans[i] == 0 ? (int)1e6 : ans[i]) <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1001;   char s[N];   bool check(char a, char b) {     if (a == b) return true;     if (a > b) swap(a, b);     if (b - a > 2) return false;     if (b - a == 2) return true;     if (b - a == 1) return false;   }   bool solve() {     int n;     scanf( %d%s , &n, s);     for (int i = 0; i < n; i++)       if (!check(s[i], s[n - 1 - i])) return false;     return true;   }   int main() {     int t;     scanf( %d , &t);     while (t--) {       if (solve())         printf( YES n );       else         printf( NO n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long mod = 1000000007;   int main() {     int num, dig;     scanf( %d%d , &num, &dig);     vector<int> a, b;     for (int i = 0; i < num / dig; i++) {       int z;       scanf( %d , &z);       a.push_back(z);     }     for (int i = 0; i < num / dig; i++) {       int z;       scanf( %d , &z);       b.push_back(z);     }     int t = 1;     for (int i = 0; i < dig - 1; i++) t *= 10;     long long ret = 1;     for (int i = 0; i < num / dig; i++) {       long long r = 0;       for (int j = 0; j < 10; j++) {         if (j != b[i]) {           r += (t * (j + 1) + a[i] - 1) / a[i];           r -= (t * j + a[i] - 1) / a[i];         }       }       ret *= r;       ret %= mod;     }     printf( %I64d n , ret);   }
#include <bits/stdc++.h>   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( Ofast ,  unroll-loops )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   const long long inf = numeric_limits<long long>::max() / 2;   const long double eps = 1e-9;   const long double pi = acos(-1);   template <typename T>   inline bool mineq(T& a, T b) {     return (a > b) ? (a = b, 1) : 0;   }   template <typename T>   inline bool maxeq(T& a, T b) {     return (a < b) ? (a = b, 1) : 0;   }   inline void solve(), read();   const string file =   ;   int main() {     if (file !=   ) {       freopen((file +  .in ).c_str(),  r , stdin);       freopen((file +  .out ).c_str(),  w , stdout);     }     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     ;     read();     solve();     return 0;   }   const long long R = 998244353;   string a, l, r;   long long n;   vector<long long> dp, suff;   vector<long long> zl, zr;   void zet(string s, vector<long long>& z) {     long long n = (long long)((s).size());     z.assign(n, 0);     z[0] = 0;     for (long long i = 1, l = 0, r = 0; i < n; i++) {       if (i <= r) {         z[i] = min(z[i - l], r - i);       }       while (i + z[i] < n && s[z[i]] == s[i + z[i]]) {         ++z[i];       }       if (i + z[i] - 1 > r) {         r = i + z[i] - 1;         l = i;       }     }   }   inline void solve() {     zet(l +  #  + a, zl);     zet(r +  #  + a, zr);     dp.assign(n + 2, 0);     suff.assign(n + 2, 0);     long long ans = 0;     dp[n] = 1;     suff[n] = 1;     for (long long i = n - 1; i >= 0; i--) {       if (a[i] ==  0 ) {         if (l ==  0 ) {           dp[i] = dp[i + 1];         }         suff[i] = (dp[i] + suff[i + 1]) % ::R;         continue;       }       long long L = i + (long long)((l).size());       long long R = i + (long long)((r).size());       long long sleft = zl[(long long)((l).size()) + 1 + i];       long long sright = zr[(long long)((r).size()) + 1 + i];       if (sleft != (long long)((l).size())) {         if (a[i + sleft] < l[sleft]) {           ++L;         }       }       if (sright != (long long)((r).size())) {         if (a[i + sright] > r[sright]) {           --R;         }       }       if (L <= R && L <= n) {         mineq(R, n);         dp[i] = (suff[L] - suff[R + 1] + ::R) % ::R;       }       suff[i] = (dp[i] + suff[i + 1]) % ::R;     }     cout << dp[0] <<   n ;   }   inline void read() {     cin >> a >> l >> r;     n = (long long)((a).size());   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7, MAXN = 4e5 + 10;   int dp[MAXN], dp2[MAXN];   int *cur = dp2, *prv = dp;   int main() {     int r, g;     cin >> r >> g;     int b = r + g;     int n;     for (n = 1; n * (n + 1) / 2 <= b; n++)       ;     n--;     cur[0] = 1;     for (int i = 1; i <= n; i++) {       swap(cur, prv);       for (int j = 0; j <= i * (i + 1) / 2; j++) {         cur[j] = (prv[j] + (j >= i ? prv[j - i] : 0)) % MOD;       }     }     int ans = 0, sum = n * (n + 1) / 2;     for (int i = 0; i <= r; i++) {       if (i <= r && sum - i <= g) {         ans = (ans + cur[i]) % MOD;       }     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 100;   int num;   int sa[N], fir[N], sec[N], t[N];   int height[N], L[N], R[N], st[N];   char c[N];   inline long long SA(int len, char s[]) {     num = 300;     for (int i = 1; i <= num; i++) t[i] = 0;     for (int i = 1; i <= len; i++) ++t[fir[i] = s[i]];     for (int i = 1; i <= num; i++) t[i] += t[i - 1];     for (int i = len; i >= 1; i--) sa[t[fir[i]]--] = i;     for (int k = 1; k <= len; k <<= 1) {       int cnt = 0;       for (int i = len - k + 1; i <= len; i++) sec[++cnt] = i;       for (int i = 1; i <= len; i++)         if (sa[i] > k) sec[++cnt] = sa[i] - k;       for (int i = 1; i <= num; i++) t[i] = 0;       for (int i = 1; i <= len; i++) ++t[fir[i]];       for (int i = 1; i <= num; i++) t[i] += t[i - 1];       for (int i = len; i >= 1; i--) sa[t[fir[sec[i]]]--] = sec[i], sec[i] = 0;       swap(fir, sec);       fir[sa[1]] = 1, cnt = 1;       for (int i = 2; i <= len; i++)         fir[sa[i]] =             (sec[sa[i]] == sec[sa[i - 1]] && sec[sa[i] + k] == sec[sa[i - 1] + k])                 ? cnt                 : ++cnt;       if (cnt == len) break;       num = cnt;     }     int j, k = 0;     for (int i = 1; i <= len; i++) {       if (k) k--;       int j = sa[fir[i] - 1];       while (i + k <= len && j + k <= len && s[i + k] == s[j + k]) k++;       height[fir[i]] = k;     }     int top = 1;     st[top] = 1;     for (int i = 2; i <= len; i++) {       while (top && height[i] < height[st[top]]) R[st[top--]] = i;       L[i] = st[top];       st[++top] = i;     }     while (top) R[st[top--]] = len + 1;     long long ans = 1ll * len * (len + 1) / 2ll;     for (int i = 2; i <= len; i++) {       ans += 2ll * height[i] * (R[i] - i) * (i - L[i]);     }     return ans;   }   int main() {     int t;     scanf( %d , &t);     while (t--) {       scanf( %s , c + 1);       printf( %lld n , SA(strlen(c + 1), c));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     map<int, int> m;     string s;     int n, a;     cin >> n >> s;     for (int i = 1; i < 10; ++i) {       cin >> a;       m[i] = a;     }     for (int i = 0; i < n; ++i) {       if (s[i] -  0  < m[s[i] -  0 ]) {         while (s[i] -  0  <= m[s[i] -  0 ]) {           s[i] =  0  + m[s[i] -  0 ];           ++i;         }         break;       }     }     cout << s;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 15000;   int d[maxn];   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 0; i < m; i++) {       int maxx = -1, maxi = 0;       int x;       for (int j = 1; j <= n; j++) {         scanf( %d , &x);         if (x > maxx) {           maxx = x;           maxi = j;         }       }       d[maxi]++;     }     int ans = 1;     for (int i = 1; i <= n; i++) {       if (d[i] > d[ans]) {         ans = i;       }     }     printf( %d n , ans);     return 0;   }
#pragma GCC optimize(4)   #include<bits/stdc++.h>   #define FOR(i,a,b) for(int i=a;i<=b;++i)   #define REP(u) for(int i=p[u];i!=-1;i=e[i].nxt)   #define ll long long   #define rd (rand()<<16^rand())   #define PII pair<int,int>   #define pb push_back   #define sz(x) (int)(x.size())   #define gc (_p1==_p2&&(_p2=(_p1=_buf)+fread(_buf,1,100000,stdin),_p1==_p2)?EOF:*_p1++)   using namespace std;   char _buf[100000],*_p1=_buf,*_p2=_buf;   inline int gi()   {       int x=0,f=1;char ch=gc;       while(ch> 9 ||ch< 0 ){if(ch== - )f=-1;ch=gc;}       while(ch>= 0 &&ch<= 9 ){x=(x<<3)+(x<<1)+(ch^48);ch=gc;}       return (f==1)?x:-x;   }   inline int max(int a,int b){return a>b?a:b;}   inline int min(int a,int b){return a<b?a:b;}   const int maxn=105;   int T,n,m,a[maxn][maxn],sum[maxn*2];   inline void init()   {    memset(sum,0,sizeof(sum));   }   inline void input()   {    n=gi(),m=gi();   }   inline void solve()   {    FOR(i,1,n)FOR(j,1,m)a[i][j]=gi();    FOR(i,1,n)FOR(j,1,m)sum[i+j]^=a[i][j];    FOR(i,2,n+m)if(sum[i]){printf( Ashish n );return ;}    printf( Jeel n );   }   int main()   {    T=gi();    while(T--)    {     init();     input();     solve();    }    return 0;   }   ///
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     int n, x;     while (t--) {       cin >> n >> x;       if (n == 1 || n == 2)         cout << 1 << endl;       else {         if ((n - 2) % x == 0)           cout << (n - 2) / x + 1 << endl;         else           cout << (n - 2) / x + 2 << endl;       }     }   }
#include <bits/stdc++.h>   namespace io {   const char endl =   n ;   template <typename T>   inline void chkmin(T &a, T b) {     a > b ? a = b : 0;   }   template <typename T>   inline void chkmax(T &a, T b) {     a < b ? a = b : 0;   }   struct Stream {     template <class T>     Stream operator>>(T &x) {       x = 0;       register int f = 1;       register char c;       while (!isdigit(c = getchar()))         if (c ==  - ) f = -1;       while (x = (x << 1) + (x << 3) + (c ^ 48), isdigit(c = getchar()))         ;       return x *= f, *this;     }     Stream operator>>(char *str) { return scanf( %s , str), *this; }     template <class T>     Stream operator<<(T x) {       static char out[35];       static unsigned int top = 0;       if (x < 0) x = -x, putchar( - );       while (out[++top] = x % 10 ^ 48, x /= 10, x)         ;       while (putchar(out[top--]), top)         ;       return *this;     }     Stream operator<<(char *str) { return printf( %s , str), *this; }     Stream operator<<(char ch) { return putchar(ch), *this; }   } cin, cout;   }  // namespace io   const int N = 3e5 + 10;   int ver[N * 2], nxt[N * 2], head[N], tot, n, m, stk[N], top, L[N];   inline void add(int u, int v) {     ver[++tot] = v, nxt[tot] = head[u], head[u] = tot;   }   bool vis[N], loop[N];   void DFS(int u, int fa) {     vis[u] = 1;     stk[++top] = u;     for (int i = head[u]; i; i = nxt[i]) {       int v = ver[i];       if (loop[v] or v == fa) continue;       if (!vis[v])         DFS(v, u);       else {         int Max = 0, Min = n + 1;         for (int j = top, y;; j--) {           y = stk[j];           io::chkmin(Min, y);           io::chkmax(Max, y);           loop[y] = 1;           if (stk[j] == v) break;         }         if (!L[Max])           L[Max] = Min;         else           io::chkmax(L[Max], Min);       }     }     top--;   }   long long sum[N];   int main() {     io::cin >> n >> m;     for (register unsigned int i = 1, iend = m; i <= iend; ++i) {       int u, v;       io::cin >> u >> v;       add(u, v), add(v, u);     }     for (register unsigned int i = 1, iend = n; i <= iend; ++i)       if (!vis[i]) DFS(i, i);     for (register unsigned int i = 1, iend = n; i <= iend; ++i) {       io::chkmax(L[i], L[i - 1]);       sum[i] = sum[i - 1] + L[i];     }     int Q;     io::cin >> Q;     while (Q--) {       int x, y;       io::cin >> x >> y;       int l = x, r = y, p = y + 1;       long long ans = 0;       while (l <= r) {         int mid = (l + r) >> 1;         if (L[mid] >= x)           r = mid - 1, p = mid;         else           l = mid + 1;       }       ans = 1ll * (x + y) * (y - x + 1) / 2 - (sum[y] - sum[p - 1]) -             1ll * (x - 1) * (p - x);       io::cout << ans << io::endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 100005;   const long long LL_INF = (long long)2e18 + 5;   inline int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }   const long long mod = 1000000007;   bool isprime(long long n) {     for (long long i = 2; i * i <= n; ++i) {       if (n % i == 0) {         return false;       }     }     return true;   }   long long factorial(long long n) {     return (n == 1 || n == 0) ? 1 : n * factorial(n - 1);   }   long long power(long long x, long long y) {     long long res = 1;     x = x % mod;     while (y > 0) {       if (y & 1) res = ((res % mod) * (x % mod)) % mod;       y = y >> 1;       x = ((x % mod) * (x % mod)) % mod;     }     return res;   }   long long ncr(long long n, long long r) {     long long res = 1;     if (r > n) return 0;     if (r > n - r) r = n - r;     for (long long i = 0; i < r; i++) {       res = ((res % mod) * ((n - i) % mod)) % mod;       res = ((res % mod) * (power(i + 1, mod - 2)) % mod) % mod;     }     return res;   }   long long gcd(long long a, long long b) {     if (a == 0) return b;     return gcd(b % a, a);   }   long long lcm(long long a, long long b) { return (a / gcd(a, b) * b); }   long long max(long long a, long long b) {     long long sol = a > b ? a : b;     return sol;   }   long long min(long long a, long long b) {     long long sol = a < b ? a : b;     return sol;   }   map<long long, long long> mp;   inline void solve() {     long long n, k;     long long a[26] = {0};     cin >> n >> k;     string s;     cin >> s;     char ch;     while (k--) {       cin >> ch;       a[ch -  a ]++;     }     long long prev = -1, r;     long long ans = 0;     for (int i = 0; i < n; i++) {       if (a[s[i] -  a ] == 0) {         r = i - prev - 1;         ans += ((r * (r + 1)) / 2);         prev = i;       }     }     r = n - prev - 1;     ans += ((r * (r + 1)) / 2);     cout << ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     solve();   }
#include <bits/stdc++.h>   using namespace std;   string p;   bool cap = false, l = false, dig = false;   char digits[10] = { 0 ,  1 ,  2 ,  3 ,  4 ,  5 ,  6 ,  7 ,  8 ,  9 };   int main() {     cin >> p;     int s = p.length();     if (s < 5) {       cout <<  Too weak ;       return 0;     }     for (int i = 0; i < s; i++) {       if (isupper(p[i]))         cap = true;       else if (islower(p[i]))         l = true;       for (int j = 0; j < 10; j++)         if (p[i] == digits[j]) dig = true;     }     if (cap == true && l == true && dig == true)       cout <<  Correct ;     else       cout <<  Too weak ;     return 0;   }