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 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:
        #p1=(min(int(B-1),int(N-A)))
        if B-1>N-A:
            bufA=N-B+1
            bufB=N-A+1
            A=bufA
            B=bufB

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

"""
        else:
            if (A-(B-N+1)-1)%2==0:
                ans=int(N-B+1+(N-(A+(N-B+1)))/2)
                ans=min(ans,N-A)
            else:
                ans=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 = map(int, input().split())
round_count = 0

med = N / 2 + 0.5

Max = max([A, B])
Min = min([A, B])

medAB = (Max + Min) / 2
SubMM = Max - Min

if (SubMM) % 2 == 0:
    round_count = round_count + int(SubMM / 2)
else:
    if medAB > med:
        Add = N - Max
        Max = N
        Min = Min + Add + 1
        SubMM = Max - Min
        round_count = round_count + Add + int(SubMM / 2) + 1
    else:
        Sub = Min - 1
        Max = Max - Sub - 1
        Min = 1
            
        SubMM = Max - Min
        round_count = round_count + Sub + int(SubMM / 2) + 1
            
print(round_count)

Submission status: Wrong Answer

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

if (B-A) % 2 == 0:
    ans = int((B-A)/2)
else:
    ansB1 = A-1
    if (B - A) % 2 == 0:
        ansB2 = int(((B - A-1) // 2))
        ansB = ansB1 + ansB2
    else:
        ansB2 = int(((B - A-1) / 2))
        ansB = ansB1 +1+ ansB2


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

Submission status: Wrong Answer

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

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

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

if r1 % 2 == 0:
  result = r1 / 2
  print(math.ceil(result))


else:
  if N - dai + N - shou  + 1 <= shou + dai:
      result = math.ceil((N - shou + N - dai) / 2)
      print(result)
  else:
      result = math.ceil((dai + shou) / 2) - 1
      print(result)

Submission status: Wrong Answer

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


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


if __name__ == "__main__":
    main()

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:
        #p1=(min(int(B-1),int(N-A)))
        if B-1>N-A:
            bufA=N-B+1
            bufB=N-A+1
            A=bufA
            B=bufB

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

"""
        else:
            if (A-(B-N+1)-1)%2==0:
                ans=int(N-B+1+(N-(A+(N-B+1)))/2)
                ans=min(ans,N-A)
            else:
                ans=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 = 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(N-B+1+(B-A-1)/2)))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if (B-A) % 2 == 0:
    ansA = int((B-A)/2)
else:
    ansA = 10**30

ansB1 = A-1
if (B - A) % 2 == 0:
    ansB2 = int(((B - A-1) // 2))
    ansB = ansB1 + ansB2
else:
    ansB2 = int(((B - A-1) / 2))
    ansB = ansB1 +1+ ansB2


ansC1 = N-B
if (B - A) % 2 == 0:
    ansC2 = int(((B-A-1))//2)
    ansC = ansC1 + ansC2
else:
    ansC2 = int(((B - A-1)) // 2)
    ansC = ansC1 +1+ ansC2

ans = min(ansA,ansB,ansC)
print(int(ans))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if (B - A) % 2 == 0:
    print((B - A) // 2)
elif 2*B < N:
    print(B-1)
elif 2*A > N:
    print(N - A)
else:
    print(min([N-A,B-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(math.ceil(result))


else:
  if N - dai + N - shou  + 1 <= shou + dai:
      result = math.ceil((N - shou + N - dai) / 2)
      print(result)
  else:
      result = math.ceil((dai + shou) / 2) - 1
      print(result)

Submission status: Wrong Answer

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

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

print(int(ans))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N, A, B = map(int, input().split())
N *= 2
diff = abs(A - B)

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

else:
    gap_1 = (A - 1) + (B - 1)
    gap_n = (N - A) + (N - B)

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

    else:
        n = N-A if A < B else N-B
        print(n)

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

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

Submission status: Wrong Answer

Solution code:
N,A,B = list(map(int,input().split()))
diff = B - A
N2B = N - B
N2A = N - A
sumN = N2A + N2B 
sumAB = A + B 


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

Submission status: Wrong Answer

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

def dist(A, B):
  return B - A

di = dist(A, B)

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

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):
      #Aの方が中心から遠い(早くゴールに着く)
      if A >= N_center:
        #A,BがN側に向かう場合(Aが先)
        A_reach = N - A
        B_reach = N - B
        B_nokori = B_reach - A_reach
        Ans = A_reach + 1 + int((B_nokori - 1)/2)
        print(Ans)
      else:
        #A,Bが1側に向かう場合(Aが先)
        A_reach = A - 1
        B_reach = B - 1
        B_nokori = B_reach - A_reach
        Ans = A_reach + 1 + int((B_nokori - 1)/2)
        print(Ans)
    else:
      #Bの方が中心から遠い(早くゴールに着く)
      if B >= N_center:
        #A,BがN側に向かう場合(Bが先)
        A_reach = N - A
        B_reach = N - B
        A_nokori = A_reach - B_reach
        Ans = B_reach + 1 + int((A_nokori - 1)/2)
        print(Ans)
      else:
        #A,Bが1側に向かう場合(Bが先)
        A_reach = A - 1
        B_reach = B - 1
        A_nokori = A_reach - B_reach
        Ans = B_reach + 1 + int((A_nokori - 1)/2)
        print(Ans)
  else:
    N_center = int(N/2) + 1
    if abs(A-N_center) >= abs(B-N_center):
      #Aの方が中心から遠い(早くゴールに着く)
      if A >= N_center:
        #A,BがN側に向かう場合(Aが先)
        A_reach = N - A
        B_reach = N - B
        B_nokori = B_reach - A_reach
        Ans = A_reach + 1 + int((B_nokori - 1)/2)
        print(Ans)
      else:
        #A,Bが1側に向かう場合(Aが先)
        A_reach = A - 1
        B_reach = B - 1
        B_nokori = B_reach - A_reach
        Ans = A_reach + 1 + int((B_nokori - 1)/2)
        print(Ans)
    else:
      #Bの方が中心から遠い(早くゴールに着く)
      if B >= N_center:
        #A,BがN側に向かう場合(Bが先)
        A_reach = N - A
        B_reach = N - B
        A_nokori = A_reach - B_reach
        Ans = B_reach + 1 + int((A_nokori - 1)/2)
        print(Ans)
      else:
        #A,Bが1側に向かう場合(Bが先)
        A_reach = A - 1
        B_reach = B - 1
        A_nokori = A_reach - B_reach
        Ans = B_reach + 1 + int((A_nokori - 1)/2)
        print(Ans)

Submission status: Wrong Answer

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



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

Submission status: Wrong Answer

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

if (B-A) % 2 == 0:
    ansA = int((B-A)/2)
else:
    ansA = 10**30

ansB1 = A-1
if (B - A) % 2 == 0:
    ansB2 = int(((B - A) // 2))
    ansB = ansB1 + ansB2
else:
    ansB2 = int(((B - A-1) // 2))
    ansB = ansB1 + ansB2


ansC1 = N-B
if (B - A) % 2 == 0:
    ansC2 = int(((B-A))//2)
    ansC = ansC1 + ansC2
else:
    ansC2 = int(((B - A-1)) // 2)
    ansC = ansC1 + ansC2

ans = min(ansA,ansB,ansC)
print(int(ans))

Submission status: Wrong Answer

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

if (B - A) % 2 == 0:
    m = 0
    while A < B:
        A +=1
        B -=1
        m +=1
    print(m)
elif 2*B < N:
    print(B-1)
elif 2*A > N:
    print(N - A)
else:
    print(min([N-A,B-1]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

C = int(B - A)

if C > 2:
    if C % 2 == 0:
        print(int(C/2))
    elif C % 2 == 1:
        print(int(C/2))
elif C <= 2:
    if C == 0:
        print(0)
    elif C == 1:
        print(2)
    elif C == 2:
        print(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))
elif sa >= 3:
    # bの方が近い場合
    if n-b < a-1:
        ma = n-b+1+a
        ans = int((n-ma)/2) + n-b + 1
        #ans = n-b + 1 + int(abs(a + n-b + 1 -b)/2)
    # aの方が近い場合
    elif n-b >= a-1:
        mb = b-(a-1) + 1
        ans = int((mb -1)/2) + a
    print(ans)
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 (b-a)%2==0:
    print(int((b-a)/2))
else:
    if (a-1)<=(n-b):
        b-=a
        print(int((b-1)/2)+a)
    else:
        a+=n-b+1
        print(int((n-a)/2)+n-b+1)

Submission status: Wrong Answer

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

i = 0
while (B - A) > 0:
    if (B - A) >= 2:
        B = B - 1
        A = A + 1
        i = i + 1
    else:
        if (N - A) > (B - 1):
            B = B - 1
            if A != 1:
                A = A - 1
            i = i + 1


print(i)

Submission status: Wrong Answer

Solution code:
import math as m

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

dif = B-A
print(m.floor(dif/2) if dif != 1 else min(A-1, N-B)+dif)

Submission status: Wrong Answer

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

if (B-A) % 2 == 0:
    ansA = int((B-A)/2)
else:
    ansA = 10**30

ansB1 = A-1
if (B - A) % 2 == 0:
    ansB2 = int(((B - A) // 2))
    ansB = ansB1 + ansB2
else:
    ansB2 = int(((B - A-1) // 2))
    ansB = ansB1 +1+ ansB2


ansC1 = N-B
if (B - A) % 2 == 0:
    ansC2 = int(((B-A))//2)
    ansC = ansC1 + ansC2
else:
    ansC2 = int(((B - A-1)) // 2)
    ansC = ansC1 + 1 + ansC2

ans = min(ansA,ansB,ansC)
print(int(ans))

Submission status: Wrong Answer

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

if (abs(A-B)-1) % 2 == 0:
    A_right = N-A+1
    B_right = N-B+1
    M = (N+1)/2
    
    if B <= M:
        count = A
        tmpB = B-count
        print(count + int(abs(1-tmpB)/2))
    elif A <= M and B >= M:
        count = min(A, B_right)
        tmpVal = min(A_right, B) - count
        print(count + int(abs(1-tmpVal)/2))
    elif A >= M:
        count = B_right
        tmpA = A_right - count
        print(count + int(abs(1-tmpA)/2))
        
else:
    print(int(abs(A-B)/2))

Submission status: Wrong Answer

Solution code:
import sys
N, A, B=(int(x) for x in input().split())
count = 0
odd_flag = False

if (B-A) %2 == 1:
  odd_flag = True

if not odd_flag:
  print( (B-A)//2 )

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

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
    else:
        short = (dst - 1) / 2 + (long + 1)

    print(int(short))

if __name__ == "__main__":
    main()

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))
else:
    if A == 1 and B == N:
        print(int(B/2))
    elif A == 1 and B < N:
        print(int(1+B/2))
    elif A > 1 and B == N:
        print(int((N-A)/2 + 1))
    else:
        A1 = A-1
        NB = N-B
        if NB < A1:
            print(int(N-(A+B-1)/2))
        else:
            print(int((A+B-1)/2))

Submission status: Wrong Answer

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

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

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

elif A==1 and B==N:
  print(B/2)

elif (A-1)<=(N-B):
  print(int(A+(B-A)/2))

else:
  print(int(N-B+(B-A)/2))

Submission status: Wrong Answer

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

if diff % 2 != 0:
    gap_1 = (A - 1) + (B - 1)
    gap_n = (N - A) + (N - B)

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

    else:
        n = N-A if A < B else N-B
        print(n)

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

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math as m

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

dif = B-A
print(m.floor(dif/2) if dif != 1 else min(A, N-B)+dif)

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(math.ceil(result))


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

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 (a-1)<=(n-b):
    print(int(y+a))
  else:
    print(int(y+1+n-b))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

diff = b - a
mod = diff % 2

if mod == 0:
  
  print( diff // 2 )

else :
  
  left = b - 1
  right = n - a

  if left < right :
    if diff == 1 :
        print(left)

    else :
    	print (min(left, b - a + 1 ))
    
  else :
    if diff == 1 :
      	print(right)
    else :
    	print(min(right,(n-a)-(n-b+1)))

Submission status: Wrong Answer

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

cnt = 0
d = max(a, b) - ((a + b) / 2)
d1 = max(a, b) - 1
d2 = n - min(a, b)
for i in range(n):
    if a == b:
        break
    if (a + b) % 2 == 0:
        if a > b:
            a = a - d if (a - d) > 1 else 1
            b = b + d if b + d < n else n
        else:
            a = a + d if a + d < n else n
            b = b - d if (b - d) > 1 else 1
        cnt += int(d)
    else:
        if d2 < d1:
            a = a + d2 if a + d2 < n else n
            b = b + d2 if b + d2 < n else n
            cnt += d2
        else:
            a = a - d1 if a - d1 > 1 else 1
            b = b - d1 if b - d1 > 1 else 1
            cnt += d1

print(cnt)

Submission status: Wrong Answer

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

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

    else:
        shifta = N - A
        shiftb = B - 1

        if shifta >= shiftb:
            print(shiftb)

        else:
            print(shifta)

main()

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

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

if (b-a-1) > 0:
  c = (b-a-1)/2 + a
else:
  c = 10**19

if (n-(a+(n-b+1))) > 0:
  d = (n-(a+(n-b+1))) + (n - b - 1)
else:
  d = 10**19

ans = min(n-a, b-1, int(c), d)
print(ans)

Submission status: Wrong Answer

Solution code:
print("なんでA問題から答えがあわないの！！！")
print("なんでA問題から答えがあわないの！！！")
print("なんでA問題から答えがあわないの！！！")
print("なんでA問題から答えがあわないの！！！")
print("なんでA問題から答えがあわないの！！！")
print("なんでA問題から答えがあわないの！！！")
print("なんでA問題から答えがあわないの！！！")
print("なんでA問題から答えがあわないの！！！")
print("なんでA問題から答えがあわないの！！！")
print("なんでA問題から答えがあわないの！！！")
print("なんでA問題から答えがあわないの！！！")
print("なんでA問題から答えがあわないの！！！")
print("なんでA問題から答えがあわないの！！！")
print("なんでA問題から答えがあわないの！！！")
print("なんでA問題から答えがあわないの！！！")
print("なんでA問題から答えがあわないの！！！")
print("なんでA問題から答えがあわないの！！！")

Submission status: Wrong Answer

Solution code:
N,A,B = list(map(int,input().split()))
diff = B - A
N2B = N - B
N2A = N - A
sumN = N2A + N2B 
sumAB = A + B 


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

Submission status: Wrong Answer

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

if diff % 2 == 0:
    print(-1)

else:
    gap_1 = (A - 1) + (B - 1)
    gap_n = (N - A) + (N - B)

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

    else:
        n = N-A if A < B else N-B
        print(n)

Submission status: Wrong Answer

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

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

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

elif A==1 and B==N:
  print(B)

elif (A-1)<=(N-B):
  print(int(A+(B-A)/2))

else:
  print(int(N-B+(B-A)/2))

Submission status: Wrong Answer

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

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

print(ans)

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))
elif sa >= 3:
    # bの方が近い場合
    if n-b < a-1:
        ma = n-b+1+a
        ans = int((n-ma)/2) + n-b + 1
        #ans = n-b + 1 + int(abs(a + n-b + 1 -b)/2)
    # aの方が近い場合
    elif n-b >= a-1:
        mb = b-(a-1+1)
        ans = int((mb -1)/2) + a
    print(ans)
else:
    if n-b < a-1:
        print(n-a)
    elif n-b >= a-1:
        print(b-1)

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:
        #p1=(min(int(B-1),int(N-A)))
        if B-1>N-A:
            bufA=N-B+1
            bufB=N-A+1
            A=bufA
            B=bufB

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

"""
        else:
            if (A-(B-N+1)-1)%2==0:
                ans=int(N-B+1+(N-(A+(N-B+1)))/2)
                ans=min(ans,N-A)
            else:
                ans=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:
import sys
N, A, B=(int(x) for x in input().split())
count = 0
odd_flag = False

if (B-A) %2 == 1:
  odd_flag = True

if not odd_flag:
  print( (B-A)//2 )

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

Submission status: Wrong Answer

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

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(math.ceil(result))


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