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: Wrong Answer

Solution code:
from sys import stdin


def fetch_one_line():
    return stdin.readline().rstrip()


def fetch_int_input():
    return [int(s) for s in fetch_one_line().split()]


def fetch_inputs(times):
    return [fetch_one_line() for _ in range(times)]


def fetch_int_inputs(times):
    return [[int(s) for s in fetch_one_line()] for _ in range(times)]


def fetch_ints_inputs(times):
    return [fetch_int_input() for _ in range(times)]


N, A, B = fetch_int_input()

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

    #all_win_long = max(A - 1, B - 1)
    #all_win_short = min(A - 1, B - 1)
    #all_short_edge = all_win_short + 1
    #all_win_dist = all_win_long - all_short_edge
    #win_dist = int(abs(all_win_dist) / 2) + all_short_edge

    #all_lose_long = max(N - A, N - B)
    #all_lose_short = min(N - A, N - B)
    #all_short_edge = all_lose_short + 1
    #all_lose_dist = all_lose_long - all_short_edge
    #lose_dist = int(abs(all_lose_dist) / 2) + all_short_edge


    # print(int(min(all_win_long, all_lose_long, win_dist, lose_dist)))

Submission status: Wrong Answer

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

if (A+B)%2 == 0:
    print(round((A+B)/2-A))
elif (A+B)%2 != 0:
    if A == 2:
        print(N-B)
    elif A== 1:
        print(B-1)
    elif B == N-1:
        print(N-A)
    elif B == N:
        print(B-A)

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

# 最小公倍数
def gcd(a, b):
  if a < b:
      a, b = b, a
  while a % b != 0:
      a, b = b, a % b
  return b
 
# 最大公約数 
def lcm(a, b):
    y = a*b / gcd(a, b)
    return int(y)

# N = INT()
# print(N)
N, A, B = MAP()
# guusuu
if (A - B) % 2 == 0:
  s = B - A
  ans = s // 2
  print(ans)
# kisuu
else:
  # if N - A <= B
  # k = B - A
  # m = min(N - A, B)
  if A <= N - B:
    # A ni tikazuku
    # 最初の移動
    s = A - 1
    # Bが残り移動する距離
    b = B - (A - 1) - 1

    ans = s + (b + 1) // 2
    # print(ans)
  else:
    s = N - B
    ans = N - (A + s) + 1
    ans = ans // 2
    # ans = A + s + 1
    # ans = ans // 2
  print(ans)
  #   ans =(B - A + 1)//2

  # else:
  #   a = N - (A +  N - B )
  #   ans = a // 2
  # print(ans)
    



  # print(ans - k)
  # if A <= N - B:
  #   print(B - A)
  # else:
  #   print(B - A)
  # # k = B - A
  # ans = k+min(N - A, N - B)
  # B - min(N - A, N - B)
  # print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

sa = abs(a-b)

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
n, a, b = [int(x) for x in input().split(" ")]
if b > a:
    a, b = b, a
d = a - b - 1
if d % 2 == 1:
    print(int((d - 1) / 2) + 1)
else:
    da = n - a - 1
    db = b - 1 - 1
    if db < da:
        ans = db + 2
        d -= 1
        ans += int((d - 1) / 2) + 1
        print(ans)
    else:
        ans = da + 2
        d -= 1
        ans += int((d - 1) / 2) + 1
        print(ans)

Submission status: Wrong Answer

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

if (b-a) % 2 == 0:
    # 距離が偶数
    print((b-a) // 2)
    sys.exit()
else:
    print(min([int(b-1), int(n-a)]))

# print([b-1, n - a])

Submission status: Wrong Answer

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: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

aaa = A-B
new_A = A
new_B = B
times = 0
if abs(aaa%2) == 0 and not aaa==0:
  if aaa > 0:
    while True:
      new_A -= 1
      new_B += 1
      times += 1
      if new_A == new_B:
        break
  if aaa < 0:
    while True:
      new_A -= 1
      new_B += 1
      times += 1
      if new_A == new_B:
        break
      
if abs(aaa%2) == 1:
  bbb = min(abs(N-A),abs(1-A))
  ccc = min(abs(N-B),abs(1-B))
  times = max(bbb,ccc)
print(times)

Submission status: Wrong Answer

Solution code:
n,a,b=list(map(int,input().split()))
p=min(a,b)
q=max(a,b)
sum=q-p
if(sum%2==0):
    print(int(sum//2))
else:
    k=n-p
    r=q-1
    if(k<r):
        print(int(n-p))
    else:
        print(int(q-1))

Submission status: Wrong Answer

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

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

    #間隔が奇数の時
else:
    #aと右端の差
    p=num-a
    #bと左端の差
    q=b-1
    #aと左端の差
    r=a-1
    #bと右端の差
    s=num-b
    
    #もしbとaの差が3未満のとき
    if b-a <3:
        p = max(b-1,num-a)
        print(p)
    
    else:
        z=r+1+(b-(r+1)-1)//2
        y=s+1+(num-(a+(s+1)))//2
        print(min(y,z))

Submission status: Wrong Answer

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


# N, A, B = 10 ** 18, 2, 10 ** 18
# N, A, B = 9, 5, 8


def main(n, a, b):
    distance = b - a

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


print(main(N, A, B))

Submission status: Wrong Answer

Solution code:
import sys
import math

(N, A, B) = [int(e) for e in (input().split(" "))]
if (A+B) % 2 != 1:
    print(math.ceil((B-A)/2))
    exit(0)
hidari = A - 1
migi = N - B
if hidari < migi:
    print(math.floor(A+(B-A)/2))
    exit(0)
else:
    buf = N-B+1
    print(math.floor(buf + (N-(A+buf))/2))
    exit(0)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N, a, b = map(int,input().split())
if (b-a)%2 == 0:
    print(abs(b-a)//2)
else:
    if a > b:
        t = a
        a = b
        b = t
    ans = 10 ** 18
    tmp = 0
    tmp += a-1
    a -= a - 1
    b -= a
    tmp += 1
    tmp += (b-a)//2
    ans = min(tmp, ans)
    tmp = 0
    tmp += N-b
    b += N-b
    a += N-b+1
    tmp += 1
    tmp += (b-a) //2
    ans = min(tmp, ans)
    print(ans)

Submission status: Wrong Answer

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

if (B - A) % 2 == 0:
    print('a')
    print((B - A) // 2)
else:
    if N - A > B - 1:  # 1 で対戦
        print('b;')
        print(B - 1)
    else:
        print('c;')
        print(N - A)

Submission status: Wrong Answer

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

if((B-A)%2==0):
  print("(B-A)/2=",int((B-A)/2))
else:
  if(A-1 < N-B):
    print("B=",int(B-1))
  else:
    print("N-A=",int(N-A))

Submission status: Wrong Answer

Solution code:
N,A,B = input().split()
N = int(N)
A = int(A)
B = int(B)
sa = B-A-1
if sa%2 == 1:#間に奇数個のテーブルがある時
    mi = min(B-A-1,N-A,B-1)
    print(mi)
if sa%2 == 0:
    mi = min(N-A,B-1)#遠いほうが端との距離が近い方で集まる
    print(mi)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    tmp = input()
    tmp = [int(i) for i in (tmp.split())]
    n = tmp[0]
    a = tmp[1]
    b = tmp[2]
    dst = (abs(a - b))
    fst = a if a<b else b
    snd = a if a>b else b
    dst_top = snd - 1
    dst_lst = n - fst
    long = dst_top if dst_top<dst_lst else dst_lst

    if abs(a - b)%2 == 0:
        short = dst
        long = dst - (long + 1) / 2
    else:
        short = 2 * n
        long = dst - (long + 2) / 2

    print(min([short, long]))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
w, x, y = input().split(" ")
n = int(w)
a = int(x)
b = int(y)

round = 0
if abs(a - b) % 2 == 0:
    round = abs(a - b) // 2
else:
    half = n//2
    if a >= half and b >= half:
        round = max(abs(n-a), abs(n-b)) - 1
    elif a <= half and b <= half:
        round = max(a, b) - 1
    else:
        if abs(a-half) > abs(b-half):
            round = b - 1
        else:
            round = a - 1

print(round)

Submission status: Wrong Answer

Solution code:
import math
n,a,b = map(int,input().split())
i = 0
if (b-a)%2==0:
    print((b-a)//2)
else:
    print(min(b-1,n-a))
        
#5 2 3 
#5 4 5

Submission status: Wrong Answer

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

solve()

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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) / 2
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
  print(result)
  exit()
else:
  if N - dai <= shou:
    if shou <= N - shou:
      result = math.ceil((shou + N - dai) / 2)
    else:
      result = math.ceil((N - shou + N - dai) / 2)
  else:
    if dai <= N - dai:
      result = math.ceil((dai + shou) / 2)
    else:
      result = math.ceil((N - dai + shou) / 2)

print(result)

Submission status: Wrong Answer

Solution code:
from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby
import bisect
import copy
import math
l_si_i = [int(s) for s in stdin.readline().rstrip().split()]
n = l_si_i[0]
a = l_si_i[1]
b = l_si_i[2]

num = b - a


if num % 2 == 0:
    print(int(num / 2))
elif num % 2 == 1:

    res1 = a - 1
    b1 = b - (a - 1)
    a1 = 1
    num = b1 - a1
    if num % 2 != 0:
        res1 += 1
        b1 -= 1
    res1 += int((b1-a1)/2)
    res2 = n - b
    a2 = n-b+a
    b2 = n
    num = b2 - a2
    if num % 2 != 0:
        res2 += 1
        a2 += 1
    res2 += int((b2 - a2) / 2)
    res = 0
    if res1 <= res2:
        res = res1
    else:
        res = res2
    print(res)

Submission status: Wrong Answer

Solution code:
import sys
from random import choice,randint
inp=sys.stdin.readline
out=sys.stdout.write
flsh=sys.stdout.flush
 
sys.setrecursionlimit(10**9)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
 
def MI(): return map(int, inp().strip().split())
def LI(): return list(map(int, inp().strip().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines().strip()]
def LI_(): return [int(x)-1 for x in inp().strip().split()]
def LF(): return [float(x) for x in inp().strip().split()]
def LS(): return inp().strip().split()
def I(): return int(inp().strip())
def F(): return float(inp().strip())
def S(): return inp().strip()
def pf(s): return out(s+'\n')
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)

def main():
    n,a,b=MI()
    # n,a,b=randint(1,30),randint(1,10),randint(5,25)
    # print(n,a,b)
    if (b-a)%2==0:
        pf(str((b-a)//2))
    elif a==1 and n==b:
        pf(str((b-a+1)//2))
    else:
        ans = min(n-a,b-1)
        pf(str(ans))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

else:
    upper = max(a-1, b-1)
    lower = max(n-a, n-b)

    print(min(upper, lower))

Submission status: Wrong Answer

Solution code:
s=list(map(int,input().split()))
if (s[2]-s[1])%2==0:
  print(int((s[2]-s[1])//2))
else:
  if s[2]-1>=s[0]-s[1]:
    if (s[0]-(s[0]-s[2]+1+s[1]))//2+s[0]-s[2]+1>s[0]-s[1]:
      print(s[0]-s[1])
    else:
      print((s[0]-(s[0]-s[2]+1+s[1]))//2+s[0]-s[2]+1)
  else:
    if (s[2]-s[1]-1)//2+s[2]-s[1]>s[2]-1:
      print(s[2]-1)
    else:
      print((s[2]-s[1]-1)//2+s[2]-s[1])

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N, A, B = map(int, input().split())
a1 = float("inf")
a2 = float("inf")
a3 = float("inf")
if (B - A) % 2 == 0:
    a1 = int((B - A) / 2)

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

a3 = int((A + B) / 2)

print(min(a1, a2, a3))

Submission status: Wrong Answer

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

a_length=a
b_length=n-b

if not (b-a)%2:
    print(abs(a-b)//2)
elif b_length>=a_length:
    print(min(b,a+(b-a-1)//2))
elif b_length<a_length:
    print(min(a,n-b+(b-a)//2+1))

Submission status: Wrong Answer

Solution code:
from sys import stdin


def fetch_one_line():
    return stdin.readline().rstrip()


def fetch_int_input():
    return [int(s) for s in fetch_one_line().split()]


def fetch_inputs(times):
    return [fetch_one_line() for _ in range(times)]


def fetch_int_inputs(times):
    return [[int(s) for s in fetch_one_line()] for _ in range(times)]


def fetch_ints_inputs(times):
    return [fetch_int_input() for _ in range(times)]


N, A, B = fetch_int_input()

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

    #all_win_long = max(A - 1, B - 1)
    #all_win_short = min(A - 1, B - 1)
    #all_short_edge = all_win_short + 1
    #all_win_dist = all_win_long - all_short_edge
    #win_dist = int(abs(all_win_dist) / 2) + all_short_edge

    #all_lose_long = max(N - A, N - B)
    #all_lose_short = min(N - A, N - B)
    #all_short_edge = all_lose_short + 1
    #all_lose_dist = all_lose_long - all_short_edge
    #lose_dist = int(abs(all_lose_dist) / 2) + all_short_edge


    # print(int(min(all_win_long, all_lose_long, win_dist, lose_dist)))

Submission status: Wrong Answer

Solution code:
n,a,b=map(int,input().split())
k=b-a-1
if k%2!=0:#間の卓が奇数
    o_ans=(k-1)//2+1
    e_ans=min(b-1,n-a)
    print(min(o_ans,e_ans))
    
else:#偶数
    ans=min(b-1,n-a)
    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

if (B - A) % 2 == 0:
  print((B - A) // 2)
else:
  NA = N - A
  B1 = B - 1
  if NA < B1:
    distance = N - B
    adjust = distance + 1
    moveA = A + adjust
    print(((N - moveA) // 2) + adjust)
  else:
    distance = A - 1
    adjust = distance + 1
    moveB = B + adjust
    print(((A - moveB) // 2) + adjust)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
mylist = [int(x) for x in input().split()]
N=mylist[0]
A=mylist[1]
B=mylist[2]

if min(A,B)>(N/2):
    if abs(A-B)==1:
        print(N-min(A,B))
        #print(1)
    else:
        print(abs(A-B)//2)
        #print(2)
else:    

    if abs(A-B)==1:
        print(min(A,B))
        #print(3)
    else:
        print(abs(A-B)//2)
        #print(4)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, a, b = list(map(int, readline().split()))
    if (b - a) % 2 == 0:
        print((b - a) // 2)
    else:
        if abs(a - 1) < abs(n - b):
            c = a - 1
            b -= c
            a -= c
            if (b - a) % 2 == 0:
                print((b - a) // 2 + c)
            else:
                print(abs((b - 1) - a) // 2 + c + 1)
        elif abs(a - 1) > abs(n - b):
            c = n - b
            a -= c
            b -= c
            if (b - a) % 2 == 0:
                print((b - a) // 2 + c)
            else:
                print(abs(b - (a + 1)) // 2 + c + 1)


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
n,x,y = map(int,input().split(' '))
a = max(x,y);
b = min(x,y);
if((a-b)==1):
    print(min(b,n-b))
elif((a-b)%2==0):
    print((a-b)//2)
else:
    cnt1 =0
    cnt2=0
    a1 = a
    b1 = b;
    a2=a
    b2=b
    while((a1-b1)%2!=0):
        if(a1!=n):
            a1+=1
            b1+=1
        else:
            b1+=1
        cnt1+=1
    cnt1+=(a1-b1)//2
    while((a2-b2)%2!=0):
        if(b2!=1):
            a2-=1
            b2-=1
        else:
            b2-=1
        cnt2+=1
    cnt2+=(a2-b2)//2
    print(min(a-1,n-b,cnt1,cnt2))

Submission status: Wrong Answer

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

C = B-A

if C % 2 == 0:
#     print("1")
    print(int((B-A)/2))
elif C == 1:
#     print("2")
    kabe = int(min(N-B,A-1))
    print(kabe + 1)    
else:
#     print("3")
    if N-B > A-1:
        print(int((B+A-1)/2))
    else:
        print(int((B-A-1)/2))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

ANS = 0

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

elif B-A == 1:
    if A - 1 > N - B:
        ANS = N - B + 1
    else:
        ANS = A - 1 + 1

elif A - 1 > N-B:
    ANS = N - B + 1 + (B - 1 - A)/2

else:
    ANS = A - 1 + 1 + (B-A-1)/2

print(int(ANS))

Submission status: Wrong Answer

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

print(int(ans))

Submission status: Wrong Answer

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


# N, A, B = 10 ** 18, 2, 10 ** 18
# N, A, B = 9, 5, 8


def main(n, a, b):
    distance = b - a

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


print(main(N, A, B))

Submission status: Wrong Answer

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

k = b-a

a_m = n - a
b_m = n - b
k_m = [a_m, b_m]
a_M = a-1
b_M = b-1
k_M = [a_M, b_M]

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

else:
    if n == a or n == b:
        print(max(k_m))
    elif a == 1 or b == 1:
        print(max(k_M))
    else:
        print(min(k_m))

Submission status: Wrong Answer

Solution code:
from sys import stdin


def fetch_one_line():
    return stdin.readline().rstrip()


def fetch_int_input():
    return [int(s) for s in fetch_one_line().split()]


def fetch_inputs(times):
    return [fetch_one_line() for _ in range(times)]


def fetch_int_inputs(times):
    return [[int(s) for s in fetch_one_line()] for _ in range(times)]


def fetch_ints_inputs(times):
    return [fetch_int_input() for _ in range(times)]


N, A, B = fetch_int_input()

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

    #all_win_long = max(A - 1, B - 1)
    #all_win_short = min(A - 1, B - 1)
    #all_short_edge = all_win_short + 1
    #all_win_dist = all_win_long - all_short_edge
    #win_dist = int(abs(all_win_dist) / 2) + all_short_edge

    #all_lose_long = max(N - A, N - B)
    #all_lose_short = min(N - A, N - B)
    #all_short_edge = all_lose_short + 1
    #all_lose_dist = all_lose_long - all_short_edge
    #lose_dist = int(abs(all_lose_dist) / 2) + all_short_edge


    # print(int(min(all_win_long, all_lose_long, win_dist, lose_dist)))

Submission status: Wrong Answer

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

d = n[2] - n[1]

if(d % 2 == 0):
    ans = int(d/2)
else:
    ad = n[0] - n[1]
    bd = n[2] - 1
    ans = int(min(ad,bd))

if n[1] == 1:
    ans = n[2] - 1
elif n[2] == n[0]:
    ans = n[0] - n[1]

if(ans < 0):
    ans *= -1
print(ans)

Submission status: Wrong Answer

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

ans = 10000000000000000000
if abs(a-b)%2==0:
    ans = (b-a)//2


else:
    c = 0
    if a-1 <= n-b:
        while(a-1>0):
            a, b = a-1, b-1
            c = c + 1
            #print(a,b,c)
        ans = c + (b-2)//2 + 1
    else:
        while(n-b>=0):
            a, b = a+1, b+1
            c = c + 1
        ans = c + (b-2)//2 +1
            
print(ans)

Submission status: Wrong Answer

Solution code:
import math
n,a,b = map(int,input().split())
i = 0
if (b-a)%2==0:
    print((b-a)//2)
else:
    if a <= math.floor(n/2):
        print(b-1)
    else:
        print(n-a)
        
#5 2 3 
#5 4 5

Submission status: Wrong Answer

Solution code:
def main():
    tmp = input()
    tmp = "5 2 3"
    tmp = [int(i) for i in (tmp.split())]
    n = tmp[0]
    a = tmp[1]
    b = tmp[2]
    dst = (abs(a - b))
    fst = a if a<b else b
    snd = a if a>b else b
    dst_top = snd - 1
    dst_lst = n - fst
    long = dst_top if dst_top<dst_lst else dst_lst

    if abs(a - b)%2 == 0:
        short = dst
        long = dst - (long + 1) / 2
    else:
        short = 2 * n
        long = dst - (long + 2) / 2

    print(min([short, long]))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N, A, B = [int(i) for i in input().split()]
a = A - 1
b = N - B
diff = abs(A - B)
if diff == 0:
    print(a)
else:
    if diff % 2 == 0:
        print(diff // 2)
    else:
        if a < b:
            print(B - 1)
        else:
            print(N - A)

Submission status: Wrong Answer

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

solve()

Submission status: Wrong Answer

Solution code:
N, A, B = map(int, input().split())
#N, A, B
#Nは全部の卓数
#AはAさんの卓
#BはBさんの卓
count = 0

if A < B:
    if (B - A) % 2 == 0:
        while True:
            B -= 1
            A += 1
            count += 1
            if A == B:
                break
    elif not (B - A) % 2 == 0:
        if N-B > A-1:
            count = B-1
        else:
            count = N-A

print(count)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import numpy as np

val = input().split(' ')
N = int(val[0])
A = int(val[1])
B = int(val[2].strip())

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

Submission status: Wrong Answer

Solution code:
N,A,B = list(map(int,input().split()))
diff = B - A
N2B = N - B
N2A = N - A
sumN = N2A + N2B
sumAB = A + B
flag = 0
if A == 1 or B == N:
    flag = 1

if diff % 2 == 0:
    print(diff // 2)
elif flag == 0:
    if sumN < sumAB:
        print(N2A)
    else:
        print(B - 1)
else:
    tmp = diff // 2
    if sumN < sumAB:
        if N2A < tmp:
            print(N2A)
        else:
            print(tmp + 1)
    else:
        if B-1 < tmp: 
            print(B - 1)
        else:
            print(tmp + 1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, a, b = list(map(int, readline().split()))
    if (b - a) % 2 == 0:
        print((b - a) // 2)
    else:
        if abs(a - 1) < abs(n - b):
            c = a - 1
            b -= c
            a -= c
            if (b - a) % 2 == 0:
                print((b - a) // 2 + c)
            else:
                print(abs(a - (b - 1)) // 2)
        elif abs(a - 1) > abs(n - b):
            c = n - b
            a -= c
            b -= c
            if (b - a) % 2 == 0:
                print((b - a) // 2 + c)
            else:
                print(abs(b - (a + 1)) // 2)


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
n, a, b = [int(x) for x in input().split()]
r = 0

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

Submission status: Wrong Answer

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

d = abs(A - B)

if d % 2 == 0:
    print(int(d / 2))

a = A
b = B
if A > B:
    a = B
    b = A

if (N - a) >= (b - 1):
    print(b - 1)
else:
    print(N - a)

Submission status: Wrong Answer

Solution code:
tmp = input().split(" ")
N = int(tmp[0])
A = int(tmp[1])-1
B = int(tmp[2])-1
if (B-A)%2==0:#お互いに近づく
  print(int((B-A)/2))
elif (A+B) < 2*N:#お互いトップ卓
  print(max([A,B]))
else:#お互い最下位卓
  print(N-max([A,B]))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

if (B - A) % 2 == 0:
    ans = int((A + B) / 2) - A
else:
    # どちらも1に近づくとき
    ans_a = max(A - 1, B - 1)
    # どちらもNに近づくとき
    ans_b = max(N - A, N - B)
    # Aが1に行って1で1回とまってN方向へ行くとき
    ans_c = int(((A - 1 + 1) + (B - A)) / 2)
    # BがNに行ってNで1回とまって1方向へ行くとき
    ans_d = int(((N - B + 1) + (B - A)) / 2)
    
    #print(ans_a, ans_b,ans_c,ans_d)
    
    ans = min(ans_a, ans_b,ans_c,ans_d)
    
print(ans)