#include #include #include #include #include #include #include #include #include #include using ll = long long; using namespace std; int main() { int n, k, q; cin >> n >> k >> q; deque a, b; for (int i = 0; i < q; i++){ int num; cin >> num; if (num == 1) { string s; cin >> s; a.push_back(s); } if (num == 2){ int ansum = 0, tsum = 0, anum = a.size(); for (int i = 0; i < 6; i++){ string t; int d; bool f = false, sol = false; cin >> t >> d; for (int j = max(0, anum - n); j < anum; j++){ if (t == a[j]){ tsum += min(d, k); if (tsum <= 60){ ansum++; f = true; break; } } } if (!f){ tsum += d; if (tsum <= 60){ ansum++; sol = true; } } if (f || sol) a.push_back(t); } cout << ansum << endl; } } }