Problem:
 Score : 300 points    Problem Statement 2N players are running a competitive table tennis training on N tables numbered from 1 to N .  The training consists of rounds .
In each round, the players form N pairs, one pair per table.
In each pair, competitors play a match against each other.
As a result, one of them wins and the other one loses.  The winner of the match on table X plays on table X-1 in the next round,
except for the winner of the match on table 1 who stays at table 1 .  Similarly, the loser of the match on table X plays on table X+1 in the next round,
except for the loser of the match on table N who stays at table N .  Two friends are playing their first round matches on distinct tables A and B .
Let's assume that the friends are strong enough to win or lose any match at will.
What is the smallest number of rounds after which the friends can get to play a match against each other?      Constraints  2 \leq N \leq 10^{18}  1 \leq A < B \leq N  All input values are integers.         Input Input is given from Standard Input in the following format:  N  A  B       Output Print the smallest number of rounds after which the friends can get to play a match against each other.        Sample Input 1 5 2 4      Sample Output 1 1  If the first friend loses their match and the second friend wins their match, they will both move to table 3 and play each other in the next round.       Sample Input 2 5 2 3      Sample Output 2 2  If both friends win two matches in a row, they will both move to table 1 .

Solution (Python):
n, a, b = map(int, input().split())
if (abs(a - b) % 2) == 0:
    print(abs(a - b) // 2)
else:
    a, b = min(a, b), max(a, b)
    ans1 = a - 1
    if b - a == 1:
        ans1 += 1
    else:
        ans1 += (b - a) // 2 + 1
    ans2 = n - b
    if b - a == 1:
        ans2 += 1
    else:
        ans2 += (n - (a + (n - b) + 1)) // 2 + 1
    print(min(ans1, ans2))

Solution (Python):
import sys
input = sys.stdin.readline

n,a,b=map(int,input().split())
res = []
if (b-a)%2==0:
    print(abs(b-a)//2)
    exit()
else:
    if min(a-1,n-b)==a-1:
        res.append(b-1)
        res.append((b-a-1)//2+a)
    else:
        res.append(n-a)
        res.append((b-a-1)//2+n-b+1)
print(min(res))

Solution (Python):
n,a,b=map(int,input().split())
d=abs(a-b)
ans=0
if d%2==0:
	ans=d//2
else:
	ans=min(b-1,n-a,n-b+1+(b-a-1)//2,a+(b-a-1)//2)
print(ans)

Solution (Python):
x = input()
N, a, b = x.split()
N, a, b = int(N), int(a), int(b)
a, b    = min(a,b), max(a, b)

if (a + b) % 2 == 0:
    
    steps = (b-a)//2
else:
    if a - 1 < N - b:
        
        steps = a - 1
        b = b - (a - 1)
        a = 1
        
        steps += 1
        b -= 1
        
    else:
        steps = N - b
        a = a + N - b
        b = N
        
        steps += 1
        a += 1
        
    steps = steps + abs(b-a)//2
    
print(steps)

Solution (Python):

n, a, b = map(int, input().split())

diff = b - a
if abs(diff) % 2 == 0:
    print(diff // 2)
else:
    worst = min(b-1, n-a)
    if a-1 < n-b:
        t = a
    else:
        t = n-b+1
    t += (b - a - 1) // 2
    print(min(t, worst))

Solution (Python):
n,a,b = (int(x) for x in input().split())
c = b - a

if c%2==0:
    print(c//2)
else:
    d = a + (b-a-1)//2
    e = n - b + 1 + (b-a-1)//2
    print(min(b-1,n-a,d,e))

Solution (Python):
n,a,b=map(int,input().split())
sa=b-a
if sa%2==0:
	print(sa//2)
else:
	ans1=0
	ans2=0
	ans1+=a
	ans1+=(b-a-1)//2
	ans2+=n-b+1
	ans2+=(n-(a+n-b+1))//2
	print(min(ans1,ans2))

Solution (Python):
n,a,b = map(int,input().split())

sa = b-a

goal = 0

if n-b > a-1:
    goal = 1
else:
    goal = n
    

if sa % 2 == 0:
    print(sa//2)
else:
    if goal == 1:
        print(a-1+1+sa//2)
    else:
        print(n-b+1+sa//2)

Solution (Python):

N,A,B = map(int,input().split())
if (B-A)%2 == 0:
    print((B-A)//2)
else:
    right = N-B
    left = A-1
    
    ans1 = right+1+(N-(A+right+1))//2
    ans2 = left+1+(B-left-2)//2
    
    print(min(ans1,ans2))

Solution (Python):
from sys import stdout
printn = lambda x: stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True 
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n,a,b = inm()
if (a-b)%2==0:
    print(abs(a-b)//2)
else:
    p = max([a-1,b-1])
    q = max([n-a,n-b])
    r = (a+b-1)//2
    s = (2*n-a-b+1)//2
    print(min([p,q,r,s]))

Solution (Python):


n,a,b=map(int,input().split())

if((b-a)%2==0):
	print((b-a)//2)
else:
	ans=10**20

	ta=a
	tb=b
	tp=0
	tp+=ta-1
	ta=1
	tb-=tp+1
	tp+=1
	ans=min(ans,(tb-ta)//2+tp)

	ta=a
	tb=b
	tp=n-tb
	tb=n
	ta+=tp+1
	tp+=1
	ans=min(ans,(tb-ta)//2+tp)

	print(ans)

Solution (Python):
''' بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ '''

gi = lambda : list(map(int,input().split()))
n, a, b = gi()
if a > b:
	a, b = b, a
if (abs(a - b) % 2):
	x = a
	b -= a
	x += (b - 1) // 2
	b += a
	y = n - b + 1
	a += y
	y += (n - a) // 2
	print(min(x, y))
else:
	print(abs(a - b) // 2)

Solution (Python):
N, A, B = map(int,input().split())
d = B - A
ans = 0
if d % 2 == 0:
    print(d//2)
    exit()
else:
    if A == 1 or B == N:
        print(1+d//2)
        exit()
    if A-1 < N-B:
        ans += A-1
        B -= A-1
        d = B-1
        ans += 1+d//2
    else:
        ans += N-B
        A += N-B
        d = N-A
        ans += 1+d//2
print(ans)

Solution (Python):
n,a,b = map(int, input().split())
ans = b-a
if ans%2==0:
    print(ans//2)
else:
    if a-1 > n-b:
        a = a+ n-b+1
        print((n-a)//2 + n-b+1)
    else:
        b = b-a+2
        print((b-1)//2 +a-1)

Solution (Python):
import sys
input = sys.stdin.readline
N, A, B = [int(x) for x in input().split()]
a = max(A, B) - 1
b = N - min(A, B)
c = 10 ** 19
d = 10 ** 19
e = 10 ** 19
if abs(A - B) % 2 == 0:
    c = abs(A - B) // 2
else:
    d = min(A, B) - 1 + 1 + (abs(A - B) - 1) // 2
    e = N - max(A, B) + 1 + (abs(A - B) - 1) // 2
print(min(a, b, c, d, e))

Solution (Python):
import sys
input = sys.stdin.readline
N, A, B = map(int, input().split())
if A > B: A, B = B, A
x = max(abs(1 - A), abs(1 - B))
y = max(abs(N - A), abs(N - B))
z = abs(A - (A + B) // 2)
res = 0
if (A + B) % 2:
  if abs(1 - A) < abs(N - B):
    res += abs(1 - A) + 1
    B -= abs(1 - A)
    A = 1
  else:
    res += abs(N - B) + 1
    A += abs(N - B)
    B = N

  x = max(abs(1 - A), abs(1 - B))
  y = max(abs(N - A), abs(N - B))
  z = abs(A - (A + B) // 2)
print(min(x, y, z) + res)

Solution (Python):

N, A, B = map(int, input().split())

if (B - A) % 2 == 0:
    print((B - A) // 2)
else:
    print(min((N - A), (B - 1), (B - (A - 1) - 1) // 2 + A, ((N - A) - (N - B) - 1) // 2 + (N - B + 1)))

Solution (Python):
N,A,B=map(int,input().split())
if (B-A)%2==0:
    print((B-A)//2)
else:
    print(min(A-1,N-B)+(B-A+1)//2)

Solution (Python):
import math
n, a, b = map(int, input().split())

if abs(a-b) % 2 == 0:
    print(abs(a-b)//2)
else:
    ans1 = abs(1 - (b - abs(1 - a) - 1)) // 2 + abs(1 - a) + 1
    ans2 = abs(n - (a + abs(n - b) + 1)) // 2 + abs(n - b) + 1
    print(min(ans1, ans2))

Solution (Python):
N,A,B = map(int,input().split())
if abs(B-A)%2==0 :
  print(abs(B-A)//2)
else:
  x1 = N-max(A,B)
  ans1 = N- max(A,B) + 1 + (-min(A,B)+max(A,B)-1)//2

  ans2 = min(A,B)+(max(A,B)-min(A,B)-1)//2
  print(min(ans1,ans2))

Solution (Python):
def read():
    N, A, B = list(map(int, input().strip().split()))
    return N, A, B

def solve(N, A, B):
    if (A + B) % 2 == 0:
        return (B - A) // 2
    left = (A - 1) + 1 + (B - A) // 2
    right = (N - B) + 1 + (B - A) // 2
    return min(left, right)

if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))

Solution (Python):
ui = input()
uis = ui.split(" ")
N = int(uis[0])
A = int(uis[1])
B = int(uis[2])
if abs(A-B) % 2 == 0:
    print(abs(A-B) // 2)
elif A == B:
    print(0)
else:
    if B > A:
        temp = B
        B = A
        A = temp
    BDistance = B - 1
    ADistance = N - A
    if BDistance > ADistance:
        steps = ADistance + 1
        B = B + ADistance + 1
        A = N
        Distance = (N-B) // 2
        steps = steps + Distance
    else:
        steps = BDistance + 1
        B = 1
        A = A - BDistance - 1
        Distance = (A-1) // 2
        steps = steps + Distance
    print(steps)

Solution (Python):
N, A, B = map(int, input().split())

if (B - A) % 2 > 0:
    ans_up = (A + B - 1) // 2
    ans_down = N - (A + B - 1) // 2
    print(min(ans_up, ans_down))
else:
    print((B - A) // 2)

Solution (Python):
N,A,B = map(int,input().split())

if abs(A-B)%2 == 0:
  print(abs(A-B)//2)
else:
  ans = 0
  tip_A = min(abs(A-1),abs(A-N))
  tip_B = min(abs(B-1),abs(B-N))
  near_tip = min(tip_A,tip_B)
  
  if near_tip == tip_A:
    if abs(A-1) <= abs(A-N):
      ans += tip_A
      A = 1
      B -= tip_A
      
      ans += 1
      B -= 1
      
      ans += (abs(A-B)//2)
    else:
      ans += tip_A
      A = N
      B += tip_A
      
      ans += 1
      B += 1
      
      ans += (abs(A-B)//2)
  else:
    if abs(B-1) <= abs(B-N):
      ans += tip_B
      B = 1
      A -= tip_B
      
      ans += 1
      A -= 1
      
      ans += (abs(A-B)//2)
    else:
      ans += tip_B
      B = N
      A += tip_B
      
      ans += 1
      A += 1
      
      ans += (abs(A-B)//2)
  print(ans)

Solution (Python):
N, A, B = map(int, input().split())

if (B-A) % 2 == 0:
    print((B-A)//2)
else:
    a = min(N-B, A-1)
    print(((B-a)-(A-a))//2 + a + 1)

Solution (Python):
n, a, b = map(int, input().split())

if (b - a) % 2 == 0:
    ans = (b-a) // 2
else:
    ans = min(a+b-1, 2*n-a-b+1) // 2
    
print(ans)

Solution (Python):
n,a,b=map(int,input().split())
if (b-a)%2==0:
    print((b-a)//2)
else:
    aa=a
    bb=b
    tot=0
    tot+=(a)
    b-=(a)
    a=1
   
    tot+=((b-a)//2)
    a=aa
    b=bb
    tot2=0
    tot2+=(n-b+1)
    a+=(n-b+1)
    b=n

    tot2+=((b-a)//2)
    print(min(tot,tot2))

Solution (Python):
N, A, B = map(int, input().split())
C = abs(A-B)
X = max(A-1,B-1)
Y = max(N-A,N-B)
if C % 2 == 0:
  print(min(C//2,X,Y))
else:
  if B > A:
    A, B = B, A
  P = (2*N - B - A + 1)//2
  Q = (A + B - 1)//2
  print(min(P,Q,X,Y))

Solution (Python):
N,A,B = map(int,input().split(' '))

if (B - A)%2 == 0:
    print((B - A)//2)
else:
    if A-1 < N-B:
        reach_min = A
        b_num = B - A
        num_second = (b_num-1)//2
        print(reach_min+num_second)
    else:
        reach_min = N - B + 1
        b_num = A + reach_min
        num_second = (N-b_num)//2
        print(reach_min+num_second)

Solution (Python):
N, A, B = [int(x) for x in input().split()]
if (A-B)%2:
    print(min(B-1, (A-1)+ 1 + ((B-A)-1)//2, (N-B)+ 1 + (N-(A+(N-B+1)))//2, N-A))
else:
    print(min(B-1, (B-A)//2, N-A))

Solution (Python):
N,A,B = map(int,input().split())
if (B-A) % 2 == 0:
    ans = (B - A) // 2
else:
    x = (B - A - 1)//2 + A
    y = (B - A - 1)//2 + N - B + 1
    ans = min(x,y)
print(ans)

Solution (Python):
N, A, B=map(int, input().split())
if A%2==B%2:
  print((B-A)//2)
else:
  print(min((A+B-1)//2, N+(-B-A+1)//2))

Solution (Python):
N, A, B = [int(i) for i in input().split()]
if (B-A) % 2 == 0:
    print((B- A) // 2)
else:
    if A - 1 <= N - B:
        print(A + (B - A) // 2)
    else:
        print(N - B + 1 + (B - A) // 2)

Solution (Python):
n, a, b = map(int, input().split())
x = b-a
if x%2 == 0:
    print(x//2)
else:
    print(min(a-1, n-b) + (x-1)//2 + 1)

Solution (Python):
N, A, B = map(int, input().split())

if (B-A)%2 == 0:
    print((B-A)//2)
else:
    if A-1 < (N-B):
        ans = A
        B -= A
        A = 1
        ans += (B-A)//2
        print(ans)
    else:
        ans = N-B+1
        A += N-B+1
        B = N
        ans += (B-A)//2
        print(ans)

Solution (Python):
def main():
    n, a, b = [int(x) for x in input().split()]
    print(calc(n, a, b))
    return


def calc(n ,a, b):
    if a % 2 == b % 2:
        return abs(a - b) // 2
    else:
        if a > b:
            a, b = b, a
        if a - 1 < n - b:
            return calc(n, 1, b - a) + a
        else:
            return calc(n, a + n - b + 1, n) + n - b + 1


if __name__ == "__main__":
    main()

Solution (Python):
N,A,B=map(int,input().split())
print
if abs(A-B)%2==0:
  print(abs(A-B)//2)
else:
  C=min([A-1,B-1,N-A,N-B])
  if C==A-1 or C==B-1:
    print((A+B-1)//2)
  else:
    print((N-A+N-B+1)//2)

Solution (Python):
n, a, b = map(int, input().split())
if a > b: a, b = b, a
if (a + b) % 2 == 0:
    print(((a + b) // 2) - a)
else:
    t = min(a - 1, n - b)
    if a - 1 <= n - b:
        t -= -1
        b -= t
        t += (((1 + b) // 2) - 1)
        print(t)
    else:
        t -= -1
        a += t
        t += (((a + n) // 2) - a)
        print(t)

Solution (Python):
N,A,B=[int(i) for i in input().split(" ")]
delta=abs(A-B)
if delta%2==0:
    print(delta//2)
else:
    
    use1=A+(B-A-1)//2
    useN=N-B+1+(delta-1)//2
    print(min(use1,useN))

Solution (Python):
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    N, A, B = map(int, input().split())

    if not (B - A) % 2:
        ans = (B - A) // 2
    else:
        ans = min(A - 1, N - B)
        ans += (B - A + 1) // 2
    print(ans)


main()

Solution (Python):
N, A, B = [int(i) for i in input().split(" ")]
if (B - A) % 2 == 0:
    print((B-A)//2)
else:
    if A - 1 <= N-B:
        print((A-1+B)//2)
    else:
        print((N-A+N-B+1)//2)

Solution (Python):
n,a,b=(int(x) for x in input().split())
ans=max(a,b)-min(a,b)

if ans%2!=0:
	m=min(a-1,n-b)
	ans=ans//2+m+1
else:
	ans=ans//2

print(ans)

Solution (Python):
N, A, B = map(int, input().split())







a = A
b = B
if (B - A) % 2 == 0:
    
    ans = abs(B-A)//2
    print(ans)
    exit()
else:
    a = A
    b = B
    ans = 10**20
    
    left = A-1  
    tmp = left
    a -= left  
    b -= left
    
    b -= 1
    tmp += 1
    
    tmp += abs(b-a)//2
    ans = min(ans, tmp)

    
    a = A
    b = B
    right = N-b  
    tmp = right
    b = N
    a += tmp  
    
    tmp += 1
    a += 1
    tmp += abs(b-a)//2
    ans = min(tmp, ans)
    print(ans)
    exit()

Solution (Python):
N, A, B = map(int, input().split())

if (B - A) % 2 == 0:
    print((B - A) // 2)
else:
    lose = N - B + 1
    loseThenMeet = (N - (A + lose)) // 2
    win = A - 1 + 1
    winThenMeet = ((B - win) - 1) // 2
    print(min(lose + loseThenMeet, win + winThenMeet))

Solution (Python):

import sys
INF = float("inf")


def solve(N: int, A: int, B: int):
    if (B-A) % 2 == 0:
        print(min((B-A)//2, min(max(A, B)-1, N-min(A, B))))
    else:
        
        m = A + (B-A-1)//2
        m = min(m, N-B+1+(B-A-1)//2)
        print(m)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    A = int(next(tokens))  
    B = int(next(tokens))  
    solve(N, A, B)


if __name__ == '__main__':
    main()

Solution (Python):
n, a, b = map(int, input().split())
if (b - a) % 2 == 0:
  ans = (b - a) // 2
else:
  ans = min(a + (b - a - 1) // 2, n - b + 1 + (b - a - 1) // 2)
print(ans)

Solution (Python):

n, a, b = list(map(int,input().split()))
s = abs(a-b)

def chk(c,d):
    return abs(c-d)//2

if s % 2 == 0:
    print(s//2)
else:
    
    
    r = min(a-1,n-b) 
    u = r + 1 + min(chk(1,b-r-1),chk(a+r+1,n))
    print(u)

Solution (Python):
n, a, b = map(int, input().split())

if (b-a)%2 == 0:
    print((b-a)//2)
else:
    if (a-1) <= (n-b):
        print(a-1 + 1 +(b-a-1)//2)
    else:
        print(n-b + 1 +(b-a-1)//2)

Solution (Python):
n, a, b = map(int, input().split())
if (b - a) % 2 == 0:
    print((b - a) // 2)
else:
    ans1 = a
    c = b - ans1
    ans1 += (c - 1) // 2

    ans2 = n-b+1
    c = a + ans2
    ans2 += (n - c) // 2
    print(min(ans1, ans2))

Solution (Python):
n,a,b=map(int,input().split())
if abs(a-b)%2==0:
  print(abs(a-b)//2)
else:
  if abs(n-max(a,b))<=abs(1-min(a,b)):
    print(abs(n-max(a,b))+1+abs(max(a,b)-min(a,b)-1)//2)
  else:
    print(abs(1-min(a,b))+1+abs(max(a,b)-min(a,b)-1)//2)

Solution (Python):
N,A,B=map(int,input().split())

if (A+B)%2==0:
  print(abs(A-B)//2)
else:
  left=min(A,B)+(abs(A-B)-1)//2
  right=N-max(A,B)+1+(abs(A-B)-1)//2
  print(min(left,right))

Solution (Python):
n, a, b = map(int, input().split())

if (b-a)%2 == 0:
    print((b-a)//2)
else:
    if (a-1) <= (n-b):
        print(a-1 + 1 +(b-a-1)//2)
    else:
        print(n-b + 1 +(b-a-1)//2)

Solution (Python):
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline

n, a, b = [int(item) for item in input().split()]
ans = 10**20

diff = abs(a - b)
if diff % 2 == 0:
    ans = diff // 2
    print(ans)
else:
    if a > b:
        a, b = b, a
    left = a
    left += (b - left) // 2
    right = n - b + 1
    right += (n - right - a) // 2
    print(min(left, right))

Solution (Python):
N,A,B = map(int,input().split())
if A%2 == B%2:
    print(int((abs(A-B))//2))
else:
    if A-1 < N-B :
        print(A + (B-A-1)//2)
    else:
        print(N-B+1 + (B-A-1)//2)

Solution (Python):
import sys

stdin = sys.stdin

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))  
rs = lambda: stdin.readline().rstrip()  

N, A, B = rl()
if (B-A)%2 == 0:
    answer = (B-A)//2
else:
    answer = min(A-1-(-(B-1-(A-1)))//2, N-B-(-(N-(A+(N-B)))//2))

print(answer)

Solution (Python):
N, A, B  = map(int, input().split())

diff = abs(A - B)

if diff % 2 == 0:
  print(diff//2)
else:
  L = min(A, B) + (max(A, B) - min(A, B) - 1) // 2
  R = N - max(A, B) + (max(A, B) - min(A, B) + 1) // 2
  print(min(L, R))

Solution (Python):
n, a, b = map(int, input().split())

if (b-a) % 2 == 0:
    print((b-a)//2)
else:
    print(min(n-a, b-1, (a-1) + 1 + (b-(a-1)-1-1)//2, (n-b) + 1 + (n-(a+n-b+1))//2))

Solution (Python):
N,A,B=map(int,input().split())
if (B-A)%2==0:
    print((B-A)//2)
else:
    print(min((B+A-1)//2,((2*N-B+1-A)//2)))

Solution (Python):
N,A,B = map(int,input().split())
if (B-A)%2 == 0:
  print((B-A)//2)
else:
  print(min(A+(B-A-1)//2,N-B+1+(N-(A+N-B+1))//2))

Solution (Python):
import sys
n, a, b = map(int, input().split())
x = b - a
if x % 2 == 0:
    print(int(x//2))
else:
    y = a-1
    z = n-b
    w = min(y, z)
    print(int((x+2*w+1)//2))

Solution (Python):
x=[]
n,a,b=map(int,input().split())
if (b-a)%2==0:
    print((b-a)//2)
else:
    c=(a-1)+(b-a+1)//2
    d=(n-b)+(b-a+1)//2
    print(min(c,d))

Solution (Python):
n, a, b = map(int,input().split())
ans = (b-a)//2
if (b-a)%2 == 1:
    ans = min((a + (b-a-1)//2),(n-b+1 +(b-a-1)//2))
print(ans)

Solution (Python):
n, a, b = [ int(v) for v in input().split() ]
if (a + b) % 2 == 0:
    print(abs(a-b)//2)
else:
    if a > b:
        a, b = b, a
    
    up = (b + a - 1) // 2
    down = (2 * n - b - a + 1) // 2
    print(min(up, down))

Solution (Python):
n,a,b = map(int,input().split())

def ceil(a, b):
   return a // b + (a % b > 0)

if (a - b) % 2 == 0:
   print((b-a) // 2)
else:
   x = a - 1
   y = n - b
   p1 = x + ceil(b-a, 2)
   p2 = y + ceil(b-a, 2)
   print(min(p1,p2))

Solution (Python):
n,a,b=map(int,input().split())
if (a-b)%2==0:
    print((b-a)//2)
else:
    print(min(a+(b-a-1)//2, n-b+1+(b-a-1)//2))

Solution (Python):
from collections import Counter,defaultdict,deque
import sys
import bisect
import math
import itertools
import string
import queue
import copy


from itertools import permutations, combinations
from heapq import heappop, heappush

sys.setrecursionlimit(10**8)
mod = 10**9+7
 
def inp(): 
    return int(input())
def inpm(): 
    return map(int,input().split())
def inpl(): 
    return list(map(int, input().split()))
def inpls(): 
    return list(input().split())
def inplm(n): 
    return list(int(input()) for _ in range(n))
def inpll(n): 
    return [list(map(int, input().split())) for _ in range(n)]

def main():

    n,a,b = inpm()
    x = b-a
    if x%2==0:
        print(int(x//2))
        return
    else:
        n1 = b-1
        n2 = n-a
        n3 = a+int( (b-a-1)//2 )
        n4 = n-b+1+int( (b-a-1)//2 )
        print(min(n1, n2, n3, n4))
        return

if __name__ == "__main__":
    main()

Solution (Python):
N, A, B = map(int, input().split())

if (B - A) % 2 == 0:
        print((B- A) // 2)
else:
        tmp = (B - A) // 2
        pattern1 = min((N - B), (A - 1)) + (B - A)
        B = B - tmp
        A = A + tmp
        pattern2 = min((N - B), (A - 1)) + (B - A)
        print(min(pattern1, pattern2))

Solution (Python):
N,A,B = map(int,input().split())

ans = 0
if (B-A)%2 == 0:
    ans = (B-A)//2
else:
    if (A-1)<(N-B):
        ans = A+(B-A-1)//2
    else:
        ans = (N-B+1) + (B-A-1)//2
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10**9)
INF=10**18
def input():
    return sys.stdin.readline().rstrip()

def main():
    N,A,B=map(int,input().split())
    if (A-B)%2==0:
        print(abs(A-B)//2)
    else:
        X=min(max(A,B)-1,N-min(A,B))
        c=min(min(A,B)-1,N-max(A,B))+1
        Y=c+(abs(A-B)-1)//2
        print(min(X,Y))

if __name__ == '__main__':
    main()

Solution (Python):
def main():
    n,a,b = map(int,input().split())
    a,b = sorted([a,b])
    if (a-b)%2==1:
        x = min([n-b,a-1])
        y = n-a
        if x == a-1:
            y = b-1
        print(abs(x+y+1)//2)
    else:
        print(abs(a-b)//2)
    
if __name__ == '__main__':
    main()

Solution (Python):
n, a, b = map(int, input().split())
if abs(a-b)%2==0:
  print(abs(a-b)//2)
else:
  m = min(a,b)
  M = max(a,b)
  if M - m == 1:
    if m-1 < n-M:
      print((M-1))
    else:
      print((n-m))
  else:
    if m-1 < n-M:
      print((m-1)+1+(M-m-1)//2)
    else:
      print((n-M)+1+(M-m-1)//2)

Solution (Python):
N,A,B = map(int,input().split())
x = B-A
if x%2==0:
  print(x//2)
  
else:
  x = min(max(A-1,B-1),max(N-A,N-B))
  y = N-B+1+(B-A-1)//2
  z = A+(B-A-1)//2
  print(min(x,y,z))

Solution (Python):
N, A, B = map(int, input().split())
if (B - A) & 1:
    res = (B - A - 1) // 2 + A
    A, B = N - B + 1, N - A + 1
    res = min(res, (B - A - 1) // 2 + A)
    print(res)
else:
    print((B - A) // 2)

Solution (Python):
import math
N,a,b=(int(x) for x in input().split())
if abs(a-b)%2==0:
    print(abs(a-b)//2)
else:
    c1=a-1+1+(b-a)//2
    c2=N-b+1+(b-a)//2
    print(min(c1,c2))

Solution (Python):
N, A, B = map(int, input().split())
if (B-A) % 2 == 0:
    print((B-A)//2)
else:
    print(min(max(A-1, B-1), max(N-A, N-B), min(A-1, N-B)+(B-A+1)//2))

Solution (Python):

MOD = 10 ** 9 + 7

import math

import itertools



def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default




def main():
    n,a,b=map(int,input().split())
    count=0
    if (b-a)%2==0:
        count=(b-a)//2
    else:
        if a-1<=n-b:
            count=(b-a-1)//2+a
        else:
            count=(b-a-1)//2+n-b+1

    print(count)









if __name__ == "__main__":
    main()

Solution (Python):
N, A, B = map(int, input().split())

if (B - A) % 2 == 0:
    print ((B - A) // 2)
    exit()

tmp1 = A - 1
b = B - tmp1
tmp1 += (b - 1) // 2

tmp2 = N - B
a = A + tmp2
tmp2 += (N - a) // 2

print (min(tmp1, tmp2) + 1)

Solution (Python):
N,A,B = map(int,input().split())
if (A-B)%2==0:
  print((B-A)//2)
  exit()
else:
  p = N - A
  q = B - 1
  r = A - 1
  s = N - B
  if p < q:
    print(s + 1 + (p-s-1)//2)
  elif p >= q:
    print(r + 1 + (q-r-1)//2)

Solution (Python):
def main():
    N, A, B = [int(i) for i in input().split()]
    diff = B - A
    if diff % 2 == 0:
        ans = diff // 2
    else:
        ans = min(B - 1, N - A, (A - 1) + 1 + (diff - 1) // 2, (N - B) + 1 + (diff - 1) // 2)
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
input = sys.stdin.readline


def main():
    N, A, B = [int(x) for x in input().split()]
    ans = (B - A) // 2
    if (B - A) % 2 == 1:
        ans1 = A - 1
        B1 = (B - ans1)
        ans1 = ans1 - (-(B1 - 1) // 2)
        ans2 = N - B
        A1 = (A + ans2)
        ans2 = ans2 - (-(N - A1) // 2)
        print(min(ans1, ans2))
    else:
        print(ans)





if __name__ == '__main__':
    main()

Solution (Python):
n,a,b=map(int,input().split())
c=b-a
if c%2==0:
  print(c//2)
else:
  if b-1<=n-a:
    print(a+((c-1)//2))
  else:
    print(n-b+1+((c-1)//2))

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n,a,b=LI()

  if abs(a-b)%2==0:
    return abs(a-b)//2

  x=y=1
  x+=a-1
  y+=n-b
  x+=(b-a-1)//2
  y+=(b-a-1)//2
  return min(n-a,b-1,x,y)


print(main())

Solution (Python):
N,A,B=map(int,input().split())
if (B-A)%2 == 0:
  print((B-A)//2)
else:
  ans=min((B-1),(N-A))
  if (B-1)<=(N-A):
    A2=1
    B2=B-(A-1)-1
    _ans=A-1+1
    _ans+=(B2-A2)//2
  else:
    B2=N
    A2=A+(N-B)+1
    _ans=N-B+1
    _ans+=(B2-A2)//2
  ans=min(ans,_ans)
  print(ans)

Solution (Python):
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines








def main():
	n,a,b=map(int,input().split())
	
	if (b-a)%2==0:
		print((b-a)//2)
	else:
		ma=max(a,b)
		mi=min(a,b)
		ko1=min(n-mi,ma-1)
		
		ko2=n-ma+1+(n-(mi+(n-ma+1)))//2
		ko3=mi-1+1+((ma-(mi-1+1))-1)//2
		
		print(min(ko1,ko2,ko3))
		
		
		
	
	
	
	
	
if __name__ == "__main__":
	main()

Solution (Python):
N,A,B=map(int,input().split())
if (A-B)%2==0:
  print(abs(A-B)//2)
else:
  optionA=min(N-A,B-1)
  optionB=abs(A-B-1)//2+min(N-B,A-1)
  print(min(optionA,optionB))

Solution (Python):
N, A, B = map(int, input().split())
diff = A - B
if diff % 2 == 0:
    print(abs(diff//2))
else:
    l = A - 1
    r = N - B
    if l < r:
        print((B - l - 2)//2 + l + 1)
    else:
        print((N - A - r - 1)//2 + r + 1)

Solution (Python):
N, A,B = map(int, input().split())

if (A-B)%2==0:
    print((B-A)//2)

else:
    a1=A-1
    aN=N-A
    b1=B-1
    bN=N-B
    a = min(a1,b1,aN,bN)
    print(a+1+(B-A)//2)

Solution (Python):
import sys

n, a, b = map(int, sys.stdin.readline().split())

def main(a, b):
    d = b - a
    if d % 2 == 0:
        return d // 2

    if n - b >= abs(1 - a):
        res = a
        b -= res
        a = 1
    else:
        res = n - b + 1
        a += res
        b = n

    res += (b - a) // 2
    return res

if __name__ == '__main__':
    ans = main(a, b)
    print(ans)

Solution (Python):
N,A,B=map(int,input().split())

minimum=min(A,B)
maximum=max(A,B)

a=max(A,B)-1
b=N-min(A,B)
c=(max(A,B)-min(A,B))//2+(max(A,B)-min(A,B))%2+min(min(A,B)-1,N-max(A,B))
d=(max(A,B)-min(A,B))//2

if((B-A)%2!=0):
    print(min(a,b,c))
else:
    print(min(a, b, c,d))

Solution (Python):
n,a,b=map(int,input().split())
if (a-b) % 2 == 0:
    ans0= (b-a) // 2
    print(ans0)
else:
    ans1=(a-1) + (b-a+1)//2
    ans2=(n-b) + (b-a+1)//2
    print(min(ans1,ans2))

Solution (Python):
N, A, B = map(int, input().split())

if A > B:
  A, B = B, A
  
D = B - A

if D % 2 == 0:
  print(D // 2)
  exit()
else:
  answer = (D - 1) // 2 + min(A, N - B + 1)
  print(answer)
  exit()

Solution (Python):
n, a, b = map(int, input().split())

if abs(a-b) % 2 == 0:
    print(abs(a-b)//2)

else:
    to_top = max(a-1, b-1)
    to_end = max(n-a, n-b)
    to_top_2 = min(a-1, b-1)
    to_end_2 = min(n-a, n-b)
    wait = min(to_top, to_end)
    go = min(to_top_2, to_end_2) + (b-a)//2 + 1
    print(min(wait, go))

Solution (Python):
n,a,b=map(int,input().split())

if (a-b)%2 ==0:
    print((b-a)//2)
else:
    cand1=max(n-a,n-b)
    cand2=max(a-1,b-1)
    cand_edge = min(cand1,cand2)
    
    cand_reflect_right = n-b+1+(b-a-1)//2
    cand_reflect_left  = a    +(b-a-1)//2
    
    print( min( cand_edge,cand_reflect_left,cand_reflect_right))

Solution (Python):
n,a,b = map(int,input().split())

if abs(a-b)%2==0:
    print(abs(a-b)//2)
else:
    memo = ((n-a)+(n-b+1))//2
    memo2 = ((a)+(b-1))//2
    memo3 = max(a-1,b-1)
    memo4 = max((n-a),(n-b))
    
    print(min(memo,memo2,memo3,memo4))

Solution (Python):
n,a,b=map(int,input().split())

if (b-a)%2==0:
  print((b-a)//2)
else:
  x=((n-b)+(n-a)+1)//2
  y=((b-1)+(a-1)+1)//2
  print(min(x,y))

Solution (Python):
N,A,B = map( int, input().split() )
C = B - A
if C % 2 == 0:
    print( C // 2 )
else:
    start = A - 1
    position_start = B - start - 1
    D = ( position_start - 1 ) // 2 + start + 1 
    
    last = N - B
    position_last = A + last + 1
    E = ( N - position_last ) // 2 + last + 1
    
    print(min(D,E))

Solution (Python):
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
import math
import time
import random
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def GI(V,E,Directed=False,index=0):
    org_inp=[]
    g=[[] for i in range(n)]
    for i in range(E):
        inp=LI()
        org_inp.append(inp)
        if index==0:
            inp[0]-=1
            inp[1]-=1
        if len(inp)==2:
            a,b=inp
            g[a].append(b)
            if not Directed:
                g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp
            aa=(inp[0],inp[2])
            bb=(inp[1],inp[2])
            g[a].append(bb)
            if not Directed:
                g[b].append(aa)
    return g,org_inp
def bit_combination(k,n=2):
    rt=[]
    for tb in range(n**k):
        s=[tb//(n**bt)%n for bt in range(k)]
        rt+=[s]
    return rt
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase
ts=time.time()

input=lambda: sys.stdin.readline().rstrip()

def ran_input():
    import random
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

show_flg=False
show_flg=True

n,a,b=LI()
if (a-b)%2==0:
    ans=abs(b-a)//2
else:
    ans=min(max(n-a,n-b),max(a-1,b-1),a+abs(b-a-1)//2,n-b+1+abs(a+n-b+1-n)//2)
    
print(ans)

Solution (Python):
n, a, b = map(int, input().split())

ans = float('inf')
if (b - a) % 2 == 0:
    ans = min(ans, (b - a) // 2)
else:
    ans = min(ans, b - 1)
    ans = min(ans, n - a)
    ans = min(ans, (b - a - 1) // 2 + n - b + 1)
    ans = min(ans, (b - a - 1) // 2 + a)
print(ans)

Solution (Python):
N, A, B = map(int, input().split())

if abs(A - B) % 2 == 0:
    print(abs(A - B) // 2)
else:
    print(min(A-1, N-B) + 1 + (B-A-1)//2)