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

Solution (Python):
import fractions

def main():
    n, a, b = map(int, input().split())
    diff = b - a
    if diff%2 == 0:
        print(diff//2)
        return
    d1 = a + b - 1
    d2 = n - a + n - b + 1
    print(min(d1, d2)//2)

if __name__ == '__main__':
    main()

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


if __name__ == '__main__':
    solve()

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

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

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

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

Solution (Python):
n,a,b = (int(i) for i in 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):
n, a, b = map(int, input().split())
if (a-b) % 2 == 0:
    print((b-a)//2)
else:
    print(min(a+(b-a)//2, (n-b+1)+(b-a)//2))

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

l = max(a,b)
s = min(a,b)

if (l-s)%2 == 0:
  print((l-s)//2)
else:
  t = s - 1
  b = n - l
  pre = min(t,b)
  ans = pre + 1 + (l-s-1)//2
  print(ans)

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

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

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):

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):
n, a, b = map(int, input().split())


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

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

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


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

Solution (Python):
import math

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

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

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

Solution (Python):
inputLine = input().split(' ')
N = int(inputLine[0])
A = int(inputLine[1])
B = int(inputLine[2])

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

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

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

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

Solution (Python):
n,a,b = (int(i) for i in input().split())
s = b-a
if s % 2 == 0:
  print((b-a)//2)
  exit()
ans = min((a+(b-a-1)//2),(n-b+1+(b-a-1)//2))
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+B-1)//2, (2*N-A-B+1)//2))

Solution (Python):
def main():

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

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

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

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

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

if diff % 2 == 0:
    print(diff // 2)

else:
    n = (diff // 2) + 1 + min(N-B, A-1)
    print(n)

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

if dim % 2 == 0:
  print(int(dim//2))
elif dim % 2 == 1:
  dimAN = N - A
  dimBN = N - B
  dimB1 = B - 1
  dimA1 = A - 1
  
  result = min(dimA1,dimBN)+1+(dim-1) // 2
  print(result)

Solution (Python):
def A():
    temp = [int(n) for n in input().split()]
    N = temp[0]
    A = temp[1]
    B = temp[2]
    if abs(B-A)%2==0:
        print(abs(B-A)//2)
        return
    print(min(A+abs(B-A-1)//2, 
            (N-B+1)+abs(B-A-1)//2))

A()

Solution (Python):
import math
import queue
import bisect
import heapq
import time
import itertools

mod = int(1e9+7)

def swap(a,b):
    return (b,a)

def gcd(a,b): 
    if (a<b):
        a,b = swap(a,b)
    if (b==0):
        return a
    else:
        return gcd(b,a%b)

def lcm(a,b): 
    return a/gcd(a,b)*b

def divisors(a): 
    divisors = []
    for i in range(1,int(a**0.5)+1):
        if a%i==0:
            divisors.append(i)
            if i!=a//i:
                divisors.append(a//i)
    return divisors

def is_prime(a): 
    if a<2:
        return False
    elif a==2:
        return True
    elif a%2==0:
        return False
    sqrt_num = int(a**0.5)
    for i in range(3,sqrt_num+1,2):
        if a%i==0:
            return False
    return True

def prime_num(a): 
    pn = [2]
    for i in range(3,int(a**0.5),2):
        prime = True
        for j in pn:
            if i%j==0:
                prime = False
                break
        if prime:
            pn.append(i)
    return pn

def prime_fact(a): 
    sqrt = math.sqrt(a)
    res = []
    i = 2
    if is_prime(a):
        res.append(a)
    else:
        while a!=1:
            while a%i==0:
                res.append(i)
                a //= i
            i += 1
    return res

def main():
    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)
    return

if __name__=='__main__':
    main()

Solution (Python):
def is_even(num):
    return num % 2 == 0


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








is_even_a = is_even(A)
is_even_b = is_even(B)
if (is_even_a == True and is_even_b == True) or (
    is_even_a == False and is_even_b == False
):
    print((B - A) // 2)
else:
    print(min(A - 1, N - B) + 1 + ((B - A - 1) // 2))

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

Solution (Python):
import math

n, a, b = [int(i) for i in input().split()]

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

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

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

Solution (Python):
















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

def solve(n, a, b):
    m = b-a
    if m%2:
        return min(
            a     + solve(b-a, 1, b-a),
            n-b+1 + solve(n, a+(n-b+1), n),
        )
    else:
        return m//2

print(solve(N, A, B))

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

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

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

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

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

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

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

Solution (Python):
input_lines = input().split()
N = int(input_lines[0])
A = int(input_lines[1])
B = int(input_lines[2])

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

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

d=B-A

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

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

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


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

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

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

Solution (Python):



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

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

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

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

if (a-b)%2==0:
  print(abs(a-b)//2)
else:
  if (a+b)//2<=n//2:
    if abs(a-b)==1:
      print(min(a,b)-1+1)
    else:
      print(min(a,b)-1+1+(abs(a-b)-1)//2)
  else:
    if abs(a-b)==1:
      print(n-max(a,b)+1)
    else:
      print(n-max(a,b)+1+(abs(a-b)-1)//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:
        count = A
        A = 1
        B = B - count
        print((B-A) // 2 + count)
    else:
        count = (N-B+1)
        A = A + count
        B = N
        print((B-A) // 2 + count)

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

a, b = max(a, b), min(a, b)
d = a - b

if d % 2 == 0:
    ans = d // 2
    print(ans)
    exit()

count = 0
add = b-1
c = a - (add+1)
count += add+1
count += (c-1)//2
pat1 = count

count = 0
add = n-a
c = b + (add+1)
count += add + 1
count += (n-c)//2
pat2 = count

print(min(pat1, pat2))

Solution (Python):
import sys
input = sys.stdin.readline
N, A, B = map(int,input().split())




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


print(M1)

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

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

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

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

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


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

Solution (Python):
N, A, B = [int(n) for n 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())

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

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

Solution (Python):
N, A, B = map(int, input().split())
if (B - A) % 2 == 0:
    print((B - A) // 2)
else:
    print(min(A, N - B + 1) + (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] - 1) < (l[0] - l[2]):
        ans = l[2] - 1
    else:
        ans = l[0] - l[1]
else:
    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

print(ans)

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

Solution (Python):
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

n,a,b = MAP()

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

Solution (Python):
N,A,B = map(int,input().split())
 
if (A-B)%2 == 0:
  Ans=abs(A-B)//2
  print(Ans)
else:
  if N%2 == 0:
    N_center =N//2
    if abs(A-N_center) >= abs(B-N_center):
      
      if A >= N_center:
        
        A_reach = N - A
        B_reach = N - B
        B_nokori = B_reach - A_reach
        Ans = A_reach + 1 + (B_nokori - 1)//2
        print(Ans)
      else:
        
        A_reach = A - 1
        B_reach = B - 1
        B_nokori = B_reach - A_reach
        Ans = A_reach + 1 + (B_nokori - 1)//2
        print(Ans)
    else:
      
      if B >= N_center:
        
        A_reach = N - A
        B_reach = N - B
        A_nokori = A_reach - B_reach
        Ans = B_reach + 1 + (A_nokori - 1)//2
        print(Ans)
      else:
        
        A_reach = A - 1
        B_reach = B - 1
        A_nokori = A_reach - B_reach
        Ans = B_reach + 1 + (A_nokori - 1)//2
        print(Ans)
  else:
    N_center = N//2 + 1
    if abs(A-N_center) >= abs(B-N_center):
      
      if A >= N_center:
        
        A_reach = N - A
        B_reach = N - B
        B_nokori = B_reach - A_reach
        Ans = A_reach + 1 + (B_nokori - 1)//2
        print(Ans)
      else:
        
        A_reach = A - 1
        B_reach = B - 1
        B_nokori = B_reach - A_reach
        Ans = A_reach + 1 + (B_nokori - 1)//2
        print(Ans)
    else:
      
      if B >= N_center:
        
        A_reach = N - A
        B_reach = N - B
        A_nokori = A_reach - B_reach
        Ans = B_reach + 1 + (A_nokori - 1)//2
        print(Ans)
      else:
        
        A_reach = A - 1
        B_reach = B - 1
        A_nokori = A_reach - B_reach
        Ans = B_reach + 1 + (A_nokori - 1)//2
        print(Ans)

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

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

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

Solution (Python):
import sys

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

def main():
    d = b - a
    if d % 2 == 0:
        return d // 2
    else:
        return min(n - b, abs(1 - a)) + 1 + (d - 1) // 2

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

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

Solution (Python):
n,a,b=[int(j) for j in 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)

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

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

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

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

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

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

Solution (Python):
def wczytaj_liste(): 
    wczytana_lista = input()
    lista_znakow = wczytana_lista.split()
    ostateczna_lista = []
    for element in lista_znakow:
        ostateczna_lista.append(int(element))
    return ostateczna_lista

def table_tenis(): 
    N, A, B = wczytaj_liste()
    if (B-A)%2 == 0: 
        print ((B-A)//2)
    else: 
        if A - 1 <= N - B: 
            print(A+((B-A-1)//2))
        else: 
            print((N-B)+1+((B-A-1))//2)
            
table_tenis()

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 + 1)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

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

main()

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

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

print(ans)

Solution (Python):
X = input().split()
N = int(X[0])
A = int(X[1])
B = int(X[2])

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

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

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

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

v=b-(a+1)

if v%2==0:
    if a==1 or b==n:
        
        ans=(v-1)//2+1+1
    else:
        dif=min(n-b,a-1)
        
        ans1=dif+1+v//2
        if (n-b)<(a-1):
            ans2=n-a
        else:
            ans2=b-1
        
        ans=ans1
else:
    ans=(v+1)//2
print(ans)

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

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

ans = 10**20

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

print(ans)

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

ans = 10**20

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

print(ans)

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

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

def f(A, B):
  return (B - A) // 2

if (B - A) % 2 == 0:
    ans = f(A, B)
else:
    
    ans_a = A + f(1, B - A)
    
    ans_b = (N - B + 1) + f(A + N - B +1, N)
    
    
    ans = min(ans_a, ans_b)
    
print(ans)

Solution (Python):
n,a,b=map(int,input().split())
if a%2==b%2:
  print((b-a)//2)
else:
  print(min(n-b+1+(b-1-a)//2,a+(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((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())

if (A%2==0 and B%2==0) or (A%2==1 and B%2==1):
  print(int((B-A)//2))

elif (A-1)<=(N-B):
  print(int(A+(B-A-1)//2))

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

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

Solution (Python):
N, A, B = map(int, input().split())
M, m = max(A, B), min(A, B)

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

print(ans)

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

if (b - a) % 2 == 0:
    print(int(abs(a - b)//2))
elif (b - a) % 2 == 1:
    print(int(min([a, n - b + 1]) + (b - a - 1)//2))

Solution (Python):

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

dist = b-a

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

print(ans)

Solution (Python):



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

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

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

Solution (Python):
def upper_cnt(a, b):
    upper_cnt = n-b + 1
    a += upper_cnt
    upper_cnt += ((n-a) // 2)    
    return upper_cnt

def lower_cnt(a, b):
    lower_cnt = a-1 + 1
    b -= lower_cnt
    lower_cnt += ((b-1) // 2)
    return lower_cnt

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

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

else:
    up = upper_cnt(a, b)
    low = lower_cnt(a, b)
    print(min(up, low))

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

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

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

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

C = B-A

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

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

C = B-A

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

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

print(ans)

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

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

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

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

Solution (Python):
def main():
    N, A, B = map(int, input().split())
    
    sub = B - A

    left_s = A - 1
    right_s = N - B
        
    
    if sub % 2 == 0:
        return sub // 2
    
    else:
        return (min(left_s, right_s) + 1 + ((sub - 1)//2))
    
if __name__ == '__main__':
    print(main())

Solution (Python):

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

Lab = B-A
La = A-1
Lb = N-B

if Lab%2==0:
    
    ans = Lab//2
else:
    
    ans = min(La,Lb) + 1 + (Lab-1)//2
    
print(ans)

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

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

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

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

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

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

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

if (A + B) % 2 == 0:
    print((B - A)//2)
else:
    if (N - B) > (A - 1):
        print((B - A)//2 + A)
    else:
        print((B - 1 - A)//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) + 1 + (B-A) // 2)

Solution (Python):



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

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

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

    print(min([a, n - b + 1]) + (b - a - 1)//2)

Solution (Python):



n,a,b = map(int, input().split())
l = min(a, b)
r = max(a, b)
k = r - l
if k % 2 == 1:
    count = min(l - 1, n - r) + 1 + ((k - 1) // 2)
    print(int(count))
else:
    print(int(k // 2))

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

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

print(ans)

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

d = b - a

ans = 0

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

print(ans)

Solution (Python):

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

Lab = B-A
La = A-1
Lb = N-B

if Lab%2==0:
    
    ans = Lab//2
else:
    
    ans = min(La,Lb) + 1 + Lab//2

print(ans)

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

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

print(answer)

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):
import sys
from collections import deque


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

    if (B-A)%2==0:
        p1=(B-A)//2
        
        
        print(int(p1))
    else:
        
        """
        if B-1>N-A:
            bufA=N-B+1
            bufB=N-A+1
            A=bufA
            B=bufB
        """

        
            
        
        ans=min(A-1,N-B)+1+(B-A-1)//2
    
        print(int(ans))

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

from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """5 2 4"""
        output = """1"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """5 2 3"""
        output = """2"""
        self.assertIO(input, output)

if __name__ == "__main__":
    
    resolve()