#include int main() { using namespace std; unsigned N, K, Q; cin >> N >> K >> Q; map counter; deque viewed(N); counter[""] = N; for (unsigned i{}; i < Q; ++i) { unsigned type; cin >> type; if (type == 1) { string S; cin >> S; ++counter[S]; viewed.emplace_back(S); if (!--counter[viewed.front()]) counter.erase(viewed.front()); viewed.pop_front(); } else { array v{}; for (unsigned j{}; j < 6; ++j) { string S; cin >> S; unsigned time; cin >> time; if (counter.contains(S)) v[j] = min(time, K); else v[j] = time; } unsigned ans{}; for (unsigned j{}; j < 64; ++j) { unsigned time{}; for (unsigned k{}; k < 6; ++k) if (1 & (j >> k)) time += v[k]; if (time <= 60) ans = max(ans, popcount(j)); } cout << ans << endl; } } return 0; }