func_code_string: #include <bits/stdc++.h>   using namespace std;   long long strL[200005], patL[200005], n, m, pref[200005], ans, tempL[200005];   char strC[200005], tempC[200005];   vector<long long> endings;   string patC =   ;   long long lenP, lenS;   void calcPrefixFunction() {     for (long long i = 1, k = 0; i < m - 2; i++) {       while (k > 0 && (patC[k] != patC[i] || patL[k] != patL[i])) k = pref[k - 1];       if (patC[k] == patC[i] && patL[i] == patL[k])         pref[i] = ++k;       else         pref[i] = k;     }   }   void kmp() {     for (long long i = 0, k = 0; i < n; i++) {       while (k > 0 && (strL[i] != patL[k] || strC[i] != patC[k])) k = pref[k - 1];       if (strL[i] == patL[k] && strC[i] == patC[k]) k++;       if (k == m - 2) {         endings.push_back(i);         k = pref[k - 1];       }     }   }   long long tempSolve1() {     long long ret = 0;     for (long long i = 0; i < n; i++)       if (tempL[0] <= strL[i] && strC[i] == tempC[0])         ret += strL[i] - tempL[0] + 1;     return ret;   }   long long tempSolve2() {     long long ret = 0;     for (long long i = 0; i < n - 1; i++)       if (tempL[0] <= strL[i] && strC[i] == tempC[0])         if (tempL[1] <= strL[i + 1] && strC[i + 1] == tempC[1]) ret++;     return ret;   }   void solve() {     if (lenP > lenS) {       puts( 0 );       return;     }     if (m == 1) {       printf( %I64d , tempSolve1());       return;     }     if (m == 2) {       printf( %d , tempSolve2());       return;     }     calcPrefixFunction();     kmp();     for (long long i = 0; i < endings.size(); i++) {       long long start, end;       end = endings[i] + 1;       start = end - m + 1;       if (end >= n || start < 0) continue;       if (strC[start] == tempC[0] && strL[start] >= tempL[0])         if (strC[end] == tempC[m - 1] && strL[end] >= tempL[m - 1]) ans++;     }     printf( %d , ans);   }   void input() {     scanf( %d %d , &n, &m);     for (long long i = 0; i < n; i++) {       scanf( %d-%c , &strL[i], &strC[i]);       if (i && strC[i] == strC[i - 1]) {         strL[i - 1] += strL[i];         n--;         i--;       }       lenS += strL[i];     }     for (long long i = 0; i < m; i++) {       scanf( %d-%c , &tempL[i], &tempC[i]);       lenP += tempL[i];       if (i && tempC[i] == tempC[i - 1]) {         tempL[i - 1] += tempL[i];         if (i - 2 >= 0) patL[i - 2] = tempL[i - 1];         i--;         m--;       } else if (i && i < m - 1)         patC += tempC[i], patL[i - 1] = tempL[i];     }   }   int main() {     input();     solve();   }   