#P9951. [USACO20FEB] Swapity Swap B

[USACO20FEB] Swapity Swap B

Problem Description

Farmer John’s NN cows (1≤N≤1001 \le N \le 100) are standing in a line. For each 1≤i≤N1 \le i \le N, the ID of the ii-th cow from left to right is ii.

Farmer John has come up with a new morning exercise plan. He has them repeat the following two-step process KK times (1≤K≤1091 \le K \le 10^9):

  1. Reverse the order of the cows currently in positions A1…A2A_1 \ldots A_2 from left to right (1≤A1<A2≤N1 \le A1 < A2 \le N).
  2. Then, reverse the order of the cows currently in positions B1…B2B_1 \ldots B_2 from left to right (1≤B1<B2≤N1 \le B_1 < B_2 \le N).

After the cows repeat this process KK times, output the ID of the ii-th cow from left to right for each 1≤i≤N1 \le i \le N.

Input Format

The first line contains NN and KK. The second line contains A1A_1 and A2A_2, and the third line contains B1B_1 and B2B_2.

Output Format

On the ii-th line, output the ID of the ii-th cow from left to right after the exercise ends.

7 2
2 5
3 7
1
2
4
3
5
7
6

Hint

Sample Explanation 1

Initially, the cows’ order from left to right is [1,2,3,4,5,6,7][1,2,3,4,5,6,7]. After the first step of this process, the order becomes [1,5,4,3,2,6,7][1,5,4,3,2,6,7]. After the second step of this process, the order becomes [1,5,7,6,2,3,4][1,5,7,6,2,3,4]. Repeating these two steps one more time produces the sample output.

Test Point Properties

  • Test points 2−32-3 satisfy K≤100K \le 100.
  • Test points 4−134-13 have no additional constraints.

Translated by ChatGPT 5