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

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

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

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

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

Solution (Python):



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

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

    print(ans)

if __name__ == "__main__":
    main()

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

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

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

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

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

ans1=0; ans2=0
ans1+= a
aa=0 ; bb=b-a 
ans1+= (bb//2+1)

ans2=n-1-b 
b=n-1
a+=ans2
ans2+= (b-a)//2+1

print(min(ans1,ans2))

Solution (Python):
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n, a, b = LI()
    a, b = min(a,b), max(a,b)
    ans = 0
    if (b-a)%2 == 0:
        ans = (b-a)//2
    else:
        ans = min(a+(b-a-1)//2, n-b+1+(n-(a+n-b+1))//2)
    print(ans)
main()

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

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

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

if __name__ == "__main__":
    solve()

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

if __name__ == "__main__":
    solve()

Solution (Python):




def resolve():
    import sys
    input = sys.stdin.readline

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

    if a > n - b + 1:
        tmp = a
        a = n - b
        b = n - tmp
    else:
        a = a - 1
        b = b - 1

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



if __name__ == "__main__":
    resolve()

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

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

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

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

print(ans)

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

Solution (Python):
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())


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

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

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

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

p = b-a-1

if p%2==0:
    ans=0
    if a <=n-b:
        k = a-1
        a-=k
        b-=(k+1)
        ans+=k+1
    else:
        k = n-b
        a+=(k+1)
        b+=k
        ans += k+1
    p=b-a-1

    print(ans + (p+1)//2)
else:
    print((p+1)//2)

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

Solution (Python):
import math

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

sa = B - A + 1;

if sa % 2 == 1 :
	ans = min(N - A, B - 1);
	
	ans = min(ans, (B - A) // 2)

	print(ans)
else :
	ans = 10**30;

	
	ca = A
	cb = B

	ca = 1;
	cb -= A;

	cand = (cb - ca) // 2 + A;
	ans = min(ans, cand);

	
	ca = A
	cb = B
	cb = N;
	ca += N - B + 1;
	cand = (cb - ca) // 2 + (N - B + 1);

	ans = min(ans, cand);


	print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(1 << 25)
readline = sys.stdin.buffer.readline
read = sys.stdin.readline  
ra = range
enu = enumerate


def exit(*argv, **kwarg):
    print(*argv, **kwarg)
    sys.exit()


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))



def a_int(): return int(readline())


def ints(): return list(map(int, readline().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) 
    ret = []
    for _ in range(H):
        ret.append(list(map(int, readline().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, readline().split())))
    return ret


def read_matrix(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, readline().split())))
    return ret
    


MOD = 10**9 + 7
INF = 2**31  

from collections import defaultdict, Counter, deque
from operator import itemgetter, xor, add
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  
from functools import reduce
from math import gcd


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




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

Solution (Python):
'''
Created on 2020/09/03

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  
  N,A,B=map(int,pin().split())
  if (B-A)%2==0:
    print((B-A)//2)
    return 
  if A<N-B+1:
    print(A+(B-A-1)//2)
  else:
    print(N-B+1+(B-A-1)//2)
  return 
main()

Solution (Python):
import sys

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

Solution (Python):
import sys


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


N, A, B = LI()
if (B-A) % 2 == 0:
    print((B-A)//2)
    sys.exit()
a = 1
b = B-A
L = A+(b-a)//2
b = N
R = N-B+1
a = A+R
R += (b-a)//2
print(min(R, L))

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


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

else:
    
    left = ((a - 1) + (b - 1) + 1) // 2

    
    right = ((n - b) + (n - a) + 1) // 2

    print(min(left, right))

Solution (Python):
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  
def LS2(): return list(sys.stdin.readline().rstrip())  


N,A,B = MI()

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

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

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

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

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


if __name__ == "__main__":
    main()

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

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


if __name__ == "__main__":
    main()

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

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

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

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

Solution (Python):
n,a,b=map(int,input().split())
if b<a:b,a=a,b
ans=float("inf")
if abs(a-b)%2==0:print(abs(a-b)//2)

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

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

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

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

Solution (Python):



from fractions import gcd
from itertools import combinations,permutations,accumulate, product 

from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect














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


from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
  return int(readline())
n,a,b = readInts()
ab = abs(b-a)
if ab%2 == 0:
    print(ab//2)
else:
    print(min(a-1, n-b) + 1 + (b-a-1)//2)

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

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

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

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

Solution (Python):

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

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

if a < b:
  a,b = b,a

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

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

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

ans = 0

def odd():
    global ans
    ans += (B - A) // 2

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

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

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

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

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

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




def RD(): return input().rstrip().decode()
def II(): return int(input())
def FI(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))


import bisect

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

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

	else:
		if b<a:
			a,b=b,a
		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(abs(A - B) // 2)
else:
    A_top = A - 1
    B_top = B - 1
    top = (
        B_top + (A - B_top - 1) // 2 if A_top > B_top else A_top + (B - A_top - 1) // 2
    )

    A_btm = N - A
    B_btm = N - B
    btm = (
        B_btm + (N - A - B_btm) // 2 if A_btm > B_btm else A_btm + (N - B - A_btm) // 2
    )
    print(min(top, btm) + 1)

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

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

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

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

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

Solution (Python):
import sys
input = sys.stdin.readline
 
 
def main():
    n,a,b = [int(i) for i in input().strip().split()]
    if (b-a) % 2 == 0:
        print(abs(b - a) // 2)
    else:
        ans = min(a - 1, n - b) + 1 + (b - a - 1) // 2
        print(ans)
    return 
 
 
 
if __name__ == "__main__":
    main()

Solution (Python):



from fractions import gcd
from itertools import combinations,permutations,accumulate, product 

from collections import deque,defaultdict,Counter
import decimal
import re












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

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

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

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

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

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

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

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inl = lambda: [int(x) for x in sys.stdin.readline().split()]
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))


def solve():
    n, a, b = inl()
    if (b - a) % 2 == 0:
        return (b - a) // 2

    k = min(a - 1, n - b)
    return k + 1 + (b - a) // 2


print(solve())

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

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

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

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

print(ans)

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

if(b < a):
    swap(a, b)

ans = -1
if a%2 == b%2:
    ans = (b - a) // 2

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

print(ans)

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

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

print(ans)

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

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

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

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

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

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

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

margin = abs(a-b)

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

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

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

print(ans)

Solution (Python):



from fractions import gcd
from itertools import combinations,permutations,accumulate 

from collections import deque,defaultdict,Counter
import decimal
import re












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

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

Solution (Python):
import sys
input = sys.stdin.readline
 
 
def main():
    n,a,b = [int(i) for i in input().strip().split()]
    if (b-a) % 2 == 0:
        print(abs(b - a) // 2)
    else:
        ans = min(a - 1, n - b) + 1 + (b - a - 1) // 2
        print(ans)
    return 
 
 
 
if __name__ == "__main__":
    main()

Solution (Python):




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


sa = abs(b - a)

if sa % 2 == 0:
    ans = sa // 2
else:
    
    bgr = n - b + 1
    bgra = a + bgr
    rans = (n - bgra) // 2 + bgr
    
    
    agl = a - 1 + 1
    aglb = b - agl
    lans = (aglb - 1) // 2 + agl
    ans = min(rans, lans)


print(ans)

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

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

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

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

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inl = lambda: [int(x) for x in sys.stdin.readline().split()]
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))


def solve():
    n, a, b = inl()
    if a > b:
        a, b = b, a
    if (b - a) % 2 == 0:
        return (b - a) // 2

    d1 = a - 1
    d2 = n - b
    if d1 < d2:
        return d1 + 1 + (b - a) // 2
    else:
        return d2 + 1 + (b - a) // 2


print(solve())

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

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

adiff = min( abs(a-1), abs(n-a) )
bdiff = min( abs(b-1), abs(n-b) )
mdiff = min(adiff,bdiff)

ans = mdiff + 1 + diff//2
print(ans)

Solution (Python):
import math

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

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

else:

    t1 = A - 1
    t2 = B - 1
    t3 = N - A
    t4 = N - B

    t = min(t1, t2, t3, t4)

    res = t + 1 + (abs(A - B) - 1) // 2
    
    print(res)

Solution (Python):



def f(A,B,n) :
    judge=B-A

    if judge%2==0 :
        n+=judge//2
        return(n)

    else :
        if abs(A-1) < abs(N-B) :
            if A==1 :
                A=A
                B-=1
                n+=1
            else:
                B-=A-1
                n+=A-1
                A-=A-1
            return f(A,B,n)
        else :
            if B==N :
                B=B
                A+=1
                n+=1
            else :
                A+=abs(N-B)
                n+=abs(N-B)
                B+=abs(N-B)
            return f(A,B,n)

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

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

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

print(ans)

Solution (Python):
def is_even(num):
    if num % 2 == 0:
        return True
    else:
        return False


n, a, b = map(int, input().split())
tables = [n] * 2
if is_even(a) and is_even(b):
    print(abs(a - b) // 2)
elif not is_even(a) and not is_even(b):
    print(abs(a - b) // 2)
else:
    print(min(abs(1 - a), abs(b - n)) + 1 + (b - a - 1) // 2)

Solution (Python):
import collections
import sys
import numpy as np
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
MOD = 10**9+7
import itertools
import math

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

if a%2 == b%2:
    print((b-a)//2)
    sys.exit()
else:
    c = min(a-1,n-b) + 1
    ans = c + (b-a-1)//2
    print(ans)
    sys.exit()

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

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

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

Solution (Python):
import math
import sys
import bisect
readline = sys.stdin.readline


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


if __name__ == '__main__':
    main()

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

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

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

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

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

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

Solution (Python):

import sys
input=sys.stdin.readline

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

if __name__=="__main__":
    main()

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


def main():
    n,a,b = [int(i) for i in input().strip().split()]
    if (b-a) % 2 == 0:
        print(abs(b - a) // 2)
    else:
        ans = min(a - 1, n - b) + 1 + (b - a - 1) // 2
        print(ans)
    return 



if __name__ == "__main__":
    main()

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

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

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

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

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