func_code_string: #include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 7;   int n, m, len, cnt1 = 0, cnt2 = 0, cnt3 = 0, fail[maxn];   long long ans = 0;   struct Node {     long long c;     char ch;   } s[maxn], str[maxn], _str[maxn];   bool ok(int i, int j) {     if (_str[i].c != _str[j].c) return false;     if (_str[i].ch != _str[j].ch) return false;     return true;   }   bool _ok(int i, int j) {     if (s[i].c != _str[j].c) return false;     if (s[i].ch != _str[j].ch) return false;     return true;   }   void getfail() {     fail[0] = fail[1] = 0;     for (int i = 1; i < cnt3; i++) {       int j = fail[i];       while (j && !ok(i, j)) j = fail[j];       fail[i + 1] = (ok(i, j)) ? j + 1 : 0;     }   }   void KMP_search() {     for (int i = 0, j = 0; i < cnt1; i++) {       while (j && !_ok(i, j)) j = fail[j];       if (_ok(i, j)) j++;       if (j == cnt3) {         if ((i - j + 1) && i != (cnt1 - 1) && s[i - j].ch == str[0].ch &&             s[i - j].c >= str[0].c && s[i + 1].ch == str[cnt2 - 1].ch &&             s[i + 1].c >= str[cnt2 - 1].c)           ans++;       }     }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) {       scanf( %I64d-%c , &s[cnt1].c, &s[cnt1].ch);       if (i && s[cnt1].ch == s[cnt1 - 1].ch)         s[cnt1 - 1].c += s[cnt1].c;       else         cnt1++;     }     for (int i = 0; i < m; i++) {       scanf( %I64d-%c , &str[cnt2].c, &str[cnt2].ch);       if (i && str[cnt2].ch == str[cnt2 - 1].ch)         str[cnt2 - 1].c += str[cnt2].c;       else         cnt2++;     }     if (cnt2 == 1) {       for (int i = 0; i < cnt1; i++)         if (s[i].ch == str[0].ch && s[i].c >= str[0].c)           ans += s[i].c - str[0].c + 1;     } else if (cnt2 == 2) {       for (int i = 0; i < cnt1; i++)         if (s[i].ch == str[0].ch && s[i].c >= str[0].c && (i != (cnt1 - 1)) &&             s[i + 1].ch == str[1].ch && s[i + 1].c >= str[i + 1].c)           ans++;     } else {       for (int i = 1; i < cnt2 - 1; i++) _str[cnt3++] = str[i];       getfail();       KMP_search();     }     printf( %I64d n , ans);     return 0;   }   