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

import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def sign(n):
        if n == 0:
            return 0
        if n < 0:
            return -1
        return 1

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


class PriorityQueue:
    def __init__(self, l=[]):
        self.__q = l
        heapq.heapify(self.__q)
        return

    def push(self, n):
        heapq.heappush(self.__q, n)
        return

    def pop(self):
        return heapq.heappop(self.__q)


MOD = int(1e09) + 7
INF = int(1e15)


def calc(N):
    return sum(int(x) for x in str(N))


def main():
    
    N, A, B = Scanner.map_int()
    if A % 2 == B % 2:
        print((B - A) // 2)
    else:
        t1 = A + (B - A) // 2
        t2 = (N - B) + 1 + (N - (A + (N - B + 1))) // 2
        print(min(t1, t2))

    return


if __name__ == "__main__":
    main()

Solution (Python):
import numpy as np
N,A,B = map(int,input().split())
x=abs(A-B)
    

if x%2==0:
    print(x//2)
else:
    y,z=max(N-A,N-B),max(A-1,B-1)
    a,b=min(A-1,B-1),min(N-A,N-B)
    c,d=max(A-1,B-1)-a,max(N-A,N-B)-b
    e,f=c//2+a+1,d//2+b+1
    if y>z:
        print(min(z,e,f))
    else:
        print(min(y,e,f))

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

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

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


if __name__ == "__main__":
    main()

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

print(ans)

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

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

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

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

import sys
input = sys.stdin.buffer.readline


from collections import defaultdict

con = 10 ** 9 + 7

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


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


if __name__ == '__main__':
	main()

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

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

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

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

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

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

if __name__ == '__main__':
    main()

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

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

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

diff = abs(A - B)

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

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

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

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

TableTennis()

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

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

def F(n,a,b):
    
    if (b-a)%2==0:
        return (b-a)//2
    
    tmp = []
    
    x = (a-1)+(b-1)+1
    tmp.append(x//2)
    
    x = (n-a)+(n-b)+1
    tmp.append(x//2)
    return min(tmp)

print(F(n,a,b))

Solution (Python):


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

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

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

k = b-a
if k %2 == 0:
    print(k//2)
else:
    p = a-1
    bb = b-(a-1)

    p += 1
    bb -= 1
    
    res = p + (bb-1)//2


    p = n-b
    aa = a+(n-b)

    p += 1
    aa += 1

    res = min(res,p + (n-aa)//2)
    print(res)

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

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

check = abs(a-b)

if check%2 == 0:
    print(check//2)
    exit()

temp1 = min(max(a,b) - 1, n - min(a,b))
temp2 = min(min(a,b) - 1, n - max(a,b))
ans = min(temp1, temp2 + 1 + (check)//2)

print(ans)

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

Solution (Python):
N, A, B = tuple(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:
    C=min(N+1-B,N+1-A)
    D=max(N+1-B,N+1-A)
    print(min(A + (B-A-1)//2,C + (D-C-1)//2))

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

result = (abs(a-b)//2)
if (a-b)%2==1:
    
    dist = min(a-1,b-1,n-a,n-b)
    result += dist + 1

print (result)

Solution (Python):
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
sys.setrecursionlimit(10**9)
def gcd(a,b):return fractions.gcd(a,b) 
def lcm(a,b):return (a*b) // fractions.gcd(a,b) 
def iin(): return int(input()) 
def isn(): return input().split() 
def imn(): return map(int, input().split()) 
def iln(): return list(map(int, input().split())) 
def iln_s(): return sorted(iln()) 
def iln_r(): return sorted(iln(), reverse=True) 
def join(l, s=''): return s.join(l) 
def perm(l, n): return itertools.permutations(l, n) 
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) 
def comb(l, n): return itertools.combinations(l, n) 
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) 
def 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 is_prime(n):
    if n == 1: return False
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0: return False 
    return True
def primes(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n + 1, i): is_prime[j] = False
    return [i for i in range(n+1) if is_prime[i]]
def sieve_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

N,A,B = imn()

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

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

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

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

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

Solution (Python):
import sys
n, a, b = [int(i) - 1 for i in sys.stdin.readline().split()]
if (a - b) % 2 == 0:
    print((b - a) // 2)
else:
    if n - b > a:
        print(a + 1 + (b - a - 1) // 2)
    else:
        print(n - b + 1 + (b - a - 1) // 2)

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

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

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

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

from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10


def solve():
    n, a, b = LI()
    if a & 1 == b & 1:
        print((b - a) // 2)
    else:
        print(min((b - a + 1) // 2 + a - 1, ((n - a) - (n - b) + 1) // 2 + n - b))
    return



if __name__ == '__main__':
    solve()

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

print(ans)

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

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

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n,a,b = LI()
    if a % 2 == b % 2:
        return abs(a-b) // 2
    t = a + (b-a) // 2
    c = n - b + 1
    d = n - a + 1
    u = c + (d-c) // 2

    return min(t,u)


print(main())

Solution (Python):


import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, X, Y = MAP()


X, Y = min(X, Y), max(X, Y)

if X % 2 == Y % 2:
    ans = abs(X - Y) // 2

else:
    cnt1 = abs(X - 1) + 1
    Y1 = Y - cnt1
    cnt2 = abs(Y - N) + 1
    X2 = X + cnt2
    ans = min(cnt1 + abs(1 - Y1) // 2, cnt2 + abs(N - X2) // 2)
print(ans)

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

Solution (Python):

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


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

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

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

t = B - A

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

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

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

Solution (Python):
from sys import stdin
import sys
import numpy as np
import collections
from functools import cmp_to_key


def rsa(sep = ''):
    if sep == '' :
        return input().split() 
    else: return input().split(sep)
def rip(sep = ''):
    if sep == '' :
        return map(int, input().split()) 
    else: return map(int, input().split(sep))
def ria(sep = ''): 
    return list(rip(sep))
def ri(): return int(input())
def rd(): return float(input())
def rs(): return input()

def main():
    N, A, B = rip()
    if (B - A) % 2 == 0:
        print((B - A) // 2)
    else :
        a = A
        b = B
        l = 0
        l += a - 1
        b -= a - 1
        a -= a - 1
        l += 1
        b -= 1
        l += (b - a) // 2
        
        a = A
        b = B
        r = 0
        r += N - b
        a += N - b
        b += N - b
        r += 1
        a += 1
        r += (b - a) // 2
        print(min(l, r))




if __name__ == "__main__":
    main()

Solution (Python):
def solve(n, a, b):
    if (a-b) % 2 == 0:
        return (abs(a-b)+1) // 2
    else:
        s = min(n-a, n-b) + 1
        x = s + solve(n, min(a+s, n), min(b+s, n))
        t = min(a, b)
        y = t + solve(n, max(a-t, 1), max(b-t, 1))
        return min(x, y)

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

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

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

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

center = abs(a-b) // 2

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

Solution (Python):
import sys
import math

def resolve():
    stdin = sys.stdin
    mod = 10**9 + 7
    ns = lambda: stdin.readline().rstrip()
    ni = lambda: int(ns())
    na = lambda: list(map(int, stdin.readline().split()))
    sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

    n, a, b = na()

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

if __name__ == "__main__":
    resolve()

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

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

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

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

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

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

if (b-a) % 2 == 0:
	ans = (b-a) // 2
else:
	ans_2_1 = b-1
	ans_2_2 = n-a

	if b-a == 1:
		ans = min(ans_2_1, ans_2_2)
	else:


		ans_3_1 = (a-1) + 1 + (b-a+1-1-1)//2
		ans_3_2 = (n-b) + 1 + (n-(a+n-b+1))//2

		ans = min(ans_2_1,ans_2_2,ans_3_1,ans_3_2)

print(ans)

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

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

Solution (Python):
def main(N, A, B):
    if abs(A - B) % 2 == 0:
        return abs(A - B) // 2
    A, B = min(A, B), max(A, B)
    res1 = A+(B-A-1)//2

    A, B = N - B + 1, N - A + 1
    res2 = A+(B-A-1)//2
    return min(res1, res2)


if __name__ == "__main__":
    N, A, B = map(int, input().split())
    ans = main(N, A, B)
    print(ans)

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

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

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

Solution (Python):
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, a, b = list(map(int, readline().split()))
    if (b - a) % 2 == 0:
        print((b - a) // 2)
    else:
        print(min(a - 1, n - b) + (b - a - 1) // 2 + 1)


if __name__ == '__main__':
    solve()

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

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

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

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:
    ans = abs(A-B)//2
else:
    d1 = min(A, B) - 1
    r1 = max(A, B) - d1 - 1
    a1 = (r1-1)//2 + 1 + d1

    d2 = N- max(A, B)
    r2 = min(A, B) + d2 + 1
    a2 = (N - r2)//2 + 1 + d2
    ans = min(a1, a2)

print(ans)

Solution (Python):
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))



N,A,B = II()

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

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

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

if A % 2 == B % 2 :
  ret = abs(B - A) // 2

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

print(ret)

Solution (Python):
from sys import stdin

n,a,b = [int(x) for x in stdin.readline().rstrip().split()]

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

Solution (Python):
import sys

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

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

Solution (Python):
n,a,b = map(int,input().split())
x = b-a
if x%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 defaultdict, deque
import bisect
from heapq import *
from math import factorial
sys.setrecursionlimit(200000)
input = sys.stdin.readline

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







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

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

print(a)

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=[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:
  a, b = b, a;
r = b-a
if r%2==0:
  print(r//2)
else:
  r = (b-a-1)//2
  res = min(a-1, n-b) + r+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 (A - B)% 2 == 0:
    print((B - A) // 2)
else:


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

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

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

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

Solution (Python):



def main():
    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 + (b - a - 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:
    r1 = a-1 + 1 + (b-a)//2
    r2 = n-b + 1 + (b-a)//2
    print(min(r1,r2))

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

dif = b-a

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

Solution (Python):
import sys
import math
from collections import deque
MAX_INT = int(10e15)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N, A, B = IL()

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

Solution (Python):


import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

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

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

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

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

ans = 0

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

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

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

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

Solution (Python):
def IsOdd(n):
    return n & 1

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

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

Solution (Python):
def IsEven(n):
    return n % 2 == 0

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

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