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

Solution (Python):
N,A,B = [int(i) for i in input().split()]
if A%2 == B%2:
    print(abs(A - B) // 2)
    exit()

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

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

Solution (Python):
import math
n, a, b = [int(w) for w in input().split()]
if (a + b) % 2 == 0:
    ans = (b - a) // 2
else:
    ans = min(a - 1, n - b)
    ans += 1 + (b - a) // 2
print(ans)

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

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

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

Solution (Python):
import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))


n,a,b = readints()

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

Solution (Python):

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

Solution (Python):
def main():
    n,a,b=map(int,input().split())
    di = 0
    if (b-a)%2==1:
        w = a-1
        l = n-b
        di = (w - l)
        if di < 0:
            di = -w-1
        else:
            di = l+1
        a += di
        if a < 1:
            a = 1
        b += di
        if b > n:
            b = n
    
    print((b-a)//2 + abs(di))
    
if __name__ == "__main__":
    main()

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

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

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

Solution (Python):
import sys
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

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


if __name__ == '__main__':
    main()

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

Solution (Python):
import sys
import itertools

import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines



MOD = 10 ** 4 + 7

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

if (B - A) % 2 == 0:
    print((B - A) // 2)
else:
    
    ans = []
    l = (A - 1)
    r = B - l - 1
    x = l + 1 + (r - 1) // 2
    ans.append(x)
    r = (N - B)
    l = A + r + 1
    x = r + 1 + (N - l) // 2
    ans.append(x)
    print(min(ans))

Solution (Python):
import sys
import itertools

import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines



MOD = 10 ** 4 + 7

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(_) for _ in input().split()]

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

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

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

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

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




lm = A + (B-A-1)//2;


rm = N-B+1 + (B-A-1)//2;

if (B-A)%2 == 0 :
    print((B-A)//2);
else :
    print(min(lm,rm));

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

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

        cnt1 = 0
        cnt2 = 0
        for i in range(0, (min(n-a, b-1))):
            if (b-(a-1) - i) % 2 == 0 and cnt1 == 0:
                temp.append(a - 1 + i + (b-(a-1) - i) // 2)
                cnt1 += 1
            elif (n - (a+(n-b)+i)) % 2 == 0 and cnt2 == 0:
                temp.append(n - b + i + (n - (a+(n-b)+i)) // 2)
                cnt2 += 1

            if cnt1 == 1 and cnt2 == 1:
                break

        print(min(temp))

if __name__ == "__main__":
    main()

Solution (Python):
import sys

def I(): 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 main():
    n, a, b = MI()
    d = b - a
    ans = 0
    if d%2:
        temp = min(a-1, n-b)
        ans = (d-1)//2 + temp + 1
    else:
        ans = d//2
    print(ans)

if __name__ == '__main__':
    main()

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

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

Solution (Python):
import sys
n, a, b = map(int, sys.stdin.readline().split())
c = b - a
if c % 2:
  d = min(a - 1, n - b)
  e = 1
  f = (b - a - 1) // 2
  print(d + e + f)
else:
  print(c // 2)

Solution (Python):
import math

def solve(n,a,b):
  diff = b - a
  if diff % 2 == 0:
    return (diff + 1) // 2
  
  
  root_a = a
  
  root_a += diff // 2
  
  root_b = n - b + 1
  
  root_b += diff // 2
  
  return min(root_a, root_b)

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

Solution (Python):
from collections import defaultdict

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

n,a,b = readInts()

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

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

Solution (Python):

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

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

resolve()

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

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

df = abs(A - B)
dA = A - 1
dB = N - B
ans = 0

if df % 2 == 0:
    ans = int(df // 2)
    print(ans)
else:
    if dA > dB:
        
        ans += dB + 1 + ((B-A) // 2)
        print(ans)
    else:
        ans += dA + 1 + ((B-A) // 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(min(A, B) + abs(A - B) // 2, N - max(A, B) + 1 + abs(A - B) //2))

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

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

    top = N-A
    bottom = B-1
    ans = min(A-1, N-B) + 1 + (B-A-1)//2

print(ans)

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


resolve()

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

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

dif = abs(A-B)
if dif%2 == 0:
    ans = dif//2
else:
    
    t0 = A - 1 + 1
    xa = 0
    xb = B - t0
    dif = abs(xb - xa)
    ans1 = dif//2 + t0
    
    
    t0 = B - 1 + 1
    xa = A - t0
    xb = 0
    dif = abs(xb - xa)
    ans2 = dif//2 + t0
    
    
    t0 = N - A + 1
    xa = N
    xb = B + t0
    dif = abs(xb - xa)
    ans3 = dif//2 + t0
    
    
    t0 = N - B + 1
    xa = A + t0
    xb = N
    dif = abs(xb - xa)
    ans4 = dif//2 + t0
    
    ans = min(ans1, ans2, ans3, ans4)
    
print(ans)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
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
from decimal import *

N, A, B = MAP()

if (A-B-1)%2:
	print((B-A)//2)

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

Solution (Python):


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

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

if __name__ == '__main__':
    main()

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

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

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

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

Solution (Python):
N, *AB = [int(x) for x in input().split()]
A, B = sorted(AB)
if (B - A) % 2 == 0:
    ans = (B - A) // 2
else:
    ans = (B - A + 2 * min(N - B, A - 1) + 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:
  temp=min(min(a-1,b-1),min(n-a,n-b))+1  
  print(min(temp+(abs(a-b)-1)//2,min(max(a-1,b-1),max(n-a,n-b))))

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

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

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

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

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

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

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

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

Solution (Python):


















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

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

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

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

Solution (Python):

import sys


def solve(N: int, A: int, B: int):
    if A > B:
        tmp = A
        A = B
        B = tmp
    
    count = 0
    while True:
        if (B - A) % 2 == 0:
            count += (B - A) // 2
            break
        elif A != 1 and B != N:
            if A-1 < N-B:
                count += A-1
                B = B - (A-1)
                A = 1


            else:
                count += N-B
                A = A + (N-B)
                B = N
        else:
            if A == 1:
                count += 1
                B -= 1
                
            elif B == N:
                count += 1
                A += 1
    print(count)
    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):






import sys
input = sys.stdin.readline

import math

import bisect
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache






MOD = 10**9+7
INF = float('inf')






def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]


def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()


def DD(arg): return defaultdict(arg)



def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr


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


def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


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


def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count


def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))


def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count





N,A,B = IL()

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

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


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

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

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

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

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

print(int(ans))

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

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

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

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

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

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

result = 0

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

print(int(result))

Solution (Python):
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline



def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    n, a, b = geta(int)

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


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

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
N,A,B=map(int,input().split())
if (B-A)%2:
    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())
dif1 = abs(a-b)

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

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

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

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

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

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

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

print(d)

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+1,a+b-1)//2)

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

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

Solution (Python):

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


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

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

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

ab = B - A

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

Solution (Python):

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

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

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

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

Solution (Python):
import sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N,A,B = LI()
if (A+B)%2==0:
    ans = (B-A)//2
else:
    count_move = min(A-1,N-B)
    ans = count_move+1
    ans += (B-A-1)//2
print(ans)

Solution (Python):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


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

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

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

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 6)

int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def printlist(lst, k='\n'): print(k.join(list(map(str, lst))))
INF = float('inf')

from math import ceil

def solve():
    n, a, b = MI()
    
    

    left = max(a-1, b-1)
    right = max(n-a, n-b)

    center = INF
    sa = abs(b - a)
    if a % 2 == b % 2:
        center = sa // 2
    else:
        t = min(a-1, n-b)
        center = t + (sa-1) // 2 + 1
    
    print(min([left, right, center]))


if __name__ == '__main__':
    solve()

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

Solution (Python):

N, A, B = map(int,input().split(" "))
ans = 0
diff = abs(A-B)

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

print(ans)

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


if __name__ == '__main__':
  main()

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

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

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

Solution (Python):
N,A,B = map(int,input().split())
a = min(A,B)
b = max(A,B)
d = b - a




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

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

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

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

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

r = 0
to_wall_a = a - 1
to_wall_b = n - b

if to_wall_a <= to_wall_b:
    a = 1
    b -= to_wall_a
    r += to_wall_a

    b -= 1
    r += 1

    r += (b - a) // 2
else:
    b = n
    a += to_wall_b
    r += to_wall_b

    a += 1
    r += 1

    r += (b - a) // 2
print(r)

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

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce, lru_cache  
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return (int(x) for x in input().split())
def LI(): return list(Is())
def TI(): return tuple(Is())
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(S())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18



n, a, b = Is()
if (a + b) % 2 == 0:
    print((b-a)//2)
else:
    print(min(n-b, 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)+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 = list(map(int,input().split()))
if (B-A)%2 == 0:
    print((B-A)//2)
    exit()
A1 = A
B1 = B
A2 = A
B2 = B
count1 = N-B1
ans1 = 0
A1 += (N-B1)
B1 = N
if (B1-A1)%2 == 0:
    ans1 = count1+(B1-A1)//2
else:
    ans1 = count1+1+(B1-A1)//2

count2 = A2-1
ans2 = 0
B2 -= (A2-1)
A2 = 1
if (B2-A2)%2 == 0:
    ans2 = count2+(B2-A2)//2
else:
    ans2 = count2+1+(B2-A2)//2
print(min(ans1,ans2))

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

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


if __name__ == '__main__':
    main()