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

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

print(min(A-1, N-B) + 1 + (B-A)//2)

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

# 最小公倍数
def gcd(a, b):
  if a < b:
      a, b = b, a
  while a % b != 0:
      a, b = b, a % b
  return b
 
# 最大公約数 
def lcm(a, b):
    y = a*b / gcd(a, b)
    return int(y)

# N = INT()
# print(N)
N, A, B = MAP()
# guusuu
if (A - B) % 2 == 0:
  s = B - A
  ans = s // 2
  print(ans)
# kisuu
else:
  # if N - A <= B
  # k = B - A
  # m = min(N - A, B)
  if A - 1 <= N - B:
    # A ni tikazuku
    # 最初の移動
    s = A - 1
    # Bが残り移動する距離
    b = B - (A - 1) - 1

    ans = s + (b + 1) // 2
    # print(ans)
  else:
    s = N - B
    a = N - (A + s) + 1
    ans = s +  a // 2
    # ans = A + s + 1
    # ans = ans // 2
  print(ans)
  #   ans =(B - A + 1)//2

  # else:
  #   a = N - (A +  N - B )
  #   ans = a // 2
  # print(ans)
    



  # print(ans - k)
  # if A <= N - B:
  #   print(B - A)
  # else:
  #   print(B - A)
  # # k = B - A
  # ans = k+min(N - A, N - B)
  # B - min(N - A, N - B)
  # print(ans)

Submission status: Accepted

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

if (b-a) % 2 == 0:
    # 距離が偶数
    print((b-a) // 2)
    sys.exit()
else:
    if a+1 == b:
        print(min([b-1, n-a]))
    else:
        diff = b - a
        a += diff // 2
        b -= diff // 2
        print(min([b-1, n-a]))
# print([b-1, n - a])

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def solve(n, a, b):
    if (b - a) % 2 == 0:
        return (b - a) // 2
    else:
        # straight_win
        case_1 = a + (b - a - 1) // 2
        # straight_lose
        case_2 = (n - b + 1) + (b - a - 1) // 2
        return min(case_1, case_2)


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


def test():
    assert solve(5, 2, 4) == 1
    assert solve(5, 2, 3) == 2


if __name__ == "__main__":
    test()
    main()

Submission status: Accepted

Solution code:
def even(d):
    return d // 2

def odd(A, B, N):
    if abs(A-1) > abs(B-N):
        dist2edge = abs(B-N)
        A += dist2edge
        B += dist2edge 

        return even(abs((A+1)- B)) + 1 + dist2edge

    else:
        dist2edge = abs(A - 1)
        A -= dist2edge
        B -= dist2edge
    
        return even(abs(A- (B-1))) + 1 + dist2edge


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

    if diff % 2 == 0:
        print(even(diff))
    else:
        print(odd(A, B, N))

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:
    ans1 = B-1
    ans2 = A+(B-A-1)//2
    ans3 = (N-A)
    sita = (N-B)+1
    ans4 = sita+(N-(A+sita))//2
    print(min(ans1,ans2,ans3,ans4))

Submission status: Accepted

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

if (B - A) % 2 == 0:
  print((B - A) // 2)
else:
  NA = N - A
  B1 = B - 1
  if NA < B1:
    distance = N - B
    adjust = distance + 1
    moveA = A + adjust
    print(((N - moveA) // 2) + adjust)
  else:
    distance = A - 1
    adjust = distance + 1
    moveB = B - adjust
    print(((moveB - 1) // 2) + adjust)

Submission status: Accepted

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

Submission status: Accepted

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

def calc(n, a, b, ans, move):
    if (b-a)%2 == 0:
        return ans + (b-a)//2
    else:
        if move == 1:
            a += move
        else:
            b += move
        return calc(n, a, b, ans+1, move)
            
        

def main():
    N,A,B = (int(x) for x in input().split())

    if (B-A)%2 == 0:
        print((B-A)//2)
    else:
        left = A - 1
        right = N - B
        
        if left <= right:
            print(calc(N, 1, B-left, left, -1))
        else:
            print(calc(N, A+right, N, right, 1))        



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

Submission status: Accepted

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

ans = 0
if (B-A) % 2 == 0:
    ans = (B-A) // 2
else:
    if N-B < A-1:
        ans = N-B+1+(-A+B-1)//2
    else:
        ans = A+(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:
    # Aが1まで行って時間稼ぎ
    c = A-1 + 1 + abs(1-(B-(A-1+1)))//2
    # BがNまで行って時間稼ぎ
    d = N-B + 1 + abs(N-(A+(N-B+1)))//2
    print(min(c,d))

Submission status: Accepted

Solution code:
def main():
    n = 10**18
    a = 10**18
    b = 10**18
    n, a, b = map(int, input().split())

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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


def main(n, a, b):
    distance = b - a

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


print(main(N, A, B))

Submission status: Accepted

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


# N, A, B = 10 ** 18, 2, 10 ** 18
# N, A, B = 9, 5, 8


def main(n, a, b):
    distance = b - a

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

        # if a - 1 == n - b:
        #     return b - 1
        # if a < n - b + 1:
        #     return (a - 1) + (b - a) // 2 + 1
        # if n - a > n - b:
        #     return (n - b) + (b - a) // 2 + 1


print(main(N, A, B))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float('inf')
MOD=10**9+7
input=sys.stdin.readline

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


if a==b:
    print(0)
    exit()

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

Submission status: Accepted

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

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

    #間隔が奇数の時
else:
    #aと右端の差
    p=num-a
    #bと左端の差
    q=b-1
    #aと左端の差
    r=a-1
    #bと右端の差
    s=num-b
    
    #もしbとaの差が3未満のとき
    if b-a <3:
        p = min(b-1,num-a)
        print(p)
    
    else:
        z=r+1+(b-(r+1)-1)//2
        y=s+1+(num-(a+(s+1)))//2
        print(min(y,z))

Submission status: Accepted

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

l = b-a
if l %2 == 0:
  print(l//2)
  
else:
  mi = b-1
  ma = n-a
  
  x1 = min(mi,ma)
  t1 = a-1
  c = b-(t1+1)
  t1 += (c-1)//2+1
  
  t2 = n-b
 
  a += (t2+1)

  t2 += (n-a)//2+1

  print(min(x1,t1,t2))

Submission status: Accepted

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

Submission status: Accepted

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

ans = []

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

ans = min(ans)

print(ans)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if (b-a)%2==0:
  ans=min(ans,(b-a)//2)
elif a==1 or b==n:
  ans=min(ans,(b-a+1)//2)
else:
  ans=min(ans,min(b-1,n-a))
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:
  c = max(n-a,n-b)
  d = max(a-1,b-1)
  e = min(n-a,n-b)
  f = min(a-1,b-1)
  g = min(e,f)
  h = g + (abs(a-b)+1)//2
  print(min(c,d,h))

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
n,a,b=map(int,input().split())
if (b-a)%2==0:
    print((b-a)//2)
else:
    if a-1==min(a-1,n-b):
        print(a+((b-a-1)//2))
    else:
        print(n-b+1+((b-a-1)//2))

Submission status: Accepted

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

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

ans = t // 2 + min(min(A, B) - 1, N - max(A, B)) + 1
print(ans)

Submission status: Accepted

Solution code:
N,A,B = map(int,input().split())
if ((B-A) % 2 == 0):
    print((B-A)//2)
else:
    arr = min(N-B,A-1) + 1
    if (N-B > A-1):
        #Aの方が端に近い
        print(arr + ((B-arr)-1)//2)
    else:
        # Bの方が端に近い
        print(arr + (N-(A+arr))//2)

Submission status: Accepted

Solution code:
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, a, b = list(map(int, readline().split()))
    if (b - a) % 2 == 0:
        print((b - a) // 2)
    else:
        if abs(a - 1) < abs(n - b):
            c = a - 1
            b -= c
            a -= c
            if (b - a) % 2 == 0:
                print((b - a) // 2 + c)
            else:
                print(abs((b - 1) - a) // 2 + c + 1)
        elif abs(a - 1) >= abs(n - b):
            c = n - b
            a -= c
            b -= c
            if (b - a) % 2 == 0:
                print((b - a) // 2 + c)
            else:
                print(abs(b - (a + 1)) // 2 + c + 1)


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
#if N % 2 == 1:
if (B - A) % 2 == 0:
    ans = (B - A) // 2

else:
    a = A - 1
    b = N - B

    if a > b:
        bb = b + 1
        A += bb
        ans += (N - A) // 2
        ans += bb

    else:
        aa = a + 1
        B -= aa
        ans += (B - 1) // 2
        ans += aa

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

N, A, B = map(int, input().split())
ans = []
if (A + B) % 2 == 0:
    ans.append((B - A) // 2)
if A > N - B:
    ans.append(N - A)
    ans.append(((B - A) // 2) + N - B + 1)
if A <= N - B:
    ans.append(B - 1)
    ans.append(((B - A) // 2) + A)

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

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


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

Submission status: Accepted

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

ans = 0

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

else:
    # if tmp == 1:
    #     print(tmp // 2 + 2)
    # else:
    #     print(tmp // 2 + 1)
        
    MIN = min(A, B)
    MAX = max(A, B)

    if MIN - 1 < N - MAX:
        ans = MIN - 1
    
    else:
        ans = N - MAX
    
    print(ans + (tmp+1) // 2)
    #     if tmp == 1:
    #         print(MAX - 1)
    #     else:
    #         print(MAX - 2)
    # else:
    #     if tmp == 1:
    #         print(N - MIN)
    #     else:
    #         print(N - MIN - 1)

# 25 35 44

Submission status: Accepted

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

Submission status: Accepted

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

p1 = 10e18
p2 = 10e18
p3 = 10e18
p4 = 10e18
p5 = 10e18

if (B - A) % 2 == 0:
    p1 = (B - A) // 2
else:
    p2 = B - 1 #左端による
    p3 = N - A # 右端による
    # Aを1回左端に寄せてから、折り返し
    p4 = (B - A) // 2 + A
    # Bを1回右端に寄せてから折り返し
    p5 = (-A + B -1) //2 + N -B + 1

print(min(p1, p2, p3, p4, p5))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from math import factorial
from fractions import Fraction
import heapq, bisect, fractions
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
MOD = 10**9 + 7

n, a, b = MAP()

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

Submission status: Accepted

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

Submission status: Accepted

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

else:

  if abs(a-b)>=3:
    c=min(abs(1-a),abs(n-b))
    c = c-(abs(a-b)//2)
  else:
    c=min(abs(1-a),abs(n-b))


print(c)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N,a,b=map(int,input().split())
if (b-a)%2==0:
    print((b-a)//2)
else:
    M=(a+b)//2
    if M-1<N-M:
        b-=a
        print((b-1)//2+a)
    else:
        a+=N-b+1
        print((N-a)//2+N-b+1)

Submission status: Accepted

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

l = B-A
count = 0

if l%2 == 1:
    if A-1>N-B:
        count+=N-B+1
        A,B =A+(N-B)+1,N
    else:
        count+=A
        A,B =1,B-A

l = B-A
count += l//2

print(count)

Submission status: Accepted

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

if abs(a - b) % 2 == 0:
    print(abs(a-b) // 2)
else:
    dla, dlb = n-a, n-b
    dra, drb = a-1, b-1
    ansl = min(dla, dlb) + 1 + abs(dla - dlb) // 2
    ansr = min(dra, drb) + 1 + abs(dra - drb) // 2
    print(min(ansl, ansr))

Submission status: Accepted

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

if N == 2:
    print(1)
    exit()

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

if A == 1 or B == N:
    if B - A == 1:
        print(1)
        exit()
    else:
        print(1 + (B-A)//2)
        exit()

# Aが近い
if (A-1) <= (N-B):
    flag = True
# Bが近い
else:
    flag = False

if flag:
    answer = A + (B-A)//2
else:
    move = N-B
    answer = move + 1 + (B-A)//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:
N,A,B = map(int,input().split())
if (A-B) % 2 == 0:
    print((B-A)//2)
else:
    # 右に寄せる
    if A-1 > N-B:
        print((N-B+1) + (N - (A + (N-B+1)))//2)
    else:
        print(A + (B-A)//2)

Submission status: Accepted

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

if(abs(A-B)%2==0):
    print(abs(A-B)//2)
else:
    o=max(abs(1-A),abs(1-B))
    n=max(abs(N-A),abs(N-B))
    t=min(o,n)

    t1=N-((A+B-1)//2)
    t2=((A+B+1)//2)-1
    print(min(t,t1,t2))

Submission status: Accepted

Solution code:

from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations
import sys
import bisect
import string
import math
import time
from fractions import gcd
#import random


def I(): return int(input())


def MI(): return map(int, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['Yes', 'No']
MOD = 10**9+7
inf = float('inf')
IINF = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)


# show_flg = False
show_flg = True


def main():
    N, A, B = MI()
    diff = abs(A - B)

    if diff % 2 == 0:
        print(diff // 2)
    else:
        ans = 0
        minp = min(A, B)
        maxp = max(A, B)
        # print(N - maxp + 1, maxp, minp)
        if N - maxp + 1 > minp:
            ans += minp - 1
            B -= minp - 1
            B -= 1
            ans += 1
            A = 1
            # print(ans, A, B)
            if B == 1:
                print(ans)
            else:
                ans += abs(B - A) // 2
                print(ans)
        else:
            ans += N - maxp
            A += N - maxp
            A += 1
            ans += 1
            B = N
            # print(ans, A, B)
            if A == N:
                print(ans)
            else:
                ans += abs(B - A) // 2
                print(ans)
        # # print(minp, maxp, N - maxp)
        # else:
        #     print(max(A, B) - 1)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

if A == 1:
  print(B//2)
  exit()

if B == N:
  print((N-A+1)//2)
  exit()

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(int(ans))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8

def pattern1(N, A, B):
  left = B - 1
  right= N - A
  if left < right:
    return left
  else:
    return right  
      
def pattern2(N, A, B):
  round_elapsed_mid = (A - 1) + 1
  B_position = B - round_elapsed_mid
  offset = B_position - 1
  if offset % 2 == 0:
    return (offset // 2 + round_elapsed_mid)
  
def pattern3(N, A, B):
  round_elapsed_mid = (N - B) + 1
  A_position = A + round_elapsed_mid
  offset = N - A_position
  if offset % 2 == 0:
    return (offset // 2 + round_elapsed_mid)

N, A, B = (int(n) for n in input().split())
offset = B - A
if offset % 2 == 0:
  print(offset // 2)
else:
  candi1 = pattern1(N, A, B)
  candi2 = pattern2(N, A, B)
  candi3 = pattern3(N, A, B)
  print(min([candi1, candi2, candi3]))

Submission status: Accepted

Solution code:
#!python3

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

    diff = B - A

    a = []
    if diff % 2 == 0:
        a.append(diff//2)

    a.append(diff//2 + A-1 + 1)
    a.append(diff//2 + N -B + 1)

    print(min(*a))

if __name__ == "__main__":
    resolve()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
nab=input().split(" ")
N,A,B=int(nab[0]),int(nab[1]),int(nab[2])
if abs(A-B)%2==0:
  print(abs(A-B)//2)
else:
  ans=0
  A,B=min(A,B),max(A,B)
  #まず端に近い選手を端に寄せる手数
  #Aと端の距離はA-1 Bと端の距離はN-B
  ans+=min(A-1,N-B)
  ans+=1 #端で1試合留まる
  print(ans+(abs(A-B)-1)//2)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = []
if abs(a-b) % 2 == 0:
    ans.append(abs(a-b) // 2)
x = abs(1 - max(a,b))
y = abs(n - min(a,b))
ans.append(min(x, y))

x = abs(1 - min(a,b)) + 1
y = abs(max(a,b) - x)
if abs(1-y) % 2 == 0:
    ans.append(abs(1-y) // 2 + x)

x = abs(n - max(a,b)) + 1
y = abs(min(a,b) + x)
if abs(n-y) % 2 == 0:
    ans.append(abs(n-y) // 2 + x)

print(min(ans))

Submission status: Accepted

Solution code:
import sys
from pprint import pprint

def solve(n, a, b):
    ans = 0
    if (b - a) % 2 == 0:
        ans = (b - a) // 2
    else:
        # 両端で試合するパターン
        simple = min(b - 1, n - a)

        # 両端に一回残留してから端以外で試合するパターン
        mix_a = a + (b - a) // 2
        mix_b = n - b + 1 + (b - a - 1) // 2
        ans = min(simple, mix_a, mix_b)

    print(ans)

if __name__ == '__main__':
    n, a, b = map(int, sys.stdin.readline().strip().split(" "))
    solve(n, a, b)

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