#include #include using namespace std; int main() { cin.tie(nullptr); std::ios::sync_with_stdio(false); int n, q; cin >> n >> q; string start; getline(cin, start); getline(cin, start); char* current = new char[n + 1]; strcpy(current, start.c_str()); char* next = new char[n + 1]; for (int qq = 0; qq < q; qq++) { int m, len = 0; cin >> m; string to_burn; getline(cin, to_burn); getline(cin, to_burn); int removal_count = 0; bool is_copying = false; for (int i = 0; i < n; i++) { if (i >= n-m+1 || memcmp(current + i, to_burn.c_str(), m) != 0) { if (is_copying) { next[len++] = current[i]; } } else { if (!is_copying) { is_copying = true; memcpy(next, current, i); len = i; } removal_count += 1; i += m - 1; } } if (is_copying) { next[len] = '\0'; swap(next, current); n = len; } cout << removal_count << '\n'; } }