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

ans = 0

if abs(A-B)%2 == 0:
    ans = abs(A-B)//2
elif (A-1)>(N-B):##Aのほうが端っこより遠い
    ans = N-B+1+(B-A-1)//2
else:##Bのほうが端っこより遠い
    A = N-A+1
    B = N-B
    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(1 + min(A - 1, N - B) + (B - A - 1) // 2)

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:
    edge = min([N-A, B-1])
    a_change = A  + (B- A-1)//2
    b_change = N-B+1 +(N-(A + (N-B+1)))//2
    print(min([edge, a_change, b_change]))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(answer)

Submission status: Accepted

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

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:
x = [int(i) for i in input().split()]
n = x[0]
a = x[1]
b = x[2]
if (b - a) % 2 == 0:
    ans = b - (a + b) // 2
else:
    if a - 1 <= n - b:
        tmp = b - a
        ans = tmp - (1 + tmp) // 2 + a
        if b - 1 <= a:
            ans = b - 1
    else:
        tmp = a + n - b + 1
        ans = n - (n + tmp) // 2 + (n - b + 1)
        if n - a <= n - b + 1:
            ans = n - a
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

import math
N,a, b =list(map(int,input().split(" ")))
case1 = 10 ** 20 # 卓1で戦う場合
case2 = 10 ** 20 # 卓Nで戦う場合
case3 = 10 ** 20 # 卓中間地点で戦う場合

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

else:

# a を 1に置くパターン
    step = (a-1)
    # stepかかった後に、中間地点で合流
    step = step + 1 #一回足踏み
    case1 = step +   (  ((b - step)  - 1 ) //2   )


    # b を N に置くパターン
    step = (N - b)
    step = step + 1  # 一回足踏み

    case2 = step+  (   ( N - (a + step) )//2 )



print(min([case1,case2,case3]))

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():

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

    if abs(a-b) % 2 == 0:
        print(abs(a-b)//2)
        return
    left=0
    temp = max(a,b)
    left = temp - 1
    right = 0
    temp = min(a,b)
    right = n - temp
    ans = min(left,right)

    tempR=b-a
    mid1=10**19
    if tempR-1>0:
        mid1=(tempR-1)//2 + a
    tempL=a+n-b+1
    mid2=10**19
    if n-tempL > 0:
        mid2=(n-tempL)//2 + n-b+1
    ans = min(ans,mid1,mid2)


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

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+1+(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())
dis_Start = A-1
dis_End = N-B
# print(dis_Start,dis_End)
if A%2 == B%2:
    # print("A")
    print((B-A)//2)
elif dis_Start <= dis_End:
    # print("B")
    print(A+((B-A)//2))
else:
    # print("C")
    print((N-B+1)+((B-A)//2))

Submission status: Accepted

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

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

if (b - a) % 2 == 0:
    print((b - a) // 2)
else:
    r = 0
    if (a - 1) < (n - b):
        # aは卓1まで移動して1回勝利する
        r += a - 1 + 1
        # bはその間勝ち続ける
        b = b - r
        # あとは偶数のときと同じ
        print(((b - 1) // 2) + r)
    else:
        # bは卓nまで移動して1回負ける
        r += n - b + 1
        # aはその間勝ち続ける
        a = a + r
        # あとは偶数のときと同じ
        print(((n - a) // 2) + r)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
def solve(n, a, b):
    if a > b:
        a, b = b, a
    if (b - a) % 2 == 0:
        return (b - a) // 2
    else:
        l = a + ((b - a) - 1) // 2
        r = (n - b + 1) + (n - (a + (n - b + 1))) // 2
        return min(l, r)
print(solve(*map(int, input().split())))

Submission status: Accepted

Solution code:
n,a,b = map(int, input().split())		# 5 7 2

if a>b: a,b=b,a

ans = 0
x=0

d = b-a
if d%2==1:

	if a-1 < n-b:
		x = a-1
		ans+=x+1
		a = 1
		b = b-ans
	else:
		x = n-b
		ans+=x+1
		b = n
		a = a+ans

d = abs(b-a)

ans += d//2
print(ans)

Submission status: Accepted

Solution code:
# 2019/12/28

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

Submission status: Accepted

Solution code:
N, A, B = [int(i) for i in input().split()]
# m = 10**19
if (B-A) % 2 == 0:
    print((B-A) // 2)
    quit()


l = A - 1
r = N - B

c = min(l, r)

res = c+1
d = abs(B-A)-1
# print(res, l, r)
res += d // 2

print(res)

Submission status: Accepted

Solution code:
import math
N, a, b = map(int, input().strip().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:
import sys
import math
import bisect
import re

def solve(n, a, b):
    if a > b:
        a, b = (b, a)
    if (b - a) % 2 == 0:
        return (b - a) // 2
    if a == 1:
        return 1 + solve(n, a, b - 1)
    if b == n:
        return 1 + solve(n, a + 1, b)
    delta = b - a
    val1 = (a - 1) + solve(n, 1, 1 + delta)
    val2 = (n - b) + solve(n, n - delta, n)
    return min(val1, val2)

def main():
    n, a, b = map(int, input().split())
    ans = solve(n, a, b)
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
if __name__ == "__main__":
  N, A, B = map(int, input().split())
  
  if( (B-A) % 2 == 0 ):
    print( (B-A)//2 )
  elif(N-B < A-1):
    cnt = N-B+1
    A += 1
    print( cnt + (B-A)//2 )
  else:
    cnt = A
    B -= 1
    print( cnt + (B-A)//2 )

Submission status: Accepted

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

if (a - b) % 2 == 0:
  print(abs(a - b) // 2)
else:
  if a > b:
    a, b = b, a
  if n - b > a - 1:
    print((a + b - 1) // 2)
  else:
    print((2 * n - 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] < l[2]:
        if (l[1] - 1) < (l[0] - l[2]):
            ans = l[2] - 1
        else:
            ans = l[0] - l[1]
    else:
        if (l[2] - 1) < (l[0] - l[1]):
            ans = l[1] - 1
        else:
            ans = l[0] - l[2]
else:
    if l[1] < l[2]:
        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
    else:
        if (l[2] - 1) < (l[0] - l[1]):
            ans = l[2] + (l[1] - l[2] - 1) // 2
        else:
            ans = l[0] - l[1] + 1 + (l[1] - l[2] - 1) // 2

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

s = (b - a) // 2

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

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

Submission status: Accepted

Solution code:
# coding: utf-8


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

    ret = min(max(a-1, b-1), max(n-a, n-b))

    if (b-a) % 2:
        if a-1 < n-b:
            sup = a
            ret = min(ret, sup+((b-sup-1)//2))
        else:
            sup = n-b+1
            ret = min(ret, sup+((n-a-sup)//2))
    else:
        ret = min(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())

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N, A, B = (int(i) for i in input().split())
    if (B - A) % 2 == 0:
        print((B-A)//2)
    else:
        cur = min(B-1, N-A)
        if A - 1 >= N - B:
            cur2 = (N - B)*2 + 1
            A += (N - B)*2 + 1
            cur2 += (B-A)//2
            print(min(cur, cur2))
        else:
            cur2 = (A - 1)*2 + 1
            B -= (A - 1)*2 + 1
            cur2 += (B-A)//2
            print(min(cur, cur2))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

else:
    ans = (b-a)//2

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math
import sys

(N,A,B) = list(map(int,input().split()))
# print(N,A,B)
IFN = 10 ** 19 
if (A - B) % 2 == 0:
    P1 = abs(A-B) // 2
else: 
    P1 = IFN

P2  = ((A-1) + (B-1) + 1) // 2
P3  = ((N-A) + (N-B) + 1) // 2
print(min(P1,P2,P3))

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

n, a, b = map(int, readline().split())
ans = n + 1
if (b - a) % 2 == 0:
    ans = min(ans, (b - a) // 2)
ans = min(b -1, ans)
ans = min(n - a, ans)
ans = min((n-b) + 1 + (n - (a+(n-b) +1))// 2, ans)
ans = min((a-1) + 1 + ((b - 1 - (a-1)) - 1) // 2, ans)



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

diff = b - a

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 1.0e+100

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A, B):
    if (B - A) % 2 == 0:
        C = (B - A) // 2
        D = INF
    else:
        C = (B - A) // 2 + A
        D = (B - A) // 2 + (N-B + 1)

    return min(C, D)


def main():
    N, A, B = read_int_n()
    print(slv(N, A, B))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math
n,a0,b0 = map(int,input().split())
a = min(a0,b0)
b = max(a0,b0)
ans = 0
if abs(a-b) % 2 == 0:
    ans = abs(a-b)//2
else:
    if (a-1) < (n-b):
        ans = (a-1)+(b-a+2)//2
    else:
        ans = (n-b)+(b-a+1)//2

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, A: int, B: int):
    if (B-A)%2 == 0:
        between = (B-A)//2
        print(between)

    else: #端でしか会えない
        answer = 0
        if A-1<=N-B:
            answer += A
            B -= A
            A = 1
            answer += (B-A)//2
        else:
            answer += N-B+1
            A += N-B+1
            B = N
            answer += (B-A)//2

        print(answer)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(N, A, B)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math
def com(n, a, b):
    #n ,a,b = map(int, input().split())
    if (abs(a-b) % 2) == 1:
        oneToA = a-1
        oneToB = b-1
        endToA = n-a
        endToB = n-b
        print(min((oneToA+oneToB+1)//2, (endToA+endToB+1)//2))
    else:
        print((abs(a-b)//2))

def main():
    n ,a,b = map(int, input().split())
    #n = 6
    #for i in range(n):
    #    com(6, 1, i+1)
    com(n, a, b)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import numpy as np
def main():
    NAB = [np.int64(i) for i in input().split(" ")]
    N = NAB[0]
    A = NAB[1]
    B = NAB[2]
    ans = 0

    if abs(A - B) % 2 == 0:
        ans += abs(A - B) // 2
        ans = np.int64(ans)
    else:
        if A - 1 <= N - B:
            if (B - 1) >= (A - 1) + 1:
                ans += (((B - 1) - (A - 1)) // 2) + A
            else:
                ans += B - 1
        else:
            if (B - 1) >= (A - 1) + 1:
                ans += (((N - A) - (N - B)) // 2) + N - B + 1
            else:
                ans += N - A
    print(ans)
 
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
temp = list(map(int,input().split()))
n = temp[0]
a = temp[1]
b = temp[2]

if a >= b:
  big = a
  small = b
else:
  big = b
  small = a

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

Submission status: Accepted

Solution code:
n, a, b = map(int, input().split())
if abs(a - b) % 2:
    te = [a - 1, b - 1]
    te.sort()
    rem = te[1] - te[0] + 1
    cand1 = te[0] + rem // 2

    te = [n - a, n - b]
    te.sort()
    rem = te[1] - te[0] + 1
    cand2 = te[0] + rem // 2
    print(min(cand1, cand2))
else:
    print(abs(a-b)//2)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if a%2==b%2:
  print((b-a)//2)
  exit()
  
c=b-(b-a+1)//2
d=(2*n-b+a+1)//2-a
print(min(c,d))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def test(N, A, B, E):
    assert solve(N, A, B) == E, "solve(%d, %d, %d) == %d" % (N, A, B, E)

def solve(N, A, B):
    if (B - A) % 2 == 0:
        return (B - A) // 2
    if A == 1:
        return solve(N, 1, B-1)+1
    if B == N:
        return solve(N, A+1, N)+1
    return min(solve(N, 1, B-(A-1))+(A-1), solve(N, A+(N-B), N)+(N-B))

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

Submission status: Accepted

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

Submission status: Accepted

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

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




if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
temp=list(map(int, input().split()))
N=temp[0]
A=temp[1]
B=temp[2]
cnt=0
if (B-A)%2==1:
  if A-1<=N-B:
    cnt=A
    B-=A
    A=1
  else:
    cnt=N-B+1
    A+=(N-B)+1
    B=N
if A!=B:
  cnt+=(B-A)//2
print(cnt)

Submission status: Accepted

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

if abs(A - B) % 2 == 0:
    print(abs(A - B) // 2)
else:
    ans_1 = [min(N - min(A, B), max(A, B) - 1)]
    go_hasi_and_tame = min(A - 1, N - B) + 1
    ans_1.append(abs(1 - B - go_hasi_and_tame) // 2)
    ans_1.append(abs(N - (A - go_hasi_and_tame)) // 2)

    print(min(ans_1))

Submission status: Accepted

Solution code:
import sys
import math
import time

start = time.time()
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

n, a, b = na()

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

Submission status: Accepted

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

diff = abs(a-b)

if (diff%2 == 0):
    print(diff//2)
else:
    kouho = min(max(n-a,n-b),max(a-1,b-1))
    suku = min(n-a,n-b,a-1,b-1)
    kazu = (diff-1) //2
    print(min(kouho,suku+kazu+1))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#import pysnooper
#import numpy
#import os,re,sys,operator
#from collections import Counter,deque
#from operator import itemgetter,mul
#from itertools import accumulate#,combinations,groupby,combinations_with_replacement,permutations
from sys import stdin,setrecursionlimit
#from bisect import bisect_left,bisect_right
#from copy import deepcopy
#import heapq
#import math
#import string
#from time import time
#from functools import lru_cache,reduce
#from math import factorial
#import sys
#from fractions import gcd
setrecursionlimit(10**6)
input=stdin.readline

def f(s,t):
    if (t-s)%2==0:
        return (t-s)//2
    else:
        return (t-s-1)//2+1
n,a,b=map(int,input().split())

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

D = B - A

ans = float('inf')
if D % 2 == 0:
    ans = D//2
else:
    # 左端まで行く
    move = A - 1
    L = 1
    R = B - move
    D = R - L
    if D % 2 == 0:
        ans = min(ans, D//2 + move)
    else:
        ans = min(ans, D//2+1 + move)
    # 右端まで行く
    move = N - B
    L = A + move
    R = N
    D = R - L
    if D % 2 == 0:
        ans = min(ans, D//2 + move)
    else:
        ans = min(ans, D//2+1 + move)

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

Submission status: Accepted

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

n,a,b=map(int,input().split())
res = []
if (b-a)%2==0:
    print(abs(b-a)//2)
    exit()
else:
    if min(a-1,n-b)==a-1:
        res.append(b-1)
        res.append((b-a-1)//2+a)
    else:
        res.append(n-a)
        res.append((b-a-1)//2+n-b+1)
print(min(res))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x = input()
N, a, b = x.split()
N, a, b = int(N), int(a), int(b)
a, b    = min(a,b), max(a, b)

if (a + b) % 2 == 0:
    #easy part
    steps = (b-a)//2
else:
    if a - 1 < N - b:
        #when smaller is nearer at the 1th table
        steps = a - 1
        b = b - (a - 1)
        a = 1
        #print(steps, a, b)
        steps += 1
        b -= 1
        #print(steps, a, b)
    else:
        steps = N - b
        a = a + N - b
        b = N
        #print(steps, a, b)
        steps += 1
        a += 1
        #print(steps, a, b)
    steps = steps + abs(b-a)//2
    #print(steps, a, b)
print(steps)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n, a, b = map(int, input().split())

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