#P1965. [NOIP 2013 提高组] 转圈游戏

[NOIP 2013 提高组] 转圈游戏

Description

nn friends (numbered from 00 to n1n-1) sit in a circle to play a game. The nn positions are numbered clockwise from 00 to n1n-1. Initially, friend 00 is at position 00, friend 11 is at position 11, and so on. The rules are as follows: in each round, the friend at position 00 moves clockwise to position mm, the friend at position 11 moves to position m+1m+1, and so on; the friend at position nmn-m moves to position 00, the friend at position nm+1n-m+1 moves to position 11, ... , and the friend at position n1n-1 moves clockwise to position m1m-1.

Now, after a total of 10k{10}^k rounds, determine which position friend xx ends up at.

Input Format

One line containing four integers n,m,k,xn, m, k, x, with a single space separating each pair of integers.

Output Format

One integer, the position index where friend xx is located after 10k{10}^k rounds.

10 3 4 5

5

Hint

For 30%30\% of the testdata, 0<k<70 < k < 7.

For 80%80\% of the testdata, 0<k<1070 < k < {10}^7.

For 100%100\% of the testdata, 1<n<1061 < n < {10}^6, 0<m<n0 < m < n, 0xn0 \le x \le n, 0<k<1090 < k < {10}^9.

Translated by ChatGPT 5