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

Solution (Python):
def main():
    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+1-B+(B-A-1)//2))
if __name__ == '__main__':
    main()

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

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

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

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

if (B - A) % 2 == 0:
    print((B - A) // 2)
else:
    
    ans1 = 0
    ans1 += A - 1 + 1
    a = 1
    b = B - A
    ans1 += (b - a) // 2

    
    ans2 = 0
    ans2 += N - B + 1
    a = A + (N - B + 1)
    b = N
    ans2 += (b - a) // 2

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

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

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

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

Solution (Python):
import sys
import time
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N, A, B = map(int, readline().split())
    if (B-A)%2==0:
        ans = (B-A)//2
    else:
        left = A-1
        right = N-B
        if left<=right:
            l = left + 1
            ans = l + (B-l)//2
        else:
            r = right + 1
            ans = r + (N-(A+r))//2
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, a, b = map(int, input().split())
    ab = abs(a - b)
    if ab % 2 == 0:
        print(ab // 2)
    else:
        res1 = a + (ab - 1) // 2
        res2 = n - b + 1 + (ab - 1) // 2
        print(min(res1, res2))


if __name__ == '__main__':
    resolve()

Solution (Python):
from statistics import median


from fractions import gcd
from itertools import combinations 
from collections import deque
from collections import defaultdict
import bisect










import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n,a,b = readInts()
    ab = abs(a-b)
    if ab % 2 == 0:
        print(ab//2)
    else:
        print(min(a + (ab-1)//2, n - b + 1 + (ab-1)//2))

if __name__ == '__main__':
  main()

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

Solution (Python):
N,A,B = (int(x) for x in input().split())
if (B - A) % 2 == 0:
    print((B-A)//2)
else:
    if B - A == 1:
        if A == 1 or B == N:
            print('1')
        else:
            print('2')
    else:
        if A <= N-B:
            print((A+B-1)//2)
        else:
            print((2*N-A-B+1)//2)

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) + (b-a+1)//2
print (ans)

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

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

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

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

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

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

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

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

Solution (Python):
















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

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

print(ans)

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

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


def move_left():
	return A + (B-A-1)//2


def move_right():
	return  N - B + 1 + (B-A-1)//2	


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

if (B-A) % 2 == 0:
	print(int((B-A)//2))
else:
	l = move_left()
	r = move_right()
	print(min(l, r))

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

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

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

Solution (Python):
def myAnswer(N:int,A:int,B:int) -> int:
   ans = 0
   BN = N - B
   A1 = A - 1
   while True:
      if((B - A) % 2== 0):
         ans += (B - A)//2
         break
      elif(A == 1):
         ans += 1
         B -= 1
      elif(B == N):
         ans += 1
         A += 1
      else:
         if(BN > A1):
            ans +=A1
            B -= A1
            A = 1
         else:
            ans += BN
            A += BN
            B = N
   return ans

def modelAnswer():
   tmp=1
def main():
   N,A,B = map(int,input().split())
   print(myAnswer(N,A,B))
if __name__ == '__main__':
   main()

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

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

Solution (Python):
N, A, B = map(int, input().split())
if A % 2 == B % 2:
    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())
if (B-A)%2==0:
    print((B-A)//2)
else:
    tmp=A-1+(B-A+1)//2
    a=A+(N-B);b=N
    tmpp=N-B+(b-a+1)//2
    print(min(tmp,tmpp))

Solution (Python):

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

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

print(ans)

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
def MAP(): return map(int, input().split())

n, a, b = MAP()
print(abs(a - b) // 2 if not (a - b) % 2 else abs(a - b) // 2 + min(min(a, b) - 1, n - max(a, b)) + 1)

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = True

n, a, b = MAP()
print(abs(a - b) // 2 if not (a - b) % 2 else abs(a - b) // 2 + min(min(a, b) - 1, n - max(a, b)) + 1)

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = True

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

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

if __name__ == "__main__":
    n, a, b = map(int, input().split())
    print(solve(n, a, b))

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

print(ans)

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

print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

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


resolve()

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))
    exit()

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

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

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

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

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

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

Solution (Python):
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):
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    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))

if __name__=='__main__':
    main()

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

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

Solution (Python):



import sys
input = sys.stdin.readline

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

if __name__ == '__main__':
    main()

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

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

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

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

Solution (Python):
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n,a,b = iim()

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

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

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

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

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

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

Solution (Python):
N,A,B=map(int,input().split())
if (A+B)%2==0:
	P=(B-A)//2
else:
	P=float("inf")
if (A+B)%2==1:
	Q=A
	Q+=(B-Q-(B-Q+1)//2)
else:
	Q=float("inf")

if (A+B)%2==1:
	R=N-B+1
	B=N
	A+=R
	R+=B-(A+B)//2
else:
	R=float("inf")
print(min(P,Q,R))

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

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

Solution (Python):
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): 
    return list(map(int,input().split()))
def m(): 
    return map(int,input().split())
def onem(): 
    return int(input())
def s(x): 
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): 
    return " ".join(map(str,x))
def max2(x): 
    return max(map(max,x))
def In(x,a): 
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""


n,a,b = m()

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

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

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

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

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, A, B = MAP()

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

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, A, B = MAP()

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

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

Solution (Python):
N,A,B=map(int,input().split())
C=A
D=B
ans=0
a=abs(A-B)
if a%2==0:
    print(a//2)
else:
    nb=N-B
    ans+=nb
    A+=nb
    B=N
    A+=1
    ans+=1
    ab=abs(A-B)
    ans+=ab//2

    A=C
    B=D
    val=0
    na=A-1
    B=B-na
    A=1
    val+=na
    B=B-1
    
    val+=1
    na=abs(A-B)
    
    val+=na//2
    ans=min(ans,val)
    print(ans)

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

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

Solution (Python):

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

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

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

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

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

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

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

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

if (b - a) % 2 == 0:
	print((b - a) // 2)
elif (b - a) % 2 == 1:
	na = n - a
	nb = n - b
	a1 = a - 1
	b1 = b - 1
	if na + nb <= a1 + b1:
		print((na + nb + 1) // 2)
	else:
		print((a1 + b1 + 1) // 2)

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

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

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

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

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

Solution (Python):
i=raw_input()
N,A,B=i.split()

N = int(N)
A = int(A)
B = int(B)

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

Solution (Python):

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

in_string = raw_input()
[N, A, B] = [int(v) for v in in_string.split()]
match(N, A, B)

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

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

Solution (Python):
i = raw_input()
N, A, B = i.split()

N = int(N)
A = int(A)
B = int(B)

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

Solution (Python):
in_string = raw_input()
in_arr = in_string.split()
N = int(in_arr[0])
A = int(in_arr[1])
B = int(in_arr[2])

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

Solution (Python):
import sys

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

Solution (Python):

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

in_string = raw_input()
[N, A, B] = [int(v) for v in in_string.split()]
match(N, A, B)

Solution (Python):
import numpy as np

def min_steps_v2(n, a, b):
    n = np.int64(n)
    a = np.int64(a)
    b = np.int64(b)

    if (b - a) % 2 == 0:
        return np.int64(int(b - a) // 2)
 
    
    a_diff = a - 1
    b_diff = n - b
 
    if a_diff > b_diff:
      steps_to_even = n - b + 1
      remain_steps = min_steps_v2(n, a + (n - b) + 1, n)
    else:
      steps_to_even = a
      remain_steps = min_steps_v2(n, 1, b - a)
 
    return steps_to_even + remain_steps

numbers = input().split(' ')
 
n = int(numbers[0])
a = int(numbers[1])
b = int(numbers[2])
 
print(min_steps_v2(n, a, b))

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

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

Solution (Python):
strargs = input()

n, a, b = map(lambda x: int(x), strargs.split())

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

else:
  newA = (a + (n - b + 1))
  print((n - b + 1) + (n - newA)//2)

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

Solution (Python):

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

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

Solution (Python):
strargs = input()

n, a, b = map(lambda x: int(x), strargs.split())

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

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

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

Solution (Python):
n, a, b = map(int, input().split())
if (a%2 and b%2) or (a%2==0 and b%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
else:
    p = min(A - 1, N - B)
    ans = p + (((B - A) + 1) // 2)

print(ans)

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


d = B-A
if d%2 == 1:
    d = min((B + (N-B)*2 + 1) - A, B - (A - (A-1)*2 - 1))

ans = d//2
print(ans)

Solution (Python):
import sys
import math
import string
import fractions
import random
from operator import itemgetter
import itertools
from collections import deque
import copy
import heapq
from bisect import bisect, bisect_left, bisect_right

MOD = 10 ** 9 + 7
INF = float('inf')
input = lambda: sys.stdin.readline().strip()

sys.setrecursionlimit(10 ** 8)

N, A, B = map(int, input().split())
dis = B - A - 1
if dis % 2 == 0:
    print(min((N - max(A, B) + 1) + (N - min(A, B) - (N - max(A, B) + 1)) // 2,
          min(A, B) + ((max(A, B) - min(A, B) - 1) // 2)))
else:
    print((dis + 1) // 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) + (B-A + 1)//2

print(ans)