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 = (int(x) for x in input().split())
c = b - a

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

Submission status: Accepted

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

Submission status: Accepted

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

sa = b-a

goal = 0

if n-b > a-1:
    goal = 1
else:
    goal = n
    

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdout
printn = lambda x: stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True # and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n,a,b = inm()
if (a-b)%2==0:
    print(abs(a-b)//2)
else:
    p = max([a-1,b-1])
    q = max([n-a,n-b])
    r = (a+b-1)//2
    s = (2*n-a-b+1)//2
    print(min([p,q,r,s]))

Submission status: Accepted

Solution code:


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

if((b-a)%2==0):
	print((b-a)//2)
else:
	ans=10**20

	ta=a
	tb=b
	tp=0
	tp+=ta-1
	ta=1
	tb-=tp+1
	tp+=1
	ans=min(ans,(tb-ta)//2+tp)

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

	print(ans)

Submission status: Accepted

Solution code:
''' بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ '''
#codeforces
gi = lambda : list(map(int,input().split()))
n, a, b = gi()
if a > b:
	a, b = b, a
if (abs(a - b) % 2):
	x = a
	b -= a
	x += (b - 1) // 2
	b += a
	y = n - b + 1
	a += y
	y += (n - a) // 2
	print(min(x, y))
else:
	print(abs(a - b) // 2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N, A, B = [int(x) for x in input().split()]
a = max(A, B) - 1
b = N - min(A, B)
c = 10 ** 19
d = 10 ** 19
e = 10 ** 19
if abs(A - B) % 2 == 0:
    c = abs(A - B) // 2
else:
    d = min(A, B) - 1 + 1 + (abs(A - B) - 1) // 2
    e = N - max(A, B) + 1 + (abs(A - B) - 1) // 2
print(min(a, b, c, d, e))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N, A, B = map(int, input().split())
if A > B: A, B = B, A
x = max(abs(1 - A), abs(1 - B))
y = max(abs(N - A), abs(N - B))
z = abs(A - (A + B) // 2)
res = 0
if (A + B) % 2:
  if abs(1 - A) < abs(N - B):
    res += abs(1 - A) + 1
    B -= abs(1 - A)
    A = 1
  else:
    res += abs(N - B) + 1
    A += abs(N - B)
    B = N

  x = max(abs(1 - A), abs(1 - B))
  y = max(abs(N - A), abs(N - B))
  z = abs(A - (A + B) // 2)
print(min(x, y, z) + res)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
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) - 1) // 2 + A, ((N - A) - (N - B) - 1) // 2 + (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)+(B-A+1)//2)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def read():
    N, A, B = list(map(int, input().strip().split()))
    return N, A, B

def solve(N, A, B):
    if (A + B) % 2 == 0:
        return (B - A) // 2
    left = (A - 1) + 1 + (B - A) // 2
    right = (N - B) + 1 + (B - A) // 2
    return min(left, right)

if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))

Submission status: Accepted

Solution code:
ui = input()
uis = ui.split(" ")
N = int(uis[0])
A = int(uis[1])
B = int(uis[2])
if abs(A-B) % 2 == 0:
    print(abs(A-B) // 2)
elif A == B:
    print(0)
else:
    if B > A:
        temp = B
        B = A
        A = temp
    BDistance = B - 1
    ADistance = N - A
    if BDistance > ADistance:
        steps = ADistance + 1
        B = B + ADistance + 1
        A = N
        Distance = (N-B) // 2
        steps = steps + Distance
    else:
        steps = BDistance + 1
        B = 1
        A = A - BDistance - 1
        Distance = (A-1) // 2
        steps = steps + Distance
    print(steps)

Submission status: Accepted

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

if (B - A) % 2 > 0:
    ans_up = (A + B - 1) // 2
    ans_down = N - (A + B - 1) // 2
    print(min(ans_up, ans_down))
else:
    print((B - A) // 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:
  ans = 0
  tip_A = min(abs(A-1),abs(A-N))
  tip_B = min(abs(B-1),abs(B-N))
  near_tip = min(tip_A,tip_B)
  # まず、近いほうに寄る
  if near_tip == tip_A:
    if abs(A-1) <= abs(A-N):#1のが近い場合
      ans += tip_A
      A = 1
      B -= tip_A
      # もう一回移動
      ans += 1
      B -= 1
      # お互い近づく
      ans += (abs(A-B)//2)
    else:#Nのが近い場合
      ans += tip_A
      A = N
      B += tip_A
      # もう一回移動
      ans += 1
      B += 1
      # お互い近づく
      ans += (abs(A-B)//2)
  else:
    if abs(B-1) <= abs(B-N):#1のが近い場合
      ans += tip_B
      B = 1
      A -= tip_B
      # もう一回移動
      ans += 1
      A -= 1
      # お互い近づく
      ans += (abs(A-B)//2)
    else:#Nのが近い場合
      ans += tip_B
      B = N
      A += tip_B
      # もう一回移動
      ans += 1
      A += 1
      # お互い近づく
      ans += (abs(A-B)//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:
    a = min(N-B, A-1)
    print(((B-a)-(A-a))//2 + a + 1)

Submission status: Accepted

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

if (b - a) % 2 == 0:
    ans = (b-a) // 2
else:
    ans = min(a+b-1, 2*n-a-b+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:
    aa=a
    bb=b
    tot=0
    tot+=(a)
    b-=(a)
    a=1
   # print(a,b)
    tot+=((b-a)//2)
    a=aa
    b=bb
    tot2=0
    tot2+=(n-b+1)
    a+=(n-b+1)
    b=n

    tot2+=((b-a)//2)
    print(min(tot,tot2))

Submission status: Accepted

Solution code:
N, A, B = map(int, input().split())
C = abs(A-B)
X = max(A-1,B-1)
Y = max(N-A,N-B)
if C % 2 == 0:
  print(min(C//2,X,Y))
else:
  if B > A:
    A, B = B, A
  P = (2*N - B - A + 1)//2
  Q = (A + B - 1)//2
  print(min(P,Q,X,Y))

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def main():
    n, a, b = [int(x) for x in input().split()]
    print(calc(n, a, b))
    return


def calc(n ,a, b):
    if a % 2 == b % 2:
        return abs(a - b) // 2
    else:
        if a > b:
            a, b = b, a
        if a - 1 < n - b:
            return calc(n, 1, b - a) + a
        else:
            return calc(n, a + n - b + 1, n) + n - b + 1


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N,A,B=map(int,input().split())
print
if abs(A-B)%2==0:
  print(abs(A-B)//2)
else:
  C=min([A-1,B-1,N-A,N-B])
  if C==A-1 or C==B-1:
    print((A+B-1)//2)
  else:
    print((N-A+N-B+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 == 0:
    print(((a + b) // 2) - a)
else:
    t = min(a - 1, n - b)
    if a - 1 <= n - b:
        t -= -1
        b -= t
        t += (((1 + b) // 2) - 1)
        print(t)
    else:
        t -= -1
        a += t
        t += (((a + n) // 2) - a)
        print(t)

Submission status: Accepted

Solution code:
N,A,B=[int(i) for i in input().split(" ")]
delta=abs(A-B)
if delta%2==0:
    print(delta//2)
else:
    #use1
    use1=A+(B-A-1)//2
    useN=N-B+1+(delta-1)//2
    print(min(use1,useN))

Submission status: Accepted

Solution code:
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    N, A, B = map(int, input().split())

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


main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,a,b=(int(x) for x in input().split())
ans=max(a,b)-min(a,b)

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

print(ans)

Submission status: Accepted

Solution code:
N, A, B = map(int, input().split())
# if (B - A) % 2 == 1:
#     ans = min(B-1, N-A)
# else:
#     # 中間地点で会うのがベスト
#     ans = abs(B-A)//2
#
# print(ans)
a = A
b = B
if (B - A) % 2 == 0:
    # 中間地点で会うのがベスト
    ans = abs(B-A)//2
    print(ans)
    exit()
else:
    a = A
    b = B
    ans = 10**20
    # 左側で偶奇を揃える場合
    left = A-1  # 左に行くまでの試合回数
    tmp = left
    a -= left  # Aは1に
    b -= left
    # 1回試合をして偶奇を揃える
    b -= 1
    tmp += 1
    # 中間地点で会う
    tmp += abs(b-a)//2
    ans = min(ans, tmp)

    # 右側で偶奇を揃える場合
    a = A
    b = B
    right = N-b  # 右に行くまでの回数
    tmp = right
    b = N
    a += tmp  # 試合回数文
    # 1回試合をする
    tmp += 1
    a += 1
    tmp += abs(b-a)//2
    ans = min(tmp, ans)
    print(ans)
    exit()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int, A: int, B: int):
    if (B-A) % 2 == 0:
        print(min((B-A)//2, min(max(A, B)-1, N-min(A, B))))
    else:
        # 偶奇をすらすパターン
        m = A + (B-A-1)//2
        m = min(m, N-B+1+(B-A-1)//2)
        print(m)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(N, A, B)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
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 + (b - a - 1) // 2)
print(ans)

Submission status: Accepted

Solution code:
#A
n, a, b = list(map(int,input().split()))
s = abs(a-b)

def chk(c,d):
    return abs(c-d)//2

if s % 2 == 0:
    print(s//2)
else:
    #p = max(a-1,b-1)
    #q = max(n-a,n-b)
    r = min(a-1,n-b) 
    u = r + 1 + min(chk(1,b-r-1),chk(a+r+1,n))
    print(u)

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-1 + 1 +(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 (b - a) % 2 == 0:
    print((b - a) // 2)
else:
    ans1 = a
    c = b - ans1
    ans1 += (c - 1) // 2

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline

n, a, b = [int(item) for item in input().split()]
ans = 10**20

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

Submission status: Accepted

Solution code:
N,A,B = map(int,input().split())
if A%2 == B%2:
    print(int((abs(A-B))//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:
import sys

stdin = sys.stdin

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))  # applies to numbers only
rs = lambda: stdin.readline().rstrip()  # ignores trailing space

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

print(answer)

Submission status: Accepted

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

diff = abs(A - B)

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

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-a, b-1, (a-1) + 1 + (b-(a-1)-1-1)//2, (n-b) + 1 + (n-(a+n-b+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((B+A-1)//2,((2*N-B+1-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(min(A+(B-A-1)//2,N-B+1+(N-(A+N-B+1))//2))

Submission status: Accepted

Solution code:
import sys
n, a, b = map(int, input().split())
x = b - a
if x % 2 == 0:
    print(int(x//2))
else:
    y = a-1
    z = n-b
    w = min(y, z)
    print(int((x+2*w+1)//2))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

def ceil(a, b):
   return a // b + (a % b > 0)

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

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

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
import sys
import bisect
import math
import itertools
import string
import queue
import copy
# import numpy as np
# import scipy
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
 
def inp(): # n=1
    return int(input())
def inpm(): # x=1,y=2
    return map(int,input().split())
def inpl(): # a=[1,2,3,4,5,...,n]
    return list(map(int, input().split()))
def inpls(): # a=['1','2','3',...,'n']
    return list(input().split())
def inplm(n): # x=[] 複数行
    return list(int(input()) for _ in range(n))
def inpll(n): # [[1,1,1,1],[2,2,2,2],[3,3,3,3]]
    return [list(map(int, input().split())) for _ in range(n)]

def main():

    n,a,b = inpm()
    x = b-a
    if x%2==0:
        print(int(x//2))
        return
    else:
        n1 = b-1
        n2 = n-a
        n3 = a+int( (b-a-1)//2 )
        n4 = n-b+1+int( (b-a-1)//2 )
        print(min(n1, n2, n3, n4))
        return

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**9)
INF=10**18
def input():
    return sys.stdin.readline().rstrip()

def main():
    N,A,B=map(int,input().split())
    if (A-B)%2==0:
        print(abs(A-B)//2)
    else:
        X=min(max(A,B)-1,N-min(A,B))
        c=min(min(A,B)-1,N-max(A,B))+1
        Y=c+(abs(A-B)-1)//2
        print(min(X,Y))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    n,a,b = map(int,input().split())
    a,b = sorted([a,b])
    if (a-b)%2==1:
        x = min([n-b,a-1])
        y = n-a
        if x == a-1:
            y = b-1
        print(abs(x+y+1)//2)
    else:
        print(abs(a-b)//2)
    
if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
N,a,b=(int(x) for x in input().split())
if abs(a-b)%2==0:
    print(abs(a-b)//2)
else:
    c1=a-1+1+(b-a)//2
    c2=N-b+1+(b-a)//2
    print(min(c1,c2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#import sys
MOD = 10 ** 9 + 7
#input = sys.stdin.readline
import math

import itertools

#import bisect

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default


#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]
def main():
    n,a,b=map(int,input().split())
    count=0
    if (b-a)%2==0:
        count=(b-a)//2
    else:
        if a-1<=n-b:
            count=(b-a-1)//2+a
        else:
            count=(b-a-1)//2+n-b+1
#    print(a-1,n-b,b-a-1)
    print(count)









if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

tmp1 = A - 1
b = B - tmp1
tmp1 += (b - 1) // 2

tmp2 = N - B
a = A + tmp2
tmp2 += (N - a) // 2

print (min(tmp1, tmp2) + 1)

Submission status: Accepted

Solution code:
N,A,B = map(int,input().split())
if (A-B)%2==0:
  print((B-A)//2)
  exit()
else:
  p = N - A
  q = B - 1
  r = A - 1
  s = N - B
  if p < q:
    print(s + 1 + (p-s-1)//2)
  elif p >= q:
    print(r + 1 + (q-r-1)//2)

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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


def main():
    N, A, B = [int(x) for x in input().split()]
    ans = (B - A) // 2
    if (B - A) % 2 == 1:
        ans1 = A - 1
        B1 = (B - ans1)
        ans1 = ans1 - (-(B1 - 1) // 2)
        ans2 = N - B
        A1 = (A + ans2)
        ans2 = ans2 - (-(N - A1) // 2)
        print(min(ans1, ans2))
    else:
        print(ans)





if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
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 LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

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

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

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

# main()
print(main())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines


# mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
#import numpy as np


def main():
	n,a,b=map(int,input().split())
	
	if (b-a)%2==0:
		print((b-a)//2)
	else:
		ma=max(a,b)
		mi=min(a,b)
		ko1=min(n-mi,ma-1)
		
		ko2=n-ma+1+(n-(mi+(n-ma+1)))//2
		ko3=mi-1+1+((ma-(mi-1+1))-1)//2
		
		print(min(ko1,ko2,ko3))
		
		
		
	
	
	
	
	
if __name__ == "__main__":
	main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

else:
    a1=A-1
    aN=N-A
    b1=B-1
    bN=N-B
    a = min(a1,b1,aN,bN)
    print(a+1+(B-A)//2)

Submission status: Accepted

Solution code:
import sys

n, a, b = map(int, sys.stdin.readline().split())

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

    if n - b >= abs(1 - a):
        res = a
        b -= res
        a = 1
    else:
        res = n - b + 1
        a += res
        b = n

    res += (b - a) // 2
    return res

if __name__ == '__main__':
    ans = main(a, b)
    print(ans)

Submission status: Accepted

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

minimum=min(A,B)
maximum=max(A,B)

a=max(A,B)-1
b=N-min(A,B)
c=(max(A,B)-min(A,B))//2+(max(A,B)-min(A,B))%2+min(min(A,B)-1,N-max(A,B))
d=(max(A,B)-min(A,B))//2

if((B-A)%2!=0):
    print(min(a,b,c))
else:
    print(min(a, b, c,d))

Submission status: Accepted

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

Submission status: Accepted

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

if A > B:
  A, B = B, A
  
D = B - A

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

Submission status: Accepted

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

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

else:
    to_top = max(a-1, b-1)
    to_end = max(n-a, n-b)
    to_top_2 = min(a-1, b-1)
    to_end_2 = min(n-a, n-b)
    wait = min(to_top, to_end)
    go = min(to_top_2, to_end_2) + (b-a)//2 + 1
    print(min(wait, go))

Submission status: Accepted

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

if (a-b)%2 ==0:
    print((b-a)//2)
else:
    cand1=max(n-a,n-b)
    cand2=max(a-1,b-1)
    cand_edge = min(cand1,cand2)
    
    cand_reflect_right = n-b+1+(b-a-1)//2
    cand_reflect_left  = a    +(b-a-1)//2
    
    print( min( cand_edge,cand_reflect_left,cand_reflect_right))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N,A,B = map( int, input().split() )
C = B - A
if C % 2 == 0:
    print( C // 2 )
else:
    start = A - 1
    position_start = B - start - 1
    D = ( position_start - 1 ) // 2 + start + 1 
    
    last = N - B
    position_last = A + last + 1
    E = ( N - position_last ) // 2 + last + 1
    
    print(min(D,E))