import future, strutils proc nextString: string = result = "" while not endOfFile stdin: let nextChar = readChar stdin case nextChar of '\r': discard of "\n"[0], ' ': break else: add result, nextChar proc nextInt: int = return parseInt nextString() let n, m = nextInt() l = lc[nextString() | (i <- 0 ..< m), string] var P = lc[0 | (j <- 0 ..< n), int] j = -1 flg = 1 id: int k = 1 proc main: void = for i in 0 ..< m: j += flg j = (j + n) mod n id = j + 1 P[j] += 1 let li = l[i] case li of "number": discard of "drawtwo", "drawfour": if i <= m - 2 and li != l[i + 1]: j += flg P[(j + n) mod n] -= [2, 4][int(li != "drawtwo")] * k k = 1 else: k += 1 of "skip": j += flg of "reverse": flg *= -1 writeLine stdout, "$# $#".format(id, P[id - 1]) when isMainModule: main()