func_code_string: #include <bits/stdc++.h>   using namespace std;   int n, m;   vector<pair<char, long long> > s1;   vector<pair<char, long long> > s2;   vector<pair<char, long long> > p;   int sl, pl;   int lps[1000009];   vector<int> ii;   void calclps() {     lps[0] = 0;     int j = 0, i = 1;     while (i < pl) {       if (p[j] == p[i]) {         if (j == 0) {           lps[i] = 1;         } else {           lps[i] = j + 1;         }         j++;         i++;       } else {         if (j == 0) {           lps[i] = 0;           i++;         } else {           j = lps[j - 1];         }       }     }   }   void kmp() {     ii.clear();     if (p.size() == 1) {       for (int i = 0; i < (int)sl; i++) {         if (s1[i] == p[0]) ii.push_back(i);       }       return;     }     calclps();     int i = 0, j = 0;     while (i < sl) {       if (s1[i] == p[j]) {         if (j == pl - 1) {           ii.push_back(i - pl + 1);           j = lps[j - 1];         } else {           i++;           j++;         }       } else {         if (j == 0)           i++;         else           j = lps[j - 1];       }     }   }   void print(vector<pair<char, long long> > v) {     cout <<  printing :   << endl;     for (int i = 0; i < (int)v.size(); i++) {       cout << v[i].first <<     << v[i].second << endl;     }   }   int main() {     scanf( %d , &n);     scanf( %d , &m);     for (int i = 0; i < n; i++) {       long long a;       cin >> a;       getchar();       char c = getchar();       if (i != 0 && s1[s1.size() - 1].first == c) {         s1[s1.size() - 1].second += a;       } else {         s1.push_back(make_pair(c, a));       }     }     for (int i = 0; i < m; i++) {       long long a;       cin >> a;       getchar();       char c = getchar();       if (i != 0 && s2[s2.size() - 1].first == c) {         s2[s2.size() - 1].second += a;       } else {         s2.push_back(make_pair(c, a));       }     }     long long ans = 0;     if (s2.size() == 1) {       char c = s2[0].first;       long long v = s2[0].second;       for (int i = 0; i < (int)s1.size(); i++) {         if (c == s1[i].first && s1[i].second >= v) {           ans += s1[i].second - v + 1;         }       }     } else if (s2.size() == 2) {       char c1 = s2[0].first;       char c2 = s2[1].first;       long long v1 = s2[0].second;       long long v2 = s2[1].second;       for (int i = 1; i < (int)s1.size(); i++) {         if (s1[i - 1].first == c1 && s1[i].first == c2 &&             s1[i - 1].second >= v1 && s1[i].second >= v2)           ans++;       }     } else {       for (int i = 1; i < (int)s2.size() - 1; i++) {         p.push_back(s2[i]);       }       sl = s1.size();       pl = p.size();       kmp();       for (int i = 0; i < (int)ii.size(); i++) {         int x = ii[i];         if (x > 0 && x + pl < n && s1[x - 1].first == s2[0].first &&             s1[x - 1].second >= s2[0].second &&             s1[x + pl].first == s2[s2.size() - 1].first &&             s1[x + pl].second >= s2[s2.size() - 1].second)           ans++;       }     }     cout << ans << endl;   }   