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())
if ((b-a)%2)==0:
    print(int(((b-a)/2)))
elif ((b-a)%2)==1:
    if (a-1)<(n-b):
        dis=(a-1)
        b=b-1
        print(int(((b-a)/2))+dis+1)
    elif (a-1)>=(n-b):
        dis=(n-b)
        a=a+1
        print(int(((b-a)/2))+dis+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+int((B-(A-1+1)-1)/2))
            ans=min(ans,B-1)
        else:
            ans=int(A+1+int((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:
# 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(ans)

Submission status: Wrong Answer

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

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

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

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

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

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=min(ans,B-1)
        #else:
        #    ans=int(A+1+int((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:
n, a, b = map(int, input().split())

def jud(n,a,b):
    distance_dic_before_a = []
    distance_dic_before_b = []
    distance_dic_before_a.append(a)
    distance_dic_before_b.append(b)

    turn_count = 1
    while True:
        distance_dic_after_a = []
        for a_dir in distance_dic_before_a:
            a_dir_plus = a_dir + 1
            a_dir_minus = a_dir - 1
            if a_dir_plus > n:
                a_dir_plus = n
            if a_dir_minus == 0:
                a_dir_minus = 1
            distance_dic_after_a.append(a_dir_plus)
            distance_dic_after_a.append(a_dir_minus)
        distance_dic_before_a = distance_dic_after_a

        distance_dic_after_b = []
        for a_dir in distance_dic_before_b:
            a_dir_plus = a_dir + 1
            a_dir_minus = a_dir - 1
            if a_dir_plus > n:
                a_dir_plus = n
            if a_dir_minus == 0:
                a_dir_minus = 1
            distance_dic_after_b.append(a_dir_plus)
            distance_dic_after_b.append(a_dir_minus)
        distance_dic_before_b = distance_dic_after_b

        set_a = set(distance_dic_after_a)
        set_b = set(distance_dic_after_b)
        print(set_a, set_b)
        result_set = set_a & set_b
        if len(result_set) > 0:
            return turn_count

        turn_count +=1

def jud_2(n,a,b):
    if abs(a-b) % 2 == 0:
        return abs(a-b) // 2
 
    x = n - a
    y = b - 1
 
    if x > y:
        choice_1 = a + (y-a) // 2
        if choice_1 > y:
            return y
        else:
            return choice_1
    else:
        choice_2 = n-b+1 + (x-n-b+1) // 2
        if choice_2 > x:
            return x
        else:
            return choice_2
# print(jud(n, a, b))
print(jud_2(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 (a-1)<(n-b):
    print(int(y+a))
  else:
    print(int(y+2+n-b))

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())
d,l,r=abs(a-b),abs(a-1),abs(n-b)
if d%2==0:
	print(d//2)
else:
	if l<r:
	   print(b-1)
	elif r<l:
		print(n-a)

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)
    if B-1 >= N-A :
        print(math.ceil(-1*A+B-1))

    if B-1 < N-A :
        print(math.ceil((B-A-2)/2))

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:
        if N2B == 0:
            tmp = (N - A + N2B)//2 + N2B+1
        else:
            tmp = (N - A + N2B)//2 + N2B 
        if (N - A + N2B)%2 == 0:
            tmp = tmp + 1
        if N2A < tmp:#A slide
            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())

C = int(B - A)
min = 0

if C > 2:
    if C % 2 == 0:
        print(int(C/2))
    elif C % 2 == 1:
        print(int((C/2)+1))
elif C <= 2:
    if C == 0:
        print(0)
    elif C == 1:
        print(2)
    elif C == 2:
        print(1)

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:
n,a,b = map(int,input().split())
Sum = 0
if abs(b-a) % 2 == 1:
    if (n-a) > b-1:
        print(b-1)
    else:
        print(n-a)
else:
    pivot = (a+b) //2
    ans = pivot - a
    print(ans)

Submission status: Wrong Answer

Solution code:
if __name__ == "__main__":
    N, A, B = [int(x) for x in input().split()]
    
    if A > B:
        A, B = B, A

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

    print(int(i))

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)"""
    if B-1 >= N-A :
        print(math.ceil(-1*A+B-1))

    if B-1 < N-A :
        print(math.ceil((B-A-2)/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-1)//2+1))
    else:
      print(B-1)
  else:
    if (N-A) > (N-B):
      print(N-A-((N-B)//2 + 1))
    else:
      print(N-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 + (y - x) /2 + 1  ))
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())

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 = 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:
        if N2B == 0:
            tmp = (N - A + N2B)//2 + N2B+1
        else:
            tmp = (N - A + N2B)//2 + N2B 
        if (N - A + N2B)//2 == 0:
            tmp = tmp + 1
        if N2A < tmp:#A slide
            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())
if (b-a)%2==0:
	print(int((b-a)/2))
else:
	s=min(a-1,n-b)
	print(int(s+1+(b-a-1)/2))

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
        #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-1
    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 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 <= shou:
      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())
diff = B - A
if diff % 2 == 0:
    print(diff // 2)
else:
    g = B - 1
    s = N - A
    if g > s:
        print(s)
    else:
        print(g)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

print(answer)

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**19

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

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

Submission status: Wrong Answer

Solution code:
N, A, B = map(int, input().split())
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:
N,A,B = map(int,input().split())

min_num = min(A,B)
max_num = max(A,B)
if max_num >N : print(0)
else:
    matches = 0
    for i in range(N):
        if max_num==min_num:
            print(matches)
            break
        else:
            if max_num - min_num == 1:
                max_num-=1
                min_num-=1 if min_num != 1else 0
                matches+=1
            else:
                min_num+=1 if min_num != 1 or max_num > 2 else 0
                max_num-=1
                matches+=1

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

Submission status: Wrong Answer

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

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:
N, A, B = (int(i) for i in input().split())

def f(A, B):
  return int((B - A) / 2)

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

dif = B-A
p1 = min(N-B,A-1)+ dif

if dif %2==0:
  print(min(p1, int(dif/2)))
else:
  print(p1)

Submission status: Wrong Answer

Solution code:
i = list(map(int,input().split()))
if (i[2]+i[1])%2 == 0:
    ans=int((i[2]-i[1])/2)
else:
    a=i[0]
    i.pop(0)
    ans=(max(i)-1 if min(i)-1<a-max(i) else a-min(i))
print(ans)

Submission status: Wrong Answer

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

def f(A, B):
  return int((B - A) / 2)

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

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:
n, a, b = (int(i) for i in input().split())

x = b-a
print(int(min((a+b-1)/2, (2*n-b-a+1)/2, x/2)))

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 <= shou:
      result = min(math.ceil((N - shou + N - dai) / 2), r_cand)
      print(result)
  else:
      result = min(math.ceil((dai + shou) / 2), r_cand)
      print(result)

Submission status: Wrong Answer

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

min_num = min(A,B)
max_num = max(A,B)

min_arr = []
max_arr = []
if max_num >N : print(0)
else:
    matches = 0
    for i in range(N//2):
        if max_num==min_num:
            print(matches)
            break
        else:
            if max_num - min_num == 1:
                max_num-=1
                min_num-=1 if min_num != 1else 0
                matches+=1
                max_arr.append(max_num)
                min_arr.append(min_num)
            else:
                min_num+=1 if min_num != 1 or max_num > 2 else 0
                max_num-=1
                matches+=1
                max_arr.append(max_num)
                min_arr.append(min_num)

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

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

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 )
    print(int(x))
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:
i = list(map(int,input().split()))
if (i[2]+i[1])%2 == 0:
    ans=int((i[2]-i[1])/2)
else:
    i.pop(0)
    ans=(max(i)-1 if min(i)-1<i[0]-max(i) else i[0]-min(i))
print(ans)

Submission status: Wrong Answer

Solution code:
# 整数の入力 
a, b, c = map(int, input().split())
# AとBの間の卓数
bet_table = c - b - 1
# 間の卓数が奇数か偶数で場合分け
if  bet_table % 2 != 0: # 間の卓が奇数
    print((bet_table // 2) + (bet_table % 2))
else: # 間の卓が偶数
    bet_table2 = bet_table - 1
    if b - 1 <= a - c: # 左寄せ
        print(b + (bet_table2 // 2) + (bet_table2 % 2))
    else: # 右寄せ
        print(c + (bet_table2 // 2) + (bet_table2 % 2))

Submission status: Wrong Answer

Solution code:
n, A, B = input().split( )
n = int(n)
A = int(A)
B = int(B)
ans = 0
if (B-A) % 2 == 0:
    ans = (B-A) / 2
else:
    if n - A == B - 1:
        ans = 1
    elif n - A > B - 1:
        ans = B - 1
    else:
        ans = A - 1
print(int(ans))

Submission status: Wrong Answer

Solution code:
N, A, B = map(int, input().split())
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)

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
i = list(map(int,input().split()))
if (i[2]+i[1])%2 == 0:
    ans=(i[2]-i[1])/2
else:
    i.pop(0)
    ans=(max(i)-1 if min(i)-1<i[0]-max(i) else i[0]-min(i))
print(ans)

Submission status: Wrong Answer

Solution code:
n,a,b = input().split(" ")
cnt = 0
while a != b:
    if (int(a) == 1 and int(b) == 2) or (int(a) == int(n)-1 and int(b) == int(n)):
        cnt = 1
        break
    elif int(n)%2!=0 and int(a) == 1 and int(b) == int(n):
        cnt = int(int(n)/2)
        break
    elif (int(a)-int(b))%2==0:
        cnt=int((int(b)-int(2))/2)
        break
    else:
        if int(a) < (int(n)/2):
            cnt=int(a)
            break
        if int(b) > (int(n)/2):
            cnt=int(n)-int(a)
            break
    
print(cnt)

Submission status: Wrong Answer

Solution code:
import math
n,a,b = map(int,input().split())
ans =0
if (a-b)%2 ==0:
    print(int(abs((a-b))/2))
else:
    if n-max(a,b)<min(a,b)-1 and n!=max(a,b) and 1!=min(a,b):
        ans+=n - max(a,b)
        ans+=int(math.ceil((n-(min(a,b)+(n - max(a,b))))/2))
        print(ans)
    elif n-max(a,b)>min(a,b)-1 and n!=max(a,b) and 1!=min(a,b):
        ans+=min(a,b)-1
        ans+=math.ceil((max(a,b)-(min(a,b)-1+1))/2)
        print(ans)
    elif n == max(a,b) and 1!=min(a,b):
        ans+=1
        ans+=int((n-min(a,b)-1)/2)
        print(ans)
    elif n != max(a,b) and 1==min(a,b):
        ans+=1
        ans+=int((max(a,b)-1)/2)
        print(ans)
    elif n == max(a,b) and 1==min(a,b):
        ans+=1
        ans+=int((n-min(a,b)-1)/2)
        print(ans)
    else:
        ans +=n-max(a,b)
        ans +=math.ceil((n-(min(a,b)+(n-max(a,b))))/2)
        print(ans)

Submission status: Wrong Answer

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

result = []

#２で割れる
if (a+b)%2 == 0:
    ans = b - (a+b)/2
    result.append(int(ans))

#左に寄せる
ans = b - 1
result.append(int(ans))

#右に寄せる
ans = n - a
result.append(int(ans))

#左に寄せて真ん中
ans = b - (b - a)/2
result.append(int(ans))

#右に寄せて真ん中
ans = n - b + 1 + n - (a + (2*n) - b + 1)/2
result.append(int(ans))




print(min(result))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if dist == 0 or dist % 2 == 0:
    l = max(A-1, B-1)
    r = max(N-A, N-B)
    ans = min(r, l)
    print(ans)
else:
    if dist == 1:
        ans = 1
    else:
        ans = (dist // 2) + 1
    print(ans)

Submission status: Wrong Answer

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

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

def hoge(a,b):
    oo = []
    if a % 2 == b % 2:
        oo.append(abs(a-b)//2)
    if a == 0 or b == 0:
        c = max(a,b)
        oo.append(c)
        oo.append(N-c)
    if a == N or b == N:
        c = min(a,b)
        oo.append(c)
        oo.append(N-c)
    return min(oo,default=-1)

a = hoge(L,R)
if a > 0:
    o['a'] = a
else:
    # (L,R) から (0,R-L)
    o['b1'] = L + hoge(0,R-L-1) + 1
    o['b2'] = L + hoge(0,R-L+1) + 1
    # (L,R) から (L+(N-L),R+(N-L))
    o['c1'] = (N-L) + hoge(N,R+N-L-1) + 1
    o['c2'] = (N-L) + hoge(N,R+N-L+1) + 1

print(min(o.values()))

Submission status: Wrong Answer

Solution code:
# 整数の入力 
a, b, c = map(int, input().split())
# AとBの間の卓数
bet_table = c - b - 1
# 間の卓数が奇数か偶数で場合分け
if  bet_table % 2 != 0: # 間の卓が奇数
    print((bet_table // 2) + (bet_table % 2))
else: # 間の卓が偶数
    if b - 1 <= a - c: # 左寄せ
        print(b + (bet_table // 2) + (bet_table % 2))
    else: # 右寄せ
        print(c + (bet_table // 2) + (bet_table % 2))

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

elif (n-b)>=(a-1):
  print(int((b-a-1)/2+a))
else:
  print(int(((b-a-1)/2)+n-b+1))

Submission status: Wrong Answer

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

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 + 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 + 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 + 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 + 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 + 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 + 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 + 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 + int((A_nokori + 1)/2)
        print(Ans)

Submission status: Wrong Answer

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

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