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

Solution (Python):

import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

def ceil(x,y):
  return (x-1)//y+1
n,a,b=map(int,input().split())
if abs(b-a)%2==0:
    print(abs(b-a)//2)
else:
    if a>b: a,b=b,a
    s1=a
    b1=b-s1
    k1=(b1-1)//2+s1
    s2=n-b+1
    a2=a+s2
    k2=(n-a2)//2+s2
    print(min(k1,k2))

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

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

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

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

if judge % 2 == 0:
    print(judge//2)
    sys.exit()

d1 = n - max(a, b)
d2 = min(a, b) - 1
ans = min(d1, d2) + 1 + (judge-1)//2
print(ans)

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

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

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

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

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

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

ans = 0

sml = A
big = B

if (A-B) > 0:
    sml = B
    big = A

if (A - B) % 2 == 0:
    ans = (big - sml) // 2
else:
    s = sml - 1
    b = N - big

    if s > b:
        t = (big - sml) + (2*b) + 1
    else:
        t = (big - sml) + (2*s) + 1

    ans = t // 2

print(ans)

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

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

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

Solution (Python):

def updiv(x,y):

    if x % y == 0:
        return x // y
    else:
        return x // y + 1

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

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

else:
    ans = updiv(A+B-2 , 2)

    ans = min (ans , updiv(2 * N - A - B , 2))

    print (ans)

Solution (Python):

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

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

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

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

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

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

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

Solution (Python):
words = lambda t : list(map(t, input().split()))

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

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

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


main()

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

AdefB = B-A
if AdefB%2 == 0:
    print(AdefB//2)
else:
    Ato1=A-1
    BtoN=N-B
    Ato1Pattern=Ato1+1+((B-Ato1-1)//2)
    BtoNpattern=BtoN+1+((N-BtoN-A-1)//2)
    print(min(Ato1Pattern,BtoNpattern))

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

Solution (Python):
n, a, b = [int(_) for _ in 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):
import sys, math
def input():
    return sys.stdin.readline()[:-1]
from itertools import permutations, combinations
from collections import defaultdict

sys.setrecursionlimit(10**7)
N, A, B = map(int, input().split())


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

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

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

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

print(ans)

Solution (Python):
import sys
def input():
    return sys.stdin.readline()[:-1]
n,a,b=map(int,input().split())
if abs(a-b)%2==0:
    print(abs(a-b)//2)
else:
    tmp=min(max(a-1,b-1),max(n-a,n-b))
    tmp2=min(a+(b-a-1)//2,n-b+1+(b-a-1)//2)
    print(min(tmp,tmp2))

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

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

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

Solution (Python):





import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
 

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


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

else:
    r1 = 0
    r1 += a
    r1 += (b-a-1)//2
    
    r2 = 0
    r2 += n-b+1
    r2 += (b-a-1)//2

    print(min(r1,r2))

Solution (Python):
import math
import fractions

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 bitlist(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res




n,a,b = list(map(int, input().split()))
c = min(max(n-a,n-b),max(a-1,b-1))


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

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

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

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

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

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

else:
    print((B - A) // 2)

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

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

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

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

Solution (Python):
def ints():
  return [int(x) for x in input().split()]
def readi():
  return int(input())

def f(a, b):
  d = b-a
  if d%2==0:
    return d//2

  e = N-b
  g = a-1
  return min(e+1+f(a+e+1, N), g+1+f(1, b-g-1))

N, a, b = ints()
print(f(a, b))

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

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

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

def solve (N, A, B):
    if A == B:
        return 0
    diff = abs(A - B)
    if diff % 2 == 0:
        return diff // 2
    

    ans1 = solve2(N, A, B)
    ans2 = solve2(N, N - A + 1, N - B + 1)
    return min(ans1, ans2)

print(solve(N, A, B))

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

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

Solution (Python):

import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


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


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


N, A, B = read_ints()
sa = abs(A - B)
if sa % 2 == 0:
    print(sa // 2)
    exit()

to_haji = min(A - 1, N - B)
ans1 = to_haji + sa


ans2 = to_haji + 1 + (sa - 1) // 2
print(min(ans1, ans2))

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

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

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

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

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

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

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

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

    x = N - max(A, B) + 1
    y = min(A, B) + x
    ans2 = x + (N - y) // 2
    
    print(min(ans1, ans2))

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

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

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

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

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

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

if A>B:
  C=A
  A=B
  B=C
k=B-A

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

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

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

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

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

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

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, B-1, N-A, N-B) + 1 + diff // 2)

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

        print(ans)


main()

Solution (Python):
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]

n, a, b = ril()
if (a - b) % 2 == 0:
    print(abs(a - b) // 2)
else:
    print(min(a - 1, b - 1, n - a, 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)
else:
    tmp_a = a - (a - 1)
    tmp_b = b - (a - 1)
    ans = a - 1
    ans = ans + 1
    ans1 = ans + (tmp_b - tmp_a)//2
    
    tmp_a = a + (n - b)
    tmp_b = b + (n - b)
    ans = (n - b)
    ans = ans + 1
    tmp_a += 1
    ans2 = ans + (tmp_b - tmp_a)//2
    print(min(ans1, ans2))

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

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

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

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

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

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

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

print(ans)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,a,b = LI()
    if (b-a)&1 == 0:
        print((b-a)>>1)
    else:
        c,d = a,b
        k = a-1
        b -= a-1
        a = 1
        k += 1
        b -= 1
        k += (b-1) >> 1
        a,b = c,d
        l = n-b
        a += n-b
        b = n
        l += 1
        a += 1
        l += (n-a) >> 1
        print(min(k,l))
    return


if __name__ == "__main__":
    solve()

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

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

if (B-A) % 2 == 0:
    ans = (B-A) // 2
else:
    ans1 = A
    C, D = 1, B-ans1
    ans1 += (D-C) // 2

    ans2 = N-B+1
    C, D = A+ans2, N
    ans2 += (D-C) // 2

    ans = min(ans1, ans2)

print(ans)

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

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

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

diff = b - a
if diff % 2 == 0:
    out = diff // 2
else:
    diff1 = a - 1
    diff2 = n - b
    if diff1 <= diff2:
        out = a - 1 + 1
        a2 = 1
        b2 = b - a
    else:
        out = n -b + 1
        b2 = n
        a2 = a + (n-b+1)

    difff = (b2 - a2)
    assert difff % 2 == 0
    out += diff // 2

print(out)

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

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

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

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

main()

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

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

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

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

Solution (Python):

import sys


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




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

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

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

if B < A:
    A, B = B, A

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

a,b = sorted([a,b])
ans = a-1 + (b-a+1)//2

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

Solution (Python):

n, a, b = map(int, input().split())
if abs(a-b) % 2 == 0:
    ans = abs(a-b) // 2
else:
    x = min(a, b)
    y = max(a, b)
    c = (x + y - 1) // 2
    d = (2 * n - a - b + 1) //2
    ans = min(c, d)
print(ans)

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

if (b-a)%2==0:
    print(abs((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())
ans1,ans2=0,0
if (a-b)%2==0:print((b-a)//2)
else:
    ans1+=a
    tmpa=1
    tmpb=b-a
    ans1+=(tmpb-tmpa)//2

    ans2+=(n-b+1)
    tmpb=n
    tmpa=a+n-b
    ans2+=(tmpb-tmpa)//2
    print(min(ans1,ans2))

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

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

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

Solution (Python):
def examA():
    N, A, B = LI()
    ans = inf
    if abs(A-B)%2==0:
        ans = abs(A-B)//2
    cur = min((A+B-1)//2,(2*N-A-B+1)//2)
    ans = min(ans,cur)
    print(ans)
    return

def examB():
    return

def examC():
    return

def examD():
    return

def examE():
    return

def examF():
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,inf
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examA()

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

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

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

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

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

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

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

else:
    ans = (b - a) // 2

print(ans)

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

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

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

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 (a-b) % 2 == 0:
  print(abs(a-b)//2)
else:
  can = []
  can.append(((a-1)+(b-1))//2+1)
  can.append(((n-a)+(n-b))//2+1)
  print(min(can))

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7 
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n,a,b=map(int,input().split())
    if((a+b)%2==0):
        print(abs(b-a)//2)
        return

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

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

    print(ans)
resolve()

Solution (Python):



def ri():
    return int(input())

def rl():
    return list(input().split())

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

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

if __name__ == '__main__':
    main()

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

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

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

Solution (Python):











import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,hypot,log 
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N,A,B=MI()
    if (A-B)&1:
        if A<B:
            A,B=B,A
        if N-B<A-1:
            ans = N-B+1
            ans += (B-A)//2
        else:
            ans = A-1+1
            ans += (B-A)//2
        print(ans)
    else:
        print(abs(A-B)//2)
if __name__ == '__main__':
    main()

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

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

Solution (Python):
import sys

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

    return 0

if __name__ == "__main__":
    solve()

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):
def solve(n, a, b):
    if a > b:
        a, b = b, a
    if (b - a) % 2 == 0:
        return (b - a) // 2
    top = (b + a - 1) // 2
    c, d = n - a - 1, n - b + 1
    boo = (c + d + 1) // 2
    return min(top, boo)


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

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 = list(map(int, input().split()))

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