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

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

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

elif b-a==1:
    print(min(b-1,n-a))

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

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

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

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

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

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

D=B-A

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

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

Solution (Python):
N,A,B = map(int,input().split())
A,B = min(A,B),max(A,B)
if abs(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())

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

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

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

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

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

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

Solution (Python):
s = list(map(int, input().split()))
N = s[0]
A = s[1]
B = s[2]

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

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

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

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

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

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

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

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

Solution (Python):
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]




N, A, B = mi()

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

Solution (Python):
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt, ceil
from functools import lru_cache, reduce
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True




def warshall_floyd(d, n):
    
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d



def dijkstra_heap(s, edge, n):
    
    d = [10**20] * n
    used = [True] * n 
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d


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

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr


def lcm(x, y):
    return (x * y) // gcd(x, y)


def lcm_list(numbers):
    return reduce(lcm, numbers, 1)


def gcd_list(numbers):
    return reduce(gcd, numbers)






def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P


def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret



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

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

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

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

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

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

Solution (Python):
from itertools import groupby


def all_equal(iterable):
    g = groupby(iterable)
    return next(g, True) and not next(g, False)


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

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

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

Solution (Python):
def main():
    from sys import stdin
    n,a,b = map(int,stdin.readline().rstrip().split())
    k = b-a-1
    if k%2==1:
        print(k//2+1)
    else:
        print(k//2+1+min(n-b,a-1))
main()

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

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

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

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

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

ans = 0

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

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

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


print(ans)

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

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

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

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

Solution (Python):


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

ans = 10**18+1

if a > b:
    a, b = b, a


ans = []
ans.append(max(a-1, b-1))
ans.append(max(n-a, n-b))

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

    a_tmp, b_tmp = a+(n-b)+1, n
    ans.append(n-b+1 + abs(b_tmp-a_tmp)//2)

print(min(ans))

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

Solution (Python):

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,cos,radians,sqrt
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

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

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

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

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

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

Solution (Python):

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes) if b else print(no)






n,a,b=n1()

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

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

Solution (Python):
ma = lambda :map(int,input().split())

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

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

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

Solution (Python):
from sys import stdin
import math
import re
import queue

input = stdin.readline

MOD = 1000000007

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

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

    N, A, B = map(int, input().split())
    if (B-A) % 2 == 0:
        return  (B-A) // 2
    else:
        a = A-1 + (B-A+1)//2
        b = N-B+1 + (B-A-1) // 2
        return min([a, b])

if __name__ == '__main__':
    print(main())

Solution (Python):
def main():
    N, A, B = list(map(int, input().split(' ')))
    assert 1 <= A < B <= N
    if (B - A) % 2 == 0:
        print((B - A) // 2)
    else:
        if B - 1 <= N - A:
            print(A + max([0, B - A - 1]) // 2)
        else:
            print(N - B + 1 + max([0, 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:
    if A+B-1>=2*N-A-B+1:
        print((2*N-A-B+1)//2)
    else:
        print((A+B-1)//2)

Solution (Python):

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

    ab_diff = abs(a-b)
    if ab_diff%2 == 0:
        print(ab_diff//2)
        return
    
    a_edge_diff = min(abs(a-1),abs(n-a))
    b_edge_diff = min(abs(b-1),abs(n-b))
    
    if a_edge_diff <= b_edge_diff:
        print(a_edge_diff+1+ (ab_diff-1)//2)
    else:
        print(b_edge_diff+1+ (ab_diff-1)//2)

if __name__ == "__main__":
    main()

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

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

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

Solution (Python):
from sys import stdin, stdout

int_in = lambda: int(stdin.readline())
arr_in = lambda: [int(x) for x in stdin.readline().split()]
mat_in = lambda rows: [arr_in() for y in range(rows)]
str_in = lambda: stdin.readline().strip()
out = lambda o: stdout.write("{}\n".format(o))
arr_out = lambda o: out(" ".join(map(str, o)))
bool_out = lambda o: out("YES" if o else "NO")
tests = lambda: range(1, int_in() + 1)


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

    down_ops = min(a, b)
    up_ops = n - max(a, b) + 1

    if down_ops < up_ops:
        return solve(n, 1, max(a, b) - down_ops) + down_ops

    return solve(n, min(a, b) + up_ops, n) + up_ops


if __name__ == "__main__":
    n, a, b = arr_in()
    out(solve(n, a, b))

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

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

print(s)

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

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

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

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

Solution (Python):

N, A, B = [int(_) for _ in input().split()]
if (B - A) % 2 == 0:
    print((B-A) // 2)
else:
    print(min(N - B + 1 + (N - (A + N-B+1)) // 2, A + (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 a%2==b%2:
    print((b-a)//2); exit()
ans1 = 0
c = a
aa = 1
bb = b-a
ans1 = c
if aa!=bb:
    ans1 += (bb-aa)//2
ans2 = 0
c = n-b+1
bb = n
aa = a+c
ans2 = c
if aa!=bb:
    ans2 += (bb-aa)//2
print(min(ans1, ans2))

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n,a,b=map(int, input().split())
    if (abs(a-b))%2==0:
        print((abs(a-b))//2)
    else:
        ue=max(a,b)-1
        sita=n-min(a,b)
        hokasita=((n-max(a,b))*2+1+abs(b-a))//2
        hokaue=(((min(a,b))-1)*2+1+abs(b-a))//2
        print(min(ue,sita,hokasita,hokaue))
resolve()

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

mid = b - a

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

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

mid = (B - A)//2
left = ((A-1+B-1)+1)//2
right = ((N-B+N-A)+1)//2

if (B - A)%2==0:
    print(mid)
else:
    print(min(left, right))

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

    '''
    if N - B >= A - 1:
        ans = B - 1
    else:
        ans = N - A
'''
print(ans)

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


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

print(c)

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

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

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

if (b - a) % 2 == 1:
    dt1 = a - 1
    dt1 += 1
    b1 = b - dt1
    t1 = dt1 + (b1 - 1) // 2

    dt2 = n - b
    dt2 += 1
    a1 = a + dt2
    t2 = dt2 + (n - a1) // 2
    print(min(t1, t2))
else:
    print((b - a) // 2)

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

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

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

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

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

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

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

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

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

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

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

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

Solution (Python):

"""
Created on Sun May 10 17:22:34 2020

@author: shinba
"""
import sys 
n,a,b = map(int,input().split())

if (b-a) % 2 == 0:
    print((b-a)//2)
    sys.exit()
    
k = (a+b-1)//2

print(min(k,n-k))

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

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


if __name__ == "__main__":
    main()

Solution (Python):






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





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

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

main()

Solution (Python):


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

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

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    

    
    

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

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

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

Solution (Python):
'''
参考
https://www.hamayanhamayan.com/entry/2019/12/29/032305
https://qiita.com/c-yan/items/4724d67c171d82a2366a

パターン1：A,Bともに偶数またはA,Bともに奇数の場合
⇒そのままお互いに近づく…(B-A)/2
パターン2：A,Bのいずれかが奇数の場合
⇒左端（Aに近いほう）か、右端（Bに近いほう）のいずれかで1ターン待機後、お互いに近づく
'''
N, A, B = map(int, input().split())

def approach(x, y):
    return (B-A)//2

ans = 0

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

print(ans)

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

Solution (Python):


import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))

def resolve():
    N,A,B=pin()
    tt=abs(A-B)
    if tt%2==0:
        print(tt//2)
        return
    else:
        s= max(A,B)-1
        t=N-min(A,B)
        print(min(s,t,(tt-1)//2+1)+min(min(A,B)-1,N-max(A,B)))

resolve()

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

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

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

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

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

Solution (Python):
from sys import stdin
def main():
    
    readline=stdin.readline
    N,A,B=map(int,readline().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__":
    main()

Solution (Python):
import sys

input = sys.stdin.readline
MOD = 1000000007

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

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

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

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

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

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





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

print(ans)

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





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

print(ans)

Solution (Python):
import sys

def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))

def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]

def to_bin(x: int) -> str: return format(x, 'b') 
def to_oct(x: int) -> str: return format(x, 'o') 
def to_hex(x: int) -> str: return format(x, 'x') 
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(MAX_NUM+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(MAX_NUM**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, MAX_NUM+1, i):
            is_prime[j] = False
    return [i for i in range(MAX_NUM+1) if is_prime[i]]

from itertools import accumulate as acc
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left


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

if __name__ == '__main__':
    main()

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

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

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

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

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

  else:
    tmp = A - 1
    A = 1
    B = B - tmp - 1
    print((B - A) // 2 + tmp + 1)

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

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

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