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:
s = list(map(int, input().split()))
N = s[0]
A = s[1]
B = s[2]

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

N, A, B = mi()

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

Submission status: Accepted

Solution code:
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt, ceil
from functools import lru_cache, reduce
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True


# ワーシャルフロイド (任意の2頂点の対に対して最短経路を求める)
# 計算量n^3 (nは頂点の数)
def warshall_floyd(d, n):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d


# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# 素数判定



# limit以下の素数を列挙
def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P

# 同じものを含む順列
def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        # set（集合）型で重複を削除、ソート
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret


# ここから書き始める
n, a, b = map(int, input().split())
ans1 = INF
ans2 = INF
ans3 = INF
if (b - a) % 2 == 0:
    ans1 = (b - a) // 2
else:
    ans2 = a - 1 + 1 + (b - a - 1) // 2
    ans3 = n - b + 1 + (b - a - 1) // 2
ans = min(ans1, ans2, ans3)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import groupby


def all_equal(iterable):
    g = groupby(iterable)
    return next(g, True) and not next(g, False)


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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    from sys import stdin
    n,a,b = map(int,stdin.readline().rstrip().split())
    k = b-a-1
    if k%2==1:
        print(k//2+1)
    else:
        print(k//2+1+min(n-b,a-1))
main()

Submission status: Accepted

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

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

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

Submission status: Accepted

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

ans = 0

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

ans = 10**18+1

if a > b:
    a, b = b, a

# print(a, b)
ans = []
ans.append(max(a-1, b-1))
ans.append(max(n-a, n-b))

if abs(a-b) % 2 == 0:
    ans.append(abs(a-b)//2)
else:
    a_tmp, b_tmp = 1, b-a
    ans.append(a + abs(b_tmp-a_tmp)//2)

    a_tmp, b_tmp = a+(n-b)+1, n
    ans.append(n-b+1 + abs(b_tmp-a_tmp)//2)
# print(ans)
print(min(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,cos,radians,sqrt
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes) if b else print(no)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx
# from bisect import bisect_left,bisect_right

n,a,b=n1()

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

Submission status: Accepted

Solution code:
ma = lambda :map(int,input().split())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,a,b = map(int, input().split())
if a > b : a,b = b,a #swap
### 差が偶数
if (b-a)%2 == 0:
    print((b-a)//2)
if (b-a)%2 == 1:
    ### 1側で調整
    ichi = a + (b-a-1)//2
    ### n側で調整
    b = n-b
    a = n-a
    enu = b + 1 + (a-b-1)//2
    print(min(ichi,enu))

Submission status: Accepted

Solution code:
from sys import stdin
import math
import re
import queue

input = stdin.readline

MOD = 1000000007

def solve():
    N,A,B = map(int, input().split())
    if(abs(A - B)%2 == 0):
        print(abs(A-B)//2)
        return

    print(min(A-1,N-B)+1+(B-A-1)//2)    
if __name__ == '__main__':
    solve()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def main():

    N, A, B = map(int, input().split())
    if (B-A) % 2 == 0:
        return  (B-A) // 2
    else:
        a = A-1 + (B-A+1)//2
        b = N-B+1 + (B-A-1) // 2
        return min([a, b])

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

Submission status: Accepted

Solution code:
def main():
    N, A, B = list(map(int, input().split(' ')))
    assert 1 <= A < B <= N
    if (B - A) % 2 == 0:
        print((B - A) // 2)
    else:
        if B - 1 <= N - A:
            print(A + max([0, B - A - 1]) // 2)
        else:
            print(N - B + 1 + max([0, 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:
    if A+B-1>=2*N-A-B+1:
        print((2*N-A-B+1)//2)
    else:
        print((A+B-1)//2)

Submission status: Accepted

Solution code:

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

    ab_diff = abs(a-b)
    if ab_diff%2 == 0:
        print(ab_diff//2)
        return
    
    a_edge_diff = min(abs(a-1),abs(n-a))
    b_edge_diff = min(abs(b-1),abs(n-b))
    # near_diff = min(a_edge_diff, b_edge_diff)
    if a_edge_diff <= b_edge_diff:
        print(a_edge_diff+1+ (ab_diff-1)//2)
    else:
        print(b_edge_diff+1+ (ab_diff-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)
    exit()
else:
    c = min(a - 1, n - b)
    print(c + (b - a + 1) // 2)
    exit()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from sys import stdin, stdout

int_in = lambda: int(stdin.readline())
arr_in = lambda: [int(x) for x in stdin.readline().split()]
mat_in = lambda rows: [arr_in() for y in range(rows)]
str_in = lambda: stdin.readline().strip()
out = lambda o: stdout.write("{}\n".format(o))
arr_out = lambda o: out(" ".join(map(str, o)))
bool_out = lambda o: out("YES" if o else "NO")
tests = lambda: range(1, int_in() + 1)


def solve(n, a, b):
    if abs(a-b) % 2 == 0:
        return abs(a-b) // 2

    down_ops = min(a, b)
    up_ops = n - max(a, b) + 1

    if down_ops < up_ops:
        return solve(n, 1, max(a, b) - down_ops) + down_ops

    return solve(n, min(a, b) + up_ops, n) + up_ops


if __name__ == "__main__":
    n, a, b = arr_in()
    out(solve(n, a, b))

Submission status: Accepted

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

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

print(s)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# N = int(input())
N, A, B = [int(_) for _ in input().split()]
if (B - A) % 2 == 0:
    print((B-A) // 2)
else:
    print(min(N - B + 1 + (N - (A + N-B+1)) // 2, A + (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 a%2==b%2:
    print((b-a)//2); exit()
ans1 = 0
c = a
aa = 1
bb = b-a
ans1 = c
if aa!=bb:
    ans1 += (bb-aa)//2
ans2 = 0
c = n-b+1
bb = n
aa = a+c
ans2 = c
if aa!=bb:
    ans2 += (bb-aa)//2
print(min(ans1, ans2))

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n,a,b=map(int, input().split())
    if (abs(a-b))%2==0:
        print((abs(a-b))//2)
    else:
        ue=max(a,b)-1
        sita=n-min(a,b)
        hokasita=((n-max(a,b))*2+1+abs(b-a))//2
        hokaue=(((min(a,b))-1)*2+1+abs(b-a))//2
        print(min(ue,sita,hokasita,hokaue))
resolve()

Submission status: Accepted

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

mid = b - a

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

Submission status: Accepted

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

mid = (B - A)//2
left = ((A-1+B-1)+1)//2
right = ((N-B+N-A)+1)//2

if (B - A)%2==0:
    print(mid)
else:
    print(min(left, right))

Submission status: Accepted

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

    '''
    if N - B >= A - 1:
        ans = B - 1
    else:
        ans = N - A
'''
print(ans)

Submission status: Accepted

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

#距離
d = b-a
c = 0
if d % 2 == 0:
    c = d // 2
else:
    # 端っこに近い方に行く
    c = min(n-b, a-1)
    # 一試合距離を縮める
    c += 1
    d -= 1
    # お互い近づく
    c += (d // 2)

print(c)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if (b - a) % 2 == 1:
    dt1 = a - 1
    dt1 += 1
    b1 = b - dt1
    t1 = dt1 + (b1 - 1) // 2

    dt2 = n - b
    dt2 += 1
    a1 = a + dt2
    t2 = dt2 + (n - a1) // 2
    print(min(t1, t2))
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:
    M = min(a-1,n-b)+(b-a-1)//2+1
    print(M)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun May 10 17:22:34 2020

@author: shinba
"""
import sys 
n,a,b = map(int,input().split())

if (b-a) % 2 == 0:
    print((b-a)//2)
    sys.exit()
    
k = (a+b-1)//2

print(min(k,n-k))

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

Submission status: Accepted

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

# In[10]:


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


# In[17]:


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


# In[ ]:

Submission status: Accepted

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

main()

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/agc041/tasks/agc041_a¥

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:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    #from math import gcd

    #inf = 10**17
    #mod = 10**9 + 7

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

Submission status: Accepted

Solution code:
'''
参考
https://www.hamayanhamayan.com/entry/2019/12/29/032305
https://qiita.com/c-yan/items/4724d67c171d82a2366a

パターン1：A,Bともに偶数またはA,Bともに奇数の場合
⇒そのままお互いに近づく…(B-A)/2
パターン2：A,Bのいずれかが奇数の場合
⇒左端（Aに近いほう）か、右端（Bに近いほう）のいずれかで1ターン待機後、お互いに近づく
'''
N, A, B = map(int, input().split())

def approach(x, y):
    return (B-A)//2

ans = 0

if A % 2 == B % 2:
    ans = approach(A, B)
else:
    if A <= (N-B):
        ans += A
        A = 1
        B -= ans
    else:
        ans += N - B + 1
        B = N
        A += ans
    ans += approach(A, B)

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
def resolve():
    N,A,B=pin()
    tt=abs(A-B)
    if tt%2==0:
        print(tt//2)
        return
    else:
        s= max(A,B)-1
        t=N-min(A,B)
        print(min(s,t,(tt-1)//2+1)+min(min(A,B)-1,N-max(A,B)))
#%%submit!
resolve()

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    N,A,B=map(int,readline().split())
    if (B-A)%2==0:
        print((B-A)//2)
    else:
        print(min(N-B,A-1)+1+(B-A-1)//2)

if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline
MOD = 1000000007

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

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

#場合分けで考える
#b-aが偶数の場合、お互いに移動すればよい
#b-aが奇数の場合、末端に近いほうが端まで移動し、その後いターン消費して、距離をお互いに詰める

if (b-a)%2==0:
    ans = (b-a)//2
else:
    #端までの距離が近いほうの移動ステップ
    #端まで移動した際のお互いの距離は変化していない、そこから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())

#場合分けで考える
#b-aが偶数の場合、お互いに移動すればよい
#b-aが奇数の場合、末端に近いほうが端まで移動し、その後いターン消費して、距離をお互いに詰める

if (b-a)%2==0:
    ans = int((b-a)//2)
else:
    #端までの距離が近いほうの移動ステップ
    #端まで移動した際のお互いの距離は変化していない、そこから1ターン消費する
    #距離が偶数になるのでお互いに移動する
    ans = int(min(a-1,n-b)+1+(b-a-1)//2)

print(ans)