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 a == b:
    print(0)
    exit()
if abs(a-b)%2 == 0:
    print(abs(a-b)//2)
    exit()
if a < b:
    l,r = b-1,n-a
    ans = min(l,r)
    if ans == l:
        b = b-(a-1)
        if b%2==1:
            print(a-1+(b-1)//2)
        else:
            print(a-1+(b-1)//2+1)
    else:
        a = a+(n-b)
        if abs(n-a)%2==0:
            print(n-b+abs(n-a)//2)
        else:
            print(n-b+abs(n-a)//2+1)
else:
    l,r = a-1,n-b
    ans = min(l,r)
    if ans == l:
        a = a-(b-1)
        if a%2==1:
            print(b-1+(a-1)//2)
        else:
            print(b-1+(a-1)//2+1)
    else:
        b = b+(n-a)
        if abs(n-b)%2==0:
            print(n-a+abs(n-b)//2)
        else:
            print(n-a+abs(n-b)//2+1)

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

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

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

print(int(ans))

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

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

Solution (Python):


def pattern1(N, A, B):
  left = B - 1
  right= N - A
  if left < right:
    return left
  else:
    return right  
      
def pattern2(N, A, B):
  round_elapsed_mid = (A - 1) + 1
  B_position = B - round_elapsed_mid
  offset = B_position - 1
  if offset % 2 == 0:
    return (offset // 2 + round_elapsed_mid)
  
def pattern3(N, A, B):
  round_elapsed_mid = (N - B) + 1
  A_position = A + round_elapsed_mid
  offset = N - A_position
  if offset % 2 == 0:
    return (offset // 2 + round_elapsed_mid)

N, A, B = (int(n) for n in input().split())
offset = B - A
if offset % 2 == 0:
  print(offset // 2)
else:
  candi1 = pattern1(N, A, B)
  candi2 = pattern2(N, A, B)
  candi3 = pattern3(N, A, B)
  print(min([candi1, candi2, candi3]))

Solution (Python):


def resolve():
    N, A, B = map(int, input().rstrip().split())

    diff = B - A

    a = []
    if diff % 2 == 0:
        a.append(diff//2)

    a.append(diff//2 + A-1 + 1)
    a.append(diff//2 + N -B + 1)

    print(min(*a))

if __name__ == "__main__":
    resolve()

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

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

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

Solution (Python):
n, a, b = [int(x) for x in input().split(' ')]

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

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

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

ans = []
if abs(a-b) % 2 == 0:
    ans.append(abs(a-b) // 2)
x = abs(1 - max(a,b))
y = abs(n - min(a,b))
ans.append(min(x, y))

x = abs(1 - min(a,b)) + 1
y = abs(max(a,b) - x)
if abs(1-y) % 2 == 0:
    ans.append(abs(1-y) // 2 + x)

x = abs(n - max(a,b)) + 1
y = abs(min(a,b) + x)
if abs(n-y) % 2 == 0:
    ans.append(abs(n-y) // 2 + x)

print(min(ans))

Solution (Python):
import sys
from pprint import pprint

def solve(n, a, b):
    ans = 0
    if (b - a) % 2 == 0:
        ans = (b - a) // 2
    else:
        
        simple = min(b - 1, n - a)

        
        mix_a = a + (b - a) // 2
        mix_b = n - b + 1 + (b - a - 1) // 2
        ans = min(simple, mix_a, mix_b)

    print(ans)

if __name__ == '__main__':
    n, a, b = map(int, sys.stdin.readline().strip().split(" "))
    solve(n, a, b)

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

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

ans = 0

if abs(A-B)%2 == 0:
    ans = abs(A-B)//2
elif (A-1)>(N-B):
    ans = N-B+1+(B-A-1)//2
else:
    A = N-A+1
    B = N-B
    ans = N-B+1+(B-A-1)//2

print(int(ans))

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

if (B - A) % 2 == 0:
    print((B - A) // 2)
else:
    print(1 + min(A - 1, N - B) + (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:
    edge = min([N-A, B-1])
    a_change = A  + (B- A-1)//2
    b_change = N-B+1 +(N-(A + (N-B+1)))//2
    print(min([edge, a_change, b_change]))

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

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

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

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

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

print(answer)

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

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) + 1 + (B-A-1)//2)

Solution (Python):
x = [int(i) for i in input().split()]
n = x[0]
a = x[1]
b = x[2]
if (b - a) % 2 == 0:
    ans = b - (a + b) // 2
else:
    if a - 1 <= n - b:
        tmp = b - a
        ans = tmp - (1 + tmp) // 2 + a
        if b - 1 <= a:
            ans = b - 1
    else:
        tmp = a + n - b + 1
        ans = n - (n + tmp) // 2 + (n - b + 1)
        if n - a <= n - b + 1:
            ans = n - a
print(ans)

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

Solution (Python):
n = input()    
m = n.split()
p = [int(i) for i in m]
a = p[2] -p[1]
if a % 2 == 0:
    print(int(a//2))
else:
    A = (a-1)//2 + min(p[1]-1,p[0]-p[2]) + 1
    print(A)

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

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

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



print(ans)

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

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

Solution (Python):

import math
N,a, b =list(map(int,input().split(" ")))
case1 = 10 ** 20 
case2 = 10 ** 20 
case3 = 10 ** 20 

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

else:


    step = (a-1)
    
    step = step + 1 
    case1 = step +   (  ((b - step)  - 1 ) //2   )


    
    step = (N - b)
    step = step + 1  

    case2 = step+  (   ( N - (a + step) )//2 )



print(min([case1,case2,case3]))

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

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

Solution (Python):
def main():

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

    if abs(a-b) % 2 == 0:
        print(abs(a-b)//2)
        return
    left=0
    temp = max(a,b)
    left = temp - 1
    right = 0
    temp = min(a,b)
    right = n - temp
    ans = min(left,right)

    tempR=b-a
    mid1=10**19
    if tempR-1>0:
        mid1=(tempR-1)//2 + a
    tempL=a+n-b+1
    mid2=10**19
    if n-tempL > 0:
        mid2=(n-tempL)//2 + n-b+1
    ans = min(ans,mid1,mid2)


    print(ans)
    return
if __name__=='__main__':
    main()

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

Solution (Python):
N,A,B = map(int,input().split())
dis_Start = A-1
dis_End = N-B

if A%2 == B%2:
    
    print((B-A)//2)
elif dis_Start <= dis_End:
    
    print(A+((B-A)//2))
else:
    
    print((N-B+1)+((B-A)//2))

Solution (Python):


''' 
------------------------
author : iiou16
------------------------
'''

def main():
    N, A, B = list(map(int, input().split()))

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


if __name__ == '__main__':
    main()

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

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

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

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

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

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

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

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

Solution (Python):

def solve(n, a, b):
    if a > b:
        a, b = b, a
    if (b - a) % 2 == 0:
        return (b - a) // 2
    else:
        l = a + ((b - a) - 1) // 2
        r = (n - b + 1) + (n - (a + (n - b + 1))) // 2
        return min(l, r)
print(solve(*map(int, input().split())))

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

if a>b: a,b=b,a

ans = 0
x=0

d = b-a
if d%2==1:

	if a-1 < n-b:
		x = a-1
		ans+=x+1
		a = 1
		b = b-ans
	else:
		x = n-b
		ans+=x+1
		b = n
		a = a+ans

d = abs(b-a)

ans += d//2
print(ans)

Solution (Python):


n,a,b=map(int,input().split())
if a%2==b%2:
    print((b-a)//2)
else:
    left=a-1
    right=n-b
    if left<right:
        b-=1
        print(a-1+(b-a)//2+1)
    else:
        a+=1
        print(n-b+(b-a)//2+1)

Solution (Python):
N, A, B = [int(i) for i in input().split()]

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


l = A - 1
r = N - B

c = min(l, r)

res = c+1
d = abs(B-A)-1

res += d // 2

print(res)

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

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

Solution (Python):
import sys
import math
import bisect
import re

def solve(n, a, b):
    if a > b:
        a, b = (b, a)
    if (b - a) % 2 == 0:
        return (b - a) // 2
    if a == 1:
        return 1 + solve(n, a, b - 1)
    if b == n:
        return 1 + solve(n, a + 1, b)
    delta = b - a
    val1 = (a - 1) + solve(n, 1, 1 + delta)
    val2 = (n - b) + solve(n, n - delta, n)
    return min(val1, val2)

def main():
    n, a, b = map(int, input().split())
    ans = solve(n, a, b)
    print(ans)

if __name__ == "__main__":
    main()

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

Solution (Python):
if __name__ == "__main__":
  N, A, B = map(int, input().split())
  
  if( (B-A) % 2 == 0 ):
    print( (B-A)//2 )
  elif(N-B < A-1):
    cnt = N-B+1
    A += 1
    print( cnt + (B-A)//2 )
  else:
    cnt = A
    B -= 1
    print( cnt + (B-A)//2 )

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

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

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

l = list(map(int, input().split()))

ans = 0
if not abs(l[1] - l[2]) % 2:
    ans = abs(l[1] - l[2]) // 2
elif abs(l[1] - l[2]) == 1:
    if l[1] < l[2]:
        if (l[1] - 1) < (l[0] - l[2]):
            ans = l[2] - 1
        else:
            ans = l[0] - l[1]
    else:
        if (l[2] - 1) < (l[0] - l[1]):
            ans = l[1] - 1
        else:
            ans = l[0] - l[2]
else:
    if l[1] < l[2]:
        if (l[1] - 1) < (l[0] - l[2]):
            ans = l[1] + (l[2] - l[1] - 1) // 2
        else:
            ans = l[0] - l[2] + 1 + (l[2] - l[1] - 1) // 2
    else:
        if (l[2] - 1) < (l[0] - l[1]):
            ans = l[2] + (l[1] - l[2] - 1) // 2
        else:
            ans = l[0] - l[1] + 1 + (l[1] - l[2] - 1) // 2

print(ans)

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

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

s = (b - a) // 2

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

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

Solution (Python):



def solve(*args: str) -> str:
    n, a, b = map(int, args[0].split())

    ret = min(max(a-1, b-1), max(n-a, n-b))

    if (b-a) % 2:
        if a-1 < n-b:
            sup = a
            ret = min(ret, sup+((b-sup-1)//2))
        else:
            sup = n-b+1
            ret = min(ret, sup+((n-a-sup)//2))
    else:
        ret = min(ret, (b-a)//2)

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

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

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

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

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+(b-a)//2)
    else:
        b=n-b+1
        a=n-a+1
        print(a+(b-a)//2)

Solution (Python):
def main():
    N, A, B = (int(i) for i in input().split())
    if (B - A) % 2 == 0:
        print((B-A)//2)
    else:
        cur = min(B-1, N-A)
        if A - 1 >= N - B:
            cur2 = (N - B)*2 + 1
            A += (N - B)*2 + 1
            cur2 += (B-A)//2
            print(min(cur, cur2))
        else:
            cur2 = (A - 1)*2 + 1
            B -= (A - 1)*2 + 1
            cur2 += (B-A)//2
            print(min(cur, cur2))


if __name__ == '__main__':
    main()

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

else:
    ans = (b-a)//2

print(ans)

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

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

Solution (Python):
import math
import sys

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

IFN = 10 ** 19 
if (A - B) % 2 == 0:
    P1 = abs(A-B) // 2
else: 
    P1 = IFN

P2  = ((A-1) + (B-1) + 1) // 2
P3  = ((N-A) + (N-B) + 1) // 2
print(min(P1,P2,P3))

Solution (Python):

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

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

print(ans)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

n, a, b = map(int, readline().split())
ans = n + 1
if (b - a) % 2 == 0:
    ans = min(ans, (b - a) // 2)
ans = min(b -1, ans)
ans = min(n - a, ans)
ans = min((n-b) + 1 + (n - (a+(n-b) +1))// 2, ans)
ans = min((a-1) + 1 + ((b - 1 - (a-1)) - 1) // 2, ans)



print(ans)

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

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

t = float('inf')
if abs(A - B) % 2 == 0:
    t = min(abs(A - B) // 2, t)
t = min(B - 1, t)
t = min(N - A, t)
t = min((A - 1 + 1) + (B - A - 1) // 2, t)
t = min((N - B + 1) + (N - (A + (N - B + 1))) // 2, t)
print(t)

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

diff = b - a

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

Solution (Python):

import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 1.0e+100

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A, B):
    if (B - A) % 2 == 0:
        C = (B - A) // 2
        D = INF
    else:
        C = (B - A) // 2 + A
        D = (B - A) // 2 + (N-B + 1)

    return min(C, D)


def main():
    N, A, B = read_int_n()
    print(slv(N, A, B))


if __name__ == '__main__':
    main()

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

print(ans)

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)
    ans = min(ans,(B-A+1)//2+(A-1))
    A,B = N-B+1,N-A+1
    ans = min(ans,(B-A+1)//2+(A-1))
    print(ans)

Solution (Python):

import sys


def solve(N: int, A: int, B: int):
    if (B-A)%2 == 0:
        between = (B-A)//2
        print(between)

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

        print(answer)

    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:
    print(min(b-1,n-a,(b-a)//2))
else:
    ans=min(b-1,n-a,(b-a)//2+a,-(-(n-a-(n-b))//2)+(n-b))
    print(ans)

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

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

Solution (Python):
import math
def com(n, a, b):
    
    if (abs(a-b) % 2) == 1:
        oneToA = a-1
        oneToB = b-1
        endToA = n-a
        endToB = n-b
        print(min((oneToA+oneToB+1)//2, (endToA+endToB+1)//2))
    else:
        print((abs(a-b)//2))

def main():
    n ,a,b = map(int, input().split())
    
    
    
    com(n, a, b)


if __name__ == "__main__":
    main()

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

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

Solution (Python):
import numpy as np
def main():
    NAB = [np.int64(i) for i in input().split(" ")]
    N = NAB[0]
    A = NAB[1]
    B = NAB[2]
    ans = 0

    if abs(A - B) % 2 == 0:
        ans += abs(A - B) // 2
        ans = np.int64(ans)
    else:
        if A - 1 <= N - B:
            if (B - 1) >= (A - 1) + 1:
                ans += (((B - 1) - (A - 1)) // 2) + A
            else:
                ans += B - 1
        else:
            if (B - 1) >= (A - 1) + 1:
                ans += (((N - A) - (N - B)) // 2) + N - B + 1
            else:
                ans += N - A
    print(ans)
 
if __name__ == '__main__':
    main()

Solution (Python):
temp = list(map(int,input().split()))
n = temp[0]
a = temp[1]
b = temp[2]

if a >= b:
  big = a
  small = b
else:
  big = b
  small = a

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

Solution (Python):
n, a, b = map(int, input().split())
if abs(a - b) % 2:
    te = [a - 1, b - 1]
    te.sort()
    rem = te[1] - te[0] + 1
    cand1 = te[0] + rem // 2

    te = [n - a, n - b]
    te.sort()
    rem = te[1] - te[0] + 1
    cand2 = te[0] + rem // 2
    print(min(cand1, cand2))
else:
    print(abs(a-b)//2)

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

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

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

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

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

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

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

if a%2==b%2:
  print((b-a)//2)
  exit()
  
c=b-(b-a+1)//2
d=(2*n-b+a+1)//2-a
print(min(c,d))

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

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

Solution (Python):
def test(N, A, B, E):
    assert solve(N, A, B) == E, "solve(%d, %d, %d) == %d" % (N, A, B, E)

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

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

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

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

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


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




if __name__ == '__main__':
    main()

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

Solution (Python):
import sys
temp=list(map(int, input().split()))
N=temp[0]
A=temp[1]
B=temp[2]
cnt=0
if (B-A)%2==1:
  if A-1<=N-B:
    cnt=A
    B-=A
    A=1
  else:
    cnt=N-B+1
    A+=(N-B)+1
    B=N
if A!=B:
  cnt+=(B-A)//2
print(cnt)

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

if abs(A - B) % 2 == 0:
    print(abs(A - B) // 2)
else:
    ans_1 = [min(N - min(A, B), max(A, B) - 1)]
    go_hasi_and_tame = min(A - 1, N - B) + 1
    ans_1.append(abs(1 - B - go_hasi_and_tame) // 2)
    ans_1.append(abs(N - (A - go_hasi_and_tame)) // 2)

    print(min(ans_1))

Solution (Python):
import sys
import math
import time

start = time.time()
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

n, a, b = na()

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

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

diff = abs(a-b)

if (diff%2 == 0):
    print(diff//2)
else:
    kouho = min(max(n-a,n-b),max(a-1,b-1))
    suku = min(n-a,n-b,a-1,b-1)
    kazu = (diff-1) //2
    print(min(kouho,suku+kazu+1))

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

Solution (Python):






from sys import stdin,setrecursionlimit










setrecursionlimit(10**6)
input=stdin.readline

def f(s,t):
    if (t-s)%2==0:
        return (t-s)//2
    else:
        return (t-s-1)//2+1
n,a,b=map(int,input().split())

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

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

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

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

    else:
        c += A-1
        c += 1
        c += (B-A-1)//2
        print(c)

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

D = B - A

ans = float('inf')
if D % 2 == 0:
    ans = D//2
else:
    
    move = A - 1
    L = 1
    R = B - move
    D = R - L
    if D % 2 == 0:
        ans = min(ans, D//2 + move)
    else:
        ans = min(ans, D//2+1 + move)
    
    move = N - B
    L = A + move
    R = N
    D = R - L
    if D % 2 == 0:
        ans = min(ans, D//2 + move)
    else:
        ans = min(ans, D//2+1 + move)

print(ans)