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:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, A: int, B: int):
    from math import ceil
    if (B-A)%2 == 0:
        print((B-A)//2)
        
    else:
        print(min(A-1, N-B)+1+(B-A-1)//2)


    return



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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 1e18
# 一致してないとどっちかがエッジまでいって一回消費してe/oをマッチさせる必要がある
if A%2 != B%2:
  work = A
  b = B-A
  a = 1
  work += (b-a) // 2
  #print(work,a,b)
  ans = min(ans,work)

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

Submission status: Accepted

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

    print(roundTime)



tableTennis()

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:
# Author: cr4zjh0bp
# Created: Sat Feb 29 04:25:06 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()

n, a, b = na()

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

Submission status: Accepted

Solution code:
x,y,z = map(int, input().split())
if (z+y)%2==1:
        d = min(y + z - 2, 2*x-y-z)+1
        print(d//2)
else:
	print((abs(y-z)+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-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([1+N-B+(B-A)//2, A+(B-A)//2]))

Submission status: Accepted

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

Submission status: Accepted

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

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

if (b - a) % 2 == 0:
  ans = (b - a) // 2
  
elif (b - 1) < (n - a):
  ans = a + (b - a - 1) // 2
  
else:
  ans = n - b + 1 + abs(a - b + 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:
    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()))

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

diff = B - A

if diff % 2 == 0:
    ans = diff // 2
else:
    # 左端で会う
    d1 = A - 1  # Aが左に到達するまでにd戦する
    ans1 = d1 + (diff + 1) // 2

    # 右端で会う
    d2 = N - B  # Bが右端まで到達するのにd戦必要
    ans2 = d2 + (diff + 1) // 2

    ans = min(ans1, ans2)

print(ans)

Submission status: Accepted

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

diff = B - A

if diff % 2 == 0:
    ans = diff // 2
else:
    # d1 = A - 1
    # ans1 = d1 + (diff - 1) / 2 + 1

    # d2 = N - B
    # ans2 = d2 + (diff - 1) / 2 + 1

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

print(result)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
ans=0
def solution(a,b,c):
    if (a%2==0 and b%2==0) or (a%2!=0 and b%2!=0):
        ans=(b-a)//2
    else:
        ans=min(a-1,c-b)+1+(b-a)//2
    return ans

c,a,b=map(int,input().split())
print(solution(a,b,c))

Submission status: Accepted

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

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())
ans = -1
if (b-a) % 2 == 0:
    ans = (b-a) // 2
else:
    diff_left = a - 1
    diff_right = n - b
    if diff_left <= diff_right:
        ans = diff_left
        ans += 1
        ans += (b-a-1) // 2
    else:
        ans = diff_right
        ans += 1
        ans += (b-a-1) // 2


print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from decimal import Decimal
n, a, b = map(Decimal, input().split())
if (a+b) % 2 == 1:
  if a+b < 1+n:
    a = 1 - a
  else:
    a = 2 * n + 1 - a
print(abs((a-b)/2))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

dev =  b - ((a + b) // 2)
adjust = min(a-1,n-b) + 1 + ( (b-a-1) // 2 )

if (a+b) % 2 == 0:
  print(dev)
else:
  print(adjust)

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

if a<b:
    a,b = b,a
ans1 = b-1+(a-b+1)//2
ans2 = (n-a) + (n-(b+n-a)+1)//2

print(min(ans1,ans2))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def sign(n):
        if n == 0:
            return 0
        if n < 0:
            return -1
        return 1

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


class PriorityQueue:
    def __init__(self, l=[]):
        self.__q = l
        heapq.heapify(self.__q)
        return

    def push(self, n):
        heapq.heappush(self.__q, n)
        return

    def pop(self):
        return heapq.heappop(self.__q)


MOD = int(1e09) + 7
INF = int(1e15)


def calc(N):
    return sum(int(x) for x in str(N))


def main():
    # sys.stdin = open("sample.txt")
    N, A, B = Scanner.map_int()
    if A % 2 == B % 2:
        print((B - A) // 2)
    else:
        t1 = A + (B - A) // 2
        t2 = (N - B) + 1 + (N - (A + (N - B + 1))) // 2
        print(min(t1, t2))

    return


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import numpy as np
N,A,B = map(int,input().split())
x=abs(A-B)
    

if x%2==0:
    print(x//2)
else:
    y,z=max(N-A,N-B),max(A-1,B-1)
    a,b=min(A-1,B-1),min(N-A,N-B)
    c,d=max(A-1,B-1)-a,max(N-A,N-B)-b
    e,f=c//2+a+1,d//2+b+1
    if y>z:
        print(min(z,e,f))
    else:
        print(min(y,e,f))

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())
diff = abs(a-b)
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 = [int(x) for x in input().split()]
if abs(A-B)%2==0:
  print(abs(A-B)//2)
  exit()
a = A-1
b = N-B
c = min(a,b)
print((B-A+1)//2+c)

Submission status: Accepted

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n, a, b = map(int, input().split())
if (a-b)%2 == 0:
    print(abs(a-b)//2)
else:
    if a+b>=n+1:
        print(min([n-a, n-b])+1+(abs(a-b)-1)//2)
    else:
        print(min([a, b])+(abs(a-b)-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:
#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict

con = 10 ** 9 + 7
#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N, A, B = getlist()
	if (B - A) % 2 == 0:
		ans = int((B - A) // 2)
		print(ans)
	else:
		ans = min(int((2 * N + 1 - A - B) // 2), int((A + B - 1) // 2))
		print(ans)
	


if __name__ == '__main__':
	main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

TableTennis()

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

def F(n,a,b):
    #ab間にある要素の数が偶数
    if (b-a)%2==0:
        return (b-a)//2
    #左端で止まる
    tmp = []
    #左側からみて
    x = (a-1)+(b-1)+1
    tmp.append(x//2)
    #右側からみて
    x = (n-a)+(n-b)+1
    tmp.append(x//2)
    return min(tmp)

print(F(n,a,b))

Submission status: Accepted

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

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

Submission status: Accepted

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

k = b-a
if k %2 == 0:
    print(k//2)
else:
    p = a-1
    bb = b-(a-1)

    p += 1
    bb -= 1
    
    res = p + (bb-1)//2


    p = n-b
    aa = a+(n-b)

    p += 1
    aa += 1

    res = min(res,p + (n-aa)//2)
    print(res)

Submission status: Accepted

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

Submission status: Accepted

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

check = abs(a-b)

if check%2 == 0:
    print(check//2)
    exit()

temp1 = min(max(a,b) - 1, n - min(a,b))
temp2 = min(min(a,b) - 1, n - max(a,b))
ans = min(temp1, temp2 + 1 + (check)//2)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, A, B = tuple(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:
    C=min(N+1-B,N+1-A)
    D=max(N+1-B,N+1-A)
    print(min(A + (B-A-1)//2,C + (D-C-1)//2))

Submission status: Accepted

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

result = (abs(a-b)//2)
if (a-b)%2==1:
    # min distance to top or bottom
    dist = min(a-1,b-1,n-a,n-b)
    result += dist + 1

print (result)

Submission status: Accepted

Solution code:
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
sys.setrecursionlimit(10**9)
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(input()) #整数読み込み
def isn(): return input().split() #文字列読み込み
def imn(): return map(int, input().split()) #整数map取得
def iln(): return list(map(int, input().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def 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
def is_prime(n):
    if n == 1: return False
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0: return False 
    return True
def primes(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n + 1, i): is_prime[j] = False
    return [i for i in range(n+1) if is_prime[i]]
def sieve_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

N,A,B = imn()

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
n, a, b = [int(i) - 1 for i in sys.stdin.readline().split()]
if (a - b) % 2 == 0:
    print((b - a) // 2)
else:
    if n - b > a:
        print(a + 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:
  print((b-a)//2)
elif n-b < a-1:
  print((b-a-1)//2 + n-b+1)
else:
  print((b-a-1)//2 + a)

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

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

Submission status: Accepted

Solution code:
N,A,B=map(int,input().split())
if (B-A)%2==0:
    ans=(B-A)//2
else:
    #2人のどちらかが卓1,Nのいずれかに到達するのに必要なラウンド数
    #1は偶奇を調整するためのラウンド
    #(B-A-1)/2は偶奇の調整後に2人が出会うまでのラウンド数
    ans=min(A-1,N-B)+1+(B-A-1)//2 
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    n, a, b = LI()
    if a & 1 == b & 1:
        print((b - a) // 2)
    else:
        print(min((b - a + 1) // 2 + a - 1, ((n - a) - (n - b) + 1) // 2 + n - b))
    return


#main
if __name__ == '__main__':
    solve()

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n,a,b = LI()
    if a % 2 == b % 2:
        return abs(a-b) // 2
    t = a + (b-a) // 2
    c = n - b + 1
    d = n - a + 1
    u = c + (d-c) // 2

    return min(t,u)


print(main())

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, X, Y = MAP()

# 簡単のため大小関係を固定
X, Y = min(X, Y), max(X, Y)
# 偶奇が合ってるなら直接会いに行く
if X % 2 == Y % 2:
    ans = abs(X - Y) // 2
# 合わないなら、どっちかの端で調整してから向かう
else:
    cnt1 = abs(X - 1) + 1
    Y1 = Y - cnt1
    cnt2 = abs(Y - N) + 1
    X2 = X + cnt2
    ans = min(cnt1 + abs(1 - Y1) // 2, cnt2 + abs(N - X2) // 2)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# AGC041A - Table Tennis Training
def main():
    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)


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

Submission status: Accepted

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

Submission status: Accepted

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

t = B - A

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

Submission status: Accepted

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

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