A hall has $$$n$$$ seats numbered from $$$1$$$ to $$$n$$$. Team A has reserved three distinct seats $$$a_1,a_2,a_3$$$. Team B has written three distinct seat numbers $$$b_1,b_2,b_3$$$ on one reservation card.
Before submitting the card, Team B may choose any integer $$$k$$$ and add $$$k$$$ to all three numbers. Negative values of $$$k$$$ and $$$k=0$$$ are allowed.
Count the values of $$$k$$$ for which all three shifted numbers are between $$$1$$$ and $$$n$$$, and no shifted Team B reservation equals a Team A reservation.
The first line contains one integer $$$n$$$ ($$$3 \le n \le 10^{18}$$$), the number of seats.
The second line contains three distinct integers $$$a_1,a_2,a_3$$$ ($$$1 \le a_i \le n$$$), the seats reserved by Team A.
The third line contains three distinct integers $$$b_1,b_2,b_3$$$ ($$$1 \le b_i \le n$$$), the numbers initially written by Team B.
Print the number of valid integer values of $$$k$$$.
102 5 91 4 7
2
In the sample, keeping the card unchanged gives $$$k=0$$$, and shifting it three seats to the right gives $$$k=3$$$. The shifts $$$k=1$$$ and $$$k=2$$$ create collisions, while every other shift puts at least one reservation outside the hall.