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.



Sample input:
5 2 4


Sample output:
1

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
  return int(readline())
n,a,b = readInts()
ab = abs(b-a)
if ab%2 == 0:
    print(ab//2)
else:
    print(min(a-1, n-b) + 1 + (b-a-1)//2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#A - Table Tennis Training
N,A,B = map(int,input().split())
if abs(A-B)%2 == 0:
    ans = abs(A-B)//2
else:
    a = min(A-1,N-B)
    ans = a + 1 + (B-A-1)//2
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

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

import bisect

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

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

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

	print(ans)

















if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
N, A, B = map(int, input().split())
if A % 2 == B % 2:
    print(abs(A - B) // 2)
else:
    A_top = A - 1
    B_top = B - 1
    top = (
        B_top + (A - B_top - 1) // 2 if A_top > B_top else A_top + (B - A_top - 1) // 2
    )

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

Submission status: Accepted

Solution code:
N, A, B = map(int, input().split())
if (B - A) % 2 == 0:
    print((B - A) // 2)
else:
    # N に向かうことを考える
    A_to_N_dis = N - B + 1
    A_to_N = A + A_to_N_dis
    tmp_ans = (N - A_to_N) // 2 + A_to_N_dis

    # 1に向かうことを考える
    B_to_1_dis = A - 1 + 1
    B_to_1 = B - B_to_1_dis
    ans = (B_to_1 - 1) // 2 + B_to_1_dis
    print(min(tmp_ans, ans))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n,a,b = readInts()
sa = b-a
if sa%2 == 0:
    print(sa//2)
else:
    print(min(a-1, n-b) + 1 + (b-a-1)//2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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


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

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


print(solve())

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

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

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, A, B = map(int, input().split())
x = B - A
if x % 2 == 0:
    print(x//2)
else:
    # 左に持って行って寄せる
    l = (A-1) + 1 + (B-A-1)//2
    # 右に持って行って寄せる
    r = (N-B) + 1 + (B-A-1)//2
    print(min(r, l))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

margin = abs(a-b)

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n,a,b = readInts()
if abs(b-a)%2 == 0:
    print(abs(b-a)//2)
else:
    print(min(a + (abs(b-a)-1)//2, n-b+1+(abs(b-a)-1)//2))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
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]))

Submission status: Accepted

Solution code:
# 2020/08/08
# AtCoder Beginner Contest 174 - A

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

# Calc
sa = abs(b - a)

if sa % 2 == 0:
    ans = sa // 2
else:
    # B go Right and 1 lose
    bgr = n - b + 1
    bgra = a + bgr
    rans = (n - bgra) // 2 + bgr
    
    # A go Left and 1 lose
    agl = a - 1 + 1
    aglb = b - agl
    lans = (aglb - 1) // 2 + agl
    ans = min(rans, lans)

# Output
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys

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


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

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


print(solve())

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
import math

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

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

else:

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

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

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

Submission status: Accepted

Solution code:
# AtCoder Grand Contest 041
# A - Table Tennis Training

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

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

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

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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


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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def resolve():
    n, a, b = map(int, input().split())
    if a%2 == b%2: #偶奇が同じだと同じ場所で会える
        print((b-a)//2)
    else:#偶奇が違う→1 or Nで調整する
        print(min(a-1, n-b) + 1 + (b-a-1)//2)
resolve()

Submission status: Accepted

Solution code:
import math
import sys
import bisect
readline = sys.stdin.readline


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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

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

if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline


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



if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N,A,B = [int(i) for i in input().split()]
if A%2 == B%2:
    print(abs(A - B) // 2)
    exit()

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))


n,a,b = readints()

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n, a, b = map(int, input().split())
if (b - a) % 2 < 1:
    print((b - a) // 2)
else:
    print(min((a + b - 1) // 2, (2 * n - a - b + 1) // 2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n,a,b=map(int,input().split())
    di = 0
    if (b-a)%2==1:
        w = a-1
        l = n-b
        di = (w - l)
        if di < 0:
            di = -w-1
        else:
            di = l+1
        a += di
        if a < 1:
            a = 1
        b += di
        if b > n:
            b = n
    #print(a,b,di)
    print((b-a)//2 + abs(di))
    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

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

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, A, B = [int(_) for _ in input().split()]
d = B - A
if d % 2:
    t1 = N - B + 1
    ans = t1 + (N - (A + t1)) // 2
    t2 = A
    ans = min(ans, t2 + (B - t2 - 1) // 2)
    print(ans)
else:
    print(d // 2)

Submission status: Accepted

Solution code:
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

MOD = 10 ** 4 + 7

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)
    ans = []
    l = (A - 1)
    r = B - l - 1
    x = l + 1 + (r - 1) // 2
    ans.append(x)
    r = (N - B)
    l = A + r + 1
    x = r + 1 + (N - l) // 2
    ans.append(x)
    print(min(ans))

Submission status: Accepted

Solution code:
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

MOD = 10 ** 4 + 7

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)

Submission status: Accepted

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

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

Submission status: Accepted

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

if (B-A)%2 == 0:
    #真ん中で会う
    ans = (B-A)//2
else:
    if N-B < A-1:
        #まずBがNへ行く
        temp_ans = N-B
        A += N-B
        ans = temp_ans + 1 + (N-A)//2
    else:
        #まずAが1へ行く
        temp_ans = A-1
        B -= A-1
        ans = temp_ans + 1 + (B-1)//2
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n, a, b = map(int, input().split())
    if (b-a) % 2 == 0:
        print((b-a)//2)
    else:
        temp = [(min(n-a, b-1))]

        cnt1 = 0
        cnt2 = 0
        for i in range(0, (min(n-a, b-1))):
            if (b-(a-1) - i) % 2 == 0 and cnt1 == 0:
                temp.append(a - 1 + i + (b-(a-1) - i) // 2)
                cnt1 += 1
            elif (n - (a+(n-b)+i)) % 2 == 0 and cnt2 == 0:
                temp.append(n - b + i + (n - (a+(n-b)+i)) // 2)
                cnt2 += 1

            if cnt1 == 1 and cnt2 == 1:
                break

        print(min(temp))

if __name__ == "__main__":
    main()