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
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]
## math ##
def to_bin(x: int) -> str: return format(x, 'b') # rev => int(res, 2)
def to_oct(x: int) -> str: return format(x, 'o') # rev => int(res, 8)
def to_hex(x: int) -> str: return format(x, 'x') # rev => int(res, 16)
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(MAX_NUM+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(MAX_NUM**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, MAX_NUM+1, i):
            is_prime[j] = False
    return [i for i in range(MAX_NUM+1) if is_prime[i]]
## libs ##
from itertools import accumulate as acc
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left
#======================================================#

def main():
    n, a, b = MII()
    if (b-a)%2 == 0:
        print((b-a)//2)
    else:
        if n-a < b-1:
            print((n-b+1)+(n-(a+(n-b+1)))//2)
        else:
            print(a+((b-a)-1)//2)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,a,b=[int(x) for x in 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)%2 == 0:
  print((B - A) // 2)

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

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if (B - A) % 2 == 0:
    print((B - A) // 2)
else:
    # Aが左に到着
    ans1 = 0
    ans1 += A - 1 + 1
    a = 1
    b = B - A
    ans1 += (b - a) // 2

    # Bが右に到着
    ans2 = 0
    ans2 += N - B + 1
    a = A + (N - B + 1)
    b = N
    ans2 += (b - a) // 2

    ans = min(ans1, ans2)
    print(ans)

Submission status: Accepted

Solution code:
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:
    #     cnt = right + 1
    #     left = min(a + cnt, n)
    #     print((n - left) // 2 + cnt)
    # else:
    #     cnt = left + 1
    #     right = max(b - cnt, 1)
    #     print((right - 1) // 2 + cnt)

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

    if left > right:
        cnt = right + 1
        left = min(a + cnt, n)
        print((n - left) // 2 + cnt)
    else:
        cnt = left + 1
        right = max(b - cnt, 1)
        print((right - 1) // 2 + cnt)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import time
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N, A, B = map(int, readline().split())
    if (B-A)%2==0:
        ans = (B-A)//2
    else:
        left = A-1
        right = N-B
        if left<=right:
            l = left + 1
            ans = l + (B-l)//2
        else:
            r = right + 1
            ans = r + (N-(A+r))//2
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, a, b = map(int, input().split())
    ab = abs(a - b)
    if ab % 2 == 0:
        print(ab // 2)
    else:
        res1 = a + (ab - 1) // 2
        res2 = n - b + 1 + (ab - 1) // 2
        print(min(res1, res2))


if __name__ == '__main__':
    resolve()

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

def readInts():
  return list(map(int,input().split()))
def main():
    n,a,b = readInts()
    ab = abs(a-b)
    if ab % 2 == 0:
        print(ab//2)
    else:
        print(min(a + (ab-1)//2, n - b + 1 + (ab-1)//2))

if __name__ == '__main__':
  main()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# import re
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb

# slist = "abcdefghijklmnopqrstuvwxyz"
N,A,B = map(int,input().split())

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

print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(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 - 1 + B - 1 + 1) // 2, (N - A + N - B + 1) // 2))

Submission status: Accepted

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

# A - Table Tennis Training
def move_left():
	return A + (B-A-1)//2


def move_right():
	return  N - B + 1 + (B-A-1)//2	


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

if (B-A) % 2 == 0:
	print(int((B-A)//2))
else:
	l = move_left()
	r = move_right()
	print(min(l, r))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def myAnswer(N:int,A:int,B:int) -> int:
   ans = 0
   BN = N - B
   A1 = A - 1
   while True:
      if((B - A) % 2== 0):
         ans += (B - A)//2
         break
      elif(A == 1):
         ans += 1
         B -= 1
      elif(B == N):
         ans += 1
         A += 1
      else:
         if(BN > A1):
            ans +=A1
            B -= A1
            A = 1
         else:
            ans += BN
            A += BN
            B = N
   return ans

def modelAnswer():
   tmp=1
def main():
   N,A,B = map(int,input().split())
   print(myAnswer(N,A,B))
if __name__ == '__main__':
   main()

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def MAP(): return map(int, input().split())

n, a, b = MAP()
print(abs(a - b) // 2 if not (a - b) % 2 else abs(a - b) // 2 + min(min(a, b) - 1, n - max(a, b)) + 1)

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, acos, atan, asin, log, log10
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 debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(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()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = True

n, a, b = MAP()
print(abs(a - b) // 2 if not (a - b) % 2 else abs(a - b) // 2 + min(min(a, b) - 1, n - max(a, b)) + 1)

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, acos, atan, asin, log, log10
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 debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(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()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = True

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

Submission status: Accepted

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

if __name__ == "__main__":
    n, a, b = map(int, input().split())
    print(solve(n, a, b))

Submission status: Accepted

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

print(ans)

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

print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

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


resolve()

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

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:
    a, b = b, a

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

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    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-b+1-a)//2))

if __name__=='__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

import sys
input = sys.stdin.readline

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

if __name__ == '__main__':
    main()

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n,a,b = iim()

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
N, A, B = map(int, input().split())
print((B-A)//2 if A & 1 == B & 1 else 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 = 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==0:
	P=(B-A)//2
else:
	P=float("inf")
if (A+B)%2==1:
	Q=A
	Q+=(B-Q-(B-Q+1)//2)
else:
	Q=float("inf")

if (A+B)%2==1:
	R=N-B+1
	B=N
	A+=R
	R+=B-(A+B)//2
else:
	R=float("inf")
print(min(P,Q,R))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""


n,a,b = m()

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
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

N, A, B = MAP()

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

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
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

N, A, B = MAP()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,A,B=map(int,input().split())
C=A
D=B
ans=0
a=abs(A-B)
if a%2==0:
    print(a//2)
else:
    nb=N-B
    ans+=nb
    A+=nb
    B=N
    A+=1
    ans+=1
    ab=abs(A-B)
    ans+=ab//2

    A=C
    B=D
    val=0
    na=A-1
    B=B-na
    A=1
    val+=na
    B=B-1
    #print(B)
    val+=1
    na=abs(A-B)
    #print(na)
    val+=na//2
    ans=min(ans,val)
    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:
    M = max(A, B)
    m = min(A, B)
    print(min(N-m, M-1, (N-M+1)+(M-m)//2, m+(M-m)//2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,A,B=map(int,input().split())
if (A+B)%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:
val = input().split(' ')
N = int(val[0])
A = int(val[1])
B = int(val[2].strip())

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

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

Submission status: Accepted

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

if (B - A) % 2 == 0:
    # 間で合う
    c1 = (B - A) // 2
    # AもBも1まで行く
    # c2 = max((A - 1), (B - 1))
    # AもBもNまで行く
    # c3 = max((N - A), (N - B))
    # c = min(c1, c2, c3)
    c = c1
else:
    # AもBも1まで行く
    # c2 = max((A - 1), (B - 1))
    # # AもBもNまで行く
    # c3 = max((N - A), (N - B))
    # c = min(c2, c3)
    c = min(A - 1, N - B) + 1 + (B - A - 1) // 2
print(c)

Submission status: Accepted

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

if (b - a) % 2 == 0:
	print((b - a) // 2)
elif (b - a) % 2 == 1:
	na = n - a
	nb = n - b
	a1 = a - 1
	b1 = b - 1
	if na + nb <= a1 + b1:
		print((na + nb + 1) // 2)
	else:
		print((a1 + b1 + 1) // 2)

Submission status: Accepted

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