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: Wrong Answer

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

ANS = 0

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

elif A - 1 > N-B:
    ANS = N - B + 1 + (B - 1 - A)/2

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

print(int(ANS))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N, A, B = map(int, input().split())
c=0
for i in range(1, N+1):
    if A+1<B :
        A += 1
        B -= 1
        if A==B:
            c += 1
            if A==1 or B==1:
                continue
    if A+1==B:
        A -= 1
        B -= 1
        if A == 1 or B == 1:
            c += 1
        if A==B:
            break
print(c)

Submission status: Wrong Answer

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

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

if (b-a)%2==1:
    if (n-a) >= (b-1):
        print(b-1)
    elif (n-a) < (b-1):
        print(n-a)

Submission status: Wrong Answer

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

X = B-A

if X%2==0:
    min_round = int(X/2)
else:
    if(N-A<B-1):
        min_round = int(N-A)
    else:
        min_round = int(B-1)

print(min_round)

Submission status: Wrong Answer

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

if (A+B)%2==0:#偶奇が一致
    kaisu=int(math.log2(B-A))
    print(kaisu)
else:
    #print("偶奇が一致せず")
    if (N-B)>=(A-1):
        #Bが左端にいく
        print(B-1)
    else:
        print(N-A)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

print(int(ans))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
nab=list(map(int,input().split()))

ans=0
if (nab[2]-nab[1])%2==0:
    ans=int((nab[2]-nab[1])/2)
else:
    if nab[2]-1<nab[0]-nab[1]:
        ans=nab[2]-1
    else:
        ans=nab[0]-nab[1]
print(ans)

Submission status: Wrong Answer

Solution code:
import math
n,a,b = map(int,input().split())
if (b-a)%2==0:
    print((b-a)//2)
else:
    if a < math.floor(n/2):
        for i in range(n):
            b -= i
            if a <= 1:
                a = 1
            else:
                a -= i
            if a == b:
                print(i)
                break
    else:
        for i in range(n):
            a += i
            if b >= n:
                b = n
            else:
                b += i
            if a == b:
                print(i)
                break

Submission status: Wrong Answer

Solution code:
s=input().split()
N=int(s[0])
A=int(s[1])
B=int(s[2])
if B>A:
    c=A
    A=B
    B=c
d=A-B
if d%2==0:
    print(int(d/2))
else:
    print(int((A+B-1)/2))

Submission status: Wrong Answer

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


print(min(max(a-1,b-1),max(n-a,n-b))+1)

Submission status: Wrong Answer

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

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

        print(min(B - 1, N - A))


main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,a,b=map(int,input().split())
min_=min(a,b)
max_=max(a,b)

k=max_-min_-1

if k==1:
    print(k)
else:#偶数
    ans=min(max_-1,n-min_)
    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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))

Submission status: Wrong Answer

Solution code:
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, a, b = list(map(int, readline().split()))
    if (b - a) % 2 == 0:
        print((b - a) // 2)
    else:
        if abs(a - 1) < abs(n - b):
            c = a - 1
            b -= c
            a -= c
            if (b - a) % 2 == 0:
                print((b - a) // 2 + c)
            else:
                print(b - 1 + c)
        else:
            c = n - b
            a -= c
            b -= c
            if (b - a) % 2 == 0:
                print((b - a) // 2 + c)
            else:
                print(n - a + c)


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

dim = B - A

if dim % 2 == 0:
  print(int(dim/2))
if dim % 2 == 1:
  dimAN = N - A
  dim1B = B - 1
  
  if dimAN > dim1B:
    print(dim1B)
  elif dimAN < dim1B:
    print(dimAN)
  elif dimAN == dim1B:
    print(dimAN)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import numpy as np

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

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

else:
    near_n = (N - A) + (N - B)
    near_1 = (A - 1) + (B - 1)
    is_end_n = True if near_n < near_1 else False

    cnt = 0
    while True:
        if A == B:
            break
        if is_end_n:
            A += 1
            B += 1
        else:
            A -= 1
            B -= 1

        A = np.clip(A, 1, N)
        B = np.clip(B, 1, N)
        cnt += 1

    print(cnt)

Submission status: Wrong Answer

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

    left_s = A - 1
    right_s = N - B
    
    # 偶数なら
    if sub % 2 == 0:
        return sub / 2
    # 奇数なら
    else:
        if left_s > right_s:
            return B - 1
        else:
            return N - A
    
if __name__ == '__main__':
    print(int(main()))

Submission status: Wrong Answer

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(max(N-B, A-1))

Submission status: Wrong Answer

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

sa = abs(a-b)

if sa %2 == 0:
    print(int(sa/2))
else:
    if n-b < a-1:
        print(n-a)
    elif n-b > a-1:
        print(b-1)

Submission status: Wrong Answer

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

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

o = []

N -= 1
L,R = sorted([A,B])
L -= 1
R -= 1

if L % 2 == N % 2:
    a = N - R
    o.append(a + (N - (L+a))//2)

if R % 2 == 0:
    b = L
    o.append(b + (R-b) // 2)

o.append(N - L)
o.append(R)

print(min(o))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
#coding:utf-8
n, a, b = map(int, input().split())
#a,bのテーブル距離
dist = b-a

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

print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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


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

Submission status: Wrong Answer

Solution code:
N,A,B = map(int,input().split())
S = B-A
C = 0

if S % 2 ==0:
  C = S / 2
else:
  D = min(N-A,B-1)
  if A-1 <= N-B:
    E = A + S//2
  else:
    E = N-B+1 + S//2
  C = min(D,E)

print(int(C))

Submission status: Wrong Answer

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

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

diff = abs(A - B)

if diff == 0:
    print(int(0))
elif diff % 2 == 0:
    # diffが偶数ならdiff/2回で同じ卓に来る
    print(int(diff / 2))
else:
    # diffが奇数なら以下の3ステップで同じ卓に来る
    # 1. 1もしくはNの近いほうの端に寄る
    total = min(A-1, B-1, N-A, N-B)

    # 2. 偶数になるまで一回待つ
    diff = diff - 1
    total = total + 1

    # 3. あとは偶数と一緒
    total = total + (diff / 2)

    print(int(total))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#A - Table Tennis Training
N,A,B = list(map(int, input().split()))

Lab = B-A
La = N-A
Lb = B-1

if Lab%2==0:
    #case Lab is even
    ans = int(Lab/2)
else:
    #case Lab is odd
    ans = min(La,Lb)

print(ans)

Submission status: Wrong Answer

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

    left_s = A - 1
    right_s = N - B
    
    # 偶数なら
    if sub % 2 == 0:
        return sub / 2
    # 奇数なら
    else:
        if left_s <= right_s:
            return B - 1
        else:
            return N - A
    
if __name__ == '__main__':
    print(int(main()))

Submission status: Wrong Answer

Solution code:
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, a, b = list(map(int, readline().split()))
    if (b - a) % 2 == 0:
        print((b - a) // 2)
    else:
        if abs(a - n) < abs(n - b):
            c = a - 1
            b -= c
            a -= c
            if (b - a) % 2 == 0:
                print((b - a) // 2 + c)
            else:
                print(b - 1 + c)
        else:
            c = n - b
            a -= c
            b -= c
            if (b - a) % 2 == 0:
                print((b - a) // 2 + c)
            else:
                print(n - a + c)


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
N,a,b=map(int,input().split())
if (b-a)%2==0:
    print((b-a)//2)
else:
    b-=a
    print((b-1)//2+a)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N, A, B = map(int, input().split())
if A % 2 == B % 2: # 両方とも偶数/奇数の場合
    print(int(abs(A-B)/2))
else: # 両方が違う場合
    # 大きい値がNにいってから戻るパターン
    nReturnedCount = (N - max(A, B) + 1)
    nCount = int(N - (min(A, B) + nReturnedCount) / 2)
    # 小さい値が1にいってから戻るパターン
    minReturnedCount = min(A, B)
    minCount = int(minReturnedCount + int(max(A, B) - minReturnedCount / 2))
    print(min(nCount, minCount))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
n,a,b=map(int,input().split())
if (b-a)%2==0:
    print((b-a)//2)
else:
    print(min(n-a,b-1))

Submission status: Wrong Answer

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

ans = 0

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

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

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

# 25 35 44

Submission status: Wrong Answer

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

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

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

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

# Aが近い
if (A-1) <= (N-B):
    flag = True
# Bが近い
else:
    flag = False

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

print(answer)

Submission status: Wrong Answer

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

med = N / 2 + 0.5

if (A - B) % 2 == 0:
    while(True):
        if A > B:
            A = A - 1
            B = B + 1
        else:
            A = A + 1
            B = B - 1

        if A < 1:
            A = 1
        elif A > N:
            A = N
        elif B < 1:
            B = 1
        elif B > N:
            B = N

        round_count = round_count + 1

        if A == B:
            break

else:    
    while(True):
        Max = max([A, B])
        Min = min([A, B])
        if (Max + Min) / 2 > med:
            A = A + 1
            B = B + 1
        else:
            A = A - 1
            B = B - 1

        if A < 1:
            A = 1
        elif A > N:
            A = N
        elif B < 1:
            B = 1
        elif B > N:
            B = N
        
        round_count = round_count + 1

        if A == B:
            break

print(round_count)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import numpy as np

val = input().split(' ')
N = int(val[0])
A = int(val[1])
B = int(val[2].strip())

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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


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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():

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

    if abs(a-b) % 2 == 0:
        print(abs(a-b)//2)
        return
    left=0
    temp = max(a,b)
    left = temp - 1
    right = 0
    temp = min(a,b)
    right = n - temp
    ans = min(left,right)

    tempR=b-a
    mid1=10**19
    if tempR-1>0:
        mid1=(tempR-1)//2 + a 
    tempL=a+n-b+1
    mid2=10**19
    if n-tempL > 0:
        mid2=(n-tempL)//2 + n-a
    ans = min(ans,mid1,mid2)


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

Submission status: Wrong Answer

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

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

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

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


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

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

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

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

if (b-a)%2==1:
    if (n-a) > (b-1):
        print(b-1)
    if (n-a) < (b-1):
        print(n-a)

Submission status: Wrong Answer

Solution code:

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


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


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


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


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


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


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


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


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


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


# show_flg = False
show_flg = True


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

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

n, a, b = MAP()

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

Submission status: Wrong Answer

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

if (b-a) % 2 == 0:
    # 距離が偶数
    print((b-a) // 2)
    sys.exit()
else:
    print(min([b-1, n-a]))

# print([b-1, n - a])

Submission status: Wrong Answer

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

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

    if A==1 and B<N:
        t=(B+1-A)//2
    if A>1 and B==N:
        u=(B+1-A)//2
    print(min(s,t,u))

Submission status: Wrong Answer

Solution code:
from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby
import bisect
import copy
import math
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]

num = b - a
if num % 2 == 0 and num != 1:
    print(int(num / 2))
elif num == 1 and a == 1:
    print(1)
elif num == 1 and b == n:
    print(1)

elif num % 2 == 1:
    difA = a - 1
    difB = n - b
    if difA <= difB:
        res = a - 1
        a = 1
        b = b - (a - 1)
        num = b - a
        if num % 2 != 0:
            res += 1
            b -= 1
        res += int((b-a)/2)
        print(res)
    else:
        res = n - b
        a = n-b+a
        b = n
        num = b - a
        if num % 2 != 0:
            res += 1
            a += 1
        res += int((b-a)/2)
        print(res)

Submission status: Wrong Answer

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


# N, A, B = 10 ** 18, 1, 10 ** 18
# N, A, B = 5, 2, 5


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

    if distance % 2 == 0:
        return distance // 2
    else:
        if a == 1:
            return b - 1
        if b == n:
            return n - a

        if a == n - b + 1:
            return b - 1
        if a < n - b + 1:
            return b - 1
        if a > n - b + 1:
            return n - a


print(main(N, A, B))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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


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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if A>B:
    X=A-B
    if X%2 == 0:
        print(int((A-B)/2))
    else:
        if N-B>=A: 
            print(A)
        else:
            print(N-B)
        
else:
    Y=B-A
    if Y%2 == 0:
        print(int((B-A)/2))
    else:
        if N-A>=B:
            print(B)
        else:
            print(N-A)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def CheckLowestNumber(N: int,A: int,B:int):

    num_A_up = A
    num_B_up = A
    num_A_down = B
    num_B_down = B
    num_time = 0
    while (num_A_down != num_B_up or num_A_up != num_B_down) or (num_A_down != num_B_down or num_A_up != num_B_up):
        if num_A_up == N : num_A_up = N
        else: num_A_up += 1
        if num_A_down == 1 : num_A_down = 1
        else : num_A_down -=1
        if num_B_up == N : num_B_up = N
        else: num_B_up += 1
        if num_B_down == 1 : num_B_down = 1
        else : num_B_down -=1
        num_time += 1

    return num_time

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
def main():

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

    if abs(a-b) % 2 == 0:
        print(abs(a-b)//2)
        return
    left=0
    temp = max(a,b)
    left = temp - 1
    right = 0
    temp = min(a,b)
    right = n - temp
    ans = min(left,right)

    tempR=b-a
    mid1=10**19
    if tempR-1>0:
        mid1=(tempR-1)//2 + a 
    tempL=a+n-b+1
    mid2=10**19
    if n-tempL > 0:
        mid2=(n-tempL)//2 + n-a+1
    ans = min(ans,mid1,mid2)


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

Submission status: Wrong Answer

Solution code:
from sys import stdin, stdout  
  
def main(): 
	n, a, b = [int(x) for x in stdin.readline().split()]
	res = []
	if (b - a) % 2 == 0:
		res.append((b - a)//2)
	res.append(b-1)
	res.append(n-a)
	stdout.write(str(min(res))+'\n')
if __name__ == "__main__": 
	main()

Submission status: Wrong Answer

Solution code:
from decimal import Decimal
N, A, B = input().split()
n=Decimal(N)
a=Decimal(A)
b=Decimal(B)
if (b-a) % 2==0:
    print((b-a)//2)
elif (b-1) < (n-a):
    print(b-1)
else:
    print(n-a)

Submission status: Wrong Answer

Solution code:
n,a,b=map(int,input().split())
cnt=0
if (b-a) != 1:
    while a:
        a+=1
        b-=1
        cnt+=1
        if a == b:
            print(cnt)
            exit()
if (b-a) == 1:
    if a-1 > n-b:
        while a:
            if b != n:
                b+=1
                a+=1
                cnt+=1
            if b == n:
                a+=1
                cnt+=1
            if a == n and b == n:
                print(cnt)
                exit()
    if a-1 < n-b:
        while a:
            if a != 1:
                a-=1
                b-=1
                cnt+=1
            if a == 1:
                b-=1
                cnt+=1
            if a == 1 and b == 1:
                print(cnt)
                exit()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
N, A, B = map(int, input().split())
if (B - A) % 2 == 1:
    # どっちの角による
    print(min(N - A, B - 1))
else:
    print((B - A) // 2)

Submission status: Wrong Answer

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

print(min(half, edge))

Submission status: Wrong Answer

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

else:
    print(min([N - A, B - 1,round((N - (A + N - B))/2) + N - B,round((B - (A - 1) + 1 ) /2)  + (A - 1)]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

diff=B-A

if diff %2==0:
    print(int(diff/2))
else:
    edge=min(N-B,A-1)
    if diff==1:
        print(int(edge+1))
    else:
        after=(diff-1)/2
        # print(after,edge)
        print(int(edge+after+1))