package net.ipipip0129.yukicoder.No769; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; class No769 { int ans = 0; int person_number; int log_number; BufferedReader reader; No769() throws IOException { reader = new BufferedReader(new InputStreamReader(System.in)); String[] split_str = reader.readLine().split(" "); person_number = Integer.parseInt(split_str[0]); log_number = Integer.parseInt(split_str[1]); int[] ans_array = analyze(); System.out.printf("%d %d\n", ans_array[0], ans_array[1]); } private int[] analyze() throws IOException { int[] persons_card = new int[person_number]; int turn_number = 0; int drawtwo_acc = 0; int drawfour_acc = 0; boolean is_reverse = false; for (int i = 0; i < log_number; i++) { switch (reader.readLine()) { case "number": if (0 < drawtwo_acc) { persons_card[turn_number] -= 2 * drawtwo_acc; drawtwo_acc = 0; turn_number = getNextTurn(turn_number, is_reverse); } else if (0 < drawfour_acc) { persons_card[turn_number] -= 4 * drawfour_acc; drawfour_acc = 0; turn_number = getNextTurn(turn_number, is_reverse); } persons_card[turn_number] += 1; break; case "drawtwo": if (0 < drawfour_acc) { persons_card[turn_number] -= 4 * drawfour_acc; drawfour_acc = 0; turn_number = getNextTurn(turn_number, is_reverse); } drawtwo_acc += 1; persons_card[turn_number] += 1; break; case "drawfour": if (0 < drawtwo_acc) { persons_card[turn_number] -= 2 * drawtwo_acc; drawtwo_acc = 0; turn_number = getNextTurn(turn_number, is_reverse); } drawfour_acc += 1; persons_card[turn_number] += 1; break; case "skip": if (0 < drawtwo_acc) { persons_card[turn_number] -= 2 * drawtwo_acc; drawtwo_acc = 0; turn_number = getNextTurn(turn_number, is_reverse); } else if (0 < drawfour_acc) { persons_card[turn_number] -= 4 * drawfour_acc; drawfour_acc = 0; turn_number = getNextTurn(turn_number, is_reverse); } persons_card[turn_number] += 1; turn_number = getNextTurn(turn_number, is_reverse); break; case "reverse": if (0 < drawtwo_acc) { persons_card[turn_number] -= 2 * drawtwo_acc; drawtwo_acc = 0; turn_number = getNextTurn(turn_number, is_reverse); } else if (0 < drawfour_acc) { persons_card[turn_number] -= 4 * drawfour_acc; drawfour_acc = 0; turn_number = getNextTurn(turn_number, is_reverse); } is_reverse = !is_reverse; persons_card[turn_number] += 1; break; } turn_number = getNextTurn(turn_number, is_reverse); } is_reverse = !is_reverse; turn_number = getNextTurn(turn_number, is_reverse); return new int[] {turn_number + 1, persons_card[turn_number]}; } private int getNextTurn(int turn, boolean reverse) { if (reverse) { if (turn == 0) { return this.person_number - 1; } else { return turn - 1; } } else { if (turn == this.person_number - 1) { return 0; } else { return turn + 1; } } } public int getAns() { return ans; } } public class Main { public static void main(String[] args) { try { No769 ques = new No769(); } catch (IOException e) { e.printStackTrace(); } } }