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:
n, m, v, p = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse=True)
ans = p
c = [0]
cnt = 0
for i in range(n):
  # 累積和
  cnt += a[i]
  c.append(cnt)
for i in range(p,n):
  h = a[i]+m
  free = v - (p-1) - (n-i)
  d = h * (i-p+1) - (c[i]-c[p-1]) # 余裕
  if d >= free*m:
    ans += 1
print(ans)

Submission status: Runtime Error

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

def f(A, B):
  return int((B - A) / 2)
  
def f2(N, A, B):
    if (B - A) % 2 == 0:
        ans = f(A, B)
    else:
        # Aが1に向かうとき
        ans_a = A + f(1, B - A)
        # BがNに向かうとき
        if (A + N - B +1) <  N:
            ans_b = (N - B + 1) + f(A + N - B +1, N)
            ans_b = N
            
        ans = min(ans_a, ans_b)
    
    return ans
  
print(f2(N, A, B))

Submission status: Runtime Error

Solution code:
i = list(map(int,input().split()))
if (i[2]+i[1])%2 == 0:
    ans=(i[2]-i[1])/2
else:
    i.pop(0)
    ans=[max(i)-1 if min(i)-1<i[0]-max(i) else i[0]-min(i)]
print(int(ans))

Submission status: Runtime Error

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

count = 0

while A != B:
  if A%2 == 0 and B%2 == 0 or A%2 != 0 and B%2 != 0:
    A = A + 1
    B = B - 1
  distanceFromAtoOne = A - 1
  distanceFromBtoN = N - B
  if distanceFromAtoOne < distanceFromBtoN:
    if A == 1:
      B = B - 1
    else: 
      A = A - 1
      B = B - 1
    count = count + 1
  else:
    if B == N:
      A = A + 1
    else:
      A = A + 1
      B = B + 1
    count = count + 1

print(count)

Submission status: Runtime Error

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

ans = 0
distAB = B - A

if distAB % 2 != 0:
    ans = distAB / 0

print(int(ans))

Submission status: Runtime Error

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

ans = 0
distAB = B - A

if distAB % 2 == 0:
    ans = distAB / 0

print(int(ans))

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

round = 0
storage = []
value = [A, B]
storage.append(value)

def check (num, N):
    if num > N:
        return num
    if num < 1:
        return 1

def win_win(A,B,N):
    A = A - 1
    B = B - 1

    A = check(A, N)
    B = check(B, N)
    if A == B:
        return 0
    value = [A, B]
    return value


def win_lose(A, B, N):
    A = A - 1
    B = B + 1

    A = check(A, N)
    B = check(B, N)
    if A == B:
        return 0
    value = [A, B]
    return value


def lose_win(A, B, N):
    A = A + 1
    B = B - 1

    A = check(A, N)
    B = check(B, N)
    if A == B:
        return 0
    value = [A, B]
    return value


def lose_lose(A, B, N):
    A = A + 1
    B = B + 1

    A = check(A, N)
    B = check(B, N)
    if A == B:
        return 0
    value = [A, B]
    return value

out = True
while(out):
    power = 4**round
    round = round + 1
    for i in range(power):
        for j in range(4):
            if j == 0:
                step1 = win_win(storage[i][0], storage[i][1], N)
                if step1 == 0:
                    out = False
                    break
                if len(storage) <= ((i * 4) + 0):
                    storage.append(step1)
                else:
                    storage[((i * 4) + 0)] = step1
            elif j == 1:
                step2 = win_lose(storage[i][0], storage[i][1], N)
                if step2 == 0:
                    out = False
                    break
                if len(storage) <= ((i * 4) + 1):
                    storage.append(step2)
                else:
                    storage[((i * 4) + 1)] = step2
            elif j == 2:
                step3 = lose_win(storage[i][0], storage[i][1], N)
                if step3 == 0:
                    out = False
                    break
                if len(storage) <= ((i * 4) + 2):
                    storage.append(step3)
                else:
                    storage[((i * 4) + 2)] = step3
            else:
                step4 = lose_lose(storage[i][0], storage[i][1], N)
                if step4 == 0:
                    out = False
                    break
                if len(storage) <= ((i * 4) + 3):
                    storage.append(step4)
                else:
                    storage[((i * 4) + 3)] = step4

        if out == False:
            break
print(round)

Submission status: Runtime Error

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

round = 0
storage = []
value = [A, B]
storage.append(value)

def check (num, N):
    if num > N:
        return num
    if num < 1:
        return 1

def win_win(A,B,N):
    A = A - 1
    B = B - 1

    A = check(A, N)
    B = check(B, N)
    if A == B:
        return 0
    value = [A, B]
    return value


def win_lose(A, B, N):
    A = A - 1
    B = B + 1

    A = check(A, N)
    B = check(B, N)
    if A == B:
        return 0
    value = [A, B]
    return value


def lose_win(A, B, N):
    A = A + 1
    B = B - 1

    A = check(A, N)
    B = check(B, N)
    if A == B:
        return 0
    value = [A, B]
    return value


def lose_lose(A, B, N):
    A = A + 1
    B = B + 1

    A = check(A, N)
    B = check(B, N)
    if A == B:
        return 0
    value = [A, B]
    return value

out = True
while(out):
    power = 4**round
    round = round + 1
    for i in range(power):
        for j in range(4):
            if j == 0:
                step1 = win_win(storage[i][0], storage[i][1], N)
                if step1 == 0:
                    out = False
                    break
                if len(storage) <= ((i * 4) + 0):
                    storage.append(step1)
                else:
                    storage[((i * 4) + 0)] = step1
            elif j == 1:
                step2 = win_lose(storage[i][0], storage[i][1], N)
                if step2 == 0:
                    out = False
                    break
                if len(storage) <= ((i * 4) + 1):
                    storage.append(step2)
                else:
                    storage[((i * 4) + 1)] = step2
            elif j == 2:
                step3 = lose_win(storage[i][0], storage[i][1], N)
                if step3 == 0:
                    out = False
                    break
                if len(storage) <= ((i * 4) + 2):
                    storage.append(step3)
                else:
                    storage[((i * 4) + 2)] = step3
            else:
                step4 = lose_lose(storage[i][0], storage[i][1], N)
                if step4 == 0:
                    out = False
                    break
                if len(storage) <= ((i * 4) + 3):
                    storage.append(step4)
                else:
                    storage[((i * 4) + 3)] = step4

        if out == False:
            break



print(round)

Submission status: Runtime Error

Solution code:

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

interval = B - A - 1
if interval % 2 != 0:
    answer = int((B - A) / 2)
elif interval % 2 == 0:
    if N - A < B - 1:
        answer = N - A
    elif N - A > B - 1:
        answer = B - 1

print(answer)

Submission status: Runtime Error

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

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)

  r2 = N - dai + shou
  r2 = math.ceil(r2)

  ab_dis = min(r1,r2)

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


  else:
    r_cand = N*2
    if max(r1,r2) % 2 == 0:
      r_cand = max(r1,r2)
    if N - dai <= shou:
      if shou <= N - shou:
        result = min(math.ceil((shou + N - dai) / 2), r_cand)
        print(result)
      else:
        result = min(math.ceil((N - shou + N - dai) / 2), r_cand)
        print(result)
    else:
      if dai <= N - dai:
        result = min(math.ceil((dai + shou) / 2) - 1, r_cand)
        print(result)
      else:
        result = min(math.ceil((N - dai + shou) / 2) - 1, r_cand)
        print(result)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys, os

if len(sys.argv) < 5:
  exit()
  
N = sys.argv[1]
A = sys.argv[2]
B = sys.argv[3]

count = 0
odd_flag = False

if (B-A) %2 == 1:
  odd_flag = True

if not odd_flag:
  print( (B-A)/2 )

else:
  if (A-1) <= (N-B):
	print(B-1)
  else:
    print(N-A)

Submission status: Runtime Error

Solution code:
def main():
    [n, m, v, p] = [int(i) for i in input().split()]
    a = [int(i) for i in input().split()]
    a.sort(reverse=True)
    ans = p
    for i in range(p,n):
        tgt = a[i]
        enemy = a[p-2]
        tgt += m
        if tgt >= enemy:
            ans += 1
        else:
            break
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
this is a test

Submission status: Runtime Error

Solution code:
import math
import numpy as np


def getNearestValue(list, num):

    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]
    



a, b, c = map(int,input().split()) 
list = [a,1]
if (c- b) % 2 == 0:
  print(math.floor((c-b) /2))
else:
  d = a - b 
  e = b - 1
  
  f = a - c 
  g = c - 1
  
  if d > e:
    h = e
  else:
    h = d
  
  if f > g:
    i = g
  else:
    i = f

  j = getNearestValue(list, b)
  k = getNearestValue(list, c)

  if j == 1 and k == 1:
    pritn(c - 1)
  elif j == a and k == a:
    print(d)
  else:
    print(c - 1)

Submission status: Runtime Error

Solution code:
def main():
    [n, m, v, p] = [int(i) for i in input().split()]
    a = [int(i) for i in input().split()]
    a.sort(reverse=True)
    ans = p
    for i in range(p,n):
        tgt = a[i]
        enemy = a[p-1]
        tgt += m
        if tgt >= enemy:
            ans += 1
        else:
            break
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

diff = abs(a-b) 
mod = diff % 2

if mod == 0:
  
  print( diff // 2 )


elif mod != 0 :
  
  if n - a < b - 1 :
    if diff == 1:
      	print(n-a)
    else :
    	print( min( n - a , (b - a - 1)  )   
  else : 
    if diff == 1 :
        print(b-1)
    else:
    	print( min( b - 1 , (b - a - 1)  )

Submission status: Runtime Error

Solution code:
import math
import numpy as np


def getNearestValue(list, num):

    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]
    



a, b, c = map(int,input().split()) 
list = [a,1]
if (c- b) % 2 == 0:
  print(math.floor((c-b) /2))
else:
  d = a - b 
  e = b - 1
  
  f = a - c 
  g = c - 1
  
  if d > e:
    h = e
  else:
    h = d
  
  if f > g:
    i = g
  else:
    i = f

  j = getNearestValue(list, b)
  k = getNearestValue(list, c)

  if j == 1 and k == i:
    pritn(c - 1)
  elif j == a and k == a:
    print(d)
  else:
    print(c - 1)

Submission status: Runtime Error

Solution code:
inputs = input()

inputs = inputs.split(" ")

inputs = list(map(int,inputs))
result = 0

if inputs[1]<inputs[2]:
    p1=inputs[1]
    p2=inputs[2]
else if inputs[2]<inputs[1]:
    p1=inputs[2]
    p2=inputs[1]

if (p1 - p2)%2 != 0 : 
    tmp1 = p1 - 1
    tmp2 = inputs[0].to_i - p2
    if tmp1 < tmp2 :
        p1 = 1
        p2 -= tmp1+1
        result += tmp1+1
    else if tmp2 < tmp1
        p1 += tmp2+1
        p2 = inputs[0]
        result += tmp2+1


while p1 != p2 :
    p1+=1
    p2-=1
    result+=1

print(result)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

ans = 0
distAB = B - A

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

print(int(ans))

Submission status: Runtime Error

Solution code:
S = input().split(" ")
N = S[0]
A = S[1]
B = S[2]
C = B - A
if C % 2 == 0:
	print(C // 2)
	exit()
print(min(B - 1,N - A))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

ans = 0
distAB = B - A

if distAB % 2 == 0:
    ans = distAB / 2
else:
    ans = distAB / 0
print(int(ans))

Submission status: Runtime Error

Solution code:
import time

def fib(n):
    if n == 0 or n == 1:
        return 1
    
    return fib(n-1) + fib(n-2)

class Fib_memo:
    def __init__(self):
        self.fib_memo = {}

    def cal_fib(self, n):
        if n == 0 or n == 1:
            self.fib_memo[n] = 1
            return 1

        if n in self.fib_memo.keys():
            return self.fib_memo[n]
        
        self.fib_memo[n] = self.cal_fib(n-1) + self.cal_fib(n-2)
        return self.fib_memo[n]

def fib_dynamic(n):
    # 結果を保持する辞書
    cal_result = {}

    # 初期値の設定
    cal_result[0] = 1
    cal_result[1] = 1

    for i in range(2, n+1):
        cal_result[i] = cal_result[i-1] + cal_result[i-2]

    return cal_result[n]

# n = int(input())
cost_1 = []
cost_2 = []
cost_3 = []

max_n = 15
for n in range(1, max_n+1):
    print("n:{}".format(n))
    time_sta = time.perf_counter()
    fib(n)
    time_end = time.perf_counter()
    print("It takes {} seconds".format(time_end-time_sta))
    cost_1.append(time_end-time_sta)

    time_sta = time.perf_counter()
    fib_memo = Fib_memo()
    fib_memo.cal_fib(n)
    time_end = time.perf_counter()
    print("It takes {} seconds".format(time_end-time_sta))
    cost_2.append(time_end-time_sta)

    time_sta = time.perf_counter()
    fib_dynamic(n)
    time_end = time.perf_counter()
    print("It takes {} seconds".format(time_end-time_sta))
    cost_3.append(time_end-time_sta)

import matplotlib.pyplot as plt
x = [i for i in range(1, max_n+1)]
fig = plt.figure()
fig.subplots_adjust(left=0.15)
plt.plot(x, cost_1, label="Normal")
plt.plot(x, cost_2, label="Memo")
plt.plot(x, cost_3, label="Dynamic")
plt.xlim([0, max_n])
plt.xticks(x)
# 凡例の表示
plt.legend()
plt.title("Cost Time")
plt.xlabel("n")
plt.ylabel("time[s]")
# 画像保存
plt.savefig("./cal_time.png")

Submission status: Runtime Error

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

n1 = B - 1
nx = int((B-A)/2)
nn = N - A
n1x = int((B-A+(A-1)*2+1)/2)
nnx = int((B-A+(N-B)*2+1)/2)

if (B-A)%2 != 0 :
    print(min(n1, nn, n1x, nnx))
else:
    print(nx))

Submission status: Runtime Error

Solution code:
n,a,b = map(int, raw_input().split())
try:
    if (b-a == 1 or a-b==1):
    print(1)
    if (b-a == 2 or a-b ==2):
        print(2)
    if (b-a > 3 or a-b > 3):
        if (b>a):
            print(b-1) 
        elif (a>b): 
            print(a-1)
except:
    if (n<2 and n>10000000):
        pass
    if((a <1 or b<1) and a < n and b<n):
        pass

Submission status: Runtime Error

Solution code:
N, A, B = map(int, input().split())
c=0
for i in range(1, N+1):
    if A < B :
        A += 1
        B -= 1
        if A==B:
            c += 1
            break
    else:
        A -= 1
        B += 1
        if A == B:
            c += 1
            break

    if A+1 == B:
        A -= 1
        B -= 1
        c+=1
        if A==1:
            A = 1
        if B==1:
            B =1
        if A==B:
            break
  print(c)

Submission status: Runtime Error

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

if (A+B)%2==0:#偶奇が一致
    kaisu=int(math.log2(B-A))
    print(kaisu)
else:
    if (N-B)>=(A-1):
        #Bが左端にいく
        nA=1
        nB=B-A
        if nA==nB:
            print(A)
        else:
            kaisu=int(math.log2(nB-nA))
            if kaisu+A<=B-1:    
                print(kaisu+A)
            else:
                print(B-1)
    else:
        nB=N
        nA=A+(N-B)+1
        if nA==nB:
            print(N-B)+1
        else:    
            kaisu=int(math.log2(nB-nA))
            if kaisu+(N-B)+1<=N-A:
                print(kaisu+(N-B)+1)
            else:
                print(N-A)

Submission status: Runtime Error

Solution code:
n,a,b = map(int, raw_input().split())
try:
    if (b-a == 1 or a-b==1):
    print(1)
    if (b-a == 2 or a-b ==2):
        print(2)
    if (b-a > 3 or a-b > 3):
        if (b>a):
            print(b-1) 
        elif (a>b): 
            print(a-1)
except:
    if (n<2):
        pass
    if(a <1 or b<1):
        pass

Submission status: Runtime Error

Solution code:
n,a,b = map(int, raw_input().split())
if (b-a == 1 or a-b==1):
    print(1)
if (b-a == 2 or a-b ==2):
    print(2)
if (b-a > 3 or a-b > 3):
    if (b>a):
        print(b-1) 
    elif (a>b): 
        print(a-1)

Submission status: Runtime Error

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

if (A+B)%2==0:#偶奇が一致
    kaisu=int(math.log2(B-A))
    print(kaisu)
else:
    if (N-B)>=(A-1):
        #Bが左端にいく
        nA=1
        nB=B-A
        if nA==nB:
            print(A)
        else:
            kaisu=int(math.log2(nB-nA))
            if kaisu+A<=B-1:    
                print(kaisu+A)
            else:
                print(B-1)
    else:
        newB=N
        newA=A+(N-B)+1
        if nA==nB:
            print(N-B)+1
        else:    
            kaisu=int(math.log2(nB-nA))
            if kaisu+(N-B)+1<=N-A:
                print(kaisu+(N-B)+1)
            else:
                print(N-A)

Submission status: Runtime Error

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

ans = 0
distAB = B - A

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

print(int(ans))

Submission status: Runtime Error

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

ans = 0
distAB = B - A

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

print(int(ans))

Submission status: Runtime Error

Solution code:
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n,a,b;
  	cin>>n>>a>>b;
  	long long absol = abs(a-b);
  	long long r1 = 0x3f3f3f3f,r2,r3;
  	if(absol%2==0)
  		r1 = absol/2;
  	r2 = max(a,b) - 1;
  	r3 = n - min(a,b);
  	long long r4 = a + (b - a -1)/2;
  	long long r5 = n - b + 1 + (a + n - b - 1)/2;
  	cout<<min(r1,min(r2,min(r3,min(r4,r5))))<<'\n';
}

Submission status: Runtime Error

Solution code:




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

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

Submission status: Runtime Error

Solution code:
N = int(input())
A = int(input())
B = int(input())
a = A
b = B
n = abs(a - b)
def HAHA(n):
    ans = 0
    while n != 0:
        if n == 1:
            ans = ans + 2
            n = n - 1
            break
        elif n == 2:
            ans = ans + 1
            n = n - 2
            break
        elif n % 2 == 0:
            ans = ans + 1
            n = n - 2
        elif n % 2 != 0:
            ans = ans + 1
            n = n - 2
    print(ans)
HAHA(n)

Submission status: Runtime Error

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

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

        c = 0
        if 1 < A:
            A1 = 1
            c += A - 1
        c += 1
        B1 = (B - c)
        X = abs(A1 - ((A1 + B1) // 2)) + c

        c = 0
        if B < N:
            B2 = N
            c += B - 1
        c += 1
        A2 = (A + c)
        Z = abs(A2 - ((A2 + B2) // 2)) + c

        print(min(Y, X, Z))


main()

Submission status: Runtime Error

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

if (A+B)%2==0:#偶奇が一致
    kaisu=int(math.log2(B-A))
    print(kaisu)
else:
    if (N-B)>=(A-1):
        #Bが左端にいく
        newA=1
        newB=B-A
        kaisu=int(math.log2(newB-newA))
        if kaisu+A<=B-1:    
            print(kaisu+A)
        else:
            print(B-1)
    else:
        newB=N
        newA=A+(N-B)+1
        kaisu=int(math.log2(newB-newA))
        if kaisu+(N-B)+1<=N-A:
            print(kaisu+(N-B)+1)
        else:
            print(N-A)

Submission status: Runtime Error

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

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

        c = 0
        if 1 < A:
            A1 = 1
            c += A - 1
        c += 1
        B1 = (B - c)
        X = abs(A1 - ((A1 + B1) // 2) + c)

        c = 0
        if B < N:
            B2 = N
            c += B - 1
        c += 1
        A2 = (A + c)
        Z = (abs(A2 - ((A2 + B2) // 2)) + c)

        print(min(Y, X, Z))


main()

Submission status: Runtime Error

Solution code:
def Main(N: int,A: int,B:int):
    num_A_up = A
    num_B_up = B
    num_A_down = A
    num_B_down = B
    while num_A_down != num_B_up and num_A_up != num_B_down:
        num_A_up += 1
        num_A_down -= 1
        num_B_up += 1
        num_B_down -= 1
        if num_A_up > N - 1: num_A_up = N
        if num_B_up > N - 1: num_B_up = N
        if num_B_down < 1: num_B_down = 1
        if num_A_down < 1: num_A_down = 1
        print(f" {num_A_down} , {num_A_up} , {num_B_down} , {num_B_up} ")
        if num_A_down - num_B_down == 0 or num_A_up - num_B_up == 0: break

    return num_B_up - B

Submission status: Runtime Error

Solution code:
N, A, B = map(int, input().split())
a = [0] * (N+1)
b = [0] * (N+1)

a[0] = "x"
b[0] = "x"

a[A] = 1
b[B] = 1

dist = (B - A) - 1

if dist == 0 or dist % 2 == 0:
    left_edge_a = A - 1
    left_edge_b = B - 1
    l = max(left_edge_a, left_edge_b)
    right_edge_A =  N - A
    right_edge_B =  N - B
    r = max(right_edge_A, right_edge_B)
    ans = r if l > r else l
    print(ans)
else:
    if dist == 1:
        ans = 1
    else:
        ans = dist // 2
    print(ans)

Submission status: Runtime Error

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


a = A
b = B

if A > B:
    a = B
    b = A

k = abs(A - B)

if k % 2 == 0:
    print(int(k / 2))
    exit()

j = min([N - a, b - 1])
print(int(j - (k / 2) + k % 2))
~

Submission status: Runtime Error

Solution code:
def CheckLowestNumber(N: int,A: int,B:int):
    num_A_up = A
    num_B_up = B
    num_A_down = A
    num_B_down = B
    while num_A_down != num_B_up and num_A_up != num_B_down:
        num_A_up += 1
        num_A_down -= 1
        num_B_up += 1
        num_B_down -= 1
        if num_A_up > N - 1: num_A_up = N
        if num_B_up > N - 1: num_B_up = N
        if num_B_down < 1: num_B_down = 1
        if num_A_down < 1: num_A_down = 1
        print(f" {num_A_down} , {num_A_up} , {num_B_down} , {num_B_up} ")
        if num_A_down - num_B_down == 0 or num_A_up - num_B_up == 0: break

    return num_B_up - B

Submission status: Runtime Error

Solution code:
N, A, B = map(int, input().split())
a = [0] * (N+1)
b = [0] * (N+1)

a[0] = "x"
b[0] = "x"

a[A] = 1
b[B] = 1

dist = (B - A) - 1

if dist == 0 or dist % 2 == 0:
    left_edge_a = A - 1
    left_edge_b = B - 1
    l = max(left_edge_a, left_edge_b)
    right_edge_A =  N - A
    right_edge_B =  N - B
    r = max(right_edge_A, right_edge_B)
    if r == l 
    ans = r if l > r else l
    print( ans)
else:
    if dist == 1:
        ans = 1
    else:
        ans = dist // 2
    print(ans)

Submission status: Runtime Error

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

if (A+B)%2==0:#偶奇が一致
    kaisu=int(math.log2(B-A))
    print(kaisu)
else:
    if (N-B)>=(A-1):
        #Bが左端にいく
        newA=1
        newB=B-A
        kaisu=int(math.log2(newB-newA))
        if kaisu+A<=B-1:    
            print(kaisu+A)
        else:
            print(B-1)
    else:
        newB=N
        newA=A+(N-B)+1
        kaisu=int(math.log2(B-A))
        if kaisu+(N-B)+1<=N-A:
            print(kaisu+(N-B)+1)
        else:
            print(N-A)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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


def dfs(n,a,b,count):
    if not (b-a)%2:
        return (b-a)//2
    if a==1:
        return math.ceil(b//2)+count
    if b==n:
        return math.ceil((n-a)//2)+count
    if n-b<a:
        return dfs(n,a+1,b+1,count+1)
    if n-b>=a:
        return dfs(n,a-1,b-1,count+1)
print(dfs(n,a,b,0))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N, A, B = map(int, input().split())
a = [0] * (N+1)
b = [0] * (N+1)

a[0] = "x"
b[0] = "x"

a[A] = 1
b[B] = 1

dist = (B - A) - 1

if dist == 0 or dist % 2 == 0:
    left_edge_a = A - 1
    left_edge_b = B - 1
    l = max(left_edge_a, left_edge_b)
    right_edge_A =  N - A
    right_edge_B =  N - B
    r = max(right_edge_A, right_edge_B)
    ans = r if l > r else l
    print( ans)
else:
    ans = 1
    while(dist > 1):
        dist = dist -2
        ans += 1
    print(ans)

Submission status: Runtime Error

Solution code:
def CheckLowestNumber(N: int,A: int,B:int):

    num_A_up = A
    num_B_up = B
    num_A_down = A
    num_B_down = B
    num_time = 0
    while num_A_down != num_B_up and num_A_up != num_B_down:
        num_A_up += 1
        num_A_down -= 1
        num_B_up += 1
        num_B_down -= 1
        if num_A_up > N - 1: num_A_up = N
        if num_B_up > N - 1: num_B_up = N
        if num_B_down < 1: num_B_down = 1
        if num_A_down < 1: num_A_down = 1
        print(f" {num_A_down} , {num_A_up} , {num_B_down} , {num_B_up} ")
        num_time += 1
        if num_A_down - num_B_down == 0 or num_A_up - num_B_up == 0: break

    return num_time

Submission status: Runtime Error

Solution code:
# import doctest

def solve(N, A, B):
    """
    >>> solve(2, 1, 2)
    1
    >>> solve(3, 1, 2)
    1
    >>> solve(3, 1, 3)
    1
    >>> solve(3, 2, 3)
    1
    >>> solve(4, 1, 2)
    1
    >>> solve(4, 1, 3)
    1
    >>> solve(4, 1, 4)
    2
    >>> solve(4, 2, 3)
    2
    >>> solve(4, 2, 4)
    1
    >>> solve(4, 3, 4)
    1
    >>> solve(5, 1, 2)
    1
    >>> solve(5, 1, 3)
    1
    >>> solve(5, 1, 4)
    2
    >>> solve(5, 1, 5)
    2
    >>> solve(5, 2, 3)
    2
    >>> solve(5, 2, 4)
    1
    >>> solve(5, 2, 5)
    2
    >>> solve(5, 3, 4)
    2
    >>> solve(5, 4, 5)
    1
    """
    rounds = 0
    for i in range(N):
        # print A, B
        if A == B:
            return rounds
        average = float(A + B) / 2.0
        if average.is_integer():
            rounds += int(average) - A
            return rounds
        rounds += 1
        if (A - 1) < (N - B):
            A = max(1, A - 1)
            B = max(1, B - 1)
        else:
            A = min(N, A + 1)
            B = min(N, B + 1)

# doctest.testmod()
print solve(*map(int, raw_input().split()))

Submission status: Runtime Error

Solution code:
n,a,b=map(int,input().split())
ans1=(k-1)//2+1
ans2=min(b-1,n-a)
print(min(ans1,ans2))