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())
o = {}

def hoge(a,b):
    if a % 2 == b % 2:
        return abs(a-b)//2
    else:
        return -1

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

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

print(min(o.values()))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

C = int(B - A)
min = 0


while C > 2:
    if C % 2 == 0:
         min = min + 1
    elif C % 2 == 1:
         min = min + 2

    C = int(C / 2)
    print(C)

if C == 2:
    print(min + 1)
    exit
elif C == 1:
    print(min + 2)
    exit

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

    if (B-A-1) % 2 == 1:
        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 = list(map(int, input().split()))

if (b - a) % 2 == 0:
  print((b - a) // 2)
else:
  x = (a - 1) * 2 + 1
  y = (n - b) * 2 + 1
  anses = [b - 1, n - a]
  if (b - x - a) >= 0:
    anses.append(x+(b - x - a) // 2)
  if b - (a + y) >= 0:
    anses.append(y+(b - (a + y)) // 2)
  print(min(anses))

Submission status: Wrong Answer

Solution code:
from sys import stdin
lines = stdin.readlines()
 
N, A, B = map(int, lines[0].split())

a = B - A
b = N - B

if a % 2 == 0:
  print(int(a / 2))  
else:
  if b >= A:
    print(A)
  else:
    print(b)

Submission status: Wrong Answer

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

d = b - a
if d == 1:
    ans = max(min(n-a,a-1),min(n-b,b-1))
    print(ans)
else:
    ans = int(d/2)
    print(ans)

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

else:
  print(N-1-A)

Submission status: Wrong Answer

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

if (B - A) % 2 == 0:
    print((B - A) // 2)
else:
    a1 = B - 1
    a2 = N - A
    a3 = (B - (A + 1)) // 2 + A
    print(min(a1, a2, a3))

Submission status: Wrong Answer

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

v=b-(a+1)

if v%2==0:
    if a==1 or b==n:
        ans=int((v+1)/2)+1
    else:
        dif=min(n-b,a-1)
        #ans1=dif+int((v+2*dif)/2)+1
        ans1=dif+1+v//2
        if (n-b)<(a-1):
            ans2=n-a
        else:
            ans2=b-1
        ans=min(ans1,ans2)
else:
    ans=(v+1)//2
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import math as m

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

dif = abs(B-A)
half = N/2
a2half = half - A
b2half = B - half - 1
if a2half == b2half:
  print(m.ceil(a2half))
else:
  n = N-B
  nearest = min(A, n)
  k = A - B -1 +n/2 if nearest == n else B-A-1 +n/2
  print(m.ceil(k))

Submission status: Wrong Answer

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

res.append(len(range(a,n)))
res.append(b-1)

print(min(res))

Submission status: Wrong Answer

Solution code:
n, a, b = [int(i) for i in input( ).split()] 
x=int(b-a)
if x%2==0:
    print(x/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())
cnt=0
if (b-a)%2 == 0:
  cnt=round(b-(b+a)/2)
  print(cnt)
  exit()
if (b-a)%2 == 1:
  if a==1:
    cnt=round(1+((b-1)-(((b-1)+a)/2)))
    print(cnt)
    exit()
  if b==n:
    cnt=round(1+(b-(b+a+1)/2))
    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:
# 21:01
n,a,b = map(int,input().split())
if abs(b-a) % 2 == 0:
    print((b-a)//2)
else:
    ans = min(max(a-1,b-1),max(n-a,n-b))
    if (a-1) >= (n-b):
        t = (n-((n+1-b)+a))//2 + (n-b+1)
        print(min(ans,t))
    else:
        t = (-(1-((1+1-a)+b)))//2 + (a-1+1)
        print(min(ans,t))

Submission status: Wrong Answer

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

dif = b-a

if(dif%2 == 0):
  print(int(dif/2))
else:
  #小さい方が最小に行くまで必要な戦い数
  up = a - 1
  #大きい方が最大に行くまで必要な戦い数
  down = n - b
  #print("up",up)
  #print("down",down)
  if(up > down):
    #downに行くべき
    #print("down",down)
    print((-(b-a)//2) + down)
  else:
    #upに行くべき
    #print("up",up)
    print((-(b-a)//2) + up)

Submission status: Wrong Answer

Solution code:
S = input().split(" ")
N = int(S[0])
A = int(S[1])
B = int(S[2])
C = B - A
if C % 2 == 0:
	print(C // 2)
	exit()
print(min(B - 1,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
    print(ans)

Submission status: Wrong Answer

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

    if A+1 == B:
        A -= 1
        B -= 1
        c += 1
        if A == 1:
            A = 1
        if B == 1:
            B = 1
        if A == B:
            break
    else:
        A -= 1
        B -= 1
        c += 1
        if A == 1:
            A = 1
        if B == 1:
            B = 1
        if A == B:
            break
print(c)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

def hoge(a,b):
    if a % 2 == b % 2:
        return abs(a-b)//2
    else:
        return -1

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

a = hoge(L,R)
if a > 0:
    o['a'] = a
else:
    b = hoge(0,R-L)
    if b > 0:
        o['b'] = L + b
    else:
        o['b'] = L + hoge(0,R-L-1) + 1
    c = hoge(N,R+L)
    if c > 0:
        o['c'] = R + c
    else:
        o['c'] = R + hoge(N,R+L+1) + 1

print(min(o.values()))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
X,A,B = map(int,input().split())
if A+B %2 == 0:
    A_min = A- 1
    B_min = X - B
    AB_div = A - B
    if A_min - B_min > 0:
    	if B_min < AB_div:
    		print(AB_div)
    	else:
    		print(B_div)
    else:
    	if A_min < AB_div:
    		print(AB_div)
    	else:
    		print(A_min)
else:
	A_min = A-1
	B_min = X - B
	if A_min < B_min:
		print(B_min)
	else:
		print(A_min)

Submission status: Wrong Answer

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

sa = B-A

if sa % 2 == 0:
    print(sa//2)
else:
    B += 3
    sa = B-A
    print(sa//2)

Submission status: Wrong Answer

Solution code:
n,a,b = map(int, input().split())
rs = (b-a)//2

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

print(int(x))

Submission status: Wrong Answer

Solution code:
from sys import stdin
lines = stdin.readlines()
 
N, A, B = map(int, lines[0].split())

a = B - A
b = N - B

if a % 2 == 0:
  print(int(a / 2))  
else:
  if b > A:
    print(A)
  else:
    print(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<=int(n/2):
        print(b-1)
    else:
        print(n-a)

Submission status: Wrong Answer

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

def jud(n,a,b):
    if abs(a-b) % 2 == 0:
        return abs(a-b) // 2

    x = n - a
    y = b - 1

    if x > y:
        return y
    else:
        return x
print(jud(n, a, b))

Submission status: Wrong Answer

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

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

print(how_match_play(N, A, B))

Submission status: Wrong Answer

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

if dif % 2 == 0:
    print(int(dif/2))
else:
    if a + b - 2 <= 2*n - a -b:
        print(int((a + b - 1)/2))
    else:
        print(int((2*n - a - b + 1)/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 n-a < b-1:
    al = n-b+1
    b = n
    a += al
    r = int((b-a)/2)+al
    print(max(r, 1))
else:
    be = a
    b -= a
    a = 1
    r = int((b-a)/2)+be
    print(max(r, 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

if N-B > A-1:
    ans1 = A-1
    ans2 = int(((B-1) - (A-1))//2)
    ansB = ans1+1+ans2

elif N-B < A-1:
    ans1 = N-B
    ans2 = int(((N-A) - (N-B))//2)
    ansB = ans1+1+ans2
else:
    ans1 = N - B
    ans2 = int(((N - A) - (N - B)) // 2)
    if (B-A) % 2 == 0:
        ansB = ans1 + ans2
    else:
        ansB = ans1 +1+ans2

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

Submission status: Wrong Answer

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

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

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

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

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

Submission status: Wrong Answer

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

res.append(len(range(a,n)))
res.append(b-1)

print(min(res))

Submission status: Wrong Answer

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

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

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

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

else:
  print(N-1-A)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

def jud(n,a,b):
    if abs(a-b) % 2 == 0:
        return abs(a-b) // 2

    x = n - a
    y = b - 1

    if x > y:
        return x
    else:
        return y
print(jud(n, a, b))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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:
    #print('mode a')
    ans = f(A, B)
else:
    #print('mode b')
    # Aが1に向かうとき
    ans_a = A + f(1, B - A + 1)
    # BがNに向かうとき
    ans_b = (N - B + 1) + f(A + N - B +1, N)
    ans = min(ans_a, ans_b)
    #print(ans_a, ans_b)
    
print(ans)

Submission status: Wrong Answer

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

diff = B - A
if diff % 2 == 0:
  print(int(diff / 2))
else:
  if N - B < A - 1:
    tmp = A
    A = 1 + N - B
    B = N - (tmp - 1)
  if diff > A - 1:
    print(A - 1 + math.ceil(((B - (A - 1)) - 1)/ 2))
  else:
    print(B - 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
    
if N-B > A-1:
    ans1 = A-1
    ans2 = int(((B-1) - (A-1))//2)
    ansB = ans1+1+ans2

elif N-B < A-1:
    ans1 = N-B
    ans2 = int(((N-A) - (N-B))//2)
    ansB = ans1+1+ans2
else:
    ans1 = N - B
    ans2 = int(((N - A) - (N - B)) // 2)
    if (B-A) % 2 == 0:
        ansB = ans1 + 1 + ans2
    else:
        ansB = ans1 + ans2

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

Submission status: Wrong Answer

Solution code:
from sys import stdin
N,A,B = [int(x) for x in stdin.readline().rstrip().split()]
if (B - A) % 2 == 0:
    print((B-A)//2)
else:
    ans1 = 0
    a1 = A
    b1 = B
    ans1 += (a1-1)
    a1 = 1
    b1 -= (a1-1)
    if b1 % 2 == 0:
        b1 -= 1
        ans1 += 1
    ans1 += ((b1 -1)//2)
    
    ans2 = 0
    a2 = A
    b2 = B
    ans2 += (N-B)
    a2 += (N-B)
    b2 += (N-B)
    if (a2 % 2) != (b2 % 2):
        a2 += 1
        ans2 += 1
    ans2 += ((b2 - a2)//2)
    print(min(ans1,ans2))

Submission status: Wrong Answer

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


if (li[2]-li[1])%2==0:
    print(int((li[2]-li[1])/2))
else:
    x=min(li[0]-li[2],li[1]-1)
    y=(li[2]-li[1]-1)//2+1
    print(x+y)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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


diff_t=abs(A-B)
if diff_t%2==0:
    print(int(diff_t/2))
else:
    go_top=max(abs(1-A),abs(1-B))
    go_bottom=max(abs(N-A),abs(N-B))
    print(int(min(go_top,go_bottom)))

Submission status: Wrong Answer

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

deff = b - a
distBN = n - b

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

def Bool(A, B) :
    return (B - A)%2 == 0

if Bool(a, b) :
    print(half(a, b))
else :
    resultA = n - b + 1 + half(n + a - b + 1, n)
    resultB = a + half(1, b - a)
    if resultA > resultB :
        print(resultB)
    else :
        print(resultA)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

        c = 0
        if 1 < A:
            c += A - 1
        c += 1
        B1 = B - c
        A1 = 1
        X = abs(A1 - ((A1 + B1) // 2)) + c
        if B1 < A1:
            X = 9999999999999999999999999999

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

        print(min(Y, X))


main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

if Lab%2==0:
    #case Lab is even
    ans = int(Lab/2)
else:
    #case Lab is odd
    if La<=Lb:
        ans = La + 1 + int((Lab-1)/2)
    else:
        ans = Lb + 1 + int((Lab-1)/2)
        
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = max(min(n-a,a-1),min(n-b,b-1))
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

def jud(n,a,b):
    if abs(a-b) % 2 == 0:
        return abs(a-b) // 2

    x = a - 1
    y = b - n

    if x > y:
        return x
    else:
        return y
print(jud(n, a, b))

Submission status: Wrong Answer

Solution code:
def CheckLowestNumber(num):
    nums = num.split()
    num_A_up = nums[1]
    num_B_up = nums[2]
    num_A_down = nums[1]
    num_B_down = nums[2]
    while num_A_down != num_B_up and num_A_up != num_B_down:
        num_A_up += 1
        num_A_down -= 1
        num_B_up += 1
        num_B_down -= 1
        if num_A_up > nums[2] - 1: num_A_up = nums[2]
        if num_B_up > nums[2] - 1: num_B_up = nums[2]
        if num_B_down < 1: num_B_down = 1
        if num_A_down < 1: num_A_down = 1
        if num_A_down - num_B_down == 0 or num_A_up - num_B_up == 0: break

    return num_B_up - nums[2]

Submission status: Wrong Answer

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

n1 = B - 1
nx = int((B-A)/2)
nn = N - A
n1x = int((B-A+(A-1)*2+1)/2)
nnx = int((B-A+(N-B)*2+1)/2)

if (B-A)%2 != 0 :
    print(min(n1, nn, n1x, nnx))
else:
    print(nx)

Submission status: Wrong Answer

Solution code:
import math

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


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

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

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

ab_dis = min(r1,r2)

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


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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

diff = abs(a-b) 
mod = diff % 2

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


elif mod != 0 :
  
  if n - a < b - 1 :
    if diff == 1:
      	print(n-a)
    else :
    	print( min( n - a , (b - a - 1) // 2) )   
  else : 
    if diff == 1 :
        print(b-1)
    else:
    	print( min( b - 1 , (b - a - 1) // 2) )

Submission status: Wrong Answer

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

dif = b-a

#print(dif)

if(dif%2 == 0):
  print(int(dif/2))
else:
  #小さい方が最小に行くまで必要な戦い数
  up = a - 1
  #大きい方が最大に行くまで必要な戦い数
  down = n - b
  #print("up",up)
  #print("down",down)
  if(up > down):
    #downに行くべき
    #print("down",down)
    print((math.ceil((b-a)/2)) + down)
  else:
    #upに行くべき
    #print("up",up)
    print((math.ceil((b-a)/2)) + up)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

def hoge(a,b):
    if a % 2 == b % 2:
        return abs(a-b)//2
    else:
        return -1

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

a = hoge(L,R)
if a > 0:
    o['a'] = a
else:
    if L < N-R:
        o['b'] = L + hoge(0,R-L-1) + 1
    else:
        o['c'] = R + hoge(N,R+L+1) + 1

print(min(o.values()))

Submission status: Wrong Answer

Solution code:
from decimal import Decimal, ROUND_HALF_UP
def answer(N, A, B):
  round = 0
  range = B-A-1
  if range == 0:
    left = A-1
    right = N-B
    if left < right:
      round = B-1
    elif left > right:
      round = N-A
    else:
      round = B-1
  elif range % 2 == 0:
    left = A-1
    right = N-B
    if left < right:
      round = left + 1
      range = range - 1
      round = round + Decimal(str(range/2)).quantize(Decimal('0'), rounding=ROUND_HALF_UP)
    elif left > right:
      round = right + 1
      range = range - 1
      round = round + Decimal(str(range/2)).quantize(Decimal('0'), rounding=ROUND_HALF_UP)
    else:
      round = right + 1
      range = range - 1
      round = round + Decimal(str(range/2)).quantize(Decimal('0'), rounding=ROUND_HALF_UP)
  else:
    round = Decimal(str(range/2)).quantize(Decimal('0'), rounding=ROUND_HALF_UP)
  return round

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

Submission status: Wrong Answer

Solution code:
n, a, b = map(int, input().split())
aa = a - (a - 1)
bb = b - a
aaa = a + (n - b) + 1
bbb = n
result = []
if (a + b)%2 == 0:
    result.append(int(abs(((a+b)/2) - a)))
result += list(map(int, (b - 1, n - a, int(abs(((aa+bb)/2) - aa)) + a, int(abs(((aaa+bbb)/2) - aaa) + n - b + 1))))

print(min(result))

Submission status: Wrong Answer

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

n1 = (B - 1)*2
nx = (B-A)
nn = (N - A)*2
n1x = (B+A+1)
nnx = (2*N-B-A+1)

if (B-A)%2 != 0 :
    print(int(min(n1, nn, n1x, nnx)/2))
else:
    print(nx)

Submission status: Wrong Answer

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

    if A+1 == B:
        A -= 1
        B -= 1
        c+=1
        if A==1:
            A = 1
        if B==1:
            B =1
        if A==B:
            break
print(c)

Submission status: Wrong Answer

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

if (B - A) % 2 == 0:
  ans = (B + A) / 2
else:
  if (N - A) > (B - 1):
    ans = B - 1
  else:
    ans = N - A
  
print(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_n = (N - A) + (N - B)
    gap_1 = (A - 1) + (B - 1)

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

Submission status: Wrong Answer

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


if (li[2]-li[1])%2==0:
    print(int((li[2]-li[1])/2))
else:
    x=min(li[0]-li[2],li[1]-1)
    y=(li[2]-li[1]-1)/2+1
    print(x,y)

Submission status: Wrong Answer

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

def jud(n,a,b):
    if abs(a-b) % 2 == 0:
        return abs(a-b) // 2

    x = a - 1
    y = b - 1

    if x > y:
        return x
    else:
        return y
print(jud(n, a, b))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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


a = A
b = B

if A > B:
    a = B
    b = A

k = abs(A - B)

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

C = B - A

min = 0
while C > 2:
    if C % 2 == 0:
         min = min + 1
    elif C % 2 == 1:
         min = min + 2


    C = int(C / 2)

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

Submission status: Wrong Answer

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

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

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

print(C)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

dif = b-a

#print(dif)

if(dif%2 == 0):
  print(int(dif/2))
else:
  #小さい方が最小に行くまで必要な戦い数
  up = a - 1
  #大きい方が最大に行くまで必要な戦い数
  down = n - b
  #print("up",up)
  #print("down",down)
  if(up > down):
    #downに行くべき
    #print("down",down)
    print((math.ceil((b-a)/2)) + down)
  else:
    #upに行くべき
    print("up",up)
    print((math.ceil((b-a)/2)) + up)