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:
def CheckLowestNumber(N: int,A: int,B:int):
    num_A_up = A
    num_B_up = B
    num_A_down = A
    num_B_down = B
    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 > N - 1: num_A_up = N
        if num_B_up > N - 1: num_B_up = N
        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 - B

Submission status: Wrong Answer

Solution code:
import math

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

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

Submission status: Wrong Answer

Solution code:
import math

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

Submission status: Wrong Answer

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

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

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
    d_nearest_side2 = min((a+(d-1)/2)-1, n-(b-(d-1)/2))
    move_side2 = 1 + d_nearest_side2
    # print(int(move_side))
    print(int(move_side2))

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

ans = 0

if (b - a) % 2 == 0:
    ans = (b - a) // 2
else:
    first_move = (b - a) // 2
    p = (a + b) // 2
    second_move = min(p, n - p)
    ans = first_move + second_move
    if b - a != 1:
        ans = min(ans, (b - a - 1) // 2 + 1)  # 1試合後偶になるやつ
# print(ans, b - 1, n - a)
ans = min(ans, b - 1, n - a)

print(ans)

Submission status: Wrong Answer

Solution code:

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

sa = abs(a-b)

if sa % 2 == 0:#差が偶数の場合
    print(int(sa / 2))
else:#差が奇数の場合
    if abs(b-1) < abs(a-1):
        l = abs(a-1)
    else:
        l = abs(b-1)

    if abs(b-5) < abs(a-5):
        r = abs(a-5)
    else:
        r = abs(b-5)

    if l < r:
        print(r)
    else:
        print(l)

Submission status: Wrong Answer

Solution code:
import sys
bbn=1000000007
	
#+++++
		
def main():
	n, a, b= map(int, input().split())
	if a> b:
		a,b=b,a
	k=b-a
	if k %2 ==0:
		return 2//k
		
	to=a+((b-a-1)//2)
	tn=(n-b+1)+(n-(a+(n-b+1)))//2
	return min(to,tn)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Wrong Answer

Solution code:
def main():
    N, A, B = map(int, input().split())
    result = N
    if (A % 2 == 0 and B % 2 == 0) or  (A % 2 == 1 and B % 2 == 1):
        result = abs(A - B) // 2
    else:
        if A - 1 < N - B:
            result = B - 1
        else:
            result = N - A

    print(int(result))

if __name__ == '__main__':
    main()

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
    if (B - (A + 1)) == 0:
        print(min(a1, a2))
    else:    
        print(min(a1, a2, a3))

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


main()

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

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

Submission status: Wrong Answer

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

    ans1=n-b
    dist=n-(a+b-n)
    if(dist%2==0):
        ans1+=dist//2
    else:
        ans1+=1+(dist-1)//2
    #print(dist)
    ans2=a-1
    dist=(b-(a-1))-1
    if(dist%2==0):
        ans2+=dist//2
    else:
        ans2+=1+(dist-1)//2
    #print(ans1,ans2)
    print(min(ans1,ans2))

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
x, y, z = input().split()
n = int(x)
a = int(y)
b = int(z)
num_round = 0
num1 = 0

if (abs(a - b) == 0):
  print(num_round)
elif (abs(a - b) % 2 == 0):
  average = int((a + b) / 2)
  num_round = abs(a - average)
  print(num_round)
else:
  num1 = n - b
  if (num1 < a):
    print(n - a)
  else:
    print(b - 1)

Submission status: Wrong Answer

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

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

# print(N)
# print(A)
# print(B)

ans = 0

if (A-B)%2 == 0:
    ans =  abs(A-B)/2
else:
    ans = min(max(A, B)-1, max(N-A, N-B))

print(int(ans))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N, A, B = [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])
print(d)

Submission status: Wrong Answer

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

if(A == B):
  ans = 0

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

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

Submission status: Wrong Answer

Solution code:
n, a, b = map(int, "10 2 9".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:
L=input().split()
n=int(L[0])
a=int(L[1])
b=int(L[2])

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

print(int(x))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

print(N,A,B)

if(A == B):
  ans = 0

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 = 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)
elif flag == 1:
    tmp = diff // 2
    if sumN < sumAB:
        if N2A < tmp:
            print(N2A)
        else:
            print(tmp + 1)
    else:
        if B-1 < tmp: 
            print(B - 1)
        else:
            print(tmp + 1)
else:
    if sumN < sumAB:
        tmp = (N - A + N2B)//2 + N2B
        if (N - A + N2B)//2 == 0:
            tmp = tmp + 1
        if N2A < tmp:#A slide
            print(N2A)
        else:
            print(((N - A + N2B)//2 + N2B))
    else:
        tmp = (B - A - 1 + 1)//2 + A - 1
        if (B - A - 1 + 1)//2 == 0:
            tmp = tmp + 1
        if B-1 < tmp: 
            print(B - 1)
        else:
            print(tmp)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

if N-A > B-1:
  print(B-1)
else:
  print(N-A)

Submission status: Wrong Answer

Solution code:
N, A, B = [ int(i) for i in input().split(" ")]
 
Awin = A
Alose = A
Bwin = B
Blose = B
count = 0
 
while True:
  if A == B:
    print(count)
    break;

  count += 1
 
  if Awin == 1:
    Awin = 1
  else:
    Awin -= 1
  
  if Bwin == 1:
    Bwin = 1
  else:
    Bwin -= 1
  
  if Alose == N:
    Alose = N
  else:
    Alose += 1
  
  if Alose == N:
    Alose = N
  else:
    Blose += 1
 
  
  if Awin == Bwin or Awin == Blose or Alose == Bwin or Bwin == Blose:
    print(count)
    break;

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 :
    if distBN < a - 1:
        print(n - b + 1 + half(n + a - b + 1, n))
    else :
        print(a + half(1, b - a))

Submission status: Wrong Answer

Solution code:
N, A, B = map(int, input().split())
ans = 0
if abs(A - B) % 2 == 0:
    ans = abs(A - B)//2
else:
    standard = N / 2
    if A - standard < 0:
        if B - standard < 0:
            far_from_edge_person = max(A, B)
            ans = far_from_edge_person - 1
        else:#0<A<standard<B<N
            if A < N-B:
                far_from_edge_person = B
                ans = far_from_edge_person - 1
            else:
                ans = N-1-A
    else:
        if B - standard < 0:
            if B < N-A:
                far_from_edge_person = A
                ans = far_from_edge_person - 1
            else:
                ans = N-1-A            
        else:#AもBも右半分
            far_from_edge_person = min(A, B)
            ans = (N-1)-far_from_edge_person

print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

ans1 = 10000000000000000000

# a勝ち続け, & b負け続けで会える場合
if abs(a-b)%2==0:
    ans1 = (b-a)//2

# 1 or n テーブルで会える場合
ans2 = min(b-1, n-a)


# 17, 2, 7 とか, 一旦どちらかが端に行ってから途中で会う場合
c = 0
ans3 = 10000000000000000000
if (b-a)%2 == 1:
    if a-1 <= n-b:
        c = a - 1
        a, b = 1, b-c
        ans3 = c + (b-2)//2 + 1
    else:
        c = n - b
        a, b = a + c, n
        ans3 = c + (n-(a+c+1))//2 +1
print(min(ans1, ans2, ans3))

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) % 2 == 0):
    print(min(min(b-1,n-a),(b-a)//2))
elif a == 1 and (b - a) % 2 != 0:
    print(min(min(b - 1, n - a), (b - 1 - a) // 2 + 1))
elif b == n and (b - a) % 2 != 0:
    print(min(min(b - 1, n - a), (b - 1 - a) // 2 + 1))
elif (b - a) == 3:
    print(min(b - 1, n - a) - 1)
elif (b - a) >= 5 and (b - a) % 2 != 0:
    print(min(b - 1, n - a) - 2)
else:
    print(min(b-1,n-a))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Half = (A + B)//2

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

Submission status: Wrong Answer

Solution code:
number = input()
n,a,b = [int(ele)for ele in number.split(' ')]
res =[]
if (a % 2) == 0 and b % 2 == 0 or a % 2 != 0 and b % 2 != 0:
    res.append(len(range(a,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)%2==0:
    print(str(int(B-(B+A)/2)))
else:
    if N-A>B-1:
        print(str(int(A+(B-A-1)/2)))
    else:
        print(str(int(N-B+1+(B-A-1)/2)))

Submission status: Wrong Answer

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

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

print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

diff = abs(B - A)

if diff % 2 == 0:
    x = diff/2
elif N == 2:
    x = 1
elif diff == 1:
    x_1 = N - A
    x_2 = A - 1
    x = min(x_1, x_2) + 1
else:
    x1 = N - A
    x2 = B - 1
    x3 = min(x1, x2)

    # 端に近い方が端で数を合わせ、真ん中で再開するパターン
    diff_small = A - 1
    diff_big = N - B

    x4 = (diff - 1)/2 + min(diff_small, diff_big) + 1

    x = min(x3, x4)


print(int(x))

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)
  print(min(B - 1, A - 1 + math.ceil(B - (A - 1)/ 2)))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import math

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

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

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

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

Submission status: Wrong Answer

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

Awin = A
Alose = A
Bwin = B
Blose = B
count = 0

while True:

  if Awin == Bwin or Awin == Blose or Alose == Bwin or Bwin == Blose:
    print(count)
    break;

  count += 1

  if Awin == 1:
    Awin = 1
  else:
    Awin -= 1

  if Bwin == 1:
    Bwin = 1
  else:
    Bwin -= 1

  if Alose == N:
    Alose = N
  else:
    Alose += 1

  if Alose == N:
    Alose = N
  else:
    Blose += 1

  print(Awin, Alose, Bwin, Blose)

  if Awin == Bwin or Awin == Blose or Alose == Bwin or Bwin == Blose:
    print(count)
    break;

Submission status: Wrong Answer

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

dim = B - A

if dim % 2 == 0:
  print(int(dim/2))
elif dim % 2 == 1:
  dimAN = N - A
  dimBN = N - B
  dimB1 = B - 1
  dimA1 = A - 1
  
  if dimAN > dimB1:#Aが1にいって折り返す
    print(dimA1+1 + int((dim-1)/2))
  elif dimAN < dimB1:#BがNにいって折り返す
    print(dimBN+1 + int((dim-1)/2))
  elif dimAN == dimB1:
    print(dimA1+1 + int((dim-1)/2))

Submission status: Wrong Answer

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

    while True:
        left_s = A - 1
        right_s = N - B
        sub = B - A
        
        if A == B:
            return ans
        # 偶数なら
        if sub % 2 == 0:
            return ans + (sub / 2)
        # 奇数なら
        else:
            if left_s < right_s:
                if A != 1:
                    A -= 1
                B -= 1
            else:
                if B != N:
                    B += 1
                A += 1
        ans += 1

if __name__ == '__main__':
    print(int(main()))

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:
    if 2*n - a -b >= 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())
  
N -= 1
A -= 1
B -= 1

ans = 0
distAB = B - A

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

print(int(ans))

Submission status: Wrong Answer

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


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


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
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-1 > N - A:
        print(N-A)
    elif N-A > B-1:
        print(B-1)

Submission status: Wrong Answer

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

if (B - A) % 2 == 0:
    print(int((B-A)/2))
else:
    if A == 1:
        print(int((B - 1 - A) / 2) + 1)
    elif B == N:
        print(int((B - A - 1) / 2) + 1)
    elif A - 1 <= N - B:
        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())
mid = N/2
if (B-A)%2 == 0:
  answer = -1#int((B-A)/2)
else:
  answer = min(int(N-A), int(B-1))

print(answer)

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys

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

    c = abs(A-B)
    if (c - 1) % 2 == 1:
        point = int((A + B) // 2)
        print(abs(A - point))
        sys.exit()

    else:
        ansa = abs(1 - B)
        ansb = abs(N - A)

        if ansa >= ansb:
            print(ansb)

        else:
            print(ansa)

main()

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)
else:
    if A > B:
        ans = A - 1
    else:
        ans = B - 1
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

print(answer)

Submission status: Wrong Answer

Solution code:

# 入力 =stdin.readline().rstrip()
# 分割 = stdin.readline().rstrip().split()

'''
条件に合うものを絞り込む
data = [1, 2, 3]
s = [x for x in data if x % 3 == 0]
'''

'''
文字配列を数値に
l_si = ['-10', '0', '100']

l_si_i = [int(s) for s in l_si]
'''

'''
a = [2, 4, 6, 8]
b = [3, 6, 9]

print(list(set(a) | set(b)))  # 和集合
print(list(set(a) & set(b)))  # 積集合
'''

'''
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
count = 0
while len([x for x in A if x % 2 == 0]) == N:
    A = list(map(lambda y: y / 2, A))
    count += 1
print(count)
'''

'''
.append(要素)
.extend(要素)
.insert(場所,要素)
del 配列名[場所]
-1で末尾で末尾から一つ前
'''
'''
間に空白追加
' '.join(lis)
'''
'''
copy.copy(配列名)6

'''
'''
sort()50
sorted(reverse=true)
'''
'''
2分探索
bisect.bisect_left(リスト, 要素)
'''


from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby
import bisect
import copy
import math
l_si_i = [int(s) for s in stdin.readline().rstrip().split()]
n = l_si_i[0]
a = l_si_i[1]
b = l_si_i[2]

num = b - a


if num % 2 == 0:
    print(int(num / 2))
elif num % 2 == 1:

    res1 = a - 1
    b1 = b - (a - 1)
    a1 = 1
    num = b1 - a1
    if num % 2 != 0:
        res1 += 1
        b1 -= 1
    res1 += int((b1-a1)/2)

    res2 = n - b
    a2 = n-b+a
    b2 = n
    num = b2 - a2
    if num % 2 != 0:
        res2 += 1
        a2 += 1
    res2 += int((b2 - a2) / 2)
    res = 0
    if res1 <= res2:
        res = res1
    else:
        res = res2
    print(res)

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 ) )   
  else : 
    if diff == 1 :
        print(b-1)
    else:
    	print( min( b - 1 , b - a) )

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

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)
  print(min(B - 1, A - 1 + math.ceil(B / 2)))