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:
import math

inpt = input().split(" ")
inpt = [int(i) for i in inpt]
N = inpt[0]
A = inpt[1]
B = inpt[2]


difab = abs(A - B)
r1 = math.ceil(difab)

dai = max(A,B)
shou = min(A,B)

r2 = N - dai + shou
r2 = math.ceil(r2)

ab_dis = min(r1,r2)

if ab_dis % 2 == 0:
  result = ab_dis / 2
  print(int(result))


else:
  r_cand = N*2
  if max(r1,r2) % 2 == 0:
    r_cand = max(r1,r2)
  if N - dai <= shou:
    if shou <= N - shou:
      result = min(math.ceil((shou + N - dai) / 2), r_cand)
      print("a",result)
    else:
      result = min(math.ceil((N - shou + N - dai) / 2), r_cand)
      print("b",result)
  else:
    if dai <= N - dai:
      result = min(math.ceil((dai + shou) / 2), r_cand)
      print("c",result)
    else:
      result = min(math.ceil((N - dai + shou) / 2), r_cand)
      print("d",result)

Submission status: Wrong Answer

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

print(answer)

Submission status: Wrong Answer

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

def f(A, B):
        return int((A + B) / 2) - A
  
if (B - A) % 2 == 0:
    ans = int((A + B) / 2) - A
else:
    # Aが1に向かうとき
    ans_a = A + f(1, B - A + 1)
    # BがNに向かうとき
    ans_b = (N - B + 1) + f(A + N - B +1, N)
    ans = min(ans_a, ans_b)
    #print(ans_a, ans_b)
    
print(ans)

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

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

        print(min(Y, X, Z))


main()

Submission status: Wrong Answer

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

matches = 0
for i in range(N):
    if A==B:
        print(matches)
        break
    elif abs(B-A) == 1:
        if A == min(A,B):
            A-=1 if A!=1 else 0
            B-=1
            matches +=1
        else:
            B-=1 if B!=1 else 0
            A-=1
            matches +=1
    else:
        if A == min(A,B):
            A+=1 if A!=1 else 0
            B-=1
            matches +=1
        else:
            B+=1 if B!=1 else 0
            A-=1
            matches +=1

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Half = (A + B)//2

if Half == (A + B)/2:
    if Half >= A:
        print(Half - A)
    elif Half < A:
        print(A - Half)
else:
    if N/2 >= A and N/2 >= B:
        print(B - 1)
    elif N/2 <= A and N/2 <= B:
        print(N - A)
    elif B > N/2 > A:
        if (N - A) < (B - 1):
            print(N - A)
        elif (N - A) > (B - 1):
            print(B - 1)
        else:
            print(N//2)

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+b)/2<=((n+1)/2):
    if a!=1:
      print(a+((b-1-a)//2))
    else:
      print(b//2)
  else:
    if b!=n:
      print((n-b)+(1+b-a)//2)
    else:
      print((1+n-a)//2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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


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


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
a,b,c = input().split(" ")
a=int(a)
b=int(b)
c=int(c)

minum = c-b-1
res = 0


if (minum%2==0):
    if (a-b>b-1):
        res = b-1
        res += c-1
        print(res)
    else:
        a -= b+1
        a -= c-1
        print(a*-1)
elif (minum%2!=0):
    print(minum)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

C = B-A

if C % 2 == 0:
#     print("1")
    print(int((B-A)/2))
elif C == 1:
#     print("2")
    print(int(max(N-B,A-1)))
else:
#     print("3")
    if N-B > A-1:
        print(int((B+A)/2))
    else:
        print(int(N-(A+B-1)/2))

Submission status: Wrong Answer

Solution code:
mylist = [int(x) for x in input().split()]
N=mylist[0]
A=mylist[1]
B=mylist[2]

if A==1:
    print(B-1)
 
elif min(A,B)>(N/2):
    if abs(A-B)==1:
        print(N-min(A,B))
        #print(1)
    else:
        print(abs(A-B)//2)
        #print(2)
else:    
 
    if abs(A-B)==1:
        print(min(A,B))
        #print(3)
    else:
        print(abs(A-B)//2)
        #print(4)

Submission status: Wrong Answer

Solution code:
number = input()
n,a,b = [int(ele)for ele in number.split(' ')]
res =[]
if (a % 2) == 0 and b % 2 == 0 or a % 2 != 0 and b % 2 != 0:
    res.append(len(range(a+1,b)))
    
res.append(len(range(a,n)))
res.append(b-1)

print(min(res))

Submission status: Wrong Answer

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)
    a1 = 1
    b1 = b1 - 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: Wrong Answer

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

Submission status: Wrong Answer

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

elif abs(B-A+1)%2==0:
    if B <= math.ceil(N/2):
        print(B-1)
    elif A >= math.ceil(N/2):
        print(N-A)
    elif B-1 > N - A:
        print(N-A)
    elif N-A > B-1:
        print(B-1)

Submission status: Wrong Answer

Solution code:
import math

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

output = 0
if d % 2 == 0:
  output = int(d / 2)
else:
  # 「aと1の距離」の方が「bとn」の距離より近い場合
  if a-1 < n-b:
    if (b-(a-1)-1) % 2 == 0:
      output = (a-1) + int(math.floor((b-(a-1)-1)) / 2)
    else:
      output = (a-1) + int(math.floor((b-(a-1)-1) / 2)) + 1
  else:
    if (n-(n-b+a)) % 2 == 0:
      output = (n-b) + int(math.floor((n-(n-b+a))) / 2)
    else:
      output = (n-b) + int(math.floor((n-(n-b+a))) / 2) + 1
print(output)

Submission status: Wrong Answer

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

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

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

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)
    elif (a-1) == (n-b):
        ans = n/2
    else:
        ans = n-b+1+((b-a-1)/2)

print(int(ans))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
input_data = input()
input_data = input_data.split()

n = int(input_data[0])
a = int(input_data[1])
b = int(input_data[2])

if a > b:
    a = int(input_data[2])
    b = int(input_data[1])

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N, A, B = map(int, input().split())
X = B - A
Y = (A + B)/2

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

Submission status: Wrong Answer

Solution code:
# 1行目の入力を空白で分割された数字として扱う
N, A, B = map(int, input().split())

# 答えの準備
res = 0

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

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

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

# print(n)
# print(a)
# print(b)

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def how_match_play(N, A, B):
    return_value = 0
    if (B - A) % 2 == 0:
        return_value = (B - A) / 2
    else:
        diff_1A = A - 1
        diff_BN = N - B
        if diff_1A < diff_BN:
            return_value = B - 1
        else:
            return_value = N - A
    
    return int(return_value)

n, a, b = input().split()
N = int(n)
A = int(a)
B = int(b)

print(how_match_play(N, A, B))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import math
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(min(b-1,a+(b-a-1)//2))
elif b_length<a_length:
    print(min(n-a,n-b+(b-a-1)//2))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

to_top_A = A - 1
to_end_A = N - A
to_top_B = B - 1
to_end_B = N - B

dif = max([A-B, B-A])

if dif%2 == 0:  
    dif = int(dif/2)
else:
    min_to_edge = min([to_top_A, to_top_B, to_end_A, to_end_B])
    dif = min_to_edge + int((dif-min_to_edge)/2) + 1

rnd = min([max([to_top_A, to_top_B]), max([to_end_A, to_end_B]), dif])
print(rnd)

Submission status: Wrong Answer

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

d = n[2] - n[1]

if(d % 2 == 0):
    ans = int(d/2)
else:
    ad = n[0] - n[1]
    bd = n[2] - 1
    if d == 1:
        ans = int(min(ad,bd))
        print(ans)
        sys.exit()
    else:
        ans = 0
        ans = n[0] - n[2] + 1
        n[1] += ans
        ans += int((n[0] - n[1])/2)
        print(ans)
        sys.exit()

if n[1] == 1:
    if (d % 2 != 0):
        ans = 1
        n[2] -= 1
        ans += int((n[2] - 1)/2)
    else:
        ans = int((n[2] - 1)/2)
    print(ans)
    sys.exit()
elif n[2] == n[0]:
    if (d % 2 != 0):
        ans = 1
        n[1] += 1
        ans += int((n[2] - n[1])/2)
    else:
        ans = int((n[2] - n[1])/2)
    print(ans)
    sys.exit()

if(ans < 0):
    ans *= -1
print(ans)

Submission status: Wrong Answer

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

print(answer)

Submission status: Wrong Answer

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

elif abs(B-A+1)%2==1:
    if B <= math.ceil(N/2):
        print(B-1)
    elif A >= math.ceil(N/2):
        print(N-A)
    elif B-1 > N - A:
        print(N-A)
    elif N-A > B-1:
        print(B-1)

Submission status: Wrong Answer

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

if (B-A)%2==0:
  print(int(abs((B-A)/2)))
elif (B-A)%2!=0:
  if A<B and (A-1)<=(N-B):
    print(abs(B-1))
  elif A<B and (A-1)>(N-B):
    print(abs(A-N))
  elif B<A and (B-1)<=(N-A):
    print(abs(A-1))
  elif B<A and (B-1) > (N-A):
    print(abs(B-N))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
input_data = input()
input_data = input_data.split()

n = int(input_data[0])
a = int(input_data[1])
b = int(input_data[2])

if a > b:
    a = int(input_data[2])
    b = int(input_data[1])

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

Submission status: Wrong Answer

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:
        C=N-A
    elif A-1 < N-B:
        C=B-1
    else:
        C=B-1

print(C)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
n, a, b = [int(x) for x in input().split(" ")]
if b > a:
    a, b = b, a
d = a - b - 1

def check(x):
    y = (x - 1) / 2
    if y >= 0:
        return int(y)
    else:
        return -int(-y)

if d % 2 == 1:
    print(check(d) + 1)
else:
    da = n - a - 1
    db = b - 1 - 1
    if db < da:
        ans = db + 2
        d -= 1
        ans += check(d) + 1
    else:
        ans = da + 2
        d -= 1
        ans += check(d) + 1
    print(ans)

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:
    gap_n = (N - A) + (N - B)
    gap_1 = (A - 1) + (B - 1)

    if gap_n == gap_1:
        n = A if (N - A) < B else (N - B)
        print(N - n)
    else:
        if (A == N or A == 1) or (B == N or B == 1):
            n = gap_n if gap_n < gap_1 else gap_1
            print(n)
        else:
            n = N - gap_n if gap_n < gap_1 else gap_1 - 1
            print(n)

Submission status: Wrong Answer

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

if (n_a_b[2] - n_a_b[1]) % 2 == 0:
    print(int(abs(n_a_b[2] - n_a_b[1]) / 2))
elif (n_a_b[2] - n_a_b[1]) % 2 == 1:
    c = n_a_b[0] - n_a_b[2]
    d = n_a_b[1] - 1
    if d >= c:
        if (n_a_b[0] - n_a_b[1]) >= 3:
            ss = (n_a_b[0] - (n_a_b[1] + c + 1))/ 2
            print(int((c + 1) + ss))
        else:
            print(n_a_b[0] - n_a_b[1])
    else:
        print(n_a_b[2] - 1)

Submission status: Wrong Answer

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


a = A
b = B

if A > B:
    a = B
    b = A

k = abs(A - B)

if k % 2 == 0:
    print(int(k / 2))
    exit()

j = min([N - a, b - 1])
print(int(j - int(k / 2) + k % 2))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

    nn = min(B, NA) - 1
    print(nn)

Submission status: Wrong Answer

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

top=max(a-1,b-1)
bottom=max(n-a,n-b)

if (a-b) % 2 == 0:
  print(min(top,bottom,max(a-b,b-a) // 2))
else:
  print(min(top,bottom))

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque

inf=10**9+7

def resolve():
    input = sys.stdin.readline
    N,A,B=map(int,input().rstrip().split())

    if (int(B)-int(A))%2==0:
        p1=(int(B/2)-int(A/2))
        #p2=min(B-1,N-A)
        #print(min(p1,p2))
        print(p1)
    else:
        print(min(int(B-1),int(N-A)))


from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """5 2 4"""
        output = """1"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """5 2 3"""
        output = """2"""
        self.assertIO(input, output)

if __name__ == "__main__":
    #unittest.main()
    resolve()

Submission status: Wrong Answer

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


a = A
b = B

if A > B:
    a = B
    b = A

k = abs(A - B)

if k % 2 == 0:
    print(int(k / 2))
    exit()

j = min([N - a, b - 1])
print(int(j - int(k / 2) - k % 2))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

matches = 1
for i in range(N):
    if A==B:
        print(matches)
        break
    elif (abs(A-B)==1):
        print(min(A,B)) 
        break
    elif abs(A-B)==2:
        print(abs(A-B)-1)
        break
    else:
        if A == min(A,B):
            A+=1 if A!=1 else 0
            B-=1
            matches +=1
        else:
            B+=1 if B!=1 else 0
            A-=1
            matches +=1

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

v=b-(a+1)

if v%2==0:
    if a==1 or b==n:
        ans=int((v+1)/2)+1
    else:
        dif=min(n-b,a-1)
        ans1=dif+int((v+2*dif)/2)+1
        if (n-b)<(a-1):
            ans2=n-a
        else:
            ans2=b-1
        ans=min(ans1,ans2)
else:
    ans=int((v+1)/2)
print(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+b)/2<=((n+1)/2):
    if a!=1:
      print(a+((b-1-a)//2))
    else:
      print((1+b-a)//2)
  else:
    if b!=n:
      print((n-b)+(1+b-a)//2)
    else:
      print(1+((n-a)//2))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

elif abs(A-B)%2==1:
    if B <= math.ceil(N/2):
        print(B-1)
    elif A >= math.ceil(N/2):
        print(N-A)
    elif B-1 > N - A:
        print(N-A)
    elif N-A > B-1:
        print(B-1)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
def how_match_play(N, A, B):
    return_value = 0
    if (B - A) % 2 == 0:
        return_value = (B - A) / 2
    else:
        diff_1A = A - 1
        diff_BN = N - B
        if diff_1A < diff_BN:
            return_value = B - 1
        else:
            return_value = N - A - 1
    
    return int(return_value)

n, a, b = input().split()
N = int(n)
A = int(a)
B = int(b)

print(how_match_play(N, A, B))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
input_data = input()
input_data = input_data.split()

n = int(input_data[0])
a = int(input_data[1])
b = int(input_data[2])

if a > b:
    a = int(input_data[2])
    b = int(input_data[1])

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

Submission status: Wrong Answer

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)
    a1 = 1
    b1 = b1 - a1
    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: Wrong Answer

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

if B-A==1:
  if N-B<=A-1:
    if B==N:
      print(1)
    else:
      print(N-B+1)
  elif A==1:
    print(1)
  else:
    print(A)

elif (B-A)%2==0:
  i=0
  while B-A>=2:
    B=B-1
    A=A+1
    i=i+1
    if B==A:
      print(i)
      break

elif (A-1)<(N-B):
  print(B-2)

else:
  print(N-1-A)

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))
if abs(a-b)%2==1 and (a-1 >= n-b):
  c = (n-b)+1
  d = ((n-(c+a))/2)
  print(int(c+d))
if abs(a-b)%2==1 and (a-1 < n-b):
  c = (a-1) +1
  d = ((b-c)-1)/2
  print(int(c+d))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#code
import math
n,a,b = input().split()
n=int(n)
a=int(a)
b=int(b)
if a==b:
    print(0)
else:

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

result = 0
if (B-A)%2==0:
    result = (B-A)/2
else:
    result = min(A-1,N-B)+1+math.floor((B-A)/2)

print(int(result))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
L=input().split()
n=int(L[0])
a=int(L[1])
b=int(L[2])

if (b-a)%2==0:
  x=(b-a)/2
elif n-a>=b-1:
  x=b-1
elif b-1>n-a:
  x=n-a

print(int(x))

Submission status: Wrong Answer

Solution code:
number = input()
n,a,b = [int(ele)for ele in number.split(' ')]
res =[]
if (a % 2) == 0 and b % 2 == 0 or a % 2 != 0 and b % 2 != 0 and b != n:
    res.append(len(range(a+1,b)))
else:
    res.append(len(range(a,n)))
    res.append(b-1)

print(min(res))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    tmp = input()
    tmp = [int(i) for i in (tmp.split())]
    n = tmp[0]
    a = tmp[1]
    b = tmp[2]
    dst = b - a
    top_a = a - 1
    b_lst = n - b
    long = top_a if top_a<b_lst else b_lst

    if dst % 2 == 0:
        short = dst / 2
        wait = b-1 if (b-1)<(n-a) else n-a
        long = (dst - 2) / 2 + (long + 2)
    else:
        short = 2 * n
        wait = b-1 if (b-1)<(n-a) else n-a
        long = (dst - 1) / 2 + (long + 1)

    print(int(min([short, long, wait])))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

countA,countB = 0, 0

while(A<N):
  A+=1
  B-=1
  if(A==1):
    A=1
  if(A==B):
    countA+=1

while(B<N):
  B+=1
  A-=1
  if(A==N):
    A=N
  if(A==B):
    countB+=1

if(countA<countB):
  print(countB)
else:
  print(countA)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

Submission status: Wrong Answer

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

print(N,A,B)

if(A == B):
  ans = 0
elif(A > B):
  ooi = A
  sukunai = B
else:
  ooi = B
  sukunai = A

if (ooi - sukunai) % 2 == 0:
  while True:
    ooi = ooi - 1
    sukunai = sukunai + 1
    ans += 1
    if(ooi == sukunai):
      break
else:
  if (N - sukunai) > (ooi - 1):
    ans = ooi - 1
  else:
    ans = N - sukunai
  
print(ans)

Submission status: Wrong Answer

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

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