qyliang/CodeNanoFix huggingface dataset:
Buggy code:
N,M = map(int,input().split())
A = sorted(list(map(int,input().split())),reverse=True)
bi = [0]*(A[0]+1)
for a in A:
  bi[a]+=1
  
cum = [0]*(A[0]+1)
for i in range(1,A[0]+1):
  cum[i]=cum[i-1]+bi[i]

cum_max=cum[-1]
left = 0
right = A[0]*2
while right-1!=left:
  x = (right+left)//2
  num = 0
  for a in A:
    b = max(x-a,1)
    if b<=A[0]:
      num += cum_max-cum[b-1]
    
  if num>M:
    left=x
  else:
    right=x
ans = 0
cum_A = [0]*(N+1)
for i in range(1,N+1):
  cum_A[i]=cum_A[i-1]+A[i-1]
for a in A:
  b = max(left-a,1)
  c = cum_max-cum[b-1]
  M-=c
  ans+=(a*c)+cum_A[c]
  
ans+=(M*left)
print(ans)

Fixed code:
N,M = map(int,input().split())
A = sorted(list(map(int,input().split())),reverse=True)
bi = [0]*(A[0]+1)
for a in A:
  bi[a]+=1
  
cum = [0]*(A[0]+1)
for i in range(1,A[0]+1):
  cum[i]=cum[i-1]+bi[i]

cum_max=cum[-1]
left = 0
right = A[0]*2+1
while right-1!=left:
  x = (right+left)//2
  num = 0
  for a in A:
    b = max(x-a,1)
    if b<=A[0]:
      num += cum_max-cum[b-1]
    
  if num>=M:
    left=x
  else:
    right=x

ans = 0
cum_A = [0]*(N+1)
for i in range(1,N+1):
  cum_A[i]=cum_A[i-1]+A[i-1]
for a in A:
  b = max(right-a,1)
  if b>A[0]:
    break
  c = cum_max-cum[b-1]
  M-=c
  ans+=(a*c)+cum_A[c]
  

ans+=M*left
print(ans)
Buggy code:
def ints():
  return [int(x) for x in input().split()]
def ii():
  return int(input())

N, M = ints()
A = ints()
A.sort()

def combinations(x):
  s = 0
  i = 0
  j = N-1
  while j>=0:
    while i<N and A[i]+A[j]<x:
      i += 1
    s += N-i

    j -= 1
    
  return s

def koufukudo(x):
  s = 0
  si = 0
  j = 0
  i = N-1
  while j<N:
    while i>=0 and A[i]+A[j]>=x:
      si += A[i]
      i -= 1
    s += si + A[j]*(N-1-i)

    j += 1
    
  return s


def bsearch(lower, upper):
  l = lower
  u = upper
  m = (l+u)//2
  c = combinations(m)
  if c<M:
    return bsearch(l, m)
  else:
    if l==m:
      return (l, c-M)
    return bsearch(m, u)

x, dm = bsearch(0, A[-1]*2+1)
print(x)
print(koufukudo(x)-dm*x)


Fixed code:
def ints():
  return [int(x) for x in input().split()]
def ii():
  return int(input())

N, M = ints()
A = ints()
A.sort()

def combinations(x):
  s = 0
  i = 0
  j = N-1
  while j>=0:
    while i<N and A[i]+A[j]<x:
      i += 1
    s += N-i

    j -= 1
    
  return s

def koufukudo(x):
  s = 0
  si = 0
  j = 0
  i = N-1
  while j<N:
    while i>=0 and A[i]+A[j]>=x:
      si += A[i]
      i -= 1
    s += si + A[j]*(N-1-i)

    j += 1
    
  return s


def bsearch(lower, upper):
  l = lower
  u = upper
  m = (l+u)//2
  c = combinations(m)
  if c<M:
    return bsearch(l, m)
  else:
    if l==m:
      return (l, c-M)
    return bsearch(m, u)

x, dm = bsearch(0, A[-1]*2+1)
print(koufukudo(x)-dm*x)
Buggy code:
from bisect import bisect_left as bl
from itertools import accumulate as ac
n,m=map(int,input().split())
a=sorted(list(map(int,input().split())))
s=[0]+list(ac(a[::-1]))
l,r=2*a[-1]*(n**2)+1,0
while l-r>1:
    t=(l+r)//2
    p=0
    for i in range(n):
        if a[i]+a[-1]<=t:
            x=bl(a,t-a[i])
            p+=n-x
    if p<m:
        l=t
    else:
        r=t
c,d=0,0
w=0
for i in range(n):
    if a[i]+a[-1]<=t:
        g=bl(a,r-a[i])
        x=n-g
        c+=s[x]+x*a[i]
        w+=x
print(c-r*max(0,(w-m)))


Fixed code:
from bisect import bisect_left as bl
from itertools import accumulate as ac
n,m=map(int,input().split())
a=sorted(list(map(int,input().split())))
s=[0]+list(ac(a[::-1]))
l,r=2*a[-1]*(n**2)+1,0
while l-r>1:
    t=(l+r)//2
    p=0
    for i in range(n-1,-1,-1):
        if a[i]+a[-1]>=t:
            x=bl(a,t-a[i])
            p+=n-x
        else:
            break
    if p<m:
        l=t
    else:
        r=t
c,d=0,0
w=0
for i in range(n-1,-1,-1):
    if a[i]+a[-1]>=r:
        g=bl(a,r-a[i])
        x=n-g
        c+=s[x]+x*a[i]
        w+=x
    else:
        break
print(c-r*max(0,(w-m)))
Buggy code:
N, A, B = map(int,input().split())

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

Fixed 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)
Buggy code:
n,a,b=map(int,input().split())
if (abs(a-b)%2)==0:
    print((abs(a-b)))
    print(int((abs(a-b))/2))
else:
    if abs(a-1)<abs(n-b):
        dis=abs(a-1)
        b=b-1
        print(int((abs(a-b))/2)+dis+1)
    elif abs(a-1)>=abs(n-b):
        dis=abs(b-n)
        a=a+1
        print(int((abs(a-b))/2)+dis+1)


Fixed code:
n,a,b=map(int,input().split())
if ((b-a)%2)==0:
    print(int(((b-a)//2)))
elif ((b-a)%2)==1:
    if (a-1)<(n-b):
        dis=(a-1)
        b=b-1
        print(int(((b-a)//2))+dis+1)
    elif (a-1)>=(n-b):
        dis=(n-b)
        a=a+1
        print(int(((b-a)//2))+dis+1)
Buggy code:
N, A, B =  map(int, input().split())

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

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

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

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

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

print(ans)

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

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

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


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

if a % 2 == b % 2:
  print((b - a) // 2)
else:
  distA = a - 1
  distB = n - b
  if distA < distB:
    ans = distA + (b - distA - 1) // 2
    if b - distA % 2 == 1:
      print(ans)
    else:
      print(ans + 1)
  else:
    ans = distB + (n - (a + distB)) // 2
    if a + distB % 2 == n % 2:
      print(ans)
    else:
      print(ans + 1)
Buggy code:
n, a, b = (int(x) for x in input().split())
if (b - a) % 2 == 0:
  ans = (b-a) // 2
else:
  ans = min(a-1, n-b) + 1 + (b−a−1)//2
print(ans)


Fixed code:
n, a, b = (int(x) for x in input().split())
if (b - a) % 2 == 0:
	ans = (b-a) // 2
else:
	ans = min(a-1, n-b) + 1 + (b-a-1)//2
print(ans)
Buggy code:
n,a,b = map(int,input().split())

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

Fixed 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)
Buggy code:
def main():
    n, a, b = map(int, input().split())
    if abs(a - b) % 2 == 0:
        print(abs(a - b) / 2)
    else:
        mi = min(a, b) - 1
        ma = n - max(a, b)
        print(min(mi, ma) + abs(a - b))


if __name__ == '__main__':
    main()

Fixed code:
def main():
    n, a, b = map(int, input().split())
    if abs(a - b) % 2 == 0:
        print(abs(a - b) // 2)
    else:
        mi = min(a, b) - 1
        ma = n - max(a, b)
        print(min(mi, ma) + (abs(a - b) + 1) // 2)


if __name__ == '__main__':
    main()
Buggy code:
import sys
from math import factorial
from fractions import Fraction
import heapq, bisect, fractions
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
MOD = 10**9 + 7

n, a, b = MAP()

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



Fixed code:
import sys
from math import factorial
from fractions import Fraction
import heapq, bisect, fractions
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
MOD = 10**9 + 7

n, a, b = MAP()

if (a-b)%2 == 0:
    print((b-a)//2)
else:
    k = min(n-b, a-1)
    print((b-a-1)//2 + k+1)
Buggy code:
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:
    diff = N - B if A - 1 > N - B else A - 1
    flip = diff + 1
    distance = int((B - A - 1) / 2)
    x_1 = flip + distance
    x_2 = x_1 if N - A - 1 > x_1 else N - A - 1
    x_3 = x_2 if B - 2 > x_2 else B - 2
    print(x_3)


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

if (B - A) % 2 == 0:
    print((B-A)//2)
else:
    diff = N - B if A - 1 > N - B else A - 1
    flip = diff + 1
    distance = (B - A - 1) // 2
    print(flip + distance)
Buggy code:
def main():
    N, A, B = map(int, input().split())
    if A % 2 == B % 2:
        return abs(A - B)//2
    else:
        x = A + 1 + (B - A - 1)//2
        y = (N - B + 1) + (- A + B + 1)//2
        return min(x, y)

print(main())


Fixed code:
def main():
    N, A, B = map(int, input().split())
    if A % 2 == B % 2:
        return abs(A - B)//2
    else:
        x = A + (B - A - 1)//2
        y = (N - B) + (- A + B + 1)//2
        return min(x, y)

print(main())
Buggy code:
n, a, b = map(int, input().split())

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

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

dist = b - a
if dist & 1:
  print(min(a - 1, n - b) + 1 + (dist - 1)//2)
else:
    print(dist//2)
Buggy 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)

Fixed code:
N,A,B = map(int,input().split())
temp = 0
if (B-A)%2 == 0:
    print(int((B-A)//2))
else:
    a = N - A + 1
    b = N - B + 1
    print(min([B-1,N-A,A + (B-A-1)//2,a + (b-a-1)//2]))
Buggy code:
def min_steps_v2(n, a, b):
    n = np.int64(n)
    a = np.int64(a)
    b = np.int64(b)

    if (b - a) % 2 == 0:
        return np.int64(int(b - a) // 2)
 
    # odd case
    a_diff = a - 1
    b_diff = n - b
 
    if a_diff > b_diff:
      steps_to_even = n - b + 1
      remain_steps = min_steps_v2(n, a + (n - b) + 1, n)
    else:
      steps_to_even = a
      remain_steps = min_steps_v2(n, 1, b - a)
 
    return steps_to_even + remain_steps

numbers = input().split(' ')
 
n = int(numbers[0])
a = int(numbers[1])
b = int(numbers[2])
 
print(min_steps_v2(n, a, b))


Fixed code:
import numpy as np

def min_steps_v2(n, a, b):
    n = np.int64(n)
    a = np.int64(a)
    b = np.int64(b)

    if (b - a) % 2 == 0:
        return np.int64(int(b - a) // 2)
 
    # odd case
    a_diff = a - 1
    b_diff = n - b
 
    if a_diff > b_diff:
      steps_to_even = n - b + 1
      remain_steps = min_steps_v2(n, a + (n - b) + 1, n)
    else:
      steps_to_even = a
      remain_steps = min_steps_v2(n, 1, b - a)
 
    return steps_to_even + remain_steps

numbers = input().split(' ')
 
n = int(numbers[0])
a = int(numbers[1])
b = int(numbers[2])
 
print(min_steps_v2(n, a, b))
Buggy 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)



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


Fixed 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) // 2)
Buggy code:
import sys
input = sys.stdin.readline


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




if __name__ == '__main__':
    main()


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


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




if __name__ == '__main__':
    main()
Buggy 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)

Fixed code:
import sys

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

def main(a, b):
    d = b - a
    if d % 2 == 0:
        return d // 2

    if n - b >= abs(1 - a):
        res = a
        b -= res
        a = 1
    else:
        res = n - b + 1
        a += res
        b = n

    res += (b - a) // 2
    return res

if __name__ == '__main__':
    ans = main(a, b)
    print(ans)
Buggy code:
from decimal import *
def resolve():

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

    print(int(ans))

Fixed code:
from decimal import *
def resolve():

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

    print(int(ans))

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

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

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

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

else:
  tmp = n-b
  a += n-b
  b = n
  print(tmp+((b-a)//2)+1)
Buggy code:
n, a, b = map(int, input().split())
if abs(a-b)%2==0:
  print(abs(a-b)//2)
else:
  m = min(a,b)
  M = max(a,b)
  if M - m == 1:
    if m-1 < n-M:
      print((m-1))
    else:
      print((n-m))
  else:
    if m-1 < n-M:
      print((m-1)+1+(M-m-1)//2)
    else:
      print((n-m)+1+(M-m-1)//2)

Fixed code:
n, a, b = map(int, input().split())
if abs(a-b)%2==0:
  print(abs(a-b)//2)
else:
  m = min(a,b)
  M = max(a,b)
  if M - m == 1:
    if m-1 < n-M:
      print((M-1))
    else:
      print((n-m))
  else:
    if m-1 < n-M:
      print((m-1)+1+(M-m-1)//2)
    else:
      print((n-M)+1+(M-m-1)//2)
Buggy code:
n, a, b = map(int,input().split())

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

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

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

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

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


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

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

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

d = min(a - 1, n - b)
print(d + 1 + (b-a-1)//2)
Buggy 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))

Fixed 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))
Buggy 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)


Fixed 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)
Buggy code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
n, a, b = map(int, input().split())

if (a - b) % 2 == 0:
    if a - b > 0:
        print((a-b)//2)
    else :
        print((b-a)//2)
else:
    min_x = 0
    top_a = a - 1
    top_b = b - 1
    if top_a < top_b:
        min_x = (top_b - (top_a - 1) )//2
    else:
        min_x = (top_a - (top_b - 1) )//2
    
    bot_a = n - a
    bot_b = n - b
    if bot_a < bot_b:
        min_x1 = (bot_b - (bot_a - 1) )//2
    else:
        min_x1 = (bot_a - (bot_b - 1) )//2
    if min_x > min_x1:
        min_x = min_x1
    print(min_x)
    


Fixed code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
n, a, b = map(int, input().split())

if (a - b) % 2 == 0:
    if a - b > 0:
        print((a-b)//2)
    else:
        print((b-a)//2)
else:
    d = 0
    if a - b > 0:
        d = a - b
    else:
        d = b - a
    min_x = 0
    top_a = a - 1
    top_b = b - 1
    if top_a < top_b:
        min_x = top_a + (d + 1)//2 
    else:
        min_x = top_b + (d + 1)//2 
    
    bot_a = n - a
    bot_b = n - b
    if bot_a < bot_b:
        min_x1 = bot_a + (d + 1)//2 
    else:
        min_x1 = bot_b + (d + 1)//2 
    if min_x > min_x1:
        min_x = min_x1
    print(min_x)
Buggy code:
n, a, b = map(int, input().split())
if abs(a - b) % 2:
    te = [a - 1, b - 1]
    te.sort()
    rem = te[1] - te[0] + 1
    cand1 = te[0] + rem // 2

    te = [n - a, n - b]
    te.sort()
    rem = te[1] - te[0] + 1
    cand2 = te[0] + rem // 2
    print(min(cand2, cand2))
else:
    print(abs(a-b)//2)


Fixed code:
n, a, b = map(int, input().split())
if abs(a - b) % 2:
    te = [a - 1, b - 1]
    te.sort()
    rem = te[1] - te[0] + 1
    cand1 = te[0] + rem // 2

    te = [n - a, n - b]
    te.sort()
    rem = te[1] - te[0] + 1
    cand2 = te[0] + rem // 2
    print(min(cand1, cand2))
else:
    print(abs(a-b)//2)
Buggy code:

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

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


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

if (B - A) % 2 == 0:
    print((B - A) // 2)
else:
    lose = N - B + 1
    loseThenMeet = (N - (A + lose)) // 2
    win = A - 1 + 1
    winThenMeet = ((B - win) - 1) // 2
    print(min(lose + loseThenMeet, win + winThenMeet))
Buggy code:
import sys
input = sys.stdin.readline
N, A, B = map(int, input())

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


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

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

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

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

m = abs(B-A)
if m%2==0:
    ans = m//2
else:
    ans1 = N-B+1
    A1 = A+N-B+1
    ans1 += (N-A1)//2
    
    ans2 = A-1+1
    B2 = B-A-2
    ans2 += (B2-1)//2
    ans = min(ans1,ans2)
    
    
print(ans)        

Fixed code:

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

m = abs(B-A)
if m%2==0:
    ans = m//2
else:
    ans1 = N-B+1
    A1 = A+N-B+1
    ans1 += (N-A1)//2
    
    ans2 = A
    B2 = B-A
    ans2 += (B2-1)//2
    ans = min(ans1,ans2)
    
    
print(ans)
Buggy code:
def main2():
    N, A, B = map(int, input().split())

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

if __name__ == "__main__":
    main()

Fixed code:
def main3():
    N, A, B = map(int, input().split())
    
    d = B - A
    if d % 2 == 0:
        print(d // 2)
    else:
        print(min(((d + 1) // 2 + N - B ), ((d + 1) // 2 + A - 1)))
         
if __name__ == "__main__":
    main3()
Buggy code:
n, a, b = [int(i) for i in input().split()]
if b - a % 2 == 0:
    print((b - a) // 2)
else:
    print(min(b - 1, n - a))

Fixed code:
n, a, b = [int(i) for i in input().split()]
if (b - a) % 2 == 0:
    print((b - a) // 2)
else:
    print(min(a - 1, n - b) + 1 + (b - a - 1) // 2)
Buggy code:
N,a,b=map(int,input().split())

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

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

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

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


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

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

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

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

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

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

Fixed 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)
Buggy code:
N, A, B = map(int, input().split())
ans = min(A - 1, N - B) + 1 + (B - A - 1)/2


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

print(ans)

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

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


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


Fixed code:
n, a, b = map(int, input().split())
if (b-a)%2 == 0:
  print((b-a)//2)
elif n-b < a-1:
  print((b-a-1)//2 + n-b+1)
else:
  print((b-a-1)//2 + a)
Buggy code:
import math

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

if (b-a)%2 == 0:
    print(int(b-a/2))
else:
    ans = 0
    ans += math.ceil((b-a)/2)
    ans += min(a-1, n-b)
    print(ans)

Fixed code:
import math

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

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

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


if __name__ == "__main__":
    main()


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

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


if __name__ == "__main__":
    main()