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())
cnt=0
if (b-a)%2 == 0:
  cnt=b-(b+a)/2
  print(cnt)
  exit()
if (b-a)%2 == 1:
    if a-1 >= n-b:
      cnt=n-a
      print(cnt)
      exit()
    if a-1 <= n-b:
      cnt=b-1
      print(cnt)
      exit()

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(max(A-1,B-1),max(N-A,N-B)))

Submission status: Wrong Answer

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

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:
    U=A+N-B
    F=N-U
    if F%2 == 0:
        Q=(N-U)/2
        print(int(Q)+N-B)
    else:
        Q=(B+1-A)/2
        print(int(Q)+N-B)

Submission status: Wrong Answer

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

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:
#A - Table Tennis Training
N,A,B = list(map(int, input().split()))

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

if Lab%2==0:
    #case Lab is even
    ans = int(Lab/2)
else:
    #case Lab is odd
    L1a = A-1
    Lbn = N-B
    pattern1 = L1a + 1 + int((Lab-1)/2)
    pattern2 = Lbn + 1 + int((Lab-1)/2)
    ans = min(pattern1,pattern2)

print(ans)

Submission status: Wrong Answer

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

matches = 1
for i in range(N):
    if A==B:
        print(matches)
        break
    elif abs(A-B) == 1:
        print(matches)
        break
    else:
        if A == min(A,B):
            A+=1 if A!=1 else 0
            B-=1
            matches +=1
        else:
            B+=1 if B!=1 else 0
            A-=1
            matches +=1

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

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

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

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

Submission status: Wrong Answer

Solution code:
import sys
from random import choice,randint
inp=sys.stdin.readline
out=sys.stdout.write
flsh=sys.stdout.flush
 
sys.setrecursionlimit(10**9)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
 
def MI(): return map(int, inp().strip().split())
def LI(): return list(map(int, inp().strip().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines().strip()]
def LI_(): return [int(x)-1 for x in inp().strip().split()]
def LF(): return [float(x) for x in inp().strip().split()]
def LS(): return inp().strip().split()
def I(): return int(inp().strip())
def F(): return float(inp().strip())
def S(): return inp().strip()
def pf(s): return out(s+'\n')
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)

def main():
    n,a,b=MI()
    # n,a,b=randint(1,30),randint(1,10),randint(5,25)
    # print(n,a,b)
    if (b-a)%2==0:
        pf(str((b-a)//2))
    elif a==1 or b==n:
        pf(str((b-a+1)//2))
    else:
        mn = min(a-1,n-b)
        ans=0
        if mn<(b-a):
            ans = (b-a)+(mn-2)
        else:
            ans = (b-a)+(mn-1)
        ans = min([ans,n-a,b-1])
        pf(str(ans))

if __name__ == "__main__":
    main()

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

Submission status: Wrong Answer

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

C = B-A

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

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

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

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 B-A==1:
        if N-A>B-1:
            print(B-1)
        else:
            print(N-A)
    else:
        if N-A>B-1:
            print(A+(A-B)/2)
        else:
            print(B+(B-A)/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=[]
	if(a==1):
		ans.append((b-2)//2 + 1)
	if(b==n):
		ans.append((n-a-1)//2 + 1)
	else:
		ans.append((b-(a-1)-2)//2 + (a-1)+1)
		ans.append((a+(n-b)+1)//2+ n-b+1)
	print(min(ans))

Submission status: Wrong Answer

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

if (B - A) % 2 == 0:
    ans = int((A + B) / 2) - A
else:
    # どちらも1に近づくとき
    ans_a = max(A - 1, B - 1)
    # どちらもNに近づくとき
    ans_b = max(N - A, N - B)
    # Aが1に行って1で1回とまってN方向へ行くとき
    ans_c = A + int((1 + (B - A)) / 2) - 1
    # BがNに行ってNで1回とまって1方向へ行くとき
    ans_d = (N - B + 1) + int(((A + N - B + 1) + N) / 2) - (A + N - B + 1) 
    
    #print(ans_a, ans_b,ans_c,ans_d)
    
    ans = min(ans_a, ans_b,ans_c,ans_d)
    
print(ans)

Submission status: Wrong Answer

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

if a==1 and b==n:
    print(n-1)
if (b-a)%2==0:
    print((b-a)//2)
else:
    if n-b < a-1:
        print(n-a)
    elif n-b > a-1:
        print(b-1)
    else:
        print(n-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 (b-(n+1)/2)<=(-a+(n+1)/2):
    if a!=1:
      print(a+((b-1-a)//2))
    else:
      print((1+b-a)//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())
if((b-a)%2==0):
	print((b-a)//2)
else:
	ans=[]
	if(a==1):
		ans.append((b-2)//2 + 1)
	if(b==n):
		ans.append((n-a-1)//2 + 1)
	else:
		ans.append((b-(a-1)-2)//2 + (a-1)+1)
		ans.append((a+(n-b)+1)//2+ n-b+1)

Submission status: Wrong Answer

Solution code:
players = [int(x) for x in input().split(" ")]
end = [1, players[0]]
endState = True if players[1] in end or players[2] in end else False
sub = abs((players[1] - players[2]))
if sub % 2 == 0: print(sub//2)
elif endState and sub == 1: print(1)
elif sub == 1: print(players[0] - min(players[1], players[2]))
elif endState: print(sub)
elif sub % 2 != 0: print(min(players[0] - min(players[1], players[2]), max(players[1], players[2]) - 1))

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

result = 0
if (B-A)%2==0:
    result = (B-A)/2
else:
    result = min(A-1,N-B)+1+math.floor((B-A)/2)

print(result)

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))
if abs(a-b)%2==1 and (a-1 >= n-b):
  c = (n-b)+1
  d = ((n-(c+a))/2)
  print(int(c+d))
if abs(a-b)%2==1 and (a-1 < n-b):
  c = (a-1) +1
  d = ((b-c)-1)/2
  ans=(int(c+d))
  if d == 0:
    print(int(a))
  else:
    print(int(c+d))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=list(map(int,input().split()))
count=0
s=abs(n[2]-n[1])
a=n[1]-1
b=n[0]-n[2]
if(s%2==0):
    count=int(s/2)
else:
    if(s>1):
        if(a>b):
            count=b+1+(s-1)/2
        else:
            count=a+1+(s-1)/2
    else:
        if(a>b):
            count=b+1
        else:
            count=a+1
print(int(count))

Submission status: Wrong Answer

Solution code:
import sys
from random import choice,randint
inp=sys.stdin.readline
out=sys.stdout.write
flsh=sys.stdout.flush
 
sys.setrecursionlimit(10**9)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
 
def MI(): return map(int, inp().strip().split())
def LI(): return list(map(int, inp().strip().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines().strip()]
def LI_(): return [int(x)-1 for x in inp().strip().split()]
def LF(): return [float(x) for x in inp().strip().split()]
def LS(): return inp().strip().split()
def I(): return int(inp().strip())
def F(): return float(inp().strip())
def S(): return inp().strip()
def pf(s): return out(s+'\n')
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)

def main():
    n,a,b=MI()
    # n,a,b=randint(1,30),randint(1,10),randint(5,25)
    # print(n,a,b)
    if (b-a)%2==0:
        pf(str((b-a)//2))
    elif a==1 or b==n:
        pf(str((b-a+1)//2))
    else:
        mn = min(a-1,n-b)
        ans=0
        if mn<(b-a):
            ans = (b-a)+(mn-2)
        else:
            ans = (b-a)+(mn-1)
        pf(str(ans))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

    print(min(first, last))

Submission status: Wrong Answer

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

if ((b-a) % 2) == 0:
  print(rs)
else:
  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())
m = 1
l = b - a
x = min(n - b, a - m)

if l % 2 == 0:
    print(int(l / 2))
else:
    print(int(x + 1 + (l - 1) / 2))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if __name__ == '__main__':
  run()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    tmp = input()
    tmp = [int(i) for i in (tmp.split())]
    n = tmp[0]
    a = tmp[1]
    b = tmp[2]
    dst = a - b
    top_a = a - 1
    b_lst = n - b
    long = top_a if top_a<b_lst else b_lst

    if dst % 2 == 0:
        short = dst / 2
        wait = b-1 if (b-1)<(n-a) else n-a
        long = (dst - 2) / 2 + (long + 2)
    else:
        short = 2 * n
        wait = b-1 if (b-1)<(n-a) else n-a
        long = (dst - 1) / 2 + (long + 1)

    print(min([short, long, wait]))

if __name__ == "__main__":
    main()

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
        ans+=1
        # 偶数なら
        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

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

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 = b1 - a1
    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:
N, A, B = map(int, input().split())
if (B-A) % 2 == 0:
    print((B-A) / 2)
else:
    first = (A-1) + 1 + (B-A-1)/2
    last = (N-B) + 1 + (B-A-1)/2

    print(min(first, last))

Submission status: Wrong Answer

Solution code:
N, a, b=list(map(int,input().split()))
ans=0
if((b-a)%2==0):
	ans = int((b-a)/2)
else: 
	ans = min([int(a+(b-a-1)/2),b-1, N-a, int((2*N-b-a+1)/2)])

print(ans)

Submission status: Wrong Answer

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

if S % 2 ==0:
  C = S / 2
else:
  D = min(N-A,B-1)
  if A-1 <= N-B:
    E = A + S//2
  else:
    E = N-B+1 + S//2
  C = min(D,E)

print(int(C-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(min(n1, nn, n1x, nnx, nx))

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
n,a,b=map(int,input().split())
d=b-a
if d%2==0:
    ans=d//2
    print(ans)
else:
    ans=min(b-1,n-a)
    print(ans)

Submission status: Wrong Answer

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

T = B - A - 1

if(T < 0):
    Ans = 0
elif(T % 2 == 1):
    Ans = (int)((T + 1) / 2)
else:
    if(A - 1 < N - B):
        Ans = B - 1
    else:
        Ans = N - A

print(Ans)

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

Submission status: Wrong Answer

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

if S % 2 ==0:
  C = S / 2
else:
  D = min(N-A,B-1)
  if A-1 <= N-B:
    E = A + S//2
  else:
    E = N-B+1 + S//2
  C = min(D,E)

print(int(C+1))

Submission status: Wrong Answer

Solution code:
n,a,b=list(map(int,input().split()))
p=min(a,b)
q=max(a,b)
sum=q-p
if(sum%2==0):
    print(int(sum//2))
else:
    k=n-q
    r=p-1
    s=min(k,r)
    t=q
    ans=0
    ans=ans+s
    t=t-s
    if(t!=1):
        ans=ans+1
        t=t-1
        u=t-1
        ans=ans+u//2
    print(ans)

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ANS = 0

if (B-A)%2 == 0:
    ANS = (B-A)/2

elif B-A == 1:
    if A - 1 > N - B:
        ANS = N - B + 1
    else:
        ANS = A

elif A - 1 > N - B:
    ANS = N - B + 1 + (B - 1 - A)/2

else:
    ANS = A + (B-A-1)/2

print(int(ANS))

Submission status: Wrong Answer

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

startA = (a == 1)
endB = (b == n)
aida = b-a-1



if any([startA, endB]):
    # 端に点があれば、間の卓数＋１
    print(aida+1)
else:
    if aida % 2 != 0:
        #　間の卓数が奇数なら、間の個数/2 +1
        print(aida//2+1)
    else:
        if (a-1) > (n - b):
            print(n-a)
        else:
            print(b-1)

Submission status: Wrong Answer

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

d = n[2] - n[1]

if(d % 2 == 0):
    ans = int(d/2)
else:
    ad = n[0] - n[1]
    bd = n[2] - 1
    if d == 1:
        ans = int(min(ad,bd))
    else:
        ans = 0
        ans = n[0] - n[2] + 1
        n[1] += ans
        ans += int((n[0] - n[1])/2)

if n[1] == 1:
    ans = n[2] - 1
elif n[2] == n[0]:
    ans = n[0] - n[1]

if(ans < 0):
    ans *= -1
print(ans)

Submission status: Wrong Answer

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

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**18
if N-B > A-1:
    ans1 = A-1
    ans2 = int(((B-1) - (A-1))//2)
    ansB = ans1+1+ans2

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

ans = min(ansA,ansB)
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)
elif Y < N/2:
  	print(B - 1)
else:
  	print(N - A + 1)

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:
    a = N - A
    b = B - 1
    print(min(a, b))

Submission status: Wrong Answer

Solution code:
n,a,b = [int(i) for i in input().split()]
if a%2==b%2:
    print(abs(a-b)//2)
else:
    p1 = min(a-1,b-1)
    p2 = min(n-a,n-b)
    # print(p1,p2)
    c = 0
    if p1 > p2:
        p = max(a-p2, b-p2)
        c = -1
    else:
        p = max(a-p1, b-p1)
    ans = p1 + c + p//2
    print(ans)

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

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
    a = 1
    b -= a
    r = int((b-a)/2+be)
    print(max(r, 1))

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 (N-A) < (A +(B-A-1)/2):
            print(N-A)
        else:
            print(int(A+(B-A-1)/2))
    else:
        if (B-1) < ((N-B+1)+(N-A-(N-B+1))/2):
            print(B-1)
        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(int((max(a,b) - min(a,b))/2))
else:
    print(int((max(a,b) - min(a,b))/2)+ min(n-max(a,b),min(a,b)-1) + 1)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
N, A, B = map(int, input().split())
# A < B が保証

if (B - A) % 2 == 1:
    # どっちの角による
    if B - A >= 3:
        ans = 0
        if A - 1 < N - B:
            ans += A - 1
            B -= A - 1 - 1
            print(ans + (B - 1) // 2)
        else:
            ans += N - B
            A += N - B + 1
            print(ans + (N - A) // 2)
    else:
        print(min(N - A, B - 1))
else:
    print((B - A) // 2)

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 + (b-2)//2 +1
print(min(ans1, ans2, ans3))

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
n, a, b = map(int, input().split())
aa = a - (a - 1)
bb = b - (a - 1)
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) - a)) + a + 2, int(abs(((aaa+bbb)/2) - a) + n - b + 3))))

print(min(result))

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+1,b)))
else:
    res.append(len(range(a,n)))
    res.append(b-1)

print(min(res))

Submission status: Wrong Answer

Solution code:
s=raw_input().split()
[N, A, B] = s
N = int(N)
A = int(A)
B = int(B)

def halfdist(x,y):
    return (y-x)/2

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

Submission status: Wrong Answer

Solution code:
import sys

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

    if A > B:
        tmp = A
        A = B
        B = tmp

    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:
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-1>=b-1:
  x=b-1
elif b-1>n-1:
  x=n-1

print(int(x))

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

Submission status: Wrong Answer

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

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

diff = abs(A - B)

if diff == 0:
    print(int(0))
elif diff % 2 == 0:
    # diffが偶数ならdiff/2回で同じ卓に来る
    print(int(diff / 2))
else:
    # diffが奇数なら以下の3ステップで同じ卓に来る
    # 1. 1もしくはNの近いほうの端に寄る
    if A - 1 > N - B:
        total = N - B
    else:
        total = A - 1
    #total = min(A-1, B-1, N-A, N-B)

    # 2. 偶数になるまで一回待つ
    diff = diff - 1
    total = total + 1

    # 3. あとは偶数と一緒
    total = total + (diff / 2)

    print(int(total))

Submission status: Wrong Answer

Solution code:
# 1行目の入力を空白で分割された数字として扱う
N, A, B = map(int, input().split())

# 答えの準備
res = 0

if A == B:
    print(0)
    exit(0)

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def agc_041a(input): 
    N,A,B=map(int,input.split())
    a=abs(B-A)/2
    r=max([A,B])-1
    l=N-min([A,B])
    if abs(B-A) % 2 == 0:
        return a
    return min([l,r])
  
  
print(agc_041a(input()))

Submission status: Wrong Answer

Solution code:
N, A, B = map(int, input().split())
if A % 2 == B % 2: # 両方とも偶数/奇数の場合
    print(int(abs(A-B)/2))
else: # 両方が違う場合
    # 大きい値がNにいってから戻るパターン
    nReturnedCount = (N - max(A, B) + 1)
    tmpCount = nReturnedCount + int((N - (min(A, B) + nReturnedCount)) / 2)
    nCount = 10**18
    if tmpCount > 0: nCount = tmpCount
    # 小さい値が1にいってから戻るパターン
    minReturnedCount = min(A, B)
    tmpCount = minReturnedCount + int(((max(A, B) - minReturnedCount) - 1) / 2)
    minCount = 10**18
    if tmpCount > 0: minCount = tmpCount
    print(min(nCount, minCount))

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 = diff_1A + 1
            
        else:
            return_value = diff_BN + 1
    
    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 = map(int,input().split())

sa = abs(a-b)
if sa %2 == 0:
    print(int(sa/2))
else:
    if n-b < a-1:
        print(n-a)
    elif n-b > a-1:
        print(b-1)
    else:
        print(b-1)

Submission status: Wrong Answer

Solution code:
def num():
    return int(input())
def nums():
    return list(map(int,input().split()))

N,A,B = nums()
import math
if  (B - A) % 2 == 0:
    print( int((B - A) / 2))
else:
    print(math.ceil((B-A)/2) + 1)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

    if(b_i-1)%2 == 0:
      print((b_i-1)//2 + ans)
    else:
      print((b_i-2)//2 + ans+1)
  else:
    ans = n-b
    a_i = a + (n-b) 
    if (n- a_i)%2 ==0:
      print((n- a_i)//2 + ans)
    else:
      print( (n-a_i+1)//2 +ans+1 )

Submission status: Wrong Answer

Solution code:
def main():
    tmp = input()
    tmp = [int(i) for i in (tmp.split())]
    n = tmp[0]
    a = tmp[1]
    b = tmp[2]
    dst = a - b
    top_a = a - 1
    b_lst = n - b
    long = top_a if top_a<b_lst else b_lst

    if dst % 2 == 0:
        short = dst / 2
        wait = b-1 if (b-1)<(n-a) else n-a
        long = (dst - (long + 2)) / 2 + (long + 2)
    else:
        short = 2 * n
        wait = b-1 if (b-1)<(n-a) else n-a
        long = (dst - (long + 1)) / 2 + (long + 1)

    print(min([short, long, wait]))

if __name__ == "__main__":
    main()