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:
import sys

def I(): 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 main():
    n, a, b = MI()
    d = b - a
    ans = 0
    if d%2:
        temp = min(a-1, n-b)
        ans = (d-1)//2 + temp + 1
    else:
        ans = d//2
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

def solve(n,a,b):
  diff = b - a
  if diff % 2 == 0:
    return (diff + 1) // 2
  
  # foward to "1" table and A stay 1 round
  root_a = a
  # A kicks back to B
  root_a += diff // 2
  # foward to "N" table B stay 1 round
  root_b = n - b + 1
  # B kicks back to A
  root_b += diff // 2
  
  return min(root_a, root_b)

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

Submission status: Accepted

Solution code:
from collections import defaultdict

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

n,a,b = readInts()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

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

resolve()

Submission status: Accepted

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

Submission status: Accepted

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

df = abs(A - B)
dA = A - 1
dB = N - B
ans = 0

if df % 2 == 0:
    ans = int(df // 2)
    print(ans)
else:
    if dA > dB:
        #端までの距離
        ans += dB + 1 + ((B-A) // 2)
        print(ans)
    else:
        ans += dA + 1 + ((B-A) // 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:
    print(min(min(A, B) + abs(A - B) // 2, N - max(A, B) + 1 + abs(A - B) //2))

Submission status: Accepted

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

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

    top = N-A
    bottom = B-1
    ans = min(A-1, N-B) + 1 + (B-A-1)//2

print(ans)

Submission status: Accepted

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


resolve()

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

Submission status: Accepted

Solution code:
# ans

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

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

Submission status: Accepted

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

dif = abs(A-B)
if dif%2 == 0:
    ans = dif//2
else:
    #A left
    t0 = A - 1 + 1
    xa = 0
    xb = B - t0
    dif = abs(xb - xa)
    ans1 = dif//2 + t0
    
    #B left
    t0 = B - 1 + 1
    xa = A - t0
    xb = 0
    dif = abs(xb - xa)
    ans2 = dif//2 + t0
    
    #A right
    t0 = N - A + 1
    xa = N
    xb = B + t0
    dif = abs(xb - xa)
    ans3 = dif//2 + t0
    
    #B right
    t0 = N - B + 1
    xa = A + t0
    xb = N
    dif = abs(xb - xa)
    ans4 = dif//2 + t0
    
    ans = min(ans1, ans2, ans3, ans4)
    
print(ans)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
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()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

N, A, B = MAP()

if (A-B-1)%2:
	print((B-A)//2)

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

Submission status: Accepted

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

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

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, *AB = [int(x) for x in input().split()]
A, B = sorted(AB)
if (B - A) % 2 == 0:
    ans = (B - A) // 2
else:
    ans = (B - A + 2 * min(N - B, A - 1) + 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:
  temp=min(min(a-1,b-1),min(n-a,n-b))+1  
  print(min(temp+(abs(a-b)-1)//2,min(max(a-1,b-1),max(n-a,n-b))))

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from fractions import gcd
#from itertools import combinations # (string,3) 3回
#from collections import deque
#from collections import defaultdict
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n,a,b = readInts()
if abs(b-a)%2 == 0:
    print(abs(b-a)//2)
else:
    print(min(a + (abs(b-a)-1)//2, n-b+1+(abs(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:
    left = a+((b-a)-1)//2
    right = (n-b+1)+(n-(a+n-b+1))//2
    print(min(right,left))

Submission status: Accepted

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


def solve(N: int, A: int, B: int):
    if A > B:
        tmp = A
        A = B
        B = tmp
    
    count = 0
    while True:
        if (B - A) % 2 == 0:
            count += (B - A) // 2
            break
        elif A != 1 and B != N:
            if A-1 < N-B:
                count += A-1
                B = B - (A-1)
                A = 1


            else:
                count += N-B
                A = A + (N-B)
                B = N
        else:
            if A == 1:
                count += 1
                B -= 1
                
            elif B == N:
                count += 1
                A += 1
    print(count)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

N,A,B = IL()

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

Submission status: Accepted

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


if (A-B)%2 == 0:
    print(abs(A-B)//2)
else:
    a = abs(A+B-1)//2 ##壁にぶつからない 
    b = abs(2*N-A-B+1)//2 ##壁にぶつかる
 
    print(min(a,b))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

ans = 0
if (b-a)%2 == 0:
    ans = (b-a)//2
else:
    if a-1 >= n-b:
        ans = n + (1-a-b)//2
    else:
        ans = (a+b)//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:
    if A-1<=N-B:
        #Aが1に到達するまで+AとBの距離が2の倍数になるまで
        x=A-1+1
        #Aは負け続け、Bは勝ち続ける
        y=(B-A)//2
        print(x+y)
        
    else:
        #BがNに到達するまで+AとBの距離が2の倍数になるまで
        x=N-B+1
        #Aは勝ち続け、Bは負け続ける
        y=(B-A)//2
        print(x+y)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

result = 0

if (A-B)%2 == 0:
    #差が偶数
    result = (B - A) // 2
else:
    #差が奇数
    result = min(A-1,N-B)+1+(B-A-1)//2

print(int(result))

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    n, a, b = geta(int)

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

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, A, B = map(int, input().split())
dif = abs(A - B)
ans = 0

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

Submission status: Accepted

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

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

print(d)

Submission status: Accepted

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

Submission status: Accepted

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

dif = abs(A-B)
if(dif%2 == 0):
  ans = dif//2
else:
  A1_diff = A-1
  #B1_diff = B-1
  #AN_diff = N-A
  BN_diff = N-B
  ans = min(A1_diff, BN_diff)+1+(dif-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 a - 1 > n - b:
        print((n-b+n-a+1)//2)
    else:
        print((a-1+b-1+1)//2)

Submission status: Accepted

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

Submission status: Accepted

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

ab = B - A

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n, a, b = map(lambda x: int(x) - 1, input().split())
if (b - a) % 2 == 0:
    print((b - a) // 2)
else:
    m = min(a, n - b)
    print(m + (b - a + 1) // 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:
    print(min((A+B-1)//2, (2*N+1-A-B)//2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N,A,B = LI()
if (A+B)%2==0:
    ans = (B-A)//2
else:
    count_move = min(A-1,N-B)
    ans = count_move+1
    ans += (B-A-1)//2
print(ans)

Submission status: Accepted

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

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

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def printlist(lst, k='\n'): print(k.join(list(map(str, lst))))
INF = float('inf')

from math import ceil

def solve():
    n, a, b = MI()
    # a -= 1
    # b -= 1

    left = max(a-1, b-1)
    right = max(n-a, n-b)

    center = INF
    sa = abs(b - a)
    if a % 2 == b % 2:
        center = sa // 2
    else:
        t = min(a-1, n-b)
        center = t + (sa-1) // 2 + 1
    # print(left, right, center)
    print(min([left, right, center]))


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

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

print(ans)

Submission status: Accepted

Solution code:
def main():
  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)


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

Submission status: Accepted

Solution code:
N,A,B = map(int,input().split())
a = min(A,B)
b = max(A,B)
d = b - a

#差が偶数の時：d/2
#差が奇数の時：どちらかの端で一回稼ぐ

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

Submission status: Accepted

Solution code:
n,a,b = list(map(int, input().split()))
if abs(b-a)%2==0:
    print(abs(b-a)//2)
else:
    #卓1に行くコスト
    c1=max(a,b)-1
    #卓Nに行くコスト
    c2=n-min(a,b)
    
    ans=0
    cost=min(c1,c2)
    if c1<c2:
        ans+=min(a,b)-1
    else:
        ans+=n-max(a,b)
    cost-=ans
    ans+=(cost+1)//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+(B-A-1)//2,N-B+1+(B-A-1)//2)
print(ans)

Submission status: Accepted

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

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

r = 0
to_wall_a = a - 1
to_wall_b = n - b

if to_wall_a <= to_wall_b:
    a = 1
    b -= to_wall_a
    r += to_wall_a

    b -= 1
    r += 1

    r += (b - a) // 2
else:
    b = n
    a += to_wall_b
    r += to_wall_b

    a += 1
    r += 1

    r += (b - a) // 2
print(r)

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

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce, lru_cache  # @lru_cache(None)
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return (int(x) for x in input().split())
def LI(): return list(Is())
def TI(): return tuple(Is())
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(S())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18
# ----------------------------------------------------------- #


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

Submission status: Accepted

Solution code:
N,A,B = list(map(int,input().split()))
if (B-A)%2 == 0:
    print((B-A)//2)
    exit()
A1 = A
B1 = B
A2 = A
B2 = B
count1 = N-B1
ans1 = 0
A1 += (N-B1)
B1 = N
if (B1-A1)%2 == 0:
    ans1 = count1+(B1-A1)//2
else:
    ans1 = count1+1+(B1-A1)//2

count2 = A2-1
ans2 = 0
B2 -= (A2-1)
A2 = 1
if (B2-A2)%2 == 0:
    ans2 = count2+(B2-A2)//2
else:
    ans2 = count2+1+(B2-A2)//2
print(min(ans1,ans2))

Submission status: Accepted

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

elif b-a==1:
    print(min(b-1,n-a))

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

D=B-A

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

Submission status: Accepted

Solution code:
n,a,b = [int(x) for x in 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 (b - a) % 2:
    print((b - a - 1) // 2 + 1 + min(n - b, a - 1))
else:
    print((b - a) // 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 - 1, n - b) + 1 + (b - a - 1) // 2)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

dif = B-A
if dif%2 == 0:
  print(dif//2)
else:
  print(min(A-1, N-B)+1+((dif-1)//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:
        ans=A+(B-A)//2
    else:
        ans=N-B+1+(B-A)//2
    print(ans)

Submission status: Accepted

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

if a % 2 == b % 2:
  print((b - a) // 2)
else:
  distA = a - 1
  distB = n - b
  if distA < distB:
    ans = distA + (b - distA - 1) // 2
    if b - distA % 2 == 1:
      print(ans)
    else:
      print(ans + 1)
  else:
    ans = distB + (n - (a + distB)) // 2
    if a + distB % 2 == n % 2:
      print(ans)
    else:
      print(ans + 1)