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} draw = 0 idx = 0 while idx < M lastturn = turn c = commands[idx] if draw > 0 if c == commands[idx-1] draw += c == 'drawtwo' ? 2 : 4 numcards[turn] += 1 turn += 1*vec else numcards[turn] -= draw turn += 1*vec draw = 0 idx -= 1 end else case c when 'number' numcards[turn] += 1 turn += 1*vec when 'drawtwo' numcards[turn] += 1 draw = 2 turn += 1*vec when 'drawfour' numcards[turn] += 1 draw = 4 turn += 1*vec when 'skip' numcards[turn] += 1 turn += 2*vec when 'reverse' numcards[turn] += 1 vec *= -1 turn += 1*vec end end turn = (turn + N) % N idx += 1 end puts "#{lastturn+1} #{numcards[lastturn]-1}"