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 heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
import math
import time
import random
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def GI(V,E,Directed=False,index=0):
    org_inp=[]
    g=[[] for i in range(n)]
    for i in range(E):
        inp=LI()
        org_inp.append(inp)
        if index==0:
            inp[0]-=1
            inp[1]-=1
        if len(inp)==2:
            a,b=inp
            g[a].append(b)
            if not Directed:
                g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp
            aa=(inp[0],inp[2])
            bb=(inp[1],inp[2])
            g[a].append(bb)
            if not Directed:
                g[b].append(aa)
    return g,org_inp
def bit_combination(k,n=2):
    rt=[]
    for tb in range(n**k):
        s=[tb//(n**bt)%n for bt in range(k)]
        rt+=[s]
    return rt
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase
ts=time.time()
#sys.setrecursionlimit(10**5)
input=lambda: sys.stdin.readline().rstrip()

def ran_input():
    import random
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

show_flg=False
show_flg=True

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n, a, b = [int(x) for x in input().strip().split()]
if (a + b) % 2 == 0:
    print((b - a) // 2)
else:
    if a - 1 <= n - b:
        ans = a - 1
        b -= ans
        if b % 2 == 0:
            ans += 1
            b -= 1
        ans += (b - 1) // 2
    else:
        ans = n - b
        a += ans
        if (n - a) % 2 == 1:
            ans += 1
            a += 1
        ans += (n - a) // 2
    print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

def ceil(x,y):
  return (x-1)//y+1
n,a,b=map(int,input().split())
if abs(b-a)%2==0:
    print(abs(b-a)//2)
else:
    if a>b: a,b=b,a
    s1=a
    b1=b-s1
    k1=(b1-1)//2+s1
    s2=n-b+1
    a2=a+s2
    k2=(n-a2)//2+s2
    print(min(k1,k2))

Submission status: Accepted

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

Submission status: Accepted

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

if judge % 2 == 0:
    print(judge//2)
    sys.exit()

d1 = n - max(a, b)
d2 = min(a, b) - 1
ans = min(d1, d2) + 1 + (judge-1)//2
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

ans = 0

sml = A
big = B

if (A-B) > 0:
    sml = B
    big = A

if (A - B) % 2 == 0:
    ans = (big - sml) // 2
else:
    s = sml - 1
    b = N - big

    if s > b:
        t = (big - sml) + (2*b) + 1
    else:
        t = (big - sml) + (2*s) + 1

    ans = t // 2

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

def updiv(x,y):

    if x % y == 0:
        return x // y
    else:
        return x // y + 1

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

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

else:
    ans = updiv(A+B-2 , 2)

    ans = min (ans , updiv(2 * N - A - B , 2))

    print (ans)

Submission status: Accepted

Solution code:

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
words = lambda t : list(map(t, input().split()))

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

Submission status: Accepted

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

Submission status: Accepted

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


main()

Submission status: Accepted

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

AdefB = B-A
if AdefB%2 == 0:
    print(AdefB//2)
else:
    Ato1=A-1
    BtoN=N-B
    Ato1Pattern=Ato1+1+((B-Ato1-1)//2)
    BtoNpattern=BtoN+1+((N-BtoN-A-1)//2)
    print(min(Ato1Pattern,BtoNpattern))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, a, b = [int(_) for _ in 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:
import sys, math
def input():
    return sys.stdin.readline()[:-1]
from itertools import permutations, combinations
from collections import defaultdict

sys.setrecursionlimit(10**7)
N, A, B = map(int, input().split())


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

if A-1<N-B:
    d1 = A-1
    d2 = B-1
    print((d1+d2+1)//2)
else:
    d1 = N-A
    d2 = N-B
    print((d1+d2+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+B-1)//2,(2*N-A-B+1)//2)

print(ans)

Submission status: Accepted

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]
n,a,b=map(int,input().split())
if abs(a-b)%2==0:
    print(abs(a-b)//2)
else:
    tmp=min(max(a-1,b-1),max(n-a,n-b))
    tmp2=min(a+(b-a-1)//2,n-b+1+(b-a-1)//2)
    print(min(tmp,tmp2))

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
 
#n = int(input())
n,a,b = [int(i) for i in readline().split()]


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

else:
    r1 = 0
    r1 += a
    r1 += (b-a-1)//2
    
    r2 = 0
    r2 += n-b+1
    r2 += (b-a-1)//2

    print(min(r1,r2))

Submission status: Accepted

Solution code:
import math
import fractions

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

    # divisors.sort()
    return divisors

def bitlist(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

#a = list(map(int, input().split()))


n,a,b = list(map(int, input().split()))
c = min(max(n-a,n-b),max(a-1,b-1))


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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

else:
    print((B - A) // 2)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def ints():
  return [int(x) for x in input().split()]
def readi():
  return int(input())

def f(a, b):
  d = b-a
  if d%2==0:
    return d//2

  e = N-b
  g = a-1
  return min(e+1+f(a+e+1, N), g+1+f(1, b-g-1))

N, a, b = ints()
print(f(a, 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(b - 1, n - a, a + (b - a - 1) // 2, n - b + 1 + (b - a - 1) // 2))

Submission status: Accepted

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

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

def solve (N, A, B):
    if A == B:
        return 0
    diff = abs(A - B)
    if diff % 2 == 0:
        return diff // 2
    

    ans1 = solve2(N, A, B)
    ans2 = solve2(N, N - A + 1, N - B + 1)
    return min(ans1, ans2)

print(solve(N, A, B))

Submission status: Accepted

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

if (B - A) % 2 == 0:
    print((B-A)//2)
else:
    C = B - A
    D = A + (N - B + 1)
    print(min((C-1)//2 + A, (N-D)//2 + (N - B + 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, B-1)
    ans2 = min(N-A, N-B)
    tmp = max((A-ans), (B-ans))
    ans = tmp // 2 + tmp % 2 + ans
    tmp2 = max(N-(A+ans2), N-(B+ans2))
    ans2 = tmp2 // 2 + tmp2 % 2 + ans2
    ans = min(ans, ans2)
print(ans)

Submission status: Accepted

Solution code:
# 入力が10**5とかになったときに100ms程度早い
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


N, A, B = read_ints()
sa = abs(A - B)
if sa % 2 == 0:
    print(sa // 2)
    exit()

to_haji = min(A - 1, N - B)
ans1 = to_haji + sa

# 一回端でとどまったほうが早い場合
ans2 = to_haji + 1 + (sa - 1) // 2
print(min(ans1, ans2))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

ans=0
c=(a+b)%2
if c==0:
    ans=abs(a-b)//2
else:
    ans=min((a+b-1)//2,(2*n-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:
    x = min(A, B)
    y = max(A, B) - x
    ans1 = x + (y - 1) // 2

    x = N - max(A, B) + 1
    y = min(A, B) + x
    ans2 = x + (N - y) // 2
    
    print(min(ans1, ans2))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

if A>B:
  C=A
  A=B
  B=C
k=B-A

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

        print(ans)


main()

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]

n, a, b = ril()
if (a - b) % 2 == 0:
    print(abs(a - b) // 2)
else:
    print(min(a - 1, b - 1, n - a, n - b) + (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:
    tmp_a = a - (a - 1)
    tmp_b = b - (a - 1)
    ans = a - 1
    ans = ans + 1
    ans1 = ans + (tmp_b - tmp_a)//2
    
    tmp_a = a + (n - b)
    tmp_b = b + (n - b)
    ans = (n - b)
    ans = ans + 1
    tmp_a += 1
    ans2 = ans + (tmp_b - tmp_a)//2
    print(min(ans1, ans2))

Submission status: Accepted

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

Submission status: Accepted

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

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

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 + (b - a - 1) // 2, (n - b + 1) + (n - (a + n - 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:
    c, d = max([a, b]), min([a, b])
    if min([d-1, n-c]) == d-1:
        k = d-1
        c = c-k+1
        print(k+abs(c-1)//2)
    else:
        k = n-c
        d = d+k-1
        print(k+abs(n-d)//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:
    a, b = b, a
  a1, b1 = a, b
  s, t = 0, 0
  s += a1-1
  b1 -= s+1
  s += (b1-1)//2
  t += n-b
  a += t+1
  t += (n-a)//2
  print(min(s+1, t+1))

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,a,b = map(int,input().split())
ans = 10**20
if abs(a-b)%2==0:
    ans = abs(a-b)//2
else:
    #右でパリティを変えて近づく
    tmp = (abs(a-b)-1)//2+min(n-a,n-b)+1
    ans = min(ans,tmp)
    #左でパリティを変えて近づく
    tmp = (abs(a-b)-1)//2+min(a-1,b-1)+1
    ans =min(ans,tmp)
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def L(a, b):
    res = a - 1
    b -= res
    a -= res
    b -= 1
    res += 1
    return res + (b-a)//2

def R(a, b):
    return L(n - b + 1, n - a + 1)
    
n, a, b = map(int, input().split())
if a > b: a, b = b, a
if (a - b) % 2 == 0:
    ans = (b - a) // 2
else:
    ans = min(L(a, b), R(a, b))
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,a,b = LI()
    if (b-a)&1 == 0:
        print((b-a)>>1)
    else:
        c,d = a,b
        k = a-1
        b -= a-1
        a = 1
        k += 1
        b -= 1
        k += (b-1) >> 1
        a,b = c,d
        l = n-b
        a += n-b
        b = n
        l += 1
        a += 1
        l += (n-a) >> 1
        print(min(k,l))
    return

#Solve
if __name__ == "__main__":
    solve()

Submission status: Accepted

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

Submission status: Accepted

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

if (B-A) % 2 == 0:
    ans = (B-A) // 2
else:
    ans1 = A
    C, D = 1, B-ans1
    ans1 += (D-C) // 2

    ans2 = N-B+1
    C, D = A+ans2, N
    ans2 += (D-C) // 2

    ans = min(ans1, ans2)

print(ans)

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

Submission status: Accepted

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

diff = b - a
if diff % 2 == 0:
    out = diff // 2
else:
    diff1 = a - 1
    diff2 = n - b
    if diff1 <= diff2:
        out = a - 1 + 1
        a2 = 1
        b2 = b - a
    else:
        out = n -b + 1
        b2 = n
        a2 = a + (n-b+1)

    difff = (b2 - a2)
    assert difff % 2 == 0
    out += diff // 2

print(out)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def main():
    n, a, b = map(int, raw_input().split())
    if a < b:
        a, b = b, a
    if (a - b) % 2 == 0:
        print (a - b) / 2
        return
    print min(b - 1, n - a) + (a - b - 1) / 2 + 1

main()

Submission status: Accepted

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

if (b - a) % 2 == 0:
    print((b - a) // 2)
else:
    res = min(b - 1, n - a)
    d = min(a - 1, n - b)
    s = b - a - 1
    res2 = d + 1 + (s // 2)
    print(min(res, res2))
    # print(res, res2, d)

Submission status: Accepted

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

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

Submission status: Accepted

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


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


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(N, A, B)

if __name__ == '__main__':
    main()

Submission status: Accepted

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


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

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


if __name__ == '__main__':
  main()

Submission status: Accepted

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

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

Submission status: Accepted

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

if B < A:
    A, B = B, A

diff = B - A
if diff % 2 == 0:
    print(diff // 2)
else:
    ans = min(N-B, A-1) + (diff + 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)
    exit()
# 左にaを
a,b = sorted([a,b])
ans = a-1 + (b-a+1)//2
# 右にbを
ans2 = n-b + (b-a+1)//2
ans = min(ans, ans2)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

if (b-a)%2==0:
    print(abs((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())
ans1,ans2=0,0
if (a-b)%2==0:print((b-a)//2)
else:
    ans1+=a
    tmpa=1
    tmpb=b-a
    ans1+=(tmpb-tmpa)//2

    ans2+=(n-b+1)
    tmpb=n
    tmpa=a+n-b
    ans2+=(tmpb-tmpa)//2
    print(min(ans1,ans2))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def examA():
    N, A, B = LI()
    ans = inf
    if abs(A-B)%2==0:
        ans = abs(A-B)//2
    cur = min((A+B-1)//2,(2*N-A-B+1)//2)
    ans = min(ans,cur)
    print(ans)
    return

def examB():
    return

def examC():
    return

def examD():
    return

def examE():
    return

def examF():
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,inf
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examA()

Submission status: Accepted

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