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:
from sys import stdin
import sys
import numpy as np
import collections
from functools import cmp_to_key

##  input functions for me
def rsa(sep = ''):
    if sep == '' :
        return input().split() 
    else: return input().split(sep)
def rip(sep = ''):
    if sep == '' :
        return map(int, input().split()) 
    else: return map(int, input().split(sep))
def ria(sep = ''): 
    return list(rip(sep))
def ri(): return int(input())
def rd(): return float(input())
def rs(): return input()
##
def main():
    N, A, B = rip()
    if (B - A) % 2 == 0:
        print((B - A) // 2)
    else :
        a = A
        b = B
        l = 0
        l += a - 1
        b -= a - 1
        a -= a - 1
        l += 1
        b -= 1
        l += (b - a) // 2
        
        a = A
        b = B
        r = 0
        r += N - b
        a += N - b
        b += N - b
        r += 1
        a += 1
        r += (b - a) // 2
        print(min(l, r))




if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def solve(n, a, b):
    if (a-b) % 2 == 0:
        return (abs(a-b)+1) // 2
    else:
        s = min(n-a, n-b) + 1
        x = s + solve(n, min(a+s, n), min(b+s, n))
        t = min(a, b)
        y = t + solve(n, max(a-t, 1), max(b-t, 1))
        return min(x, y)

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

Submission status: Accepted

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

def main():
    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+1-A-B)//2))
    
if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
import math

def resolve():
    stdin = sys.stdin
    mod = 10**9 + 7
    ns = lambda: stdin.readline().rstrip()
    ni = lambda: int(ns())
    na = lambda: list(map(int, stdin.readline().split()))
    sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

    n, a, b = na()

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

if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

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

Submission status: Accepted

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

if (b-a) % 2 == 0:
	ans = (b-a) // 2
else:
	ans_2_1 = b-1
	ans_2_2 = n-a

	if b-a == 1:
		ans = min(ans_2_1, ans_2_2)
	else:


		ans_3_1 = (a-1) + 1 + (b-a+1-1-1)//2
		ans_3_2 = (n-b) + 1 + (n-(a+n-b+1))//2

		ans = min(ans_2_1,ans_2_2,ans_3_1,ans_3_2)

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def main(N, A, B):
    if abs(A - B) % 2 == 0:
        return abs(A - B) // 2
    A, B = min(A, B), max(A, B)
    res1 = A+(B-A-1)//2

    A, B = N - B + 1, N - A + 1
    res2 = A+(B-A-1)//2
    return min(res1, res2)


if __name__ == "__main__":
    N, A, B = map(int, input().split())
    ans = main(N, A, B)
    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((D - 1) // 2 + min(A - 1, N - B) + 1)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys


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


if __name__ == '__main__':
    solve()

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#coding:utf-8
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:
    ans = abs(A-B)//2
else:
    d1 = min(A, B) - 1
    r1 = max(A, B) - d1 - 1
    a1 = (r1-1)//2 + 1 + d1

    d2 = N- max(A, B)
    r2 = min(A, B) + d2 + 1
    a2 = (N - r2)//2 + 1 + d2
    ans = min(a1, a2)

print(ans)

Submission status: Accepted

Solution code:
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

N,A,B = II()

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

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

Submission status: Accepted

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

if A % 2 == B % 2 :
  ret = abs(B - A) // 2

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

print(ret)

Submission status: Accepted

Solution code:
from sys import stdin

n,a,b = [int(x) for x in stdin.readline().rstrip().split()]

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

Submission status: Accepted

Solution code:
import sys

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N, A, B = MAP()
if (B-A)%2 == 0:
	print((B-A)//2)
else:
	# Aが勝ち続けて調整した後負ける
	win = (A-1)+1
	lose = (N-B)+1
	#print(win, lose, B-win-1, N-A-lose)
	print(min(B-1, win+((B-win)-1)//2, N-A, lose+(N-(A+lose))//2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict, deque
import bisect
from heapq import *
from math import factorial
sys.setrecursionlimit(200000)
input = sys.stdin.readline

N, A, B = map(int, input().split())
# N = int(input())
# L = [int(v) for v in input().split()]
# L = [[int(v) for v in input().split()] for _ in range(N)]
# L = [int(input()) for _ in range(N)]
# L = [list(input().strip())  for _ in range(N)]
# S = input().strip()

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

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

print(a)

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

else:
  tmp = n-b
  a += n-b
  b = n
  print(tmp+((b-a)//2)+1)

Submission status: Accepted

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


def main():
    n, a, b = map(int, input().split())
    diff = b - a

    # See:
    # https://img.atcoder.jp/agc041/editorial.pdf
    # KeyInsight: 移動パターンを分解する

    # ◯：A, Bの位置の偶奇が一致しているかどうかの場合分け
    #   ：A, Bの位置の偶奇が不一致のときに，片方が端部まで移動する
    # ×：上記のcaseでの最短roundを計算する部分
    if diff % 2 == 0:
        print(diff // 2)
    else:
        # A, Bが端部に移動するまでの回数: min(a - 1, n - b)
        # 偶奇を調整する回数           : 1
        # AとBが合流するまでに必要な回数: (b - a - 1) // 2
        print(min(a - 1, n - b) + 1 + (b - a - 1) // 2)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math
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+(b-a-1)//2)

Submission status: Accepted

Solution code:
import sys
import math
from collections import deque
MAX_INT = int(10e15)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N, A, B = IL()

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

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:
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def IsOdd(n):
    return n & 1

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

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

Submission status: Accepted

Solution code:
def IsEven(n):
    return n % 2 == 0

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

if IsEven(B-A):
    # (A-B) / 2 とはお互いの距離の半分
    print((B-A) // 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 abs(A - B) % 2 == 0:
    print((abs(A - B) // 2))
else:
    ans = min(A - 1, N - B) + 1
    if A - 1 > N - B:
        ans += (N - A - ans) // 2
    else:
        ans += (B - 1 - ans) // 2
    print(ans)

Submission status: Accepted

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

if (A-B) % 2 == 0:
    # (A-B) / 2 とはお互いの距離の半分
    print((B-A) // 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) % 2 == 0:
    print((B - A) // 2)
else:
    print(min(A, N - B + 1) + (B - A - 1) // 2)

Submission status: Accepted

Solution code:
import fractions

def main():
    n, a, b = map(int, input().split())
    diff = b - a
    if diff%2 == 0:
        print(diff//2)
        return
    d1 = a + b - 1
    d2 = n - a + n - b + 1
    print(min(d1, d2)//2)

if __name__ == '__main__':
    main()

Submission status: Accepted

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


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

l = max(a,b)
s = min(a,b)

if (l-s)%2 == 0:
  print((l-s)//2)
else:
  t = s - 1
  b = n - l
  pre = min(t,b)
  ans = pre + 1 + (l-s-1)//2
  print(ans)

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

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

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 = map(int, input().split())


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

Submission status: Accepted

Solution code:
import math

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

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

Submission status: Accepted

Solution code:
import math
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-a-b+1)//2))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

if (b - a) % 2 == 0:
    print(b - (a + b) // 2)
else:
    # 折り返して会いにいく
    ans = 0
    if a - 1 < n - b:
        ans = a
        a, b = 1, b - a
    else:
        ans = n - b + 1
        a, b = a + (n - b) + 1, n
    print(b - (a + b) // 2 + ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

if diff % 2 == 0:
    print(diff // 2)

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

Submission status: Accepted

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

if dim % 2 == 0:
  print(int(dim//2))
elif dim % 2 == 1:
  dimAN = N - A
  dimBN = N - B
  dimB1 = B - 1
  dimA1 = A - 1
  
  result = min(dimA1,dimBN)+1+(dim-1) // 2
  print(result)

Submission status: Accepted

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

A()

Submission status: Accepted

Solution code:
import math
import queue
import bisect
import heapq
import time
import itertools

mod = int(1e9+7)

def swap(a,b):
    return (b,a)

def gcd(a,b): #最大公約数
    if (a<b):
        a,b = swap(a,b)
    if (b==0):
        return a
    else:
        return gcd(b,a%b)

def lcm(a,b): #最小公倍数
    return a/gcd(a,b)*b

def divisors(a): # 約数列挙
    divisors = []
    for i in range(1,int(a**0.5)+1):
        if a%i==0:
            divisors.append(i)
            if i!=a//i:
                divisors.append(a//i)
    return divisors

def is_prime(a): #素数判定
    if a<2:
        return False
    elif a==2:
        return True
    elif a%2==0:
        return False
    sqrt_num = int(a**0.5)
    for i in range(3,sqrt_num+1,2):
        if a%i==0:
            return False
    return True

def prime_num(a): #素数列挙
    pn = [2]
    for i in range(3,int(a**0.5),2):
        prime = True
        for j in pn:
            if i%j==0:
                prime = False
                break
        if prime:
            pn.append(i)
    return pn

def prime_fact(a): #素因数分解
    sqrt = math.sqrt(a)
    res = []
    i = 2
    if is_prime(a):
        res.append(a)
    else:
        while a!=1:
            while a%i==0:
                res.append(i)
                a //= i
            i += 1
    return res

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

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
def is_even(num):
    return num % 2 == 0


N, A, B = [int(i) for i in input().split()]
#  N, A, B = [5, 2, 4]
#  N, A, B = [5, 2, 3]
#  N, A, B = [10, 2, 3]
#  N, A, B = [10, 7, 8]
#  N, A, B = [5, 2, 5]
#  N, A, B = [10, 2, 8]
#  N, A, B = [2, 1, 2]
#  N, A, B = [2, 1, 1]
is_even_a = is_even(A)
is_even_b = is_even(B)
if (is_even_a == True and is_even_b == True) or (
    is_even_a == False and is_even_b == False
):
    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(int((b-a)//2))
else:
  print(int((b-a-1)//2+min(n-b,a-1)+1))

Submission status: Accepted

Solution code:
import math

n, a, b = [int(i) for i in input().split()]

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# 10 1 8 

# 1, 8
# 1, 7
# 2, 6
# 3, 5
# 4, 4

# 1, 8
# 2, 9
# 3, 10
# 4, 10
# 5, 9
# 6, 8
# 7, 7

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

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

print(solve(N, A, B))

Submission status: Accepted

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

Submission status: Accepted

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

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

    #B-ans=A-(A-1)+(ans-1-(A-1))=ans-A+1
    #ans=(A+B-1)/2
    #print(min(int((2*N-A-B+1)/2),int((A+B-1)/2)))
    
#    if A-1 < N-B:
#        ans = A-1+1
#        A = 1
#        B -= (ans)
#    else:
#        ans = N-B+1
#        A += (ans)
#        B = N
#    print(int((B-A-1)/2)+ans)

#    ans = int((A-B-1)/2)
#    A+=ans
#    B-=ans
#    print(min(N-A,B-1)+ans)

Submission status: Accepted

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

d=B-A

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

Submission status: Accepted

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

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

#AとBの偶奇が同じか？
if abs(a-b) % 2 == 0:
    #そのまま近づき合う
    ans = abs(a-b) // 2
    print(ans)
else:
    #近づき合うだけでは無理。
    #一旦どちらかが端にいき、
    #偶奇を調節する必要がある。
    
    #どちらかが1orNのいずれかに到達するのに必要なラウンド数 + 偶奇調節(+1)
    adj = min(a-1, n-b) + 1
    #調節後、二人が会うのに必要なラウンド数
    meet = (b-a-1)//2
    #合計する
    print(adj+meet)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#https://linus-mk.hatenablog.com/entry/2019/05/26/234642
#pythonのfloatは2^56->10^17乗程度しか精度が出ない。
#int(a/2)
N,A,B = list(map(int, input().split()))
diff = B-A

if diff %2 == 0:
    # print(int(diff/2))ではダメ
    print(diff//2)
else:
    edge=min(N-B,A-1)
    if diff==1:
        print(edge+1)
    else:
        after=(diff-1)//2
        print(edge+after+1)

Submission status: Accepted

Solution code:
N, A, B = map(int, input().split())
if A % 2 == B % 2: # 両方とも偶数/奇数の場合
    print((B - A) // 2)
else: # 両方が違う場合
    # BがNにいってから戻るパターンとAが1にいってから戻るパターン
    print(min(A, (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(abs(a-b)//2)
else:
  if (a+b)//2<=n//2:
    if abs(a-b)==1:
      print(min(a,b)-1+1)
    else:
      print(min(a,b)-1+1+(abs(a-b)-1)//2)
  else:
    if abs(a-b)==1:
      print(n-max(a,b)+1)
    else:
      print(n-max(a,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:
    if A-1 <= N-B:
        count = A
        A = 1
        B = B - count
        print((B-A) // 2 + count)
    else:
        count = (N-B+1)
        A = A + count
        B = N
        print((B-A) // 2 + count)

Submission status: Accepted

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

a, b = max(a, b), min(a, b)
d = a - b

if d % 2 == 0:
    ans = d // 2
    print(ans)
    exit()

count = 0
add = b-1
c = a - (add+1)
count += add+1
count += (c-1)//2
pat1 = count

count = 0
add = n-a
c = b + (add+1)
count += add + 1
count += (n-c)//2
pat2 = count

print(min(pat1, pat2))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N, A, B = map(int,input().split())

#M1 = float("inf")
#M2 = B-1
#M3 = N-A
if (B-A)%2==0:
	M1 = (B-A)//2
else:
	M1 = min(A-1,N-B) + (B-A+1)//2

#print(min(M1,M2,M3))
print(M1)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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