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: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

l = list(map(int, input().split()))

ans = 0
if not abs(l[1] - l[2]) % 2:
    ans = abs(l[1] - l[2]) // 2
elif abs(l[1] - l[2]) == 1:
    if (l[1] - 1) < (l[0] - l[2]):
        ans = l[2] - 1
    else:
        ans = l[0] - l[1]
else:
    if (l[1] - 1) < (l[0] - l[2]):
        ans = l[1] + (l[2] - l[1] - 1) // 2
    else:
        ans = l[0] - l[2] + 1 + (l[2] - l[1] - 1) // 2

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

n,a,b = MAP()

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

n, a, b = map(int, sys.stdin.readline().split())

def main():
    d = b - a
    if d % 2 == 0:
        return d // 2
    else:
        return min(n - b, abs(1 - a)) + 1 + (d - 1) // 2

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def wczytaj_liste(): 
    wczytana_lista = input()
    lista_znakow = wczytana_lista.split()
    ostateczna_lista = []
    for element in lista_znakow:
        ostateczna_lista.append(int(element))
    return ostateczna_lista

def table_tenis(): 
    N, A, B = wczytaj_liste()
    if (B-A)%2 == 0: 
        print ((B-A)//2)
    else: 
        if A - 1 <= N - B: 
            print(A+((B-A-1)//2))
        else: 
            print((N-B)+1+((B-A-1))//2)
            
table_tenis()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

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

main()

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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
        ans=(v-1)//2+1+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)
        ans=ans1
else:
    ans=(v+1)//2
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 10**20

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

print(ans)

Submission status: Accepted

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

ans = 10**20

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

t = float('inf')
if abs(A - B) % 2 == 0:
    t = min(abs(A - B) // 2, t)
t = min((A - 1 + 1) + (B - A - 1) // 2, t)
t = min((N - B + 1) + (N - (A + (N - B + 1))) // 2, t)
print(t)

Submission status: Accepted

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

if (A%2==0 and B%2==0) or (A%2==1 and B%2==1):
  print(int((B-A)//2))

elif (A-1)<=(N-B):
  print(int(A+(B-A-1)//2))

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, A, B = map(int, input().split())
M, m = max(A, B), min(A, B)

if (M - m) % 2 == 0:
  ans = (M - m) // 2
else:
  ans = min(N-M, m-1)
  ans += (M - m + 1)//2

print(ans)

Submission status: Accepted

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

if (b - a) % 2 == 0:
    print(int(abs(a - b)//2))
elif (b - a) % 2 == 1:
    print(int(min([a, n - b + 1]) + (b - a - 1)//2))

Submission status: Accepted

Solution code:
#coding:utf-8
n, a, b = map(int, input().split())
#a,bのテーブル距離
dist = b-a

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

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8


def solve(*args: str) -> str:
    n, a, b = map(int, args[0].split())

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

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

Submission status: Accepted

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

t = float('inf')
if abs(A - B) % 2 == 0:
    t = min(abs(A - B) // 2, t)
    
t = min(B - 1, t)
t = min(N - A, t)
t = min((A - 1 + 1) + (B - A - 1) // 2, t)
t = min((N - B + 1) + (N - (A + (N - B + 1))) // 2, t)

print(t)

Submission status: Accepted

Solution code:
N,A,B = map(int,input().split())
temp = 0
if (B-A)%2 == 0:
    print(int((B-A)//2))
else:
    a = N - A + 1
    b = N - B + 1
    print(min([B-1,N-A,A + (B-A-1)//2,a + (b-a-1)//2]))

Submission status: Accepted

Solution code:
def upper_cnt(a, b):
    upper_cnt = n-b + 1
    a += upper_cnt
    upper_cnt += ((n-a) // 2)    
    return upper_cnt

def lower_cnt(a, b):
    lower_cnt = a-1 + 1
    b -= lower_cnt
    lower_cnt += ((b-1) // 2)
    return lower_cnt

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

if 0 == (b-a) % 2:
    print((b-a) // 2)

else:
    up = upper_cnt(a, b)
    low = lower_cnt(a, b)
    print(min(up, low))

Submission status: Accepted

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-1)//2
  else:
    E = N-B+1 + (S-1)//2
  C = min(D,E)
 
print(int(C))

Submission status: Accepted

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

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

Submission status: Accepted

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

C = B-A

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

Submission status: Accepted

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

C = B-A

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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:
        return (min(left_s, right_s) + 1 + ((sub - 1)//2))
    
if __name__ == '__main__':
    print(main())

Submission status: Accepted

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 = Lab//2
else:
    #case Lab is odd
    ans = min(La,Lb) + 1 + (Lab-1)//2
    
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

n,a,b = map(int, input().split())
k = abs(a - b)
if k % 2 == 1:
    count = 0
    if n - b > a - 1:
        count += a - 1 + 1 + ((k - 1) // 2)
    else:
        count += n - b + 1 + ((k - 1) // 2)
    print(int(count))
else:
    print(k // 2)

Submission status: Accepted

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

if (b - a) % 2 == 0:
    print(int(abs(a - b)//2))
elif (b - a) % 2 == 1:

    print(min([a, n - b + 1]) + (b - a - 1)//2)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

n,a,b = map(int, input().split())
l = min(a, b)
r = max(a, b)
k = r - l
if k % 2 == 1:
    count = min(l - 1, n - r) + 1 + ((k - 1) // 2)
    print(int(count))
else:
    print(int(k // 2))

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

d = b - a

ans = 0

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

print(ans)

Submission status: Accepted

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 = Lab//2
else:
    #case Lab is odd
    ans = min(La,Lb) + 1 + Lab//2

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

print(answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from collections import deque


def resolve():
    input = sys.stdin.readline
    N,A,B=map(int,input().rstrip().split())

    if (B-A)%2==0:
        p1=(B-A)//2
        #p2=min(B-1,N-A)
        #print(min(p1,p2))
        print(int(p1))
    else:
        #p1=(min(int(B-1),int(N-A)))
        """
        if B-1>N-A:
            bufA=N-B+1
            bufB=N-A+1
            A=bufA
            B=bufB
        """
#        if B-1<N-A:
        #if (B-(A-1+1)-1)%2==0:
            #ans=int(A+int((B-(A-1+1)-1)/2))
        #ans=int(min(A-1,N-B)+1+(B-A-1)/2)
        ans=min(A-1,N-B)+1+(B-A-1)//2
    
        print(int(ans))

"""
        else:
            if (A-(B-N+1)-1)%2==0:
                ans=int(N-B+1+(N-(A+(N-B+1)))/2)
                ans=min(ans,N-A)
            else:
                ans=N-A
"""

from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """5 2 4"""
        output = """1"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """5 2 3"""
        output = """2"""
        self.assertIO(input, output)

if __name__ == "__main__":
    #unittest.main()
    resolve()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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: Accepted

Solution code:
def main():
    n, a, b = map(int, input().split())
    ans = 0
    diff = b - a
    if diff % 2 == 0:
        ans = diff // 2
    else:
        ab = [a, b]
        len_to_opp = [0] * 2
        len_to_opp[0] = n - ab[0]
        len_to_opp[1] = ab[1] - 1
        ans = min(len_to_opp)

        len_to_self = [0] * 2
        len_to_self[0] = ab[0] - 1
        len_to_self[1] = n - ab[1]
        if len_to_self[0] < len_to_self[1]:
            ab[0] = ab[0] - (len_to_self[0] + 1) * 2
        else:
            ab[1] = ab[1] + (len_to_self[1] + 1) * 2
        temp_ans = abs(ab[0] - ab[1]) // 2
        ans = min(ans, temp_ans)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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


print(answer)

Submission status: Accepted

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

if (B-A) % 2 == 0:
    ans = int((B-A)//2)
else:
    # ansB1 = A-1
    # ansB2 = int((B - A-1) / 2)
    # ansB = A-1 +1+ ansB2

    ansC2 = int((B - A-1) // 2)
    ans = min(N-B,A-1) +1+ ansC2

print(int(ans))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
[N, A, B] = [int(x) for x in input().split()]
 
dif = B-A
print((dif//2) if dif % 2== 0 else min(A-1, N-B)+ 1 + (dif-1)//2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, A, B = [int(i) for i in input().split()]
print(int((B-A)//2)) if (B-A)%2 == 0 else print(int((B-A)//2+1+min([A-1,N-B])))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#!/Library/Frameworks/Python.framework/Versions/3.5/bin/python3

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

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

Submission status: Accepted

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

print(answer)

Submission status: Accepted

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


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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

med = N / 2 + 0.5
Sub = B - A

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,a,b = [int(i) for i in input().split()]
if (b-a)%2==0:
    print((b-a)//2)
else:
    r = a + (b-a-1)//2
    l = n-b+1 + ( n - (a+n-b+1) )//2 
    print(min(r,l))

Submission status: Accepted

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

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

Submission status: Accepted

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

if (b-a) % 2 == 0:
    ans = (b-a)//2
else:
    if (a-1) < (n-b):
        ans = a+((b-a-1)//2)
    elif (a-1) == (n-b):
        ans = n/2
    else:
        ans = n-b+1+((b-a-1)//2)

print(int(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,A,B = list(map(int,input().split()))
diff = B - A
N2B = N - B
N2A = N - A
sumN = N2A + N2B 
sumAB = A + B 


if diff % 2 == 0:
    print(diff // 2)
else:
    if N2B < A - 1:
        tmp = (N - (A + N2B))//2 + N2B
        if (N - (A + N2B))%2 == 1:
            tmp = tmp + 1
        if N2A < tmp:
            print(N2A)
        else:
            print(tmp)
    else:
        tmp = ((B + 1 - A) - 1)//2 + A - 1
        if ((B + 1 - A) - 1)%2 == 1:
            tmp = tmp + 1
        if B-1 < tmp: 
            print(B - 1)
        else:
            print(tmp)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,A,B = list(map(int,input().split()))
diff = B - A
N2B = N - B
N2A = N - A
sumN = N2A + N2B 
sumAB = A + B 


if diff % 2 == 0:
    print(diff // 2)
else:
    if N2B < A - 1:
        tmp = (N - (A + N2B))//2 + N2B
        if (N - A - N2B)%2 == 1:
            tmp = tmp + 1
        if N2A < tmp:
            print(N2A,"a")
        else:
            print(tmp)
    else:
        tmp = ((B + 1 - A) - 1)//2 + A - 1
        if ((B + 1 - A) - 1)%2 == 1:
            tmp = tmp + 1
        if B-1 < tmp: 
            print(B - 1)
        else:
            print(tmp)

Submission status: Accepted

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

if (b-a) % 2 == 0:
    ans = (b-a)//2
else:
    if (a-1) < (n-b):
        ans = a+((b-a-1)//2)
    elif (a-1) == (n-b):
        ans = n/2
    else:
        ans = n-b+1+((b-a-1)//2)

print(int(ans))

Submission status: Accepted

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

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

Submission status: Accepted

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

N -= 1
A -= 1
B -= 1

ans = 0
distAB = B - A

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

print(int(ans))

Submission status: Accepted

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

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

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

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

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

        turn_count +=1

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