B. Arranging Utensils
time limit per test
2 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

The Olympiad is over, and while the jury is tallying the scores, the participants decided to go to the nearest restaurant.

Due to epidemiological restrictions, the restaurant has only one round table with $$$n$$$ seats and exactly two waiters. The seats at the table are numbered from $$$1$$$ to $$$n$$$ in clockwise order. Thus, adjacent seats are $$$i$$$ and $$$i + 1$$$ for all $$$1 \le i \lt n$$$, as well as seats $$$n$$$ and $$$1$$$.

The restaurant manager, seeing that so many visitors have come, instructed the waiters to arrange utensils in front of each seat. Initially, there are no utensils anywhere. The first waiter stands next to seat number $$$a$$$, and the second waiter stands next to seat number $$$b$$$. In one second, a waiter can move from one seat to the adjacent one on the left or right. Each waiter has a cart with an infinite number of utensils, and if they are standing next to a seat without utensils, they instantly place them on that seat.

While the participants are waiting, they became interested in the minimum number of seconds required for the waiters to arrange utensils in front of each seat. Help them find the answer to this question.

Input

The first line of input contains exactly one integer $$$n$$$ - the number of seats at the round table ($$$1 \le n \le 10^{18}$$$).

The second line contains two integers $$$a$$$ and $$$b$$$ separated by a space - the numbers of the seats next to which the first and second waiters are initially located ($$$1 \le a, b \le n$$$).

Output

Print a single integer - the minimum number of seconds required for the waiters to arrange utensils in front of each seat.

Scoring

Points for each subtask are awarded only if all tests for that subtask and the necessary subtasks are passed successfully.

SubtaskPointsConstraints Necessary subtasks Verification information
19$$$n \le 10$$$first error
214 Seats $$$a$$$ and $$$b$$$ are the same or adjacent first error
317$$$n \le 1\,000$$$1first error
431$$$n \le 100\,000$$$1, 3first error
529No additional constraints1–4first error
Examples
Input
5
1 3
Output
2
Input
7
3 1
Output
3
Note

One of the ways to arrange utensils in the first example:

  • Route of the first waiter: $$$1 \rightarrow 2 \rightarrow 3$$$.
  • Route of the second waiter: $$$3 \rightarrow 4 \rightarrow 5$$$.

One of the ways to arrange utensils in the second example:

  • Route of the first waiter: $$$3 \rightarrow 4 \rightarrow 5 \rightarrow 6$$$.
  • Route of the second waiter: $$$1 \rightarrow 2 \rightarrow 1 \rightarrow 7$$$.