qyliang/CodeNanoFix huggingface dataset:
Buggy code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())

    A.sort()
    n = max(A)

    i = 0
    while i < N - 1 and 2 * A[i] < n:
        i += 1

    if i in (0, N - 1):
        r = A[i]
    elif abs(2 * A[i] - n) < abs(2 * A[i - 1] - n):
        r = A[i]
    else:
        r = A[i - 1]

    print(n, r)
    return


if __name__ == '__main__':
    main()


Fixed code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())

    A.sort()
    n = max(A)

    i = 0
    while i < N - 2 and 2 * A[i] < n:
        i += 1

    if i in (0, N - 1):
        r = A[i]
    elif abs(2 * A[i] - n) < abs(2 * A[i - 1] - n):
        r = A[i]
    else:
        r = A[i - 1]

    print(n, r)
    return


if __name__ == '__main__':
    main()
Buggy code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

N = ii()
A = sorted(li())
half = A[-1]//2

ind = bisect.bisect_left(A, half)

if A[ind]!=half:
    if ind > 0 and half - A[ind-1] < A[ind] - half:
        ind -= 1

print(A[-1], A[ind])

Fixed code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

N = ii()
A = sorted(li())
half = A[-1]//2
#if N % 2 == 0
ind = bisect.bisect_left(A, half)
#if ind > 0 and A[ind] - half > A[ind-1] - half:
    #ind -= 1
if A[ind]!=half:
    if ind > 0 and half - A[ind-1] < A[ind] - half:
        ind -= 1
if ind == N-1:
    ind -= 1
print(A[-1], A[ind])
Buggy code:
n = int(input())
a = list(map(int, input().split()))
k = max(a)
b = [0] * n
for i in range(n):
    b[i] = abs(a[i]-k/2)
r = a[b.index(min(b))]
print(k, r)

Fixed code:
n = int(input())
a = list(map(int, input().split()))
k = max(a)
b = [0] * n
for i in range(n):
    if a[i] == k:
        b[i] = k
    else: b[i] = abs(a[i]-k/2)
r = a[b.index(min(b))]
print(k, r)
Buggy code:
import sys
input=sys.stdin.readline

def main():
    _ = int(input())
    A = list(map(int,input().split()))
    A.sort()
    a = A.pop()
    b = a
    for x in A:
        if abs(a/2-x) < abs(a/2-b):
            b = x
    print(a, b)

if __name__ == '__main__':
    main()


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

def main():
    _ = int(input())
    A = list(map(int,input().split()))
    A.sort()
    a = A.pop()
    b = 0
    for x in A:
        if abs(a/2-x) < abs(a/2-b):
            b = x
    print(a, b)

if __name__ == '__main__':
    main()
Buggy code:
import bisect

n=int(input())
s=list(map(int,input().split()))
s.sort()
a=s[-1]
index=bisect.bisect_left(s,a//2)
diff1=abs(a//2-s[index-1])
diff2=abs(a//2-s[index])
if diff1>=diff2:
    k=s[index]
else:
    k=s[index-1]
print(a,k)

Fixed code:
import bisect

n=int(input())
s=list(map(int,input().split()))
s.sort()
a=s[-1]
index=bisect.bisect_left(s,a//2)
diff1=abs(a//2-s[index-1])
diff2=abs(a//2-s[index])
if diff1>=diff2:
    k=s[index]
else:
    k=s[index-1]
if a==k:
    k=s[0]
print(a,k)
Buggy code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().strip()

n = ni()
a = na()

if n == 2:
    print(a[0],a[1])
x = max(a)
mid = x / 2
a.remove(x)

diff = mid - a[0]
ans = 0
for i in range(len(a)):
    if diff > abs(mid - a[i]):
        diff = abs(mid - a[i])
        ans = i
print(x,a[ans])


Fixed code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().strip()

n = ni()
a = na()

if n == 2:
    if a[0] > a[1]:
        print(a[0],a[1])
    else:
        print(a[1],a[0])
else:
    x = max(a)
    mid = x / 2
    a.remove(x)

    diff = abs(mid - a[0])
    ans = 0
    for i in range(len(a)):
        if diff > abs(mid - a[i]):
            diff = abs(mid - a[i])
            ans = i
    print(x,a[ans])
Buggy code:
import bisect
import math

N = int(input())
a = list(map(int, input().split()))
a.sort()
n = a[-1]
harf = n//2
ri = bisect.bisect_left(a, harf)
r = a[ri]
if ri > 0 and abs(harf-r) >= abs(harf-a[ri-1]):
  r = a[ri-1]
print(n, r)

Fixed code:
import bisect
import math

N = int(input())
a = list(map(int, input().split()))
a.sort()
n = a[-1]
harf = n/2
ri = bisect.bisect_left(a, harf)
r = a[ri]
if ri > 0 and abs(harf-r) >= abs(harf-a[ri-1]):
  r = a[ri-1]
print(n, r)
Buggy code:
input();a=list(map(int,input().split()))[::-1];print(a[0],sorted(a,key=lambda x:abs(a[0]-2*x))

Fixed code:
input();a=sorted(list(map(int,input().split())));print(a[-1],sorted(a,key=lambda x:abs(a[-1]-2*x))[0])
Buggy code:
n = int(input())
A = list(map(int, input().split()))
a_max = max(A)


def find_nearest(arr, target):
    m = min(arr)
    dist = abs(m-target)
    for a in arr[1:]:
        if abs(a-target) < dist:
            dist = abs(a - target)
            m = a
            # print(m)
    return m


print(a_max, find_nearest(A, a_max/2))


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


def find_nearest(arr, target):
    m = min(arr)
    dist = abs(m-target)
    for a in arr:
        if abs(a-target) < dist:
            dist = abs(a - target)
            m = a
            # print(m, dist)
    return m


print(a_max, find_nearest(A, a_max/2))
Buggy code:
import bisect

n = int(input())
A = sorted(list(map(int,input().split())))
ma = A[-1]
half = ma // 2
index = bisect.bisect_left(A,half)

if index != 0:
    ans = A[index-1] if half - A[index-1] < A[index] - half else A[index]
else:
    ans = A[0]

print(ma,ans)

Fixed code:
import bisect

n = int(input())
A = sorted(list(map(int,input().split())))
ma = A[-1]
half = ma / 2
index = bisect.bisect_left(A,half)

if index != 0:
    ans = A[index-1] if half - A[index-1] <= A[index] - half else A[index]
else:
    ans = A[0]

print(ma,ans)
Buggy code:
import scipy.misc

N=int(input())
X=list(map(int,input().split()))
SX=sorted(X)
M=SX.pop()
MV=10**9
ANS=0
for x in SX:
  z = M - x
  if MV > z:
    MV = z
    ANS = x
print("{} {}".format(M,ANS))



Fixed code:
import scipy.misc

N=int(input())
X=list(map(int,input().split()))
SX=sorted(X)
M=SX.pop()
MV=10**9
ANS=0
for x in SX:
  z = abs(M - x - x)
  if MV > z:
    MV = z
    ANS = x
print("{} {}".format(M,ANS))
Buggy code:
n = int(input())
aa = sorted(list(map(int,input().split())))
a_max = max(aa)

half = a_max/2
p = bisect_left(aa, half)
if abs(half - aa[p]) >= abs(half - aa[p-1]):
  print(a_max,aa[p-1])  
else:
  print(a_max,aa[p])  

Fixed code:
from bisect import bisect_left

n = int(input())
aa = sorted(list(map(int,input().split())))
a_max = max(aa)

half = a_max/2
p = bisect_left(aa, half)
if abs(half - aa[p]) >= abs(half - aa[p-1]):
  print(a_max,aa[p-1])  
else:
  print(a_max,aa[p])
Buggy code:
a = list(map(int, input().split()))

x = max(a)
b1 = x//2
b2 = (x+1)//2

y = x
z = x
for i in range(len(a)):
    if a[i] != x:
        tmp = min(abs(a[i]-b1), abs(a[i]-b2))
        if tmp < y:
            z = a[i]
        y = min(tmp, y) 

ans = x*z
print(x, z)

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

x = max(a)
b1 = x//2
b2 = (x+1)//2

y = x
z = x
for i in range(len(a)):
    if a[i] != x:
        tmp = min(abs(a[i]-b1), abs(a[i]-b2))
        if tmp < y:
            z = a[i]
        y = min(tmp, y) 

ans = x*z
print(str(x) + ' '+ str(z))
Buggy code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
ai = a[-1]
aj = ai
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()))
a.sort()
ai = a[-1]
aj = a[0]
for i in a[:-1]:
    if abs(ai/2-i) < abs(ai/2-aj):
        aj = i
print(ai, aj)
Buggy code:
from bisect import bisect_left

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

A.sort()
for i in reversed(range(N)):
    a = A[i]
    ia = bisect_left(A, a/2)
    a1, a2 = A[ia-1], A[ia]
    if min(a1, a-a1) > min(a2, a-a2):
        b = a1
    else:
        b = a2
    break
    
print(a, b)

Fixed code:
from bisect import bisect_left

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

A.sort()
for i in reversed(range(N)):
    a = A[i]
    ia = bisect_left(A, a/2)
    a1, a2 = A[ia-1], A[ia]
    if a2 == a:
        b = a1
    elif min(a1, a-a1) > min(a2, a-a2):
        b = a1
    else:
        b = a2
    break
    
print(a, b)
Buggy code:
import bisect
import math

n = int(input())
a = [int(item) for item in input().split()]
a.sort()
ai = a[-1]

left = bisect.bisect(a, ai/2) - 1
right = left + 1

if a[right] - ai/2 > ai/2 - a[left]:
  print(ai, a[left])
else:
  print(ai, a[right])  

Fixed code:
import bisect
import math

n = int(input())
a = [int(item) for item in input().split()]
a.sort()
ai = a[-1]

left = bisect.bisect(a, ai/2) - 1
right = left + 1

if a[right] - ai/2 >= ai/2 - a[left]:
  print(ai, a[left])
else:
  print(ai, a[right])
Buggy code:
# -*- coding: utf-8 -*-

n = int(input())
a = list(map(int, input().split()))
a_max = max(a)
half_max = a_max / 2
tmp = [abs(half_max - v) for v in a]
b = a[tmp.index(min(tmp))]
print("{} {}".format(a_max, b))

Fixed code:
# -*- coding: utf-8 -*-

n = int(input())
a = list(map(int, input().split()))
a_max = max(a)
half_max = a_max / 2
tmp = [abs(half_max - v) for v in a]
b = a[tmp.index(min(tmp))]
if b == a_max and 0 in a:
    print("{} 0".format(a_max))
else:
    print("{} {}".format(a_max, b))
Buggy code:
n = int(input())
ali = list(map(int,input().split()))

amax = max(ali)
b=min(ali,key=lambda x: abs(2*x-amax))
print(amax,end=' ')
print(b)


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

amax = max(ali)
ali.remove(amax)
b=min(ali,key=lambda x: abs(2*x-amax))
print(amax,end=' ')
print(b)
Buggy code:
n = int(input())
a = list(map(int,input().split()))
a.sort()
q = a[-1]
p = a[0]
m = q
for x in a:
  if abs(q//2-x)<m:
    p = x
    m = abs(q//2-x)
print(p,q) 

Fixed code:
n = int(input())
a = list(map(int,input().split()))
a.sort()
p = a[-1]
q = a[0]
m = p
for x in a:
  if abs(p-2*x)<m:
    q = x
    m = abs(p-2*x)
print(p,q)
Buggy code:
N = int(input())
A = sorted(list(map(int, input().split())))

ans_n = A.pop()
target = ans_n / 2

ans_r = - 1
high_score = 0
for r in A:
    min_r = min(ans_n - r, r)
    if min_r > high_score:
        high_score = r
        ans_r = r

print(ans_n, ans_r)


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

ans_n = A.pop()
target = ans_n / 2

ans_r = - 1
high_score = 0
for r in A:
    min_r = min(ans_n - r, r)
    if min_r >= high_score:
        high_score = r
        ans_r = r

print(ans_n, ans_r)
Buggy code:
from bisect import bisect_left
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
x = a[-1]
b = (x+1)*1.0/2
num = bisect_left(a,int(b))
if num==0: y = a[0]
else:
	if b-a[num-1] >= a[num]-b: y = a[num]
	else: y = a[num-1]
print(x,y)

Fixed code:
from bisect import bisect_left
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
x = a[-1]
b = (x+1)*1.0/2
num = bisect_left(a,int(b))
if num==0: y = a[0]
else:
	if b-a[num-1] > a[num]-b: y = a[num]
	else: y = a[num-1]
if n==2: y=a[0]
print(x,y)
Buggy code:
n=int(input())
A=list(map(int,input().split()))
x=max(A)
B=[abs(x/2-a) for a in A]
y=A[B.index(min(B))]
print(x,y)

Fixed code:
n=int(input())
A=list(map(int,input().split()))
x=max(A)
A.remove(x)
B=[abs(x/2-a) for a in A]
y=A[B.index(min(B))]
print(x,y)
Buggy code:
N = int(input())
A = list(map(int, input().split()))

A.sort()
x = A[-1]
A.pop()

z = x

for a in A:
    if abs(x-a*2) < abs(x-z*2):
        z = a

print(x, z)

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

A.sort()
x = A[-1]
A.pop()

z = x*10

for a in A:
    if abs(x-a*2) < abs(x-z*2):
        z = a

print(x, z)
Buggy code:
N = int(input())
L = list(map(int, input().split()))
L = sorted(L)

import math
import bisect
max = L[-1]
maxdiv2 = max//2
posleft = bisect.bisect_left(L, maxdiv2)
posright = bisect.bisect_right(L, maxdiv2)

if posleft!= posright:
	print(max, L[posleft])
	exit()

if abs(max/2 - L[posleft]) > abs(max/2 - L[posleft-1]):
	print(max, L[posleft-1])
else:
	print(max, L[posleft])

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

import math
import bisect
max = L[-1]
maxdiv2 = max//2
posleft = bisect.bisect_left(L, maxdiv2)
posright = bisect.bisect_right(L, maxdiv2)

if len(L) == 2:
	print(L[1], L[0])
	exit()

if posleft!= posright:
	print(max, L[posleft])
	exit()

if abs(max/2 - L[posleft]) > abs(max/2 - L[posleft-1]):
	print(max, L[posleft-1])
else:
	print(max, L[posleft])
Buggy code:
N=int(input())
A = list(map(int, input().split()))

ans1 = max(A)
kouho = ans1 // 2
A.sort()
for i in range(N):
    if(A[i] >= kouho):
        kouho1 = A[i]
        kouho2 = A[i-1]

if (ans1 == kouho1):
    ans2 = kouho2
elif (abs(ans1-2*kouho1) <= abs(ans1-2*kouho2)):
    ans2 = kouho1
else:
    ans2 = kouho2

print(ans1,ans2)

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

ans1 = max(A)
kouho = ans1 // 2
A.sort()
for i in range(N):
    if(A[i] >= kouho):
        kouho1 = A[i]
        kouho2 = A[i-1]
        break

if (ans1 == kouho1):
    ans2 = kouho2
elif (abs(ans1-2*kouho1) <= abs(ans1-2*kouho2)):
    ans2 = kouho1
else:
    ans2 = kouho2

print(ans1,ans2)
Buggy code:
import math
def com(x, y):
    k = math.factorial(x)
    s = math.factorial(y)
    l = math.factorial(x - y)
    return k // (s * l)
n = int(input())
a = list(map(int, input().split()))
a.sort()
max = a[-1]
target = max / 2
min = max
for i in range(n):
    if abs(a[i] - target) < abs(min - target):
        min = a[i]
print("{} {}".format(max, min))


Fixed code:
import math
def com(x, y):
    k = math.factorial(x)
    s = math.factorial(y)
    l = math.factorial(x - y)
    return k // (s * l)
n = int(input())
a = list(map(int, input().split()))
a.sort()
max = a[-1]
target = max / 2
min = a[0]
for i in range(n - 1):
    if abs(a[i] - target) < abs(min - target):
        min = a[i]
print("{} {}".format(max, min))
Buggy code:
n = int(input())
a = [0]*n
a = list(map(int, input().split()))

a.sort()
hoge = a[n-1] / 2 - a[0]
ans = 0
for i in range(n-1):
    print(abs(a[n-1] / 2 - a[i+1]))
    if abs(a[n-1] / 2 - a[i+1]) > hoge:
        ans = i
        break
    else:
        hoge = abs(a[n-1] / 2 - a[i+1])

print(a[n-1], a[ans])

Fixed code:

n = int(input())
a = [0]*n
a = list(map(int, input().split()))

a.sort()
hoge = a[n-1] / 2 - a[0]
ans = 0
for i in range(n-1):
    if abs(a[n-1] / 2 - a[i+1]) > hoge:
        ans = i
        break
    else:
        hoge = abs(a[n-1] / 2 - a[i+1])

print(a[n-1], a[ans])
Buggy code:
n = int(input())
a = list(map(int,input().split()))
d = max(a)
f = d
for v in a:
  if abs(v-d/2) < abs(f-d/2):
    f = v
print(d,f)

Fixed code:
n = int(input())
a = list(map(int,input().split()))
d = max(a)
f = d
for v in a:
  if abs(v-d/2) < abs(f-d/2):
    f = v
  elif abs(v-d/2) == abs(f-d/2):
    f = min(f,v)
print(d,f)
Buggy code:
n = int(input())
a_n = list(map(int, input().split()))
result1 = max(a_n)
min_delta = max(a_n)
result2 = max(a_n)
for num in a_n:
    if abs(num-n/2)<min_delta:
        result2 = num
print('{} {}'.format(result1, result2))

Fixed code:
n = int(input())
a_n = list(map(int, input().split()))
result1 = max(a_n)
min_delta = max(a_n)
result2 = max(a_n)
for num in a_n:
    if num == result1:
        pass
    elif abs(num-result1/2)<=min_delta:
        min_delta = abs(num-result1/2)
        result2 = num
print('{} {}'.format(result1, result2))
Buggy code:
n = int(input())
l = list(map(int, input().split()))
l.sort()
m = l.pop()
a = 0
ans = 0
for r in l:
  if abs((m / 2) - r) < a:
    a = abs((m / 2) - r)
    ans = r
print(m, ans)

Fixed code:
n = int(input())
l = list(map(int, input().split()))
l.sort()
m = l.pop()
a = m
ans = 0
for r in l:
  if abs((m / 2) - r) < a:
    a = abs((m / 2) - r)
    ans = r
print(m, ans)
Buggy code:
n=int(input())
a=list(map(int,input().split()))
b=max(a)
c=b
d=0
for i in a:
  if c<abs(b/2-i):c=abs(b/2-i);d=i
print(b,d)

Fixed code:
n=int(input())
a=list(map(int,input().split()))
b=max(a)
c=b
d=0
for i in a:
  if c>=abs(b/2-i):c=abs(b/2-i);d=i
print(b,d)
Buggy code:
import bisect as bs
l=int(input())
lst=sorted(list(map(int,input().split())))
n=lst[l-1]
lst[l-1]=float("inf")
m=bs.bisect_left(lst,n/2)
if n/2 - lst[m] <= lst[m+1] -n/2:
  print(n,lst[m])
else:
  print(n,lst[m+1])


Fixed code:
import bisect as bs
l=int(input())
lst=sorted(list(map(int,input().split())))
n=lst[l-1]
lst[l-1]=float("inf")
m=bs.bisect_right(lst,n/2)
if n/2 - lst[m-1] <= lst[m] -n/2:
  print(n,lst[m-1])
else:
  print(n,lst[m])
Buggy code:
n=int(input())
A=list(map(int,input().split()))
A.sort()

a=A[-1]/2 + 0.5
tmp=A[-1]
ans=0
for i in range(n):
    if(abs(a-A[i]) < tmp):
        tmp=abs(a-A[i])
        ans=A[i]

print("{} {}".format(A[-1],ans))

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

a=A[-1]/2
tmp=A[-1]
ans=0
for i in range(n):
    if(abs(a-A[i]) < tmp):
        tmp=abs(a-A[i])
        ans=A[i]

print("{} {}".format(A[-1],ans))
Buggy code:
N = int(input())
A = [int(x) for x in input().split()]
A.sort()
a_half = A[-1] // 2
def binsearch(upper, lower):
  if upper - lower == 1:
    if abs(A[upper] - a_half) > abs(a_half - A[lower]):
      return lower
    else:
      return upper
  med = (upper + lower) // 2
  if A[med] == a_half:
    return med
  elif A[med] > a_half:
    return binsearch(med, lower)
  else:
    return binsearch(upper, med)
print(A[-1], A[binsearch(N - 1, 0)])

Fixed code:
N = int(input())
A = [int(x) for x in input().split()]
A.sort()
a_half = A[-1] // 2
def binsearch(upper, lower):
  if upper - lower == 1:
    if A[upper] == A[-1] or abs(A[upper] - a_half) > abs(a_half - A[lower]):
      return lower
    else:
      return upper
  med = (upper + lower) // 2
  if A[med] == a_half:
    return med
  elif A[med] > a_half:
    return binsearch(med, lower)
  else:
    return binsearch(upper, med)
print(A[-1], A[binsearch(N - 1, 0)])
Buggy code:
n=int(input())
a=[0]+sorted(list(map(int,input().split())))
x=a[-1]
m=a[-1]
for i in a:
  if m>abs(i-x):y=i
print(x,y)

Fixed code:
n=int(input())
a=[0]+sorted(list(map(int,input().split())))
x=a[-1]
m=a[-1]
for i in a:
  if m>abs(i-x/2):
    y=i
    m=abs(i-x/2)
print(x,y)
Buggy code:
a = int(input())
x = list(map(float, input().split()))
m = max(x)
M = m/2
t = 0
s = float("INF")
for i in x:
    print(s,abs(M-i),i,M)
    if s >= abs(M-i):
        s = min(s,abs(M-i))
        t = i
print(str(m)+" "+str(t))

Fixed code:
a = int(input())
x = list(map(float, input().split()))
m = max(x)
M = m/2
t = 0
s = float("INF")
for i in x:
    #print(s,abs(M-i),i,M)
    if s >= abs(M-i):
        s = min(s,abs(M-i))
        t = i
print(str(int(m))+" "+str(int(t)))
Buggy code:
n=int(input())
a=list(map(int, input().split()))
ans=[]
x=max(a)
ans.append(x)
y=x//2+1
b=10**9
d=10**9
for i in range(n):
    c=abs(a[i]-y)
    if b>c:
        d=a[i]
    b=min(b,c)
ans.append(d)
print(*ans)

    



Fixed code:
n=int(input())
a=list(map(int, input().split()))
ans=[]
x=max(a)
ans.append(x)
a.remove(max(a))
y=x/2
b=10**10
d=10**10

for i in range(n-1):
    c=abs(a[i]-y)
    if b>c:
        d=a[i]
    b=min(b,c)
ans.append(d)
print(*ans)
Buggy code:
n=int(input())
a=list(map(int,input().split()))
mx=max(a)
d=mx
ans=0
for i in a:
  if abs(i-mx/2)<d:
    d=abs(i-mx/2)
    ans=i
print(mx,ans)



Fixed code:
n=int(input())
a=list(map(int,input().split()))
mx=max(a)
d=mx/2
ans=0
for i in a:
  if abs(i-mx/2)<d:
    d=abs(i-mx/2)
    ans=i
print(mx,ans)
Buggy code:
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    a = list(map(int, input().split()))

    ans1 = max(a)
    half = ans1 // 2
    min_ = abs(a[0] - half)
    ans2 = a[0]
    for i in range(1, N):
        if a[i] != ans1:
            tmp = abs(a[i] - half)
            if tmp <= min_:
                ans2 = a[i]
                min_ = tmp
    print(ans1, ans2)

if __name__ == "__main__":
    main()

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

def main():
    N = int(input())
    a = list(map(int, input().split()))

    ans1 = max(a)
    half = ans1 / 2
    min_ = abs(a[0] - half)
    ans2 = a[0]
    for i in range(1, N):
        if a[i] != ans1:
            tmp = abs(a[i] - half)
            if tmp <= min_:
                ans2 = a[i]
                min_ = tmp
    print(ans1, ans2)

if __name__ == "__main__":
    main()
Buggy code:
n = int(input())
a = list(map(int, input().split()))
i = max(a)
j = min(a, key=lambda x:abs(i - x*2))
print(i, j)

Fixed code:
n = int(input())
a = list(map(int, input().split()))
a_sorted = sorted(a)
i = max(a_sorted)
j = min(a_sorted, key = lambda x:abs(i - 2 * x))
print(i, j)
Buggy code:
n = int(input())
a = list(map(int, input().split()))
m = max(a)
print(m,min(a,key=lambda x:abs(m-x*2)))

Fixed code:
n = int(input())
a = sorted(list(map(int, input().split())))
m = max(a)
print(m,min(a,key=lambda x:abs(m-x*2)))
Buggy code:
import bisect

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

    A.sort()
    n = A[-1]
    i = bisect.bisect_left(A, n // 2)
    r = A[i]
    print(n, r)

main()


Fixed code:
import bisect

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

    A.sort()
    n = A[-1]
    i = bisect.bisect_left(A, n / 2)
    if n / 2 - A[i-1] <= A[i] - n / 2:
        r = A[i-1]
    else:
        r = A[i]
    print(n, r)

main()
Buggy code:
from bisect import bisect_left

n=int(input())
a=list(map(int,input().split()))
a.sort()

maxi=a[-1]
tmp=maxi/2
idx=bisect_left(a,tmp)
if idx==n-1:
  idx -=1

if a[idx]-tmp>a[idx-1]-tmp:
  idx -=1 
  
print(maxi,a[idx])

Fixed code:
from bisect import bisect_left,bisect_right

n=int(input())
a=list(map(int,input().split()))
a.sort()

maxi=a[-1]
tmp=maxi/2
idx=bisect_left(a,tmp)

if a[idx]-tmp > tmp-a[idx-1] :
  idx += -1

if idx==n-1:
  idx += -1
  
print(maxi,a[idx])
Buggy code:
n = int(input())
a = list(map(int, input().split()))

N = max(a)

li = [abs(N/2 - k) for k in a]
index = li.index(min(li))

print("{0} {1}".format(N, a[index]))


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

a.sort()

N = a[-1]
a.pop()

li = [abs(N/2 - k) for k in a]
index = li.index(min(li))

print("{0} {1}".format(N, a[index]))
Buggy code:
n = int(input())
a = list(map(int, input().split()))
comb = []

N = max(a)
comb.append(N)

li = [abs(N/2 - k) for k in a]
index = li.index(min(li))

comb.append(a[index])

print("{0} {1}".format(N, a[index]))

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

N = max(a)
a.remove(N)

li = [abs(N/2 - k) for k in a]
index = li.index(min(li))

print("{0} {1}".format(N, a[index]))
Buggy code:
n = int(input())
A = list(map(int,input().split()))
A.sort()
diff = 10**10
ans = A[0]
print(A[n-1]//2+1)
for i in range(n-1):
    if abs((A[n-1]//2+1)-A[i]) < diff:
         ans = A[i]
         diff = min(diff,abs((A[n-1]//2+1)-A[i]))
print(A[n-1],ans)

Fixed code:
n = int(input())
A = list(map(int,input().split()))
A.sort()
diff = 10**10
ans = A[0]
#print(A[n-1]//2+1)
for i in range(n-1):
    if abs(A[n-1]/2-A[i]) < diff:
         ans = A[i]
         diff = min(diff,abs(A[n-1]/2-A[i]))
print(A[n-1],ans)