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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

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

else:
    ans = (b - a) // 2

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

if (b-a)%2 == 0:
  out = (b-a)//2
else:
  aa = a - 1
  bb = n - b
  if aa < bb:
    a = 1
    b = b - aa - 1
    out += (aa + 1)
    out += (b-a)//2
  else:
    b = n
    a = a + bb + 1
    out += (bb + 1)
    out += (b-a)//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:
    if A - 1 < N - B:
        print(A + (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 (a-b) % 2 == 0:
  print(abs(a-b)//2)
else:
  can = []
  can.append(((a-1)+(b-1))//2+1)
  can.append(((n-a)+(n-b))//2+1)
  print(min(can))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7 # 998244353
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n,a,b=map(int,input().split())
    if((a+b)%2==0):
        print(abs(b-a)//2)
        return

    ans=INF
    # 1 側に向かう
    score=a
    score+=(b-a-1)//2
    ans=min(ans,score)

    a,b=n-b+1,n-a+1
    score=a
    score+=(b-a-1)//2
    ans=min(ans,score)

    print(ans)
resolve()

Submission status: Accepted

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

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def main():
    n, a, b = rli()
    if (b-a) % 2 == 0:
        print((b-a)//2)
        return
    ans = (b-a)//2
    ans += min(a, n-b+1)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N,A,B=MI()
    if (A-B)&1:
        if A<B:
            A,B=B,A
        if N-B<A-1:
            ans = N-B+1
            ans += (B-A)//2
        else:
            ans = A-1+1
            ans += (B-A)//2
        print(ans)
    else:
        print(abs(A-B)//2)
if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys

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

    return 0

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 solve(n, a, b):
    if a > b:
        a, b = b, a
    if (b - a) % 2 == 0:
        return (b - a) // 2
    top = (b + a - 1) // 2
    c, d = n - a - 1, n - b + 1
    boo = (c + d + 1) // 2
    return min(top, boo)


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

Submission status: Accepted

Solution code:
n, a, b = [int(i) for i in input().split()]
a,b=max(a,b),min(a,b)

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys

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

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

Submission status: Accepted

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

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

ANS=10*N

if (B-A)%2==0:
    ANS=min(ANS,(B-A)//2)

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

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

print(ANS)

Submission status: Accepted

Solution code:
from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))


def main():
    n,a,b = mi()
    if not (b-a)%2:
        print((b-a)//2)
    else:
        print(min(a-1,n-b)+(b-a)//2+1)
    


    
main()

Submission status: Accepted

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

left = A-1
right = N-B

# left
a,b = 1, B-left-1
l = left + 1 + abs(b-a) // 2

# right
a,b = A+right+1, N
r = right + 1 + abs(b-a) // 2
print(min(l,r))

Submission status: Accepted

Solution code:
N,A,B = list(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:
    r1 = (a - 1 + b - 1 + 1) // 2
    r2 = (n - a + n - b + 1) // 2
    print(min(r1, r2))

Submission status: Accepted

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

ans = n

if (b - a) % 2 == 0:
    ans = min(ans, (b - a) // 2)

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

print(ans)

Submission status: Accepted

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

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

def F(N,A,B):
    if (B - A) % 2 == 0:
        return (B - A) // 2
    # 左端で止まる
    cand = []
    x = (B - 1) + (A - 1) + 1
    cand.append(x//2)
    x = (N - B) + (N - A) + 1
    cand.append(x//2)
    return min(cand)

answer = F(N,A,B)
print(answer)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


N, A, B = list(map(int, sys.stdin.buffer.readline().split()))

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
def TableTennisTraining():

    num = list(map(int,input().split()))

    if (num[1] - num[2]) % 2 == 0:
        
        print((num[1] - num[2])/2)
    
    else:
        
        right = max([num[0] - num[1], num[0] - num[2]])
        
        left = max([num[1] - 1, num[2] - 1])
        
        print(min[right, left])

if __name__ == '__main__':
    TableTennisTraining()

Submission status: Runtime Error

Solution code:
# AtCoder Grand Contest 041
# A - Table Tennis Training

def f(A,B,n) :
    judge=B-A
    if judge%2==0 :
        n+=judge//2
        return(n)

    else :
        if abs(A-1) < abs(N-B) :
            if A==1 :
                A=A
                B-=1
                n+=1
            else:
                A-=A-1
                B-=A-1
                n+=A-1
            return f(A,B,n)
        else :
            if B==N :
                B=B
                A+=1
                n+=1
            else :
                B+=N-1
                A+=N-1
                n+=N-1
            return f(A,B,n)

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

Submission status: Runtime Error

Solution code:
def f(A,B,n) :
    judge=B-A
    if judge % 2==0 :
        n+=judge//2
        return(n)

    else :
        if abs(A-1) < abs(N-B) :
            if A>1 :
                A-=A-1
            else:
                pass
            B-=A-1
            n+=A-1
            return f(A,B,n)
        else :
            if B<N :
                B+=N-1
            else :
                pass
            A+=N-1
            n+=N-1
            return f(A,B,n)

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

Submission status: Runtime Error

Solution code:
# AtCoder Grand Contest 041
# A - Table Tennis Training

def f(A,B,n) :
    judge=abs(B-A)
    if judge%2==0 :
        n+=judge//2
        return(n)
    else :
        if abs(1-A) < abs(N-B) :
            if A>1 :
                A-=1
                B-=1
                n+=1
            else:
                A=A
                B-=1
                n+=1
            return f(A,B,n)
        else :
            if B<N :
                B+=1
                A+=1
                n+=1
            else :
                B=B
                A+=1
                n+=1
            return f(A,B,n)

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

print(f(A,B,0))

Submission status: Runtime Error

Solution code:
# AtCoder Grand Contest 041
# A - Table Tennis Training

def f(A,B,n):
    judge=abs(B-A)
    if judge%2==0:
        n+=judge//2
        return(n)
    else:
        if abs(1-A) < abs(N-B) :
            if A>1:
                A-=1
                B-=1
                n+=1
            else:
                B-=1
                n+=1
            return f(A,B,n)
        else:
            if B<N:
                B+=1
                A+=1
                n+=1
            else:
                A+=1
                n+=1
            return f(A,B,n)


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

print(f(A,B,0))

Submission status: Runtime Error

Solution code:
# AtCoder Grand Contest 041
# A - Table Tennis Training

def f(A,B,n):
    judge=abs(B-A)
    if judge%2==0:
        n+=judge//2
        return(n)
    else:
        if 1-A < N-B :
            if A>1:
                A-=1
                B-=1
                n+=1
            else:
                B-=1
                n+=1
            return f(A,B,n)
        else:
            if B<N:
                B+=1
                A+=1
                n+=1
            else:
                A+=1
                n+=1
            return f(A,B,n)



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

print(f(A,B,0))

Submission status: Runtime Error

Solution code:
# AtCoder Grand Contest 041
# A - Table Tennis Training

def f(A,B,n):
    judge=abs(B-A)
    if judge%2==0:
        n+=judge//2
        return(n)
    else:
        if 1-A < N-B :
            if A>2:
                A-=1
                B-=1
                n+=1
            else:
                B-=1
                n+=1
            return f(A,B,n)
        else:
            if B<N:
                B+=1
                A+=1
                n+=1
            else:
                A+=1
                n+=1
            return f(A,B,n)



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

print(f(A,B,0))

Submission status: Runtime Error

Solution code:
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main():
    n,a,b = map(int,input().split())
    if a==b:
        print(0)
    elif a==1:
        print(str(b-1))
    elif b==1:
        print(str(a-1))
    elif a==n:
        print(str(b+1))
    elif b==n:
        print(str(a+1))
    else:
        if abs(a-b)%2==0:
            ans=abs(a-b)//2
        else:
            if n-min(a,b)>=max(a,b)-1:
                ans=max(a,b)-1
            else:
                ans=n-min(a,b)
    print(ans)

if __name__=="__main__":
    main()

Submission status: Runtime Error

Solution code:
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

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

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

if __name__=="__main__":
    main()

Submission status: Runtime Error

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


def main():
    n,a,b = [int(i) for i in input().strip().split()]
    if abs(a - b) % 2 == 0:
        print(abs(a - b) // 2)
    else:
        ans = min(a - 1, n - b) - 1 + (A - B - 1) // 2
        print(ans)
    return 



if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

Submission status: Runtime Error

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: Runtime Error

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

Submission status: Runtime Error

Solution code:
5 2 3

Submission status: Runtime Error

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: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = input()
A = input()
B = input()
if (B-A)%2==1:
  	print(A)
else:
    print((B-A)//2)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
N, A, B = map(int, input().split())
table = list(range(1, N + 1))
if A < B:
    dif = B - A
else:
    dif = A - B
if dif % 2 == 0:
    ans = int(dif / 2)
else:
    a = [abs(table[0] - table[A - 1]), abs(table[-1] - table[A - 1]), abs(table[0] - table[B - 1]), abs(table[-1] - table[B - 1])]
    a = sorted(a)
    ans = a[0] + (a[1] - a[0])
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N,A,B = map(int, input().split())
if (B-A)%2 == 0 and B-A => 0:
  print((B-A)//2+1)
if (B-A)%2 == 0 and A-B => 0:
  print((A-B)//2+1)
D = A-1
E = N-A
F = B-1
G = N-B
elif D+F > E+G and D => F:
  print(D)
elif D+F > E+G and D <= F:
  print(F)
elif D+F < E+G and E => G:
  pritn(E)
else:
  print(G)

Submission status: Runtime Error

Solution code:
N, M, V, P = map(int, input().split())
A = list(map(int, input().split()))
Asorted = sorted(A)

n = len(Asorted)
start=0
end = n-P
Ap = A[-P]
total = V*M
while start < end -1:
  #print(start, end)
  i = (start+end-1)//2
  Ai = Asorted[i]
  if Ai + M < Ap:
    start = i+1
    continue
  limit = (Ai + M)*(n-P-i-1) - sum(Asorted[i+1:n-P]) + (i+P)*M
  if limit >= total:
    end = i+1
  else:
    start = i+1
print(n-start)

Submission status: Runtime Error

Solution code:
import numpy as np

N, M, V, P = map(int, input().split())
A = list(map(int, input().split()))
if P == 1:
  Asorted = sorted(A)
else:
  Asorted = sorted(A)[:-(P-1)]

n = len(Asorted)
start=0
end = n
Ap = A[-1]
total = V*M
while start < end -1:
  #print(start, end)
  i = (start+end-1)//2
  Ai = Asorted[i]
  if i == n-1:
    start = n-1
    break
  limit = (Ai + M)*(n-i-1) - sum(Asorted[i+1:]) + (i+P)*M
  if limit >= total:
    end = i+1
  else:
    start = i+1
print(np.sum(np.asarray(A)>=Asorted[start]))

Submission status: Runtime Error

Solution code:
import numpy as np

N, M, V, P = map(int, input().split())
A = list(map(int, input().split()))
Asorted = sorted(A)[:-(P-1)]

n = len(Asorted)
start=0
end = n
Ap = A[-1]
total = V*M
while start < end -1:
  #print(start, end)
  i = (start+end-1)//2
  Ai = Asorted[i]
  if i == n-1:
    start = n-1
    break
  limit = (Ai + M)*(n-i-1) - sum(Asorted[i+1:]) + (i+P)*M
  if limit >= total:
    end = i+1
  else:
    start = i+1
print(np.sum(np.asarray(A)>=Asorted[start]))

Submission status: Runtime Error

Solution code:
import numpy as np

N, M, V, P = map(int, input().split())
A = list(map(int, input().split()))
Asorted = sorted(A)[:-(P-1)]

n = len(Asorted)
start=0
end = n
Ap = A[-1]
total = V*M
while start < end -1:
  #print(start, end)
  i = (start+end-1)//2
  Ai = Asorted[i]
  limit = (Ai + M)*(n-i-1) - sum(Asorted[i+1:]) + (i+P)*M
  if limit >= total:
    end = i+1
  else:
    start = i+1
print(np.sum(np.asarray(A)>=Asorted[start]))

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
s = list(map(int, input().split()))
N = s[0]
A = s[1]
B = s[2]

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
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
    print(min(m,M))

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

#場合分けで考える
#中央にお互い移動する
#aorbが端まで移動して、その後お互いによる

dist = []
if (b-a)%2==0:
    d = (b-a)/2
    dist.append(d)
#aのほうが近い場合
if a-1<=n-b:
    a_dist = a-1
    re_b = b-a_dist
    if (re_b-1)%2==0:
        d = a_dist+(re_b-1)/2
    else:
        d = a_dist+(re_b-2)/2+1
    dist.append(d)
if a-1>n-b:
    b_dist = n-b
    re_a = a-b_dist
    if (n-re_a)%2==0:
        d = b_dist+(n-re_a)/2
    else:
        d = a_dist+(n-re_a-1)/2+1
    dist.append(d)
print(int(min(dist)))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

print(ans)

Submission status: Runtime Error

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


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

Submission status: Runtime Error

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


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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
import argparse

parser = argparse.ArgumentParser()
parser.add_argument('integers', metavar='N', type=int, nargs='+')

args = parser.parse_args()

N = args.integers[0]
A = args.integers[1]
B = args.integers[2]


# if the distance between the two is even they can meet in the middle
# else they have to go to one end

dist = B-A

if dist % 2 == 0:
    print(int(dist/2))
else:
    # search the closer end

    steps = 0
    while dist % 2 != 0:
        if A == B:
            print('this should not happen!')
        elif (A-1) < (N-B):
            A -= 1
            B -= 1
        else:
            A += 1
            B += 1

        A = max(A, 1)
        B = min(B, N)

        dist = B-A
        steps += 1

    print(int(dist/2) + steps)

Submission status: Runtime Error

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: Runtime Error

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: Runtime Error

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: Runtime Error

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: Runtime Error

Solution code:
h,w = map(int,input().split())
masu = []
for _ in range(h):
    masu.append(list(str(input())))

ans = 0
dp = [[0]*w for i in range(h)]
if masu[0][0] == "#":
    dp[0][0] = 1

for i in range(1,h):
    if masu[i][0] != masu[i-1][0] and masu[i][0]=="#":
        dp[i][0] = dp[i-1][0]+1
    else:
        dp[i][0] = dp[i-1][0]

for j in range(1,w):
    if masu[0][j] != masu[0][j-1] and masu[0][j]=="#":
        dp[0][j] = dp[0][j-1]+1
    else:
        dp[0][j] = dp[0][j-1]


for i in range(1,h):
    for j in range(1,w):
        if masu[i][j] != masu[i-1][j] and masu[i][j]=="#":
            tate = dp[i-1][j]+1
        else:
            tate = dp[i-1][j]

        if masu[i][j] != masu[i][j-1] and masu[i][j]=="#":
            yoko = dp[i][j-1]+1
        else:
            yoko = dp[i][j-1]

        dp[i][j] = min(tate,yoko)


# print(*dp,sep="\n")
print(dp[-1][-1])

Submission status: Runtime Error

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

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

Solution code:
import numpy as np

in_string = input()
in_arr = in_string.split()
N = np.int64(in_arr[0])
A = np.int64(in_arr[1])
B = np.int64(in_arr[2])

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

Submission status: Runtime Error

Solution code:
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: Runtime Error

Solution code:
N = int(input("Define N: "), 10)
A = int(input("Define A: "), 10)
B = int(input("Define B: "), 10)
count = 0


while B != A:
	if (A - B) % 2 == 0:
		A += 1
		B -= 1
	else:
		if A - 1 < N - B:
			if A == 1:
				B -= 1
			else:
				A -= 1
				B -= 1
		else:
			if(B == N):
				A += 1
			else:
				B += 1
				A += 1			
	count += 1
print(count)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
def min_steps_v2(n, a, b):
    if (b - a) % 2 == 0:
        return 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 int(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))