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
from random import choice,randint
inp=sys.stdin.readline
out=sys.stdout.write
flsh=sys.stdout.flush
 
sys.setrecursionlimit(10**9)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
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 MI(): return map(int, inp().strip().split())
def LI(): return list(map(int, inp().strip().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines().strip()]
def LI_(): return [int(x)-1 for x in inp().strip().split()]
def LF(): return [float(x) for x in inp().strip().split()]
def LS(): return inp().strip().split()
def I(): return int(inp().strip())
def F(): return float(inp().strip())
def S(): return inp().strip()
def pf(s): return out(s+'\n')
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=MI()
    
    
    if (b-a)%2==0:
        pf(str((b-a)//2))
    elif a==1 or b==n:
        pf(str((b-a+1)//2))
    else:
        mn = min(a-1,n-b)
        ans = (b-a+(mn*2)+1)//2
        ans = min([ans,n-a,b-1])
        pf(str(ans))

if __name__ == "__main__":
    main()

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

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

result = 10 ** 19

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

print(result)

Solution (Python):
import numpy as np
from decimal import Decimal

N, A, B = map(Decimal, input().split())
ab_max = np.amax(np.array([A, B]))
ab_min = np.amin(np.array([A, B]))

if (A - B) % 2 == 0:
    print(int((ab_max - ab_min) / 2))
else:
    print(int(np.amin([ab_min - 1, N - ab_max]) + (ab_max - ab_min + 1) / 2))

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

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

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

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

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

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

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

Solution (Python):


import sys
import math


debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        
        
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    (n, a, b) = [int(e) for e in lines[0].split(" ")]

    return (n, a, b)

def solve(n, a, b):
 

    c = b - a 
    d = c // 2
    result1 = 0
    if c % 2 == 0:
        result_p = min([b-1, n-a, d])
    else:
        result_p = min([b-1, n-a])

    game_count_1 = a - 1
    a_idx = 1
    b_idx = b - game_count_1
    dist = b_idx - a_idx
    result_q = 0
    if dist % 2 == 0:
        game_count_2 = dist // 2
        result_q = game_count_1 + game_count_2 
    else:
        dist = (b_idx - 1) - a_idx
        game_count_2 = dist // 2
        result_q = game_count_1 + 1 + game_count_2 


    game_count_3 = n - b
    a_idx = a + game_count_3
    b_idx = n
    dist = b_idx - a_idx
    result_r = 0
    if dist % 2 == 0:
        game_count_4 = dist // 2
        result_r = game_count_3 + game_count_4
    else:
        dist = b_idx - (a_idx + 1)
        game_count_4 = dist // 2
        result_r = game_count_3 + 1 + game_count_4



    result = min([result_p, result_q, result_r])

    return result

def main():
    
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r, sep='')
    else:
        print("%s" % result, sep='')

if __name__ == '__main__':

    main()

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

result = 0

if A == B:
    print(0)
    exit()

if A > B:
    A, B = B, A

if abs(A - B) % 2 != 0:
    a1 = N - A if N - A < A else A - 1
    b1 = N - B if N - B < B else B - 1
    if a1 < b1:
        B -= A
        result += A
        A = 1
    else:
        A += b1 + 1
        result += b1 + 1
        B = N

if A != B:
    result += abs(A - B) // 2

print(result)

Solution (Python):
import sys
input=sys.stdin.readline
n,a,b=map(int,input().split())
d=b-a
if d%2==0:
    ans=d//2
    print(ans)
else:
    if b-1<=n-a:
        ans=(a+b-1)//2
    else:
        ans=(2*n-a-b+1)//2
    print(ans)

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

Solution (Python):



test = ""

"""
5 2 4
ans 1
"""

"""
5 2 3
ans 2
"""

"""
5 3 4
ans 2
"""

"""
7 2 5
ans 3, not 4 
"""

test = list(reversed(test.strip().splitlines()))
if test:
    def input2():
        return test.pop()
else:
    def input2():
        return input()

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

def roundup(n, d):
    if n % d:
        return n // d + 1
    else:
        return n // d


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

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

Solution (Python):
n,a,b=list(map(int,input().split()))
p=min(a,b)
q=max(a,b)
sum=q-p
if(sum%2==0):
    print(int(sum//2))
else:
    k=n-q
    r=p-1
    s=min(k,r)
    t=q
    v=p
    ans=0
    ans=ans+s
    if(s==r):
        t=t-s
        if(t!=1):
            ans=ans+1
            t=t-1
            u=t-1
            ans=ans+u//2
    else:
        v=v+s
        if(v!=n):
            ans=ans+1
            v=v+1
            h=n-v
            ans=ans+h//2
    print(ans)

Solution (Python):
s=raw_input().split()
[N, A, B] = s
N = int(N)
A = int(A)
B = int(B)

def halfdist(x,y):
    return (y-x)/2

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

Solution (Python):
from decimal import *

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

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

print(ans)

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

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

print(min(disA, disB, disC))

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

diff = B - A

_a, mod = divmod(diff, 2)

is_diff_even = (mod == 0)

if is_diff_even:
    print(diff // 2)
else:
    left = A
    right = B

    
    if (left - 1) < (N - right):
        print((left - 1) + 1 + ((right - ((left - 1) + 1) - 1) // 2))
    else:
        
        print((N - right) + 1 + ((N - (left + (N-right+1))) // 2))

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

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

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

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

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def gcd(a, b):
  if a < b:
      a, b = b, a
  while a % b != 0:
      a, b = b, a % b
  return b
 

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



N, A, B = MAP()

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

else:
  
  
  
  if A - 1 <= N - B:
    
    
    s = A - 1
    
    b = B - (A - 1) - 1

    ans = s + (b + 1) // 2
    
  else:
    s = N - B
    a = N - (A + s) + 1
    ans = s +  a // 2
    
    
  print(ans)

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

if (b-a) % 2 == 0:
    
    print((b-a) // 2)
    sys.exit()
else:
    if a+1 == b:
        print(min([b-1, n-a]))
    else:
        diff = b - a
        a += diff // 2
        b -= diff // 2
        print(min([b-1, n-a]))

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

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

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

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

Solution (Python):
s=list(map(int,input().split()))
if (s[2]-s[1])%2==0:
  print(int((s[2]-s[1])//2))
else:
  if s[2]-1>=s[0]-s[1]:
    if (s[2]-s[1]-1)//2+s[0]-s[2]+1>s[0]-s[1]:
      print(s[0]-s[1])
    else:
      print(int((s[2]-s[1]-1)//2+s[0]-s[2]+1))
  else:
    if (s[2]-s[1]-1)//2+s[1]>s[2]-1:
      print(s[2]-1)
    else:
      print(int((s[2]-s[1]-1)//2+s[1]))

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

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

Solution (Python):
def solve(n, a, b):
    if (b - a) % 2 == 0:
        return (b - a) // 2
    else:
        
        case_1 = a + (b - a - 1) // 2
        
        case_2 = (n - b + 1) + (b - a - 1) // 2
        return min(case_1, case_2)


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


def test():
    assert solve(5, 2, 4) == 1
    assert solve(5, 2, 3) == 2


if __name__ == "__main__":
    test()
    main()

Solution (Python):
def even(d):
    return d // 2

def odd(A, B, N):
    if abs(A-1) > abs(B-N):
        dist2edge = abs(B-N)
        A += dist2edge
        B += dist2edge 

        return even(abs((A+1)- B)) + 1 + dist2edge

    else:
        dist2edge = abs(A - 1)
        A -= dist2edge
        B -= dist2edge
    
        return even(abs(A- (B-1))) + 1 + dist2edge


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

    if diff % 2 == 0:
        print(even(diff))
    else:
        print(odd(A, B, N))

if __name__ == "__main__":
    main()

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

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

if (B - A) % 2 == 0:
  print((B - A) // 2)
else:
  NA = N - A
  B1 = B - 1
  if NA < B1:
    distance = N - B
    adjust = distance + 1
    moveA = A + adjust
    print(((N - moveA) // 2) + adjust)
  else:
    distance = A - 1
    adjust = distance + 1
    moveB = B - adjust
    print(((moveB - 1) // 2) + adjust)

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

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

def calc(n, a, b, ans, move):
    if (b-a)%2 == 0:
        return ans + (b-a)//2
    else:
        if move == 1:
            a += move
        else:
            b += move
        return calc(n, a, b, ans+1, move)
            
        

def main():
    N,A,B = (int(x) for x in input().split())

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



if __name__ == '__main__':
    main()

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

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

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


if __name__ == '__main__':
    main()

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


def main(n, a, b):
    distance = b - a

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


print(main(N, A, B))

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






def main(n, a, b):
    distance = b - a

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

        
        
        
        
        
        


print(main(N, A, B))

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

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

Solution (Python):
import sys

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

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

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float('inf')
MOD=10**9+7
input=sys.stdin.readline

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


if a==b:
    print(0)
    exit()

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

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

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

    
else:
    
    p=num-a
    
    q=b-1
    
    r=a-1
    
    s=num-b
    
    
    if b-a <3:
        p = min(b-1,num-a)
        print(p)
    
    else:
        z=r+1+(b-(r+1)-1)//2
        y=s+1+(num-(a+(s+1)))//2
        print(min(y,z))

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

l = b-a
if l %2 == 0:
  print(l//2)
  
else:
  mi = b-1
  ma = n-a
  
  x1 = min(mi,ma)
  t1 = a-1
  c = b-(t1+1)
  t1 += (c-1)//2+1
  
  t2 = n-b
 
  a += (t2+1)

  t2 += (n-a)//2+1

  print(min(x1,t1,t2))

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

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

ans = []

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

ans = min(ans)

print(ans)

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

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

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

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

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

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

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

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

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

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

Solution (Python):


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

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

ans = t // 2 + min(min(A, B) - 1, N - max(A, B)) + 1
print(ans)

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


if __name__ == '__main__':
    solve()

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

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

ans = 0

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

else:
    a = A - 1
    b = N - B

    if a > b:
        bb = b + 1
        A += bb
        ans += (N - A) // 2
        ans += bb

    else:
        aa = a + 1
        B -= aa
        ans += (B - 1) // 2
        ans += aa

print(ans)

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

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

N, A, B = map(int, input().split())
ans = []
if (A + B) % 2 == 0:
    ans.append((B - A) // 2)
if A > N - B:
    ans.append(N - A)
    ans.append(((B - A) // 2) + N - B + 1)
if A <= N - B:
    ans.append(B - 1)
    ans.append(((B - A) // 2) + A)

print(min(ans))

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

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


if __name__ == '__main__':
    main()

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

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

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

ans = 0

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

else:
    
    
    
    
        
    MIN = min(A, B)
    MAX = max(A, B)

    if MIN - 1 < N - MAX:
        ans = MIN - 1
    
    else:
        ans = N - MAX
    
    print(ans + (tmp+1) // 2)

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

print(ans)

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

Solution (Python):

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

p1 = 10e18
p2 = 10e18
p3 = 10e18
p4 = 10e18
p5 = 10e18

if (B - A) % 2 == 0:
    p1 = (B - A) // 2
else:
    p2 = B - 1 
    p3 = N - A 
    
    p4 = (B - A) // 2 + A
    
    p5 = (-A + B -1) //2 + N -B + 1

print(min(p1, p2, p3, p4, p5))

Solution (Python):
N,a,b = map(int,input().split())
sub = b-a
if(sub%2==0):
    print(sub//2)
else:
    bsub = N - b
    asub = a -1
    if(bsub < asub):
        ans = (N - (a + bsub + 1))//2 + bsub + 1
        print(ans)
    else:
        ans = ((b - (asub + 1)) - 1) // 2 + asub + 1
        print(ans)

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

Solution (Python):
import sys
from math import factorial
from fractions import Fraction
import heapq, bisect, fractions
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
MOD = 10**9 + 7

n, a, b = MAP()

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

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

Solution (Python):
n,a,b= map(int,input().split())
if a<b:
  tmp=a
  a=b
  b=tmp
if abs(a-b)%2==0:
  c=abs(a-b)//2

else:

  if abs(a-b)>=3:
    c=min(abs(1-a),abs(n-b))
    c = c-(abs(a-b)//2)
  else:
    c=min(abs(1-a),abs(n-b))


print(c)

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

else:
    if A>B:
        if (N-A)<(B-1):
            print((N-(B+(N-A))+1)//2+(N-A))
        else:
            print((A-(B-1))//2+(B-1))
    else:
        if (N-B)<(A-1):
            print((N-(A+(N-B))+1)//2+(N-B))
        else:
            print((B-(A-1))//2+(A-1))

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

Solution (Python):


N,a,b=map(int,input().split())
if (b-a)%2==0:
    print((b-a)//2)
else:
    M=(a+b)//2
    if M-1<N-M:
        b-=a
        print((b-1)//2+a)
    else:
        a+=N-b+1
        print((N-a)//2+N-b+1)

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

l = B-A
count = 0

if l%2 == 1:
    if A-1>N-B:
        count+=N-B+1
        A,B =A+(N-B)+1,N
    else:
        count+=A
        A,B =1,B-A

l = B-A
count += l//2

print(count)

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

if abs(a - b) % 2 == 0:
    print(abs(a-b) // 2)
else:
    dla, dlb = n-a, n-b
    dra, drb = a-1, b-1
    ansl = min(dla, dlb) + 1 + abs(dla - dlb) // 2
    ansr = min(dra, drb) + 1 + abs(dra - drb) // 2
    print(min(ansl, ansr))

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

if N == 2:
    print(1)
    exit()

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

if A == 1 or B == N:
    if B - A == 1:
        print(1)
        exit()
    else:
        print(1 + (B-A)//2)
        exit()


if (A-1) <= (N-B):
    flag = True

else:
    flag = False

if flag:
    answer = A + (B-A)//2
else:
    move = N-B
    answer = move + 1 + (B-A)//2

print(answer)

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

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

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

    t1=N-((A+B-1)//2)
    t2=((A+B+1)//2)-1
    print(min(t,t1,t2))

Solution (Python):

from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations
import sys
import bisect
import string
import math
import time
from fractions import gcd



def I(): return int(input())


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


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['Yes', 'No']
MOD = 10**9+7
inf = float('inf')
IINF = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)



show_flg = True


def main():
    N, A, B = MI()
    diff = abs(A - B)

    if diff % 2 == 0:
        print(diff // 2)
    else:
        ans = 0
        minp = min(A, B)
        maxp = max(A, B)
        
        if N - maxp + 1 > minp:
            ans += minp - 1
            B -= minp - 1
            B -= 1
            ans += 1
            A = 1
            
            if B == 1:
                print(ans)
            else:
                ans += abs(B - A) // 2
                print(ans)
        else:
            ans += N - maxp
            A += N - maxp
            A += 1
            ans += 1
            B = N
            
            if A == N:
                print(ans)
            else:
                ans += abs(B - A) // 2
                print(ans)
        
        
        


if __name__ == '__main__':
    main()

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

if A == 1:
  print(B//2)
  exit()

if B == N:
  print((N-A+1)//2)
  exit()

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