N,K,Q=gets.split.map &:to_i a=[] Q.times{ if gets.to_i==1 a.append gets.strip else z,c=60,0 6.times{ t,d=gets.split d=d.to_i if a.include? t; d = [d, K].min end z-=d if z>=0; c+=1; a.append(t) end } a.shift [0, a.size-N].max p c end }