시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB229738.889%

문제

상근이와 정인이는 로테이트라는 새로운 게임을 창안했다. 먼저, 정인이는 길이가 N인 수열을 생각한다. 그 다음, 각 섹션에 K개의 수가 들어있도록 수열을 섹션으로 나눈다. (K는 N을 나눌 수 있는 수) 첫 번째 섹션에는 수열의 첫 K개 수가 포함되고, 두 번째 섹션에는 그 다음 K개 수가 포함된다. 나머지 섹션에도 이런식으로 수가 포함된다.

상근이와 정인이는 아래와 같은 두 가지 연산을 수열에 행할 수 있다.

  1. 각 섹션을 왼쪽 또는 오른쪽으로 X만큼 회전(rotate)시킨다.
  2. 수열 전체를 왼쪽 또는 오른쪽으로 X만큼 회전시킨다.

2번 연산은 수열 전체에 행하는 연산이기 때문에, 각 섹션에 들어있는 수를 바꿀 수도 있다. 정인이느 자기가 생각한 수열에 위의 연산을 수행한 다음에 상근이에게 최종 수열을 보여준다. 최종 수열과 정인이가 행한 연산이 순서대로 주어졌을 때, 처음 수열을 구하는 프로그램을 작성하시오.

입력

첫째 줄에 수열의 길이 N, 섹션의 크기 K, 정인이가 행한 연산의 수 Q가 주어진다. (1 ≤ N, K, Q ≤ 100,000)

다음 Q개 줄에는 정인이가 수열에 행한 연산이 순서대로 주어진다. 각 줄의 처음에는 어떤 연산인지를 나타내는 A (1 ≤ A ≤ 2)가 주어지며, 그 다음 수는 얼만큼 돌렸는지를 나타내는 X (-100,000 ≤ X ≤ 100,000)이다. 음수는 왼쪽 방향, 양수는 오른쪽 방향 회전이다.

마지막 줄에는 모든 연산을 수행하고 난 뒤의 최종 수열이 공백으로 구분되어서 주어진다.

출력

첫째 줄에 처음 정인이가 생각한 수열을 출력한다.

예제 입력 1

4 2 2
2 2
1 1
3 2 1 0

예제 출력 1

0 1 2 3

예제 입력 2

8 4 4
1 3
1 15
1 -5
2 -1
6 10 14 19 2 16 17 1

예제 출력 2

6 10 14 1 2 16 17 19

예제 입력 3

9 3 5
1 1
2 -8
2 9
1 1
2 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