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:
# https://atcoder.jp/contests/agc041/tasks/agc041_a


def main():
    (n, a, b) = map(int, input().split(" "))
    ans = abs(a - b)
    if ans % 2 == 0:
        ans //= 2
    else:
        ato1 = a - 1
        bton = n - b
        if ato1 <= bton:
            # aを1に動かすほうが早い
            b = b - ato1
            if b % 2 == 0:
                ans = b // 2 + ato1
            else:
                ans = b // 2 + ato1 + 1
        else:
            # bをnに動かしたほうが早い
            a = a + bton
            if abs(n - a) % 2 == 0:
                ans = (n - a) // 2 + bton
            else:
                ans = (n - a) // 2 + bton + 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n, a, b = map(int, input().split())
if (a - 1) >= (n - b):
    count = (n-b)
    a = a + (n - b)
    b = n
else:
    count = (a - 1)
    b = b - (a - 1)
    a = 1

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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(N-A,B-1,C,D))

Submission status: Accepted

Solution code:
n, a, b = map(int, input().split())
if (a - 1) >= (n - b):
    count = (n-b)
    a = a + (n - b)
    b = n
else:
    count = (a - 1)
    b = b - (a - 1)
    a = 1
#print(count)
if ((b - a) % 2 == 0):
    print(min(min(b-1,n-a),(b-a)//2))
elif a == 1 and (b - a) % 2 != 0:
    print(min(min(b - 1, n - a), (b - 1 - a) // 2 + 1) + count)
    #print(count)
elif b == n and (b - a) % 2 != 0:
    print(min(min(b - 1, n - a), (b - 1 - a) // 2 + 1)+count)
elif (b - a) == 3:
    print(min(b - 1, n - a) - 1+count)
elif (b - a) >= 5 and (b - a) % 2 != 0:
    print(min(b - 1, n - a) - 2+count)
else:
    print(min(b-1,n-a)+count)

Submission status: Accepted

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

Submission status: Accepted

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

    if B-A == 1:
        print(B-1)

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

Submission status: Accepted

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

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:
def main():
  s = input().split()
  n = int(s[0])
  a = int(s[1])
  b = int(s[2])
  
  if (b - a) % 2 == 0:
    print((b - a) // 2)
    return
  
  if a - 1 <= n - b:
    print(a + (b - a - 1) // 2)
    return
  
  print(n - b + 1 + (b - a - 1) // 2)
  
main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,a,b=map(int,input().split())
k=b-a-1
if k%2!=0:#間の卓が奇数
    ans=(k+1)//2
    print(ans)    
else:#偶数
    ans=min(b-1,n-a)
    ans1=min(a-1,n-b)+1+k//2
    print(min(ans,ans1))

Submission status: Accepted

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

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)
    exit()
d = n - a
e = b - 1
f = ((n - b) + 1) + ((n - ((n - b) + 1 + a)) // 2)
g = a + ((b - a) // 2)
print(min([d, e, f, g]))

Submission status: Accepted

Solution code:

# 入力 =stdin.readline().rstrip()
# 分割 = stdin.readline().rstrip().split()

'''
条件に合うものを絞り込む
data = [1, 2, 3]
s = [x for x in data if x % 3 == 0]
'''

'''
文字配列を数値に
l_si = ['-10', '0', '100']

l_si_i = [int(s) for s in l_si]
'''

'''
a = [2, 4, 6, 8]
b = [3, 6, 9]

print(list(set(a) | set(b)))  # 和集合
print(list(set(a) & set(b)))  # 積集合
'''

'''
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
count = 0
while len([x for x in A if x % 2 == 0]) == N:
    A = list(map(lambda y: y / 2, A))
    count += 1
print(count)
'''

'''
.append(要素)
.extend(要素)
.insert(場所,要素)
del 配列名[場所]
-1で末尾で末尾から一つ前
'''
'''
間に空白追加
' '.join(lis)
'''
'''
copy.copy(配列名)6

'''
'''
sort()50
sorted(reverse=true)
'''
'''
2分探索
bisect.bisect_left(リスト, 要素)
'''


from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby
import bisect
import copy
import math
from decimal import *
l_si_i = [int(s) for s in stdin.readline().rstrip().split()]
n = l_si_i[0]
a = l_si_i[1]
b = l_si_i[2]

a = Decimal(a)
b = Decimal(b)
n = Decimal(n)
num = b - a


if num % 2 == 0:
    res = Decimal(num)/Decimal(2)
    print(res)
elif num % 2 == 1:

    res1 = a - 1
    b1 = b - (a - 1)
    a1 = 1
    num1 = b1 - a1
    if num1 % 2 != 0:
        res1 += 1
        b1 -= 1
    res1 += (b1 - a1)/2

    res2 = n - b
    a2 = n-b+a
    b2 = n
    num2 = b2 - a2
    if num2 % 2 != 0:
        res2 += 1
        a2 += 1
    res2 += (b2 - a2) / 2
    res = 0
    if res1 <= res2:
        res = res1
    else:
        res = res2
    print(int(res))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from sys import stdin
N,A,B = [int(x) for x in stdin.readline().rstrip().split()]
if (B - A) % 2 == 0:
    print((B-A)//2)
else:
    ans1 = 0
    a1 = A
    b1 = B
    ans1 += (a1-1)
    b1 -= (a1-1)
    a1 = 1
    
    if b1 % 2 == 0:
        b1 -= 1
        ans1 += 1
    ans1 += ((b1 -1)//2)
    
    ans2 = 0
    a2 = A
    b2 = B
    ans2 += (N-B)
    a2 += (N-B)
    b2 += (N-B)
    if (a2 % 2) != (b2 % 2):
        a2 += 1
        ans2 += 1
    ans2 += ((b2 - a2)//2)
    print(min(ans1,ans2,B-1,N-A))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

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

if (B-A) % 2 == 0:
    C=(B-A)//2
else:
    if A-1 > N-B:
        C1=N-B
        C2=(N-A-C1) // 2
        C= C1 + C2 + 1
    else:
        C1=A-1
        C2=(B-1-C1) // 2
        C= C1 + C2 + 1

print(C)

Submission status: Accepted

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

if (b - a)%2 == 0:
  ans = int((b - a)//2)
else:
  ans4 = int(int(a) + int((b-a-1)//2))
  ans5 = int(int(N-b+1) + int((b-a-1)//2))
  ans = int(min(ans4,ans5))
  
print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

if (b-a)%2 == 0:
    print((b-a)//2)
elif n-a < b-1:
    al = n-b+1
    b = n
    a += al
    r = (b-a)//2+al
    print(max(r, 1))
else:
    be = a
    b -= a
    a = 1
    r = (b-a)//2+be
    print(max(r, 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)+((1+b-a)//2),(n-b)+(1+b-a)//2))

Submission status: Accepted

Solution code:
def main():
    N, A, B = map(int, input().split())
    result = N
    if (A % 2 == 0 and B % 2 == 0) or  (A % 2 == 1 and B % 2 == 1):
        result = abs(A - B) // 2
    else:
        if A - 1 < N - B:
            result = ((B - 1) - (A - 1 + 1)) // 2 + (A - 1 + 1)
        else:
            result = ((N - A) - (N - B + 1)) // 2 + (N - B + 1)

    print(int(result))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

if (b - a) % 2 == 0:
  print((b - a) // 2)
else:
  anses = [b - 1, n - a]
  x = (a - 1) + 1
  y = (n - b) + 1
  if (b - x) - 1 > 0:
    anses.append(x + ((b - x) - 1) // 2)
  if n - (a + y) > 0:
    anses.append(y + (n - (a + y)) // 2)
  print(min(anses))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n,a,b = map(int, input().split())
rs = (b-a)//2

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
n, a, b = map(int, input().split())

if (a - b) % 2 == 0:
    if a - b > 0:
        print((a-b)//2)
    else:
        print((b-a)//2)
else:
    d = 0
    if a - b > 0:
        d = a - b
    else:
        d = b - a
    min_x = 0
    top_a = a - 1
    top_b = b - 1
    if top_a < top_b:
        min_x = top_a + (d + 1)//2 
    else:
        min_x = top_b + (d + 1)//2 
    
    bot_a = n - a
    bot_b = n - b
    if bot_a < bot_b:
        min_x1 = bot_a + (d + 1)//2 
    else:
        min_x1 = bot_b + (d + 1)//2 
    if min_x > min_x1:
        min_x = min_x1
    print(min_x)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

a_length=a-1
b_length=n-b

if not (b-a)%2:
    print((b-a)//2)
elif b_length>=a_length:
    print(a+(b-a-1)//2)
elif b_length<a_length:
    print(n-b+1+(b-a-1)//2)

Submission status: Accepted

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

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

        c = 0
        if 1 < A:
            c += A - 1
        c += 1
        B1 = B - c
        A1 = 1
        X = abs(A1 - ((A1 + B1) // 2)) + c
        if B1 < A1:
            X = 9999999999999999999999999999

        c = 0
        if B < N:
            c += N - B
        c += 1
        A2 = A + c
        B2 = N
        Z = abs(A2 - ((A2 + B2) // 2)) + c
        if B2 < A2:
            Z = 9999999999999999999999999999

        print(min(Y, X, Z))


main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, a, b = map(int,input().split())
if (b-a)%2 == 0:
    print((b-a)//2)
else:
    a0 = a
    b0 = b
    ans = 10 ** 18
    tmp = 0
    t = a-1
    tmp += t
    a -= t
    b -= t
    b -= 1
    tmp += 1
    tmp += (b-a)//2
    ans = min(tmp, ans)
    tmp = 0
    t = N-b0
    tmp += t
    b0 += t
    a0 += t
    a0 += 1
    tmp += 1
    tmp += (b0-a0)//2
    ans = min(tmp, ans)
    print(ans)

Submission status: Accepted

Solution code:
import sys
bbn=1000000007
	
#+++++
		
def main():
	n, a, b= map(int, input().split())
	
	k=b-a
	if k % 2 ==0:
		return k // 2
		
	to=a+((b-a-1)//2)
	tn=(n-b+1)+(n-(a+(n-b+1)))//2
	return min(to,tn)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, A, B = [int(x) for x in input().split(' ')]
absdist = abs(A - B)
maxdist1 = max(A-1, B-1)
maxdistN = max(N-A, N-B)

if absdist % 2 == 1:
    edgedist = min(A-1, B-1, N-A, N-B)
    returndist = (absdist + 1) // 2 + edgedist
    print(min(maxdist1, maxdistN, returndist))
else:    
    print(absdist // 2)

Submission status: Accepted

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

ans1 = 10000000000000000000

# a勝ち続け, & b負け続けで会える場合
if abs(a-b)%2==0:
    ans1 = (b-a)//2

# 1 or n テーブルで会える場合
ans2 = min(b-1, n-a)


# 17, 2, 7 とか, 一旦どちらかが端に行ってから途中で会う場合
c = 0
ans3 = 10000000000000000000
if (b-a)%2 == 1:
    if a-1 <= n-b:
        c = a - 1
        a, b = 1, b-c
        ans3 = c + (b-2)//2 + 1
    else:
        c = n - b
        a, b = a + c, n
        ans3 = c + (n-(a+1))//2 +1
print(min(ans1, ans2, ans3))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

if((dai-sho)%2==0):
    print((dai-sho)//2)
else:
    sa=[0]*2
    sa[0]=sho+dai-2
    sa[1]=2*n-sho-dai
    if(sa[0]<sa[1]):
        print((sa[0]+1)//2)
    else:
        print((sa[1]+1)//2)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n, a, b = map(int, input().split())

diff = abs(b-a)
result = 0
if diff % 2 == 0:
    result = diff // 2
else:
    if a < (n-b+1):
        n_a = 1
        n_b = b - a
        result = a
        tmp = (n_b-1)//2
        result += tmp
    else:
        n_a = a + n - b + 1
        n_b = n
        result = n-b+1
        tmp = (n-n_a)//2
        result += tmp

print(result)

Submission status: Accepted

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

    print(min(first, last))

Submission status: Accepted

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


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

Submission status: Accepted

Solution code:
# coding: utf-8
N, A, B = map(int, input().split())
# A < B が保証

if (B - A) % 2 == 1:
    # どっちの角による
    if B - A >= 3:
        ans = 0
        if A - 1 < N - B:
            ans += A - 1
            B = B - (A - 1)
            B -= 1
            ans += 1
            A = 1
            print(ans + (B - A) // 2)
        else:
            ans += N - B
            # A += N - B + 1
            A = A + (N - B)
            B = N
            A += 1
            ans += 1
            print(ans + (N - A) // 2)
    else:
        print(min(N - A, B - 1))
else:
    print((B - A) // 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 abs(b-a)%2==1:
    lst = [a-1,n-b]
    if lst[0]>lst[1]:
        print((n-b+1)+(n-(a+(n-b+1)))//2)
    elif lst[0]<lst[1]:
        print((a-1+1)+(b-a-1)//2)
    elif lst[0]==lst[1]:
        print((a-1+1)+(b-a-1)//2)

Submission status: Accepted

Solution code:
import sys
from random import choice,randint
inp=sys.stdin.readline
out=sys.stdout.write
flsh=sys.stdout.flush
 
sys.setrecursionlimit(10**9)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
 
def MI(): return map(int, inp().strip().split())
def LI(): return list(map(int, inp().strip().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines().strip()]
def LI_(): return [int(x)-1 for x in inp().strip().split()]
def LF(): return [float(x) for x in inp().strip().split()]
def LS(): return inp().strip().split()
def I(): return int(inp().strip())
def F(): return float(inp().strip())
def S(): return inp().strip()
def pf(s): return out(s+'\n')
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)

def main():
    n,a,b=MI()
    # n,a,b=randint(1,30),randint(1,10),randint(5,25)
    # print(n,a,b)
    if (b-a)%2==0:
        pf(str((b-a)//2))
    elif a==1 or b==n:
        pf(str((b-a+1)//2))
    else:
        mn = min(a-1,n-b)
        ans = (b-a+(mn*2)+1)//2
        ans = min([ans,n-a,b-1])
        pf(str(ans))

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

result = 10 ** 19

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

print(result)

Submission status: Accepted

Solution code:
import numpy as np
from decimal import Decimal

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import sys
import math


debug = False

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

def parse_input(lines_as_string = None):

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

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

    return (n, a, b)

def solve(n, a, b):
 

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

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


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



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

    return result

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

if __name__ == '__main__':

    main()

Submission status: Accepted

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

result = 0

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

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

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

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

print(result)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

################ DANGER ################
test = ""
#test = \
"""
5 2 4
ans 1
"""

"""
5 2 3
ans 2
"""

"""
5 3 4
ans 2
"""

"""
7 2 5
ans 3, not 4 
"""
########################################
test = list(reversed(test.strip().splitlines()))
if test:
    def input2():
        return test.pop()
else:
    def input2():
        return input()
########################################  
    
n, a, b = map(int, input2().split())

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


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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
from decimal import *

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

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

print(ans)

Submission status: Accepted

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

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

print(min(disA, disB, disC))

Submission status: Accepted

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

diff = B - A

_a, mod = divmod(diff, 2)

is_diff_even = (mod == 0)

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

    # distance
    if (left - 1) < (N - right):
        print((left - 1) + 1 + ((right - ((left - 1) + 1) - 1) // 2))
    else:
        # 右のほうが近い
        print((N - right) + 1 + ((N - (left + (N-right+1))) // 2))

Submission status: Accepted

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