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())
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:
        print(gap_1)

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

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)
        #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)
    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 (abs(A-B)-1) % 2 == 0:
    A_right = N-A+1
    B_right = N-B+1
    M = (N+1)/2
    
    if B <= M:
        print(B-1)
    elif A <= M and B >= M:
        print(min(A_right, B)-1)
    elif A >= M:
        print(max(A_right, B_right)-1)
        
else:
    print(int(abs(A-B)/2))

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

Submission status: Wrong Answer

Solution code:
import math
import numpy as np


def getNearestValue(list, num):

    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]

a, b, c = map(int,input().split()) 
list = [a,1]
if (c- b) % 2 == 0:
  print(math.floor((c-b) /2))
else:
  d = a - b 
  e = b - 1
  
  f = a - c 
  g = c - 1
  
  if d > e:
    h = e
  else:
    h = d
  
  if f > g:
    i = g
  else:
    i = f

  j = getNearestValue(list, b)
  k = getNearestValue(list, c)

  if j == 1 and k == 1:
    print(c - 1)
  elif j == a and k == a:
    print(d)
  elif b - 1 > a - c:
    print(a - b)  
  else:
    print(c - 1)

Submission status: Wrong Answer

Solution code:
import math as m

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

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

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
    while (True):
        if max_num==min_num:
            print(matches)
            break
        else:
            if max_num - min_num == 1:
                max_num-=1
                min_num-=1 if min_num != 1 else 0
                matches+=1
            else:
                max_num-=1
                min_num+=1 if min_num != 1 else 0
                matches+=1

Submission status: Wrong Answer

Solution code:
import sys
N, A, B=(int(x) for x in input().split())
# N = int(sys.argv[1])
# A = int(sys.argv[2])
# B = int(sys.argv[3])

count = 0
odd_flag = False

if (B-A) %2 == 1:
  # print("even")
  # print((B-A %2))
  odd_flag = True

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

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

Submission status: Wrong Answer

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

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

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

print(int(c + ((b - a) / 2)))

Submission status: Wrong Answer

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

    left_s = A - 1
    right_s = N - B
    
    if sub % 2 == 0:
        return sub / 2
    elif sub == 1:
        if left_s < right_s:
            return B - 1
        else:
            return N - A
    else:
        if left_s < right_s:
            if left_s == 0:
                left_s = 1
            return (B - 1) - left_s
        else:
            if right_s == 0:
                right_s = 1
            return (N - A) - right_s
 
if __name__ == '__main__':
    print(int(main()))

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)

Submission status: Wrong Answer

Solution code:
n, A, B = input().split( )
n = int(n)
A = int(A)
B = int(B)
ans = 0
if A == B:
    ans = 0
elif (B-A) % 2 == 0:
    ans = (B-A) / 2
else:
    if 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())

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)
        #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)
    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 = 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) + (diff-1)/2 +1))

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['b'] = L + hoge(0,R-L)
    # (L,R) から (L+(N-L),R+(N-L))
    o['c'] = (N-L) + hoge(N,R+N-L)
    o['d'] = L + hoge(0,R+L)
    o['e'] = (N-L) + hoge(N,R-N+L)


print(min(o.values()))

Submission status: Wrong Answer

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

Half = (A + B)//2

if Half == (A + B)/2:
    print(Half - A)
elif (B - A) > 2:
    if (N + 1)/2 > A and (N + 1)/2 >= B:
        print((B - A + 1)//2)
    elif (N + 1)/2 <= A and (N + 1)/2 < B:
        print((A + B)//2)
    elif B > (N + 1)/2 > A:
        if (N - A) < (B - 1):
            print((B - A + 1)//2)
        elif (N - A) > (B - 1):
            print((A + B)//2)
else:
    if (N - A) > (B - 1):
        print(B - 1)
    else:
        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:
    left_edge_a = A - 1
    left_edge_b = B - 1
    l = max(left_edge_a, left_edge_b)
    right_edge_A =  N - A
    right_edge_B =  N - B
    r = max(right_edge_A, right_edge_B)
    ans = r if l > r else 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 = list(map(int,input().split()))
diff = B - A
N2B = N - B
N2A = N - A
sumN = N2A + N2B
sumAB = A + B

flag = 0
if B == N or A == 1:
    flag = 1

if diff % 2 == 0:
    print(diff // 2)
else:
    if sumN < sumAB:
        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())
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
        round_count = round_count + Add

        SubMM = Max - Min
        if (SubMM) % 2 == 0:
            round_count = round_count + int(SubMM / 2)
        else:
            Min = Min + 1
            SubMM = Max - Min
            round_count = round_count + int(SubMM / 2) + 1
    else:
        Sub = Min - 1
        Max = Max - Sub
        Min = 1
        round_count = round_count + Sub

        SubMM = Max - Min
        if (SubMM) % 2 == 0:
            round_count = round_count + int(SubMM / 2)
        else:
            Max = Max - 1
            SubMM = Max - Min
            round_count = round_count + int(SubMM / 2) + 1
            

print(round_count)

Submission status: Wrong Answer

Solution code:
import math as m

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

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

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
        if B_nokori == 1:
          Ans = B_reach
        else:
          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
        if B_nokori == 1:
          Ans = B_reach
        else:
          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
        if A_nokori == 1:
          Ans = A_reach
        else:
          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
        if A_nokori == 1:
          Ans = A_reach
        else:
          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
        if B_nokori == 1:
          Ans = B_reach
        else:
          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
        if B_nokori == 1:
          Ans = B_reach
        else:
          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
        if A_nokori == 1:
          Ans = A_reach
        else:
          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
        if A_nokori == 1:
          Ans = A_reach
        else:
          Ans = B_reach + int((A_nokori + 1)/2)
        print(Ans)

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(l+(b-1-l))
	elif r<l:
		print(r+(abs(n-a)-r))

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

print(ans)

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

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
ansB2 = int(((B-1) - (A-1))//2)
if (B - A) % 2 == 0:
    ansB = ansB1 + ansB2
else:
    ansB = ansB1 + 1 + ansB2

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

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

Submission status: Wrong Answer

Solution code:
x,y,z = map(int,input().split())
print(x-z)

Submission status: Wrong Answer

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

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))
    print('wow')
elif a-1 < n-b:
    print(int(a-1 + (diff-1)/2))
    print('yeah')
else:
    print(int((n-b) + (diff-1)/2 +1))
    print('hoo')

Submission status: Wrong Answer

Solution code:
L=input().split()
n=int(L[0])
a=int(L[1])
b=int(L[2])
L=[]
     
if (b-a)%2==0:
  x1=(b-a)/2
  L.append(x1)
if b-a==1:
  if n-a>=b-1:
    x2=b-1
    L.append(x2)
  elif b-1>=n-a:
    x3=n-a
    L.append(x3)
if n-a>=b-1:
  x4=a+(b-a-1)/2
  L.append(x4)
if b-1>=n-a:
  x5=n-b+1+(b-a-1)/2
  L.append(x5)
     
print(int(min(L)))

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-1)
else:
    ans = min(n-a, b-1)

print(ans)

Submission status: Wrong Answer

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

    print(-(-B//2))

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['b'] = L + hoge(0,R-L)
    # (L,R) から (L+(N-L),R+(N-L))
    o['c'] = (N-L) + hoge(N,R+N-L)


print(min(o.values()))

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

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:
    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:
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+1+int(Y/2))
    else:
        print(A+int((Y-1)/2))

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:
    y = 0
    if(n-a < b-1):
        y = n-b
    else:
        y = a-1
    print(y + int((x+1)/2))
    exit()

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-1-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['b'] = L + hoge(0,R-L)
    # (L,R) から (L+(N-L),R+(N-L))
    o['c'] = (N-L) + hoge(N,R+N-L)


print(min(o.values()))

Submission status: Wrong Answer

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

d = b-a
eps = 1e-8
d_nearest_side = int(min(a-1, n-b))
if d % 2 == 0:
    print(int(d/2))
else:
    move_side = int((d+1)/2 + eps) + d_nearest_side
    print(int(move_side))

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
        round_count = round_count + Add

        SubMM = Max - Min
        if (SubMM) % 2 == 0:
            round_count = round_count + int(SubMM / 2)
        else:
            Add2 = N - Min
            round_count = round_count + Add2
    else:
        Sub = Min - 1
        Max = Max - Sub
        Min = 1
        round_count = round_count + Sub

        SubMM = Max - Min
        if (SubMM) % 2 == 0:
            round_count = round_count + int(SubMM / 2)
        else:
            Sub2 = Max - 1
            round_count = round_count + Sub2

print(round_count)

Submission status: Wrong Answer

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

flag = 0
if B == N or A == 1:
    flag = 1

if diff % 2 == 0:
    print(diff // 2)
else:
    if sumN < sumAB:
        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:
        if A == 1:
            tmp = (B - A - A)//2 + A
        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 = B-A
if diff%2 == 0:
    print(int(diff/2))
elif(A==1):
    print(int(B/2))
elif(B==N):
    print(int((N-A+1)/2))
elif((N-B) > (A-1)):
    if diff == 1:
        print(B-1)
    else:
        path = A-1 + 1 + (B-1 - A)/2
        print(int(path))
else:
    if diff == 1:
        print(N-A)
    else:
        path = N-B + 1 + (N-A - (N-B+1))/2
        print(int(path))

Submission status: Wrong Answer

Solution code:
def how_match_play(N, A, B):
    return_value = 0
    if (B - A) % 2 == 0:
        return_value = int((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 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 = (int(i) for i in input().split())

def f(A, B):
  return int((B - A) / 2)
  
def f2(N, A, B):
    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)
    
    return ans
  
print(f2(N, A, B))

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

Submission status: Wrong Answer

Solution code:
import math
N,A,B = map(int,input().split())
if B==A:
    print(0)
elif B-A+1 == 0:
    if N==B or A==1:
        print(1)
    elif B-1 >= N-A:
        print(N-A)
    else:
        print(B-1)

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

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





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

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

print(round((max_num-min_num)/2))

Submission status: Wrong Answer

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

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

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 :
    n1 = B - 1
    nn = N - A
    n1x = int((B-A+(A-1)*2+1)/2)
    nnx = int((B-A+(N-B)*2+1)/2)
    print(min(n1, nn, n1x, nnx))

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

Submission status: Wrong Answer

Solution code:
n,a,b=map(int,input().split())
if (b-a)%2==0:
  print(int((b-a)/2))
elif(b-a)==1:
  print(min(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:
i = list(map(int, input().split()))
a=[]
if abs(i[2]-i[1])%2 == 0:
    ans=(i[2]-i[1])//2
else:
    a.append(i[1])
    a.append(i[2])
    x=min(a)
    y=max(a)
    if x-1<i[0]-y:
        ans=y-1
    else:
        ans=i[0]-x
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
import math
import numpy as np


def getNearestValue(list, num):

    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]

a, b, c = map(int,input().split()) 
list = [a,1]
if (c- b) % 2 == 0:
  print(math.floor((c-b) /2))
else:
  d = a - b 
  e = b - 1
  
  f = a - c 
  g = c - 1
  
  if d > e:
    h = e
  else:
    h = d
  
  if f > g:
    i = g
  else:
    i = f

  j = getNearestValue(list, b)
  k = getNearestValue(list, c)

  if j == 1 and k == 1:
    print(c - 1)
  elif j == a and k == a:
    print(d)
  else:
    print(c - 1)

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

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

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

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))
elif bet_table % 2 == 0: # 間の卓が偶数
    print(b + (bet_table // 2) + (bet_table % 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
            
    return 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:
import math as m

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

dif = abs(B-A)
if dif %2==0:
  print(int(dif/2))
else:
  n = N - B
  n2 = A - 1
  print(m.floor(n/2 if n>n2 else n2/2) + dif)

Submission status: Wrong Answer

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

N, A, B = list(map(int, input().split()))
flg = False
cnt = 0

if abs(A - B) % 2 == 0:
    print(int(abs(A - B) / 2))
else:
    for i in range(A * 2):
        if A == B:
            print(cnt)
            break
        else:
            cnt += 1
            B -= 1
            if A == 1 and flg == False:
                flg == True
            elif A == 1 and flg == True:
                A += 1
            else:
                A -= 1

Submission status: Wrong Answer

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

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