N, K, Q = gets.split.map(&:to_i) A = Hash.new idx = 0 Q.times do t = gets.to_i if t == 1 s = gets.chomp A[s] = idx idx += 1 else j = [1, A.size - N + 1].max remain = 60 cnt = 0 solved = [] problems = [] 6.times do t, d = gets.chomp.split d = d.to_i problems << [t, d] end problems.each do |t, d| time = d if A[t] && idx - A[t] <= N time = K if time > K end if remain >= time remain -= time cnt += 1 solved << t else break end end solved.each do |t| A[t] = idx idx += 1 end puts cnt end end