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

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 = input()
N = int(in_string[0])
A = int(in_string[1])
B = int(in_string[2])

match(N, A, B)

Submission status: Runtime Error

Solution code:
INP = list(map(int, input().split))
print(int((INP[1]-INP[0]+1)/2))

Submission status: Runtime Error

Solution code:
from sys import argv

# 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
match(int(argv[1]), int(argv[2]), int(argv[3]))

Submission status: Runtime Error

Solution code:
import math

finished = False
solutions = []

def rec(A, B, n):
    global solutions
    global N

    if (A == B):
        solutions.append(n)

    if (math.floor(N/2) > n):
        if A == 1:
                rec(A+1, B+1, n+1)
                rec(A+1, B-1, n+1)
                rec(A, B+1, n+1)
                rec(A, B-1, n+1)
        elif A == N:
                rec(A, B+1, n+1)
                rec(A, B-1, n+1)
                rec(A-1, B+1, n+1)
                rec(A-1, B-1, n+1)
        elif B == 1:
                rec(A+1, B+1, n+1)
                rec(A+1, B, n+1)
                rec(A-1, B+1, n+1)
                rec(A-1, B, n+1)
        elif B == N:
                rec(A+1, B, n+1)
                rec(A+1, B-1, n+1)
                rec(A-1, B, n+1)
                rec(A-1, B-1, n+1)
        else:
                rec(A+1, B+1, n+1)
                rec(A+1, B-1, n+1)
                rec(A-1, B+1, n+1)
                rec(A-1, B-1, n+1)

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

rec(A, B, 0)
solutions.sort()
print(solutions[0])

Submission status: Runtime Error

Solution code:
finished = False
solutions = []

def rec(A, B, n):
    global finished
    global solutions

    if (A == B):
        finished = True
        solutions.append(n)

    if not finished:
        if A == 1:
                rec(A+1, B+1, n+1)
                rec(A+1, B-1, n+1)
                rec(A, B+1, n+1)
                rec(A, B-1, n+1)
        elif A == N:
                rec(A, B+1, n+1)
                rec(A, B-1, n+1)
                rec(A-1, B+1, n+1)
                rec(A-1, B-1, n+1)
        elif B == 1:
                rec(A+1, B+1, n+1)
                rec(A+1, B, n+1)
                rec(A-1, B+1, n+1)
                rec(A-1, B, n+1)
        elif B == N:
                rec(A+1, B, n+1)
                rec(A+1, B-1, n+1)
                rec(A-1, B, n+1)
                rec(A-1, B-1, n+1)
        else:
                rec(A+1, B+1, n+1)
                rec(A+1, B-1, n+1)
                rec(A-1, B+1, n+1)
                rec(A-1, B-1, n+1)

while True:
    in_string = input("Input in the Format: N A B, where N stands for the Number of Tables, A for the Position of Player A and B Position of Player B:\n")
    if len(in_string) == 5:
        in_arr = in_string.split()
        global N
        global A
        global B
        N = int(in_arr[0])
        A = int(in_arr[1])
        B = int(in_arr[2])

        if 2 <= N <= pow(10,18) and 1 <= A < B <= N:
            break
        else:
            print("Input Invalid, try again")
    else:
        print("Input Invalid, try again")

rec(A, B, 0)
solutions.sort()
print(solutions[0])

Submission status: Runtime Error

Solution code:
from sys import argv

# Function for calc
def match(n, a, b):
    if (b - a)% 2 == 0:
        print((b-a)/2)
    else:
        mid = (n / 2)
        if (n - a) > b:
            print(b)
        else:
            print(n-a-1)

# Run match
match(int(argv[1]), int(argv[2]), int(argv[3]))

Submission status: Runtime Error

Solution code:
strargs = input()

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

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

else:
  print(b - 1)

Submission status: Runtime Error

Solution code:
strargs = [10, 3, ]

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

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

else:
  print(b - 1)

Submission status: Runtime Error

Solution code:
inp = list(map(int, input().split()))
n = inp[0]
a = inp[1]
b = inp[2]

d = b - a
if d < 0:
    d *= -1

count = 0
flag = 0
if d == 0:
    count = 0
elif d % 2 == 0:
    count = d / 2
else:
    if a < b:
        if b - 1 > n - a:
            if (n - b) - (n - a) >= 3 or (n-b) - (n-a) <= -3:
                count = ((b - a - 1) / 2) + (n - b + 1)
            else:
                count = n - a
        else:
            if (n-b) - (n-a) >= 3 or (n-b) - (n-a) <= -3:
                count = ((b - a - 1) / 2) + a
            else:
                p
                count = b - 1
    else:
        if a - 1 > n - b:
            if (n - a) - (n - b) >= 3 or (n-a) - (n-b) <= -3:
                count = ((a - b - 1) / 2) + (n - a + 1)
            else:
                count = n - b
        else:
            if (n - a) - (n - b) >= 3 or (n-a) - (n-b) <= -3:
                count = ((a - b - 1) / 2) + b
            else:
                count = a - 1

print(int(count))

Submission status: Runtime Error

Solution code:
i = 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:
  print(min(max(A, B), max(N-A, N-B))

Submission status: Runtime Error

Solution code:
numbers = raw_input().split(' ')

n = numbers[0]
a = numbers[1]
b = numbers[2]

def even_diff(A, B):
  return (B - A) / 2


def odd_diff(N, A, B):
  a_diff = A - 1
  b_diff = N - B
  
  if a_diff > b_diff:
    return N - A
  else:
    return B - 1

if (a - b) % 2 == 0:
  result = even_diff(a, b)
else:
  result = odd_diff(n, a, b)    
  
print(result)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;

int main (){
  int n,a,b,ans;
  cin >> n >> a >> b;
  if ((b-a)% == 0){
    ans=(b-a)/2;
  }
  else{
    if(n-b > a-1){
      ans=a-1+1;
      b-=ans;
      a=1;
      ans+=(b-a)/2;
    }
    else{
      ans=n-b+1;
      a+=ans;
      b=n;
      ans+=(b-a)/2;
    }
  }
  cout << ans << endl;
}

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
S = list(input())
s = len(S)
K = int(input())
A = []
j = 1

for i in range(0,s-1,1):
  if S[i] == S[i+1]:
    j += 1
  else:
    A.append(j)
    j = 1
A.append(j)

a = len(A)

b = 0
for i in range(a):
  b += i//2
  
x = b*K

if S[s-1] == S[0] and A[a-1] % 2 == 1 and A[1] % 2 == 1:
  x += K-1
  
print(x)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
x,y,z = map(int, input().split())
if (z+y)%2==1:
  	d = min(y + z - 2, 2*x-y-z)+1; 
	print(d//2)
else:
	print((abs(y-z)+1)//2)

Submission status: Runtime Error

Solution code:
x,y,z = map(int, input().split())
if (z+y)%2==1:
	print(min(max(y,z)-1, max(x-y,x-z))
else:
	print((abs(y-z)+1)//2)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import numpy as np
while(1):
    N,A,B = map(int,input().split())
    x=abs(A-B)
    

    if x%2==0:
        print(x//2)
    else:
        y,z=max(N-A,N-B),max(A-1,B-1)
        a,b=min(A-1,B-1),min(N-A,N-B)
        c,d=max(A-1,B-1)-a,max(N-A,N-B)-b
        e,f=c//2+a+1,d//2+b+1
        if y>z:
            print(min(z,e,f))
        else:
            print(min(y,e,f))

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 (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 = list(map(int,input().split()))
ans = 0
if n[1] % 2 == 0 and n[2] % 2 == 0:
  ans = n[2] - n[1]
  print(ans//2)
else:
  if n[0] - n[2] < n[1] - 1:
    ans = n - n[1]
  else:
    ans = n[2] - 1
  print(ans)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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 + diff // 2)

Submission status: Runtime Error

Solution code:
N,M,V,P = map(int, input().split())
A = list(map(int,input().split()))
A.sort(reverse=True)
count = 0
for i in range (N):
  if i <= P:
    count += 1
  elif A[i] + M < A[P-1]:
    continue
  else:
    sum = M*(P-1) + M*(N-(i+1)) 
    for j in range (P,i-1):
      sum += A[P-1]+M -A[j]
    if sum >= M*V:
      count +=1
print(count)

Submission status: Runtime Error

Solution code:
import os

def main():
    list = [1,2,3]
    for i in range(2):
        num = int(input())
        list.remove(num)
    num_n = int(list[0])
    print(num_n)

if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

A.sort(reverse=True)

cum_A = [0]
for ai in A:
    cum_A.append(cum_A[-1] + ai)

cur_Ai = A[P]
ans = P
j = P
for i in range(P, N):
    if (i + 1 < N) and (A[i] == A[i + 1]):
        continue

    while A[j] >= A[i] + M:
        j += 1

    if A[i] + M < A[P - 1]:
        break
    elif (
        M * (P - 1)
        + (A[i] + M) * (i + 1 - j)
        - (cum_A[i + 1] - cum_A[j])
        + M * (N - i - 1)
        >= M * V
    ):
        ans = i + 1
    else:
        break

print(ans)

Submission status: Runtime Error

Solution code:
 読み込む
str = input()
param = str.split(" ")
n_max = int(param[0])
player_min = min(int(param[1]),int(param[2]))
player_max = max(int(param[1]),int(param[2]))
 
# 差が偶数なのかを確認
diff_number = player_max - player_min
even_number_flg = diff_number % 2 == 0
 
# 最大値と最小値の差を確認
diff_min = player_max - 1
diff_max = n_max - player_min
 
# 最大値と最小値のどちらか小さい方を採用
print_number = min([diff_min, diff_max])
 
if even_number_flg:
  print_number = min([int(diff_number/2), print_number])
 
print(print_number)

Submission status: Runtime Error

Solution code:
from inspect import currentframe

def main():
    N, M, V, P = map(int, input().split())
    A = list(map(int, input().split()))
    dic_A = {k:v for (k, v) in enumerate(A)}
    sorted_dic_A = sorted(dic_A.items(), key=lambda x: x[1], reverse=True)

    B = sorted_dic_A[:P]
    P_min_val = min(B, key=lambda  x: x[1])[1]
    C = sorted_dic_A[P:]

    num_vote = M * V
    a = 0
    b = len(C)
    flag = True
    while a < b:
        def is_margin_plus(i):
            v = C[i][1]
            margin = num_vote
            margin -= M * (P-1)
            margin_list = [v+M-w for (j,w) in C if j!=i]
            mod_margin_list = list(map(lambda x: x if x < M else M, margin_list))
            margin -= M
            margin -= sum(mod_margin_list)
            # print("margin: {}".format(margin))

            return margin > 0

        i = (a + b) // 2
        # input()
        # print("(a, i, b): ({}, {}, {})".format(a, i, b))

        if is_margin_plus(i):
            # print('is_margin_plus: {}'.format(True))
            b = i
        else:
            # print('is_margin_plus: {}'.format(False))
            a = i + 1
            flag = False

    ans = a + P + 1 if flag else (a + P)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

Solution code:
import numpy as np
import math
[N, A, B] = list(map(int, input().split()))
a = A % 2
b = B % 2
if (a == b):
  ans = int(np.abs(A - B) / 2)
else:
  path_to_1 = A - 1
  path_to_N = N - B
  if path_to_1 <= path_to_N:
    #Aが卓1に行くまでの回数 = path_to_1
    #Bの位置 = B - (path_to_1)
    #AとBが同じ位置に行くまでの回数
    path_A_to_B = math.ceil(np.abs(B - path_to_1 - 1) / 2)
    ans = int(path_to_1 + path_A_to_B)
  else:
    #Bが卓Nに行くまでの回数 = path_to_N
    #Bが卓Nに居る時のAの位置 = A + path_to_N
    #AとBが同じ位置に行くまでの回数
    path_B_to_A = math.ceil(np.abs(A + path_to_N - N) / 2)
    ans = int(path_to_N + path_B_to_A)
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 (b - a)% == 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())
ans = 0
if (B-A)%2 == 0:
    print(int((B-A)//2))
else:
    print(min(A-1,N-B)+1+int((B-A-1)//2))

Submission status: Runtime Error

Solution code:
import sys

args = sys.argv
N = int(args[1])
A = int(args[2])
B = int(args[3])

def main():
    if A == B:
        result(0)
    elif (A - B) % 2 == 0:
        result(abs((A - B) / 2))
    else:
        if N - A > B:
            result(B - 1)
        else:
            result(A)

def result(t):
    print(int(t))
    return 0

if __name__ == "__main__":
    main()

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys
from collections import defaultdict
from collections import deque

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

N, M, V, P = map(int, input().split())

A = list(map(int, input().split()))
A.sort(reverse=True)

NUM = [0] * N
ACN = [0] * N
cnt = 0
mx = A[0]

# cnt and accumulation
for a in A:
    d = mx - a
    cnt += 1
    NUM[d] += 1
    ACN[d] = cnt

# P Number Problem
PROBLEM_P = 0
p = P
for i in range(0, A[0]+1):
    if NUM[i] == 0:
        continue

    p -= NUM[i]

    if p < 0:
        PROBLEM_P = i
        break

    if i == (A[0]+1) and p > 0:
        print(N)
        exit()

#print("NUM", NUM)
#print("PROBLEM_P", PROBLEM_P)

# R Number Problem
R = PROBLEM_P + M

# P-1 Problem
ans = 0
NG_POINT = (P-1) * M
NG_POINT += (N - ACN[R]) * M
MV = M * V

# p problem num
num_p = ACN[PROBLEM_P] - P

print(1)
exit()

for r in range(R, -1, -1):
    need_point = M
    total = (need_point * NUM[r]) + NG_POINT

    for q in range(r-1, PROBLEM_P, -1):
        if NUM[q] == 0:
            continue
        total += NUM[q] * (q - r + M)

    total += num_p * (PROBLEM_P - r + M)

    if total >= MV:
        ans = r
        break
    else:
        NG_POINT += NUM[r] * M

print(ACN[ans])

Submission status: Runtime Error

Solution code:
import sys

n, a, b = map(int, sys.stdin.readline().split())

def main():
    d = b - a
    if d % 2 == 0:
        return d // 2
    else:
        return min(n - b, abs(1 - a)) + 1 + (d - 1) // 2)

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

Submission status: Runtime Error

Solution code:
lst = map(lambda x: int(x), input().split(" "))
N = lst[0]
A = lst[1]
B = lst[2]

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

Submission status: Runtime Error

Solution code:
N,M,V,P = map(int,input().split())
import numpy as np
A = list(map(int,input().split()))
A = np.array(sorted(A,reverse=True))
ans = P
x = A[P-1]
y = N-1
for i in range(P,N):
  a = A[i]
  if x==a:
    ans+=1
  else:
    y=i
    break

if y==N-1:
  print(N)
z = sum(A[P-1:y])
for i in range(y,N):
  a = A[i]
  d = a+M
  if x<=d:
    b = N-i+P-1
    c = M*(V-b)
    e = z+c
    f = d*(i-P+1)
    if f>=e:
      ans+=1
      
  z+=a
print(ans)

Submission status: Runtime Error

Solution code:
N, M, V, P = map(int, input().split())
pre = list(map(int, input().split()))
li = sorted(pre)
total = M * V
tf = False
for i in range(N):
	if li[i] + M >= li[-P]:
		tmp = i+1 + P - 1
		nokori = total - (M * tmp)
		count = i + 1
		while count <= N - P:
			if nokori <= 0:
				ans = N-i
				tf = True
				break	
			sa = (li[i]+M) - li[count]
			if sa <= 1:
				count += 1
				continue
			nokori -= sa-1
			count += 1
		if tf == True:
			break
print(ans)

Submission status: Runtime Error

Solution code:
N, a_init, b_init = map(int, input().split())
 
a_candidate = [a_init]
b_candidate = [b_init]
def next_candidate(n):
  win = n-1 if n > 1 else 1
  lose = n + 1 if n < N else N
  return [win, lose]
 
def flatten(nested_list):
    """2重のリストをフラットにする関数"""
    return [e for inner_list in nested_list for e in inner_list]
 
i = 1
while True:
  a_candidate = flatten([next_candidate(a) for a in a_candidate])
  b_candidate = flatten([next_candidate(b) for b in b_candidate])
  if len(set(a_candidate) & set(b_candidate)) > 0:
    print(i)
    break
  else:
    i += 1
N, a_init, b_init = map(int, input().split())

a_candidate = [a_init]
b_candidate = [b_init]
def next_candidate(n):
  win = n-1 if n > 1 else 1
  lose = n + 1 if n < N else N
  return [win, lose]

def flatten(nested_list):
    """2重のリストをフラットにする関数"""
    return [e for inner_list in nested_list for e in inner_list]

i = 1
while True:
  a_candidate = set(flatten([next_candidate(a) for a in a_candidate]))
  b_candidate = set(flatten([next_candidate(b) for b in b_candidate]))
  if len(a_candidate & b_candidate) > 0:
    print(i)
    break
  else:
    i += 1
提出情報

Submission status: Runtime Error

Solution code:
n,m,v,p = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
def binary_search(left, right):
    if right - left <= 1:
        return left
    middle = (left + right) // 2
    if check(middle):
        return binary_search(middle, right)
    else:
        return binary_search(left, middle)
 
def check(target):
    used_vote = (p + n - target - 1) * m
    sum_vote = 0
    for i in range(target-1, p-2, -1):
        if a[target] + m < a[i]:
            return False
        sum_vote += (a[target] + m) - a[i]
    if sum_vote >= (m * v - used_vote): 
        return True
    else:
        return False
print(binary_search(0,n) + 1)

Submission status: Runtime Error

Solution code:
N, a_init, b_init = map(int, input().split())

a_candicate = [a_init]
b_candidate = [b_init]
def next_candidate(n):
  win = n-1 if n > 1 else 1
  lose = n + 1 if n < N else N
  return [win, lose]

def flatten(nested_list):
    """2重のリストをフラットにする関数"""
    return [e for inner_list in nested_list for e in inner_list]

i = 0
while True:
  a_candidate = flatten([next_candidate(a) for a in a_candidate])
  b_candidate = flatten([next_candidate(b) for b in b_candidate])
  if len(set(a_candidate) & set(b_candidate)) > 0:
    print(i)
    return
  else:
    i += 1

Submission status: Runtime Error

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

N -= 1
A -= 1
B -= 1

def is_valid(p):
    x,y = p
    return 0 <= x < N and 0 <= y < N

def meet(p):
    x,y = p
    return abs(x-y)//2

def dist(p1,p2):
    x1,y1 = p1
    x2,y2 = p2
    return (abs(x1-x2)+abs(y1-y2))//2

oo = []
if (A + B)%2:
    o = []
    for i in [0,N]:
        for j in [1,-1]:
            o.append((i,B + j * abs(A-i)))
            o.append((A + j * abs(B-i),i))
    for x,y in filter(is_valid,o):
        for i in [1,-1]:
            for j in [1,-1]:
                xx = max(0,min(x+i,N))
                yy = max(0,min(y+i,N))
                oo.append(meet((xx,yy))+dist((A,B),(x,y))+1)
    print(min(oo))
else:
    print(meet((A,B)))

Submission status: Runtime Error

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

N -= 1
A -= 1
B -= 1

def is_valid(p):
    x,y = p
    return 0 <= x < N and 0 <= y < N

def meet(p):
    x,y = p
    return abs(x-y)//2

def dist(p1,p2):
    x1,y1 = p1
    x2,y2 = p2
    return (abs(x1-x2)+abs(y1-y2))//2

oo = []
if (A + B)//2:
    o = []
    for i in [0,N]:
        for j in [1,-1]:
            o.append((i,B + j * abs(A-i)))
            o.append((A + j * abs(B-i),i))
    for x,y in filter(is_valid,o):
        for i in [1,-1]:
            for j in [1,-1]:
                xx = max(0,min(x+i,N))
                yy = max(0,min(y+i,N))
                oo.append(meet((xx,yy))+dist((A,B),(x,y))+1)
    print(min(oo))
else:
    print(meet((A,B)))

Submission status: Runtime Error

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

elif (b - a) % 2 == 1 and b == n and a > 1:
          print(int((b - a - 1) / 2 + 1))
elif (b - a) % 2 == 1 and 2 <= b < n and a == 1:
          print(int((b - 1 - 1 ) / 2 + 1))
elif (b - a) % 2 == 1 and b == n and a == 1:
          print(int((n - 1 - 1) /2 + 1))
else:
     print(int((b - a) /

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#A - Table Tennis Training
N,A,B = list(map(int, input().split()))

if Lab%2==0:
    #case Lab is even
    ans = int(B-A/2)
else:
    #case Lab is odd
    ans = min(A-1,N-B) + 1 + int((B-A-1)/2)

print(ans)

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:

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

print(int(ans))

Submission status: Runtime Error

Solution code:
import math

inpt = input().split(" ")
inpt = [int(i) for i in inpt]
N = inpt[0]
A = inpt[1]
B = inpt[2]


difab = abs(A - B)
r1 = math.ceil(difab)

dai = max(A,B)
shou = min(A,B)

if r1 % 2 == 0:
  result = ab_dis / 2
  print(math.ceil(result))


else:
  if N - dai + N - shou  + 1 <= shou + dai:
      result = math.ceil((N - shou + N - dai) / 2)
      print(result)
  else:
      result = math.ceil((dai + shou) / 2) - 1
      print(result)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N,A,B = map(int,input().split())
temp = 0
if (B-A)%2 == 0:
    print(int((B-A)/2))
else:
    min = min([B-1,N-A])
    if A-1 < N-B and (B-A-1)% 2 == 0:
        temp = A + (B-A-1)/2
        if temp < min:
            print(temp)
    elif (b-a-1)%2 == 0:
        a = N - A + 1
        b = N - B + 1
        temp = a + (b-a-1)/2
        if temp < min:
            print(temp)
    else:
        print(temp)

Submission status: Runtime Error

Solution code:
import math

table = int(input())
a = int(input())
b = int(input())
possibility = []
temp = b - a
divide = temp/2

if temp % 2 == 0: 
    a += divide
    b -= divide
    print(divide)
else:
    up = math.ceil(temp%2)
    down = math.floor(temp%2)
    if (a - 1) < (table - b):
        a -= down
        b -= up
        print(up)
    elif (a - 1) > (table - b):
        a += up
        b += down
        print(up)

Submission status: Runtime Error

Solution code:
from decimal import Decimal
N, A, B = input().split()
n=Decimal(N)
a=Decimal(A)
b=Decimal(B)
if (b-a) % 2 == 0:
    print((b-a)/2)
elif (b-1) > (n-a):
    print((a+b-1)/2)
elif (b-1) < (n-a):
    print(n-a+1):

Submission status: Runtime Error

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

if(A>B):
  if((((A-B)%2)==0)):
    print(((A-B)/2))
  elif((((B-A)%2)!=0)):
    if((B<(N/2)):
      for(i in range(N/2)):
       print(B-1)
elif(A<B):
  if((((B-A)%2)==0)):
    print(((B-A)/2))
  elif((((B-A)%2)!=0)):
    if((B<(N/2)):
      for(i in range(N/2)):
       print(B-1)

Submission status: Runtime Error

Solution code:
try:
    n = int(input("Enter N: "))
    a = int(input("Enter A: "))
    b = int(input("Enter B: "))
except:
    print("Input must be integer")

if (abs(a - b) % 2 == 0):
    print("small lest number of round is %s" % int(((a - b) / 2)))
else:
    for i in range(n-1):
        if a != 1:
            a = a - 1
        if b != 1:
            b = b - 1
        if b == a:
            print("small lest number of round is %s" % (i+1))
            break

Submission status: Runtime Error

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

if diff % 2 == 0:
    print(diff // 2)
else:
  prrint(-1)

Submission status: Runtime Error

Solution code:
n,m,v,p = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
p-=1

a.sort(reverse=True)

ans=0
s = sum(a)

def safe(index):
    if a[p]>a[index]+m:
        return False
    i=0
    wall = -1
    while a[i]>=a[index]+m:
        if a[i]>=a[index]+m+1:
            wall = i
        i+=1
    if i>index:
        return True
    intg = 0
    while i<index:
        intg += a[index] + m - a[i]
        i+=1
    intg += (len(a)-1-index)*m + min(v,p - wall + 1)*m
    #print("intg = ",intg ,m*(v-1) )
    return intg >= m*(v-1)

left = 0
right = len(a)-1
ans = int((right - left)/2)
if safe(right):
    ans = right
else:
    j = safe(ans)
    while not(j and not safe(ans+1)):
        if j:
            left = ans
        else:
            right = ans
        ans = left + int((right - left)/2)
        j = safe(ans)
print(ans+1)
"""
for i in range(len(a)):
    print(a[i],safe(i))
"""

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

min_num = min(A,B)
max_num = max(A,B)
if max_num >N : print(0)
else:
    matches = 0
    while(True):
        if max_num==min_num:
            print(matches)
            break
        else:
            if max_num - min_num == 1:
                max_num-=1
                min_num-=1 if min_num != 1else 0
                matches+=1
                max_arr.append(max_num)
                min_arr.append(min_num)
            else:
                min_num+=1 if min_num != 1 or max_num > 2 else 0
                max_num-=1
                matches+=1
                max_arr.append(max_num)
                min_arr.append(min_num)