P9185 [USACO23OPEN] Rotate and Shift B
Description
**Note: The time limit for this problem is 4s, 2x the default.**
To celebrate the start of spring, Farmer John's $N$ cows have invented an intriguing new dance, where they stand in a circle and re-order themselves in a predictable way.
Specifically, there are $N$ positions around the circle, numbered sequentially from $0$ to $N-1$, with position $0$ following position $N-1$. A cow resides at each position. The cows are also numbered sequentially from $0$ to $N-1$. Initially, cow $i$ starts in position $i$. You are told a set of $K$ positions $0=A_1
Input Format
N/A
Output Format
N/A
Explanation/Hint
For the example above, here are the cow orders and $A$ for the first four timesteps:
```
Initial, T = 0: order = [0 1 2 3 4], A = [0 2 3]
T = 1: order = [3 1 0 2 4]
T = 1: A = [1 3 4]
T = 2: order = [3 4 0 1 2]
T = 2: A = [2 4 0]
T = 3: order = [2 4 3 1 0]
T = 3: A = [3 0 1]
T = 4: order = [1 2 3 4 0]
```
$1 \leq K \leq N \leq 2 \cdot 10^5$, $1\le T\le 10^9$.
- Inputs 2-7: $N \leq 1000, T \leq 10000$.
- Inputs 8-13: No additional constraints.