qyliang/CodeNanoFix huggingface dataset:
Buggy code:
import math
n=int(input())
a=sorted(list(map(int,input().split())),reverse=True)

def mid(a):
    if(a%2!=0):
        return (a+1)//2
    else:
        return a//2
ai=a[0]
temp=list(map(lambda x:abs(x-mid(ai)),a[1:]))
bi=a[temp.index(min(temp))+1]
print(str(ai)+" "+str(ans[bi]))

Fixed code:
n=int(input())
a=sorted(list(map(int,input().split())),reverse=True)

def mid(a):
    if(a%2!=0):
        return (a+1)//2
    else:
        return a//2

ai=a[0]
temp=list(map(lambda x:abs(x-mid(ai)),a[1:]))
bi=a[temp.index(min(temp))+1]
print(str(ai)+" "+str(bi))
Buggy code:
n = int(input())
A = list(map(int, input().split()))

a = max(A)
A.sort(key=lambda x:abs(x-a/2))
b = A[0]
print(' '.join([str(a), str(b)]))

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

a = max(A)
A.remove(a)
A.sort(key=lambda x:abs(x-a/2))
b = A[0]
print(' '.join([str(a), str(b)]))
Buggy code:
n = int(input())
a = list(map(int, input().split()))

biggest = max(a)
base = biggest / 2

res = None
diff = float("inf")
for elem in a:
    if diff > abs(base - elem):
        diff = abs(base - elem)
        res = elem
print(biggest, res)

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

biggest = max(a)
base = biggest / 2

res = None
diff = float("inf")
for elem in a:
    if diff > abs(base - elem):
        diff = abs(base - elem)
        res = elem
if biggest != res:
    print(biggest, res)
else:
    print(biggest, 0)
Buggy code:
n = int(input())
A = sorted(list(map(int, input().split())), reverse=True)
mx = A[0]; A = A[1:]
mn = A[0]
for a in A:
    if abs(mn-mx/2) > abs(a-mx/2):
        mn = a
    else:
        break
print(mx, mn)

Fixed code:
n = int(input())
A = sorted(list(map(int, input().split())), reverse=True)
mx = A[0]; A = A[1:]
mn = A[0]
for a in A[1:]:
    if abs(mn-mx/2) > abs(a-mx/2):
        mn = a
    else:
        break
print(mx, mn)
Buggy code:
import bisect
import math
n = int(input())
l = sorted(list(map(int,input().split())))
if len(l)==2 :
  print(l[-1],l[-2])
  exit()
  
a = l[-1]/2
s = bisect.bisect_left(l,a)
if l[s]==a:
  print(l[-1],l[s])
  exit()
k1 = l[s-1]
k2 = l[s]
s1 = a-k1
if k2==l[-1]:
  k2 = k1
#s2 = abs(k2-a)
print(s,k1,k2,s1,s2)
if s1<=s2:
  print(l[-1],k1)
else:
  print(l[-1],k2)

Fixed code:
import bisect
import math
n = int(input())
l = sorted(list(map(int,input().split())))
if len(l)==2 :
  print(l[-1],l[-2])
  exit()
  
a = l[-1]/2
s = bisect.bisect_left(l,a)
if l[s]==a:
  print(l[-1],l[s])
  exit()
k1 = l[s-1]
k2 = l[s]
s1 = a-k1
if k2==l[-1]:
  k2 = k1
s2 = abs(k2-a)
#print(s,k1,k2,s1,s2)
if s1<=s2:
  print(l[-1],k1)
else:
  print(l[-1],k2)
Buggy code:
N = int(input())
A = list(map(int,input().split()))
MAX = max(A)
r_A = MAX / 2
B = list(map(lambda a:abs(a-r_A),A))
B.sort()
r1 = r_A + B[0]
r2 = r_A - B[0]
if r1 in B:
    print(MAX, r1)
else:
    print(MAX, r2)


Fixed code:
N = int(input())
A = list(map(int,input().split()))
MAX = max(A)
r_A = MAX / 2
del A[A.index(MAX)]
B = list(map(lambda a:abs(a-r_A),A))
B.sort()
r1 = int(r_A + B[0])
r2 = int(r_A - B[0])
if r1 in A:
    print(MAX, r1)
else:
    print(MAX, r2)
Buggy code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n = f()[0]
    a = f()

    a = sorted(a)

    mx = a[-1]
    
    midiff = abs(mx//2 - a[0])
    minum = a[0]

    for i in a:
        if abs(i - mx//2) < midiff:
            midiff = abs(mx//2 - i)
            minum = i
    
    print(mx, midiff)

    

solve()


Fixed code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n = f()[0]
    a = f()

    a = sorted(a)

    mx = a[-1]
    
    midiff = abs(mx/2 - a[0])
    minum = a[0]

    for i in a[:-1]:
        if abs(i - mx/2) < midiff:
            midiff = abs(mx/2 - i)
            minum = i
    
    print(mx, minum)

    

solve()
Buggy code:
N=int(input())
a=[int(i) for i in input().split()]
a.sort(key=lambda x:x)
n=a[N-1]
for i in range(N-1):
  if a[i+1]>=n//2+1:
    l=i
    r=i+1
d=10**10
for i in range(l,r+1):
  if i<=N-2:
    if d>abs(a[i]-(n//2+1)):
      d=abs(a[i]-(n//2+1))
      r=a[i]
print(n,r)
  

Fixed code:
N=int(input())
a=[int(i) for i in input().split()]
a.sort(key=lambda x:x)
n=a[N-1]
d=10**10
for i in range(N):
  if i<=N-2:
    if d>abs(a[i]-(n/2)):
      d=abs(a[i]-(n/2))
      r=a[i]
print(n,r)
Buggy code:
N=int(input())
A=list(map(int,input().split()))
A.sort()

def binary(l,i):
  r=N-1
  while l<r:
    m=(l+r)//2
    if A[m]==i:
      return A[m]
    elif A[m]>i:
      r=m-1
    else:
      l=m+1
  x=abs(A[m]-i)
  for j in range(max(0,m-2),min(m+3,N)):
    if x >= abs(A[j]-i):
      res = A[j]     
      x=abs(A[j]-i)
  return res


print(A[-1],binary(1,A[-1]/2))

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

def binary(l,i):
  r=N-1
  while l<=r:
    m=(l+r)//2
    if A[m]==i:
      return A[m]
    elif A[m]>i:
      r=m-1
    else:
      l=m+1
  x=abs(A[m]-i)
  for j in range(max(0,m-2),min(m+3,N-1)):
    if x >= abs(A[j]-i):
      res = A[j]     
      x=abs(A[j]-i)
  return res


print(A[-1],binary(1,A[-1]/2))
Buggy code:
n = int(input())
a = list(map(int,(input().split())))
M = max(a)
nim = 10**9
for i in range(n):
    d = abs(M - a[i]*2)
    if d < nim:
        nim = d
        nimi = i
print(M,a[nimi])

Fixed code:
n = int(input())
a = list(map(int,(input().split())))
M = max(a)
a.remove(M)
nim = 10**9
for i in range(len(a)):
    d = abs(M - a[i]*2)
    if d < nim:
        nim = d
        nimi = i
print(M,a[nimi])
Buggy code:
n = int(input())
a = sorted(map(int, input().split()))

from bisect import bisect_left
ans_n = a[-1]

p = bisect_left(a, (ans_n+1)//2)
ans_r = a[p]
if abs(a[p] - ans_n/2) > abs(a[p-1] - ans_n/2):
  ans_r = a[p-1]

print(ans_n, ans_r)

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

from bisect import bisect_left
ans_n = a[-1]

p = bisect_left(a, (ans_n+1)//2)
ans_r = a[p] if p != n-1 else a[p-1]
if abs(a[p] - ans_n/2) > abs(a[p-1] - ans_n/2):
  ans_r = a[p-1]

print(ans_n, ans_r)
Buggy code:
n = int(input())
lst = list(map(int,input().split()))
lst.sort()

m = lst[-1]
line = m / 2
r = 10**10

for i in range(n):
    if abs(r-line) > abs(lst[i]-line):
        r = lst[i]
print(r,m)

Fixed code:
n = int(input())
lst = list(map(int,input().split()))
lst.sort()

m = lst[-1]
line = m / 2
r = 10**10

for i in range(n):
    if abs(r-line) > abs(lst[i]-line):
        r = lst[i]
print(m,r)
Buggy code:
def comb(x, y):
    return math.factorial(x) / (math.factorial(x - y) * math.factorial(y))

def solve(N, AS):
    x = max(AS)
    y = min(map(lambda z: [abs(z - x / 2), z] , AS), key=lambda x: x[0])[1]
    return (x, y)

if __name__ == '__main__':
    n = int(input())
    AS  = list(map(lambda x: int(x), input().split()))
    print(solve(n, AS))


Fixed code:
def comb(x, y):
    return math.factorial(x) / (math.factorial(x - y) * math.factorial(y))

def solve(N, AS):
    x = max(AS)
    AS = list(AS)
    AS.remove(x)
    y = min(map(lambda z: [abs(z - x / 2), z] , AS), key=lambda x: x[0])[1]
    return (x, y)

if __name__ == '__main__':
    n = int(input())
    AS  = list(map(lambda x: int(x), input().split()))
    tmp = solve(n, AS)
    print(tmp[0], tmp[1])
Buggy code:
from bisect import bisect_left
N = int(input())
A = list(map(int, input().split()))
if N == 2:
    print(A[1], A[0])
    exit()
A.sort()
a = A[-1]
k = bisect_left(A, a/2)
x = a/2-A[k-1]
y = A[k]-a/2
if x <= y:
    b = A[k-1]
else:
    b = A[k]
print(a, b)


Fixed code:
from bisect import bisect_left
N = int(input())
A = list(map(int, input().split()))
A.sort()
if N == 2:
    print(A[1], A[0])
    exit()
a = A[-1]
k = bisect_left(A, a/2)
x = a/2-A[k-1]
y = A[k]-a/2
if x <= y:
    b = A[k-1]
else:
    b = A[k]
print(a, b)
Buggy code:
n = int(input())
a = [int(i) for i in input().split()]

a.sort()

if n == 2:
	print(str(a[1])+" "+str(a[0]))
else:
	maximum = a[-1]
	a.pop()
	half = maximum/2
	a.append(half)
	a.sort()

	position = a.index(half)

	large = a[position+1]
	small = a[position-1]

	print(position)
	print(large)
	print(small)

	if large - (half) < (half) - small:
		print(str(maximum)+" "+str(large))
	else:
		print(str(maximum)+" "+str(small))

Fixed code:
n = int(input())
a = [int(i) for i in input().split()]

a.sort()

if n == 2:
	print(str(a[1])+" "+str(a[0]))
else:
	maximum = a[-1]
	a.pop()
	half = maximum/2
	a.append(half)
	a.sort()

	position = a.index(half)

	if position+1 >= len(a):
		print(str(maximum)+" "+str(int(a[position-1])))
		exit()
	else:
		large = int(a[position+1])
	if position-1 <= 0:
		print(str(maximum)+" "+str(int(a[position+1])))
		exit()
	else:
		small = int(a[position-1])

	if large - (half) < (half) - small:
		print(str(maximum)+" "+str(large))
	else:
		print(str(maximum)+" "+str(small))
Buggy code:
import sys

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

n = max(A)
mid = n / 2
r = float("inf")
for a in A:
    if abs(mid - r) > abs(mid - a):
        r = a

print(n, r)

Fixed code:
import sys

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

n = max(A)
mid = n / 2
r = float("inf")
for a in A:
    if a == n:
        continue
    if abs(mid - r) > abs(mid - a):
        r = a

print(n, r)
Buggy code:
n = int(input())
a = input().split()
for i in range(n):
    a[i] = int(a[i])

p = max(a)
q = max(a)
for i in range(n):
    m = abs(a[i]-p/2)
    if m < abs(q-p/2):
        q = a[i]
        

print(p,q)

Fixed code:
n = int(input())
a = input().split()
for i in range(n):
    a[i] = int(a[i])

p = max(a)
q = 0
for i in range(n):
    m = abs(a[i]-p/2)
    if m < abs(q-p/2):
        q = a[i]
        

print(p,q)
Buggy code:
import math
import bisect
from queue import Queue
from collections import deque

n = int(input())
a = [int(i) for i in input().split()]

a.sort()

b = a[n-1]
c = bisect.bisect_left(a,b//2)
d = max(c-1,0)

if(abs(b//2 - a[c]) < abs(b//2 - a[d])):
    print(b,a[c])
else:
    print(b,a[d])

Fixed code:
import math
import bisect
from queue import Queue
from collections import deque

n = int(input())
a = [int(i) for i in input().split()]

a.sort()

b = a[n-1]
c = bisect.bisect_left(a,b//2)
d = max(c-1,0)

if(abs(b/2 - a[c]) < abs(b/2 - a[d])):
    print(b,a[c])
else:
    print(b,a[d])
Buggy code:
n = int(input())
a_list = sorted(list(map(int, input().split())))

a_i_index = len(a_list) - 1
a_i = a_list[-1]
max = 0
max_j_index = None

nobori = True

tmp = a_list[0]
koeta = None
for j_index in range(n):
    if a_list[j_index] * 2 > a_i:
        koeta = j_index
        break
    else:
        tmp = j_index

comb2 = 0
if n == 2:
    print(*[a_list[0], a_list[1]])
elif koeta == 0:
    print(*[a_i, a_list[koeta]])
elif (a_list[koeta]- a_i/2) > (a_i/2 - a_list[koeta-1]):
    print(*[a_i,a_list[koeta-1]])
else:
    print(*[a_i, a_list[koeta]])



Fixed code:
n = int(input())
a_list = sorted(list(map(int, input().split())))
 
a_i_index = len(a_list) - 1
a_i = a_list[-1]
max = 0
max_j_index = None
 
nobori = True
 
tmp = a_list[0]
koeta = None
for j_index in range(n):
    if a_list[j_index] * 2 > a_i:
        koeta = j_index
        break
    else:
        tmp = j_index
 
comb2 = 0
if n == 2:
    print(*[a_list[1], a_list[0]])
elif koeta == 0:
    print(*[a_i, a_list[koeta]])
elif (a_list[koeta]- a_i/2) > (a_i/2 - a_list[koeta-1]):
    print(*[a_i,a_list[koeta-1]])
else:
    print(*[a_i, a_list[koeta]])
Buggy code:
import numpy as np
n=int(input())
a=list(map(int,input().split()))
i=max(a)
near=max(a)/2
j=a[np.abs(np.asarray(a)-near).argmin()]
print(i,j)

Fixed code:
import numpy as np
n=int(input())
a=list(map(int,input().split()))
i=max(a)
near=max(a)/2
j=a[np.abs(np.asarray(a)-near).argmin()]
if j==i:
    j=min(a)
print(i,j)
Buggy code:
import bisect
N = int(input())
A = sorted(list(map(int, input().split())))


if N == 2:
    print(A)
    quit()

a_i = A[-1]
a_j = bisect.bisect_left(A, a_i//2)
if a_j == 0:
    print(A[0], A[-1])
else:
    a_j1, a_j2 = A[a_j-1], A[a_j]
    if a_i - a_j1 < a_i - a_j2:
        print(a_i, a_j1)
    else:
        print(a_i, a_j2)

Fixed code:
import bisect
N = int(input())
A = sorted(list(map(int, input().split())))


if N == 2:
    print(A[-1], A[0])
    quit()

a_i = A[-1]
a_j = bisect.bisect_left(A, a_i//2)
if a_j == 0:
    print(A[-1], A[0])
else:
    a_j1, a_j2 = A[a_j-1], A[a_j]
    if abs(a_i/2 - a_j1) < abs(a_i/2 - a_j2):
        print(a_i, a_j1)
    else:
        print(a_i, a_j2)
Buggy code:
from bisect import bisect_left, bisect_right
import sys
INFTY=sys.maxsize

def readinput():
    n=int(input())
    a=list(map(int,input().split()))
    return n,a

def main(n,a):
    # order=[]
    # for i in range(n):
    #     order.append([a[i],i])
    s=sorted(a)
    ai=s[n-1]

    aj0=ai//2
    j=bisect_right(s, aj0)
    #print(s,aj0,j) 
    aj=s[j]   
    if j+1<n:
        aj1=s[j]
        aj2=s[j+1]
        if aj0-aj1>aj2-aj0:
            aj=aj2
        else:
            aj=aj1
    return ai,aj


if __name__=='__main__':
    n,a=readinput()
    i,j=main(n,a)
    print(i,j)


Fixed code:
from bisect import bisect_left, bisect_right
import sys
INFTY=sys.maxsize

def readinput():
    n=int(input())
    a=list(map(int,input().split()))
    return n,a

def main(n,a):
    # order=[]
    # for i in range(n):
    #     order.append([a[i],i])
    s=sorted(a)
    ai=s[n-1]

    aj0=ai/2
    j=bisect_right(s, aj0)-1
    #print(s,aj0,j) 
    aj=s[j]
    if aj==aj0:
        return ai,aj

    if j+1<n:
        aj1=s[j]
        aj2=s[j+1]
        if aj0-aj1<=aj2-aj0:
            aj=aj1
        else:
            aj=aj2
    return ai,aj


if __name__=='__main__':
    n,a=readinput()
    i,j=main(n,a)
    print(i,j)
Buggy code:
n,*a=map(int,open(0).read().split())
a.sort()
b=a[-1]
c=a[0]
d=b/2-c
for i in a:
    if d>abs(b/2-i):
        c=i
        d=abs(b/2-i)
print(c,b)

Fixed code:
n,*a=map(int,open(0).read().split())
a.sort()
b=a[-1]
c=a[0]
d=b/2-c
for i in a:
    if d>abs(b/2-i):
        c=i
        d=abs(b/2-i)
print(b,c)
Buggy code:
N = int(input())
A = list(map(int, input().split()))

ans1 = max(A)
diff = 10 ** 9 
for i in range(N):
  if abs(A[i] - ans1 / 2) < diff:
    ans2 = A[i]
    diff = abs(A[i] - ans1 / 2)
print(ans1, ans2)

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

ans1 = max(A)
diff = 10 ** 9 
for i in range(N):
  if abs(A[i] - ans1 / 2) <= diff:
    ans2 = A[i]
    diff = abs(A[i] - ans1 / 2)
print(ans1, ans2)
Buggy code:
n = int(input())
a = list(map(int, input().split()))

ai = max(a)
aj = a[0]
for i in a:
    if abs(ai - 2*i) < abs(ai - 2*aj):
        aj = i

print(ai,aj)


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

ai = max(a)
aj = a[0]
for i in a:
    if abs(ai - 2*i) <= abs(ai - 2*aj):
        aj = i

print(ai,aj)
Buggy code:
N = int(input().strip())
A = list(map(int,input().strip().split(' ')))

import numpy as np
sortA = np.array(sorted(A))
a_large = sortA[-1]
sortA = np.delete(sortA,-1,0)
half_of_a_large = np.array([a_large/2 for i in range(N-1)])
a_small = sortA[np.argmin(abs(sortA-half_of_a_large))]
print(a_large,a_small)a

Fixed code:
N = int(input().strip())
A = list(map(int,input().strip().split(' ')))

import numpy as np
sortA = np.array(sorted(A))
a_large = sortA[-1]
sortA = np.delete(sortA,-1,0)
half_of_a_large = np.array([a_large/2 for i in range(N-1)])
a_small = sortA[np.argmin(abs(np.array([sortA[i]-a_large/2 for i in range(N-1)])))]
print(a_large,a_small)
Buggy code:
n = int(input())
a = list(int(x) for x in input().split())
a.sort()

a_i = a[-1]

key_small, key_large = 0, n-1
border = a_i//2
while key_small < key_large-1:
    key = (key_small+key_large)//2
    if a[key] <= border:
        key_small = key
    else:
        key_large = key

p, q = a[key_small], a[key_large]

judge = a_i / 2
if abs(p-judge) < abs(q-judge):
    a_j = p
else:
    a_j = q

print(a_i, a_j)

Fixed code:
n = int(input())
a = list(int(x) for x in input().split())
a.sort()

a_i = a[-1]

key_small, key_large = 0, n-1
border = a_i//2
while key_small < key_large-1:
    key = (key_small+key_large)//2
    if a[key] <= border:
        key_small = key
    else:
        key_large = key

p, q = a[key_small], a[key_large]

judge = a_i / 2
if abs(p-judge) < abs(q-judge):
    a_j = p
else:
    a_j = q
if a_i == a_j:
    a_j = 0
print(a_i, a_j)
Buggy code:
n = int(input())

a = sorted(list(map(int, input())))

ans = 0
d_min = a[-1]
for i in range(n-1):
  d = abs(a[-1]/2 - a[i])
  if d < d_min:
    d_min = d
    ans = a[i]
    
print('{} {}'.format(a[-1], ans))

Fixed code:
n = int(input())

a = sorted(list(map(int, input().split())))

ans = 0
d_min = a[-1]
for i in range(n-1):
  d = abs(a[-1]/2 - a[i])
  if d < d_min:
    d_min = d
    ans = a[i]
    
print('{} {}'.format(a[-1], ans))
Buggy code:
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
r = a.pop(0)
s = r
temp = r
for i in range(n-1):
    if abs(r - 2*a[i]) < s:
        s = abs(r - 2*a[i])
        temp = a[i]
print(r, temp)

Fixed code:
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
r = a.pop(0)
s = r
temp = 0
for i in range(n-1):
    if abs(r - 2*a[i]) < s:
        s = abs(r - 2*a[i])
        temp = a[i]
print(r, temp)
Buggy code:
# import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial, gcd
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10 ** 7)
enu = enumerate
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep="\n")

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

fact = [1]
for i in range(1, N + 10):
    fact.append(fact[-1] * i % MOD)


def rev(x):
    return pow(x, MOD - 2, MOD)


def cmb(i, k):
    if i < k:
        return 0
    return fact[i] * rev(fact[k]) * rev(fact[i - k]) % MOD


A.sort()
if N == 2:
    print(A[1], A[0])
    exit()

mv = A[-1]
vm = mv // 2
bli = bisect_left(A, vm)
if bli == N - 1:
    print(mv, A[bli - 1])
elif bli == 0:
    print(mv, A[bli])
else:
    if vm - A[bli - 1] <= A[bli] - vm:
        print(mv, A[bli - 1])
    else:
        print(mv, A[bli])



Fixed code:
# import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial, gcd
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10 ** 7)
enu = enumerate
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep="\n")

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

fact = [1]
for i in range(1, N + 10):
    fact.append(fact[-1] * i % MOD)


def rev(x):
    return pow(x, MOD - 2, MOD)


def cmb(i, k):
    if i < k:
        return 0
    return fact[i] * rev(fact[k]) * rev(fact[i - k]) % MOD


A.sort()
if N == 2:
    print(A[1], A[0])
    exit()

mv = A[-1]
vm = mv // 2
bli = bisect_left(A, vm)
if bli == N - 1:
    print(mv, A[bli - 1])
elif bli == 0:
    print(mv, A[bli])
else:
    if vm - A[bli - 1] < A[bli] - vm:
        print(mv, A[bli - 1])
    else:
        print(mv, A[bli])
Buggy code:
from bisect import bisect_left
n = int(input())
a_list = sorted([int(x) for x in input().split()])
base = a_list[-1] // 2
i = bisect_left(a_list, base)
if i > 0:
    i -= 1
ans = [a_list[-1], a_list[i], abs(a_list[i] - base)]
for i in range(i + 1, n):
    temp = abs(a_list[i] - base)
    if temp >= ans[2]:
        break
    ans[1] = a_list[i]
    ans[2] = temp
print(ans[0], ans[1])

Fixed code:
from bisect import bisect_left
n = int(input())
a_list = sorted([int(x) for x in input().split()])
base = a_list[-1] / 2
i = bisect_left(a_list, base)
if i > 0:
    i -= 1
ans = [a_list[-1], a_list[i], abs(a_list[i] - base)]
for i in range(i + 1, n):
    temp = abs(a_list[i] - base)
    if temp >= ans[2]:
        break
    ans[1] = a_list[i]
    ans[2] = temp
print(ans[0], ans[1])
Buggy code:
import sys
from bisect import *

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline

def main():
    n=int(input())
    a=list(map(int, input().split()))
    a.sort()
    m=a[-1]/2
    i=bisect(a,m)
    d0=m-a[i-1]
    d1=a[i]-m
    if d0<d1:
        print(a[-1],a[i-1])
    else:
        print(a[-1],a[i])


main()

Fixed code:
import sys
from bisect import *

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline

def main():
    n = int(input())
    a = list(map(int, input().split()))
    a.sort()
    m = a[-1] / 2
    i = bisect(a, m)
    d0 = m - a[i - 1]
    d1 = a[i] - m
    if d0 < d1 or i == n - 1:
        print(a[-1], a[i - 1])
    else:
        print(a[-1], a[i])

main()
Buggy code:
import sys

N = int(input())
A = [int(x) for x in input().split()]

ma = max(A)

L = [(abs(A[i] - ma / 2), i) for i in range(N)]
lmin = min(L)

a = ma
b = A[lmin[1]]

print('{} {}'.format(a,b))


Fixed code:
import sys

N = int(input())
A = [int(x) for x in input().split()]
A.sort()

ma = max(A)

L = [(abs(A[i] - ma / 2), i) for i in range(N)]
lmin = min(L)

a = ma
b = A[lmin[1]]

print('{} {}'.format(a,b))
Buggy code:
#!/usr/bin/env python3
import sys
import math
import bisect

def solve(n: int, a: "List[int]"):
    a.sort()
    max_a = a[-1]

    if max_a%2 ==1:
        searchValue = max_a//2+1
    else:
        searchValue = max_a//2
        
    index = bisect.bisect_left(a,searchValue)
    if abs(max_a/2-a[index]) > abs(max_a/2-a[index-1]):
        print(max_a,a[index-1])
    else:
        print(max_a,a[index])


    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(n)]  # type: "List[int]"
    solve(n, a)

if __name__ == '__main__':
    main()


Fixed code:
#!/usr/bin/env python3
import sys
import math
import bisect

def solve(n: int, a: "List[int]"):
    if n == 2:
        print(*sorted(a,reverse=True))
        return 

    a.sort()
    max_a = a[-1]


    if max_a%2 ==1:
        searchValue = max_a//2+1
    else:
        searchValue = max_a//2

    index = bisect.bisect_left(a,searchValue)
    if abs(max_a/2-a[index]) > abs(max_a/2-a[index-1]):
        print(max_a,a[index-1])
    else:
        print(max_a,a[index])

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(n)]  # type: "List[int]"
    solve(n, a)

if __name__ == '__main__':
    main()
Buggy code:
n = int(input().split())
lis = list(map(int,input().split()))
lis.sort(reverse = True)
cou = lis[1]
for i in range(2,n-1):
  if abs(cou - (lis[0]/2)) > abs(lis[i] - (lis[0]/2)):
    cou = lis[i]
print(lis[0],cou)

Fixed code:
n = int(input())
lis = list(map(int,input().split()))
lis.sort(reverse = True)
cou = lis[1]
for i in range(2,n-1):
  if abs(cou - (lis[0]/2)) > abs(lis[i] - (lis[0]/2)):
    cou = lis[i]
print(lis[0],cou)
Buggy code:
n = int(input())
a = sorted(map(int, input().split()))
MAX = a[-1]
mid = MAX // 2
b = float('inf')
for i in a:
    # print(mid, i, b)
    if abs(mid - i) <= b:
        b = mid - i
        y = i

print(MAX, y)

Fixed code:
n = int(input())
a = sorted(map(int, input().split()))
MAX = a[-1]
mid = MAX // 2
b = float('inf')
for i in a:
    # print(mid, i, b)
    if abs(mid - i) <= b and i != MAX:
        b = mid - i
        y = i

print(MAX, y)
Buggy code:
n =int(input())
a = list(map(int,input().split()))

seta = sorted(list(set(a)))

resn = seta[-1]
resr = seta[0]
for sa in seta:
    sabun = abs(resn / 2 - sa)
    if sabun  == 0 or sabun == 0.5:
        resr == sa
        break
    elif sabun < abs(resn / 2 - resr):
        resr = sa

print(str(resn) + " " + str(resr))

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

seta = sorted(list(set(a)))

resn = seta[-1]
resr = seta[0]
for sa in seta:
    sabun = abs(resn / 2 - sa)
    if sabun  == 0 or sabun == 0.5:
        resr = sa
        break
    elif sabun < abs(resn / 2 - resr):
        resr = sa

print(str(resn) + " " + str(resr))