| Codeforces Round 1098 (Div. 2) |
|---|
| Finished |
Remilia is trying to escape, while Reimu wants to land the final hit.
The playing field consists of $$$n$$$ positions arranged in a circle. For each $$$1 \le i \lt n$$$, positions $$$i$$$ and $$$i+1$$$ are adjacent, and positions $$$1$$$ and $$$n$$$ are also adjacent.
Initially, at time $$$0$$$, Reimu is at position $$$x_1$$$ and Remilia is at position $$$x_2$$$, where $$$x_1 \ne x_2$$$.
Each second, the following happens in order:
Assuming both players play optimally, Reimu always tries to minimize the catching time, while Remilia tries to maximize it.
Find the number of seconds until Reimu catches Remilia.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The description of the test cases follows.
The only line of each test case contains four integers $$$n$$$, $$$x_1$$$, $$$x_2$$$ and $$$k$$$ ($$$2\le n\le10^8$$$, $$$1\le x_1,x_2\le n$$$, $$$x_1\ne x_2$$$, $$$0\le k\le 10^8$$$).
For each test case, output the number of seconds until Reimu catches Remilia, assuming both players play optimally.
42 1 2 04 3 2 14 2 3 116 8 4 2
1226
In the first test case, one possible sequence of actions is:
In the second test case, one possible sequence of actions is:
| Name |
|---|


