def ascan; gets.split.map(&:to_i); end N, M = ascan turn = 0 vec = 1 numcards = [1]*N lastturn = 0 commands = M.times.map{gets.chomp} idx = 0 while idx < M lastturn = turn c = commands[idx] case c when 'number' numcards[turn] += 1 turn += 1*vec when 'drawtwo' numcards[turn] += 1 d = 2 while commands[idx+1] == 'drawtwo' lastturn = turn turn = (turn + vec + N) % N numcards[turn] += 1 d += 2 idx += 1 end numcards[(turn+vec)%N] -= d turn += 2*vec when 'drawfour' numcards[turn] += 1 d = 4 while commands[idx+1] == 'drawfour' lastturn = turn turn = (turn + vec + N) % N numcards[turn] += 1 d += 4 idx += 1 end numcards[(turn+vec)%N] -= d turn += 2*vec when 'skip' numcards[turn] += 1 turn += 2*vec when 'reverse' numcards[turn] += 1 vec *= -1 turn += 1*vec end turn = (turn + N) % N idx += 1 end puts "#{lastturn+1} #{numcards[lastturn]-1}"