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:
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 = (int(x) for x in 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())

d = b - a
if d % 2 == 0:
    print(d//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())

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

Submission status: Accepted

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

N = int(N)
A = int(A)
B = int(B)

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

Submission status: Accepted

Solution code:
# Function for calc
def match(n, a, b):
    if (b - a)% 2 == 0:
        print((b-a)/2)
    else:
        if (n - b) >= a:
            print((a)+((b-(a+1))/2))
        else:
            x=(n-b+1)
            print(x+((n-(a+x))/2))
# Run match
in_string = raw_input()
[N, A, B] = [int(v) for v in in_string.split()]
match(N, A, B)

Submission status: Accepted

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

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

Submission status: Accepted

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

N = int(N)
A = int(A)
B = int(B)

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

Submission status: Accepted

Solution code:
in_string = raw_input()
in_arr = in_string.split()
N = int(in_arr[0])
A = int(in_arr[1])
B = int(in_arr[2])

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

Submission status: Accepted

Solution code:
import sys

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

Submission status: Accepted

Solution code:
import numpy as np

def min_steps_v2(n, a, b):
    n = np.int64(n)
    a = np.int64(a)
    b = np.int64(b)

    if (b - a) % 2 == 0:
        return np.int64(int(b - a) // 2)
 
    # odd case
    a_diff = a - 1
    b_diff = n - b
 
    if a_diff > b_diff:
      steps_to_even = n - b + 1
      remain_steps = min_steps_v2(n, a + (n - b) + 1, n)
    else:
      steps_to_even = a
      remain_steps = min_steps_v2(n, 1, b - a)
 
    return steps_to_even + remain_steps

numbers = input().split(' ')
 
n = int(numbers[0])
a = int(numbers[1])
b = int(numbers[2])
 
print(min_steps_v2(n, a, b))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
strargs = input()

n, a, b = map(lambda x: int(x), strargs.split())

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
N, A, B = [int(str) for str in input().strip().split()]

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

Submission status: Accepted

Solution code:
strargs = input()

n, a, b = map(lambda x: int(x), strargs.split())

if (b - a) % 2 == 0:
  print((b - a)//2)
  
elif a - 1 < n - b:
  newB = b - a
  mid = (newB - 1)//2 + 1
  print(a + mid - 1)

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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


d = B-A
if d%2 == 1:
    d = min((B + (N-B)*2 + 1) - A, B - (A - (A-1)*2 - 1))

ans = d//2
print(ans)

Submission status: Accepted

Solution code:
import sys
import math
import string
import fractions
import random
from operator import itemgetter
import itertools
from collections import deque
import copy
import heapq
from bisect import bisect, bisect_left, bisect_right

MOD = 10 ** 9 + 7
INF = float('inf')
input = lambda: sys.stdin.readline().strip()

sys.setrecursionlimit(10 ** 8)

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

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

if abs(A-B)%2==0:
	print(int(abs(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())

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

Submission status: Accepted

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

Submission status: Accepted

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


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

print(ans)

Submission status: Accepted

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

print(main())

Submission status: Accepted

Solution code:
def main():
    N, A, B = list(map(int, input().split()))
    if (A ^ B) & 1:
        return min((A - 1) + 1 + (B - A - 1) // 2,
                   (N - B) + 1 + (N - (A + N - B + 1)) // 2)
    return (B - A) // 2

print(main())

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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


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


# 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:
N,A,B=map(int,input().split())

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

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

Submission status: Accepted

Solution code:
n,a,b = map(int, input().split())
d = b - a
if d%2==0: ans = d//2 # AB間偶数
else: ans = min(a, n-b+1) + (d-1)//2 # 端寄せを一回多く行えば AB間が１つ詰まって偶数
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, a, b = [int(i) for i in input().split()]
a_distance = a-1
b_distance = n-b
ab_distance = b - a

if ab_distance % 2 == 0:
  result = ab_distance//2
else:
  if a_distance < b_distance:
    result = a_distance + (ab_distance-1)//2 + 1
  else:
    result = b_distance + (ab_distance-1)//2 + 1
print(result)

Submission status: Accepted

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

#整数値龍力　複数の入力
def input_multiple_number():
    return map(int, input().split())

N_given,A_given,B_given = input_multiple_number()

cnt = 0
while True:
    if (B_given - A_given)%2 == 0:
        print(cnt + (B_given-A_given)//2)
        exit(0)
    else:
        if (N_given - B_given) > (A_given-1):
            cnt += (A_given-1)
            cnt += 1
            A_given = 1
            B_given -= cnt
        else:
            cnt += (N_given - B_given)
            cnt += 1
            B_given = N_given
            A_given += cnt

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, A, B = map(int, input().split())
d = A - B if A > B else B - A
d2 = d // 2
d3 = d % 2
if d3 == 0:
  ans = d2
else:
  bigger = B
  smaller = A
  if A > B:
    bigger = A
    smaller = B
  shortest = smaller if N - bigger + 1 > smaller else N - bigger + 1
  ans = shortest + d2
  
  

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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


print(ans)

Submission status: Accepted

Solution code:
N,A,B = map(int,input().split())
if (A-B)%2==0:
  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 = int(input())
#l = list(map(int, input().split()))

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''
#import copy
n, a, b = map(int, input().split())

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

Submission status: Accepted

Solution code:
"""
AtCoder Grand Contest 039  A - Connection and Disconnection


Sの中で、隣り合う文字が同じ場合、連続しないよう書き換える
・abba -> abca
・abbba -> abcba：奇数個連続している場合、（連続してる個数）// 2 書き換える
・abbbba -> abcbca：偶数個連続している場合、（連続してる個数）// 2 書き換える。奇数個と同じ

また、Sを並べていく中で、「Sの末尾の文字群」と「Sの先頭の文字群」が同じ場合も、書き換えが必要。
S = abcda
SSSSS = abcda abcda abcda abcda abcda

文字列の両端は、普通に処理するのでなく、同じ文字であれば合算する形で処理したい
aaabcdaaa aaabcdaaa aaabcdaaa aaabcdaaa aaabcdaaaだと、間にaが6こ続くパターンと、全体の両端にaaaがある、みたいな。

Sが全部同じ文字だと、話がちょっと違って、交互に違う文字が出るように変える。これがコーナーケースかな？


（被らせないために）使えない文字は多くても2文字なので、書き換え先について悩むことはない。
"""
"""
AtCoder Grand Contest 041  A - Table Tennis Training

勝った人がX-1の卓、負けた人がX+1の卓で、引き分けはないから、±1のどちらかが絶対におこる
A,Bの間の距離が偶数の時、一方が勝ち一方が負けることで、差が2埋まるから、(B-A)/2回の試合後に、二人が試合できるはず
距離が奇数だと、
・端っこの卓で出会う
・一方が一回端っこの卓で足踏みしてからお互いの距離が縮まるように勝敗を決める
だと思う→一回端っこで足踏みしたら、そこで待つ必要もないので、端っこで出会うはなくていいかも。
二人の距離が奇数かつ、差が1なら両端のどちらかで出会うし、そうでなければ、一回足踏みののち、出会う方向に移動する形か

A側で一回足踏みするなら、足踏みが終わるまでにかかる試合数がa回で、そこから出会うまでが、(b-a-1) / 2回
B側で一回足踏みするなら、足踏みが終わるまでにかかる試合数がN-b+1回で、そこから出会うまでが、(N-(a+N-b+1)) / 2 = (b-a-1) / 2回
"""

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

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

Submission status: Accepted

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

def main():
    N, A, B = map(int, input().split())
    tmp = B - A
    if tmp&1:
        ans = min(A - 1, N - B)
        ans += (tmp + 1) // 2
    else:
        ans = tmp // 2
    
    print(ans)


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

Submission status: Accepted

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

d = B - A

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

print(ans)

Submission status: Accepted

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

d = B - A

if (d % 2 == 0):
    ans = d // 2
else:
    left = B - 1
    right = N - A
    mini_1 = min(left, right)
    
    kado = min(A - 1, N - B)
    mini_2 = kado + 1 + (d - 1) // 2
    
    ans = min(mini_1, mini_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+(N-(A+N-B+1))//2, A-1+1+(B-A)//2))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

# output
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

else:
    answer_1 = ((N - A) + (N - B) + 1) // 2
    answer_2 = ((A - 1) + (B - 1) + 1) // 2

    print(min(answer_1, answer_2))

Submission status: Accepted

Solution code:
n, a, b = (int(x) for x in input().split())
if (b - a) % 2 == 0:
  ans = (b - a) // 2
elif (a - 1) < (n - b):
  ans = (a - 1) + 1 + (b - a - 1) // 2
else:
  ans = (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)
elif (B-1)>=(N-A):#Nに近づいたほうが早い時
  #ans+=N-B+1
  #B=N
  #A+=(N-B)+1
  print(((B-A-1)//2)+(N-B+1))
else:#1に近づいたほうが早い時
  #ans=A-1+1
  #A=1
  #B-=A
  print(((B-A-1)//2)+A)

Submission status: Accepted

Solution code:
n, a, b = map(int, input().split())
ans = [max(a-1, b-1), max(n-a, n-b)]
dis = abs(a-b)
if dis % 2 == 0:
    ans.append(dis//2)
else:
    if abs(a-b) > 2:
        cto = min(a, b)
        ans.append((dis-1)//2+cto)
        ctn = min(n-a, n-b)
        ans.append((dis-1)//2+ctn+1)
print(min(ans))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/python3
import sys
import re
from decimal import *

l = sys.stdin.readline()
l = l.split(' ')
l = [int(str) for str in l]

n = Decimal(l[0])
a = Decimal(l[1])
b = Decimal(l[2])

pre = 10**19
if(abs(a-b)%2==0):
	pre = int(abs(a -b)/2)
smax = ( a + b - 2 + 1) / 2
emax = ( n - a + n - b + 1) / 2
tmin = min( smax, emax)
v = int(tmin)
print(min(v,pre))

sys.stdout.flush()

Submission status: Accepted

Solution code:
from decimal import *
def resolve():

    tn,ta, tb = map(int, input().split())
    n=Decimal(tn)
    a=Decimal(ta)
    b=Decimal(tb)
    if (b-a)%2 == 1:
        ans=min(a-1,n-b)+1+(b-a-1)/2
    else:
        ans=(b-a)/2

    print(int(ans))

resolve()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

    print(ans)


resolve()

Submission status: Accepted

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

    print(int(ans))


resolve()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,a,b=map(int,input().split())
c=min(a,b)
d=max(a,b)
e=min(2*n-a-b,a+b-2)
f=min(c-1,n-d)
if d-c==1:
  print(f+1)
elif (d-c)%2==0:
  print((d-c)//2)
else:
  print((e+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+(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+(b-a-1)//2)

Submission status: Accepted

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

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

print(int(ans))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

print(min(a + (b-a-1)//2, n - b + 1 + (n - (a + (n - b + 1)))//2))

Submission status: Accepted

Solution code:

[N,A,B] = list(map(int,input().split()))
AA = A-1
BB = N-B
sa = B - A
if sa%2==0:  #偶数
    out=sa//2

else:  #奇数
    if AA<BB:
        out = AA + 1 + (sa-1)//2
    else:
        out = BB + 1 + (sa-1)//2

print(out)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# import bisect
# from collections import Counter, deque
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
# import math

import sys

# import numpy as np

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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