qyliang/CodeNanoFix huggingface dataset:
Buggy code:
import bisect

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

ans1=a[-2]

index=bisect.bisect_right(a,(ans1)//2)

b1=a[index-1]
b2=a[index]

if abs((ans1)/2-b1)<abs((ans1)/2-b2):ans2=b1
else:ans2=b2

print(a)
print(b1,b2)
print(index)

print(ans1,ans2,sep=" ")

Fixed code:
import bisect

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

ans1=a[-2]

index=bisect.bisect_right(a,(ans1)//2)

b1=a[index-1]
b2=a[index]

if abs((ans1)/2-b1)<=abs((ans1)/2-b2):ans2=b1
else:ans2=b2

print(ans1,ans2,sep=" ")
Buggy code:

n = int(input())
num_list = sorted([ int(v) for v in input().split() ])

x = num_list[-1]
x_half = x / 2
y = bisect.bisect_left(num_list,x_half)
if y != 0:
    if y == n-1:
        y -= 1
    else:
        if abs(num_list[y] - x_half) >= abs(num_list[y-1] - x_half):
            y -= 1
print(x,num_list[y])

Fixed code:
import bisect

n = int(input())
num_list = sorted([ int(v) for v in input().split() ])

x = num_list[-1]
x_half = x / 2
y = bisect.bisect_left(num_list,x_half)
if y != 0:
    if y == n-1:
        y -= 1
    else:
        if abs(num_list[y] - x_half) >= abs(num_list[y-1] - x_half):
            y -= 1
print(x,num_list[y])
Buggy code:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque

INF = 1 << 50

def run():
    n = int(sysread())
    A = list(map(int, sysread().split()))
    #print(A)
    A = sorted(A)
    #print(n, A)
    idx = bisect.bisect_left(A, A[-1] / 2)
    if idx == 0:
        print(f'{A[-1]} {A[0]}')
    else:
        val1 = A[idx]
        val2 = A[idx-1]
        if abs(val1 - A[-1]) / 2 > abs(val2 - A[-1]) / 2:
            print(f'{A[-1]} {val2}')
        else:
            print(f'{A[-1]} {val1}')


if __name__ == "__main__":
    run()

Fixed code:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque

INF = 1 << 50

def run():
    n = int(sysread())
    A = list(map(int, sysread().split()))
    #print(A)
    A = sorted(A)
    #print(n, A)
    idx = bisect.bisect_left(A, A[-1] / 2)
    if idx == 0:
        print(f'{A[-1]} {A[0]}')
    elif idx == n-1:
        print(f'{A[-1]} {A[-2]}')
    else:
        val1 = A[idx]
        val2 = A[idx-1]
        if abs(val1 - A[-1] / 2) > abs(val2 - A[-1] / 2):
            print(f'{A[-1]} {val2}')
        else:
            print(f'{A[-1]} {val1}')


if __name__ == "__main__":
    run()
Buggy code:
n=int(input())
a=list(map(int,input().split()))

b=max(a)
d=b/2

c=abs(d-a[0])
#print(c)
ans=a[0]
for i in a:
  #print(abs(i-d))
  if abs(i-d)<c:
    ans=i
    c=abs(i-d)
    
print(b,end=" ")
print(ans)

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

b=max(a)
d=b/2

c=abs(d-a[0])
#print(c)
if a[0]==b:
  c=99999
ans=a[0]
for i in a:
  #print(abs(i-d))
  if i==b:
    continue
  if abs(i-d)<c:
    ans=i
    c=abs(i-d)
    
print(b,end=" ")
print(ans)
Buggy code:
n = int(input())
a = list(map(int,input().split()))

sort_a = sorted(a,reverse=True)
max_a = sort_a[0]

ans=0
for i in range(n):
  if min(abs(max_a//2-sort_a[i]),abs(max_a//2-ans)) == abs(max_a//2-sort_a[i]):
    ans = sort_a[i]
print(max_a,ans)

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

sort_a = sorted(a,reverse=True)
max_a = sort_a[0]

ans=0
for i in range(n):
  if min(abs(max_a/2-sort_a[i]),abs(max_a/2-ans)) == abs(max_a/2-sort_a[i]):
    ans = sort_a[i]
print(max_a,ans)
Buggy code:
n = int(input())
numbers =list(map(int,input().split()))
sornum =sorted(numbers, reverse=True)

ans =0
d_min = sornum[0]

for i in range(n):
   d =abs(sornum[0]/2-sornum[i])
   if d<d_min:
      d_min =d
      ans = sornum[i]

print('{} {}'.format(sornum[0], ans))



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

ans =0
d_min = sornum[0]

for i in range(n-1):
   d =abs(sornum[0]/2-sornum[i+1])
   if d<d_min:
      d_min =d
      ans = sornum[i+1]

print('{} {}'.format(sornum[0], ans))
Buggy code:
# coding:utf-8

import sys


input = sys.stdin.readline


def inpl(): return list(map(int, input().split()))


N = int(input())
A = inpl()

a = max(A)
tmp = 0
for i in range(N):
    x = A[i]
    if x == a: continue
    x = max(x, a - x)
    if tmp < a - x:
        b = A[i]
        tmp = a - x

print(a, b)


Fixed code:
# coding:utf-8

import sys


input = sys.stdin.readline


def inpl(): return list(map(int, input().split()))


N = int(input())
A = inpl()

a = max(A)
tmp = 0
b = min(A)
for i in range(N):
    x = A[i]
    if x == a: continue
    x = max(x, a - x)
    if tmp < a - x:
        b = A[i]
        tmp = a - x

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

enu=max(a)

k=(enu)/2
sa=float("inf")

for i in range(n):
    if abs(k-a[i])<sa:
        sa=k-a[i]
        aru=a[i]

print(enu,aru)

Fixed code:
n=int(input())
a=[int(i) for i in input().split()]
 
enu=max(a)
 
k=(enu)/2
sa=float("inf")
 
for i in range(n):
    if abs(k-a[i])<sa and a[i]!=enu:
        sa=abs(k-a[i])
        aru=a[i]
 
print(enu,aru)
Buggy code:

n=int(input())
A=sorted(list(map(int, input())))
amax=max(A)
half=amax/2

ans=0
now=amax
for a in A:
  if abs(a-half)<=now:
    now=abs(a-half)
    ans=a
print(amax, ans)

Fixed code:

n=int(input())
A=sorted(list(map(int, input().split())))
amax=max(A)
half=amax/2

ans=0
now=amax
for a in A:
  if abs(a-half)<=now and a<amax:
    now=abs(a-half)
    ans=a
print(amax, ans)
Buggy code:
import bisect
n = int(input())
a = sorted(list(map(int,input().split())))
ans = 0
mini = float('inf')
for i in range(n):
    if mini > abs(a[i]-a[n-1]//2):
        ans = i
        mini = abs(a[i]-a[n-1]//2)
print(a[n-1],a[ans])

Fixed code:
import bisect
n = int(input())
a = sorted(list(map(int,input().split())))
ans = 0
mini = float('inf')
for i in range(n):
    if mini > abs(a[i]-a[n-1]/2):
        ans = i
        mini = abs(a[i]-a[n-1]/2)
print(a[n-1],a[ans])
Buggy code:
n = int(input())
a = list(map(int, input().split()))

half = max(a) / 2
sa = float("inf")
ans = 0
for i in a:
    if i != max(a):
        if abs(half - i) < sa:
            ans = i
            sa = abs(half - i)

print(a[0], ans)

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

m = max(a)
half = m / 2
sa = float("inf")
ans = 0
for i in a:
    if i != m:
        if abs(half - i) < sa:
            ans = i
            sa = abs(half - i)

print(m, ans)
Buggy code:
N = int(input())
a = list(map(int, input().split()))

n = max(a)
d = list(map(lambda ai: abs(n / 2 - ai), a))
i = d.index(min(d))
r = a[i]

print(n, r)


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

n = max(a)
a.remove(n)
d = list(map(lambda ai: abs(n / 2 - ai), a))
i = d.index(min(d))
r = a[i]

print(n, r)
Buggy code:
import sys
Input = sys.stdin.readline
#Input = input

n = int(Input())
a = list(map(int, Input().split()))

c_n = max(a)
c_r = None
c_r_err = float("inf")
for i in a:
    err = abs((c_n//2) - i)
    if err < c_r_err:
        c_r = i
        c_r_err = err

print("{0} {1}".format(c_n, c_r))

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

n = int(Input())
a = list(map(int, Input().split()))

c_n = max(a)
c_r = None
c_r_err = float("inf")
for i in a:
    if i == c_n:
        continue
    err = abs((c_n/2) - i)
    if err < c_r_err:
        c_r = i
        c_r_err = err

print("{0} {1}".format(c_n, c_r))
Buggy code:

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

def f(N, A):
    
    if len(A) == 2:
        A.sort()
        print(A[1], A[0])
        return

    maxA = max(A)
    res = 0
    
    for a in A:
        if a == maxA:
            continue
        
        b = min(a, maxA - a)
        if res < b:
            res = b
        
    return print(maxA, res)

f(N, A)   

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

def f(N, A):
    
    if len(A) == 2:
        A.sort()
        print(A[1], A[0])
        return

    res = 0
    temp = 0
    maxA = max(A)

    for a in A:
        if a == maxA:
            continue
        
        b = min(a, maxA - a)
        if temp < b:
            temp = b
            res = a
        
    return print(maxA, res)

f(N, A)
Buggy code:
n = int(input())
a = list(map(int, input().split()))

a_max = sorted(a)[-1]

dif = []
for i,ai in enumerate(a):
    dif.append((i,abs(ai-(a_max/2))))

dif_i = sorted(dif, key=lambda x:x[1])[0][0]
dif_min = a[dif_i]

print(a_max, dif_min)

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

sorted_a = sorted(a)
a_max = sorted_a[-1]

dif = []
for i,ai in enumerate(sorted_a[:n-1]):
    dif.append((i,abs(ai-(a_max/2))))

min_i = sorted(dif, key=lambda x:x[1])[0][0]
dif_min = sorted_a[min_i]

print(a_max, dif_min)
Buggy code:
def main():
    n = int(input())
    A = list(map(int, input().split()))

    A = sorted(A)
    x = A[-1]
    del A[-1]
    b = x // 2

    m = 10**9
    y = A[0]
    for a in A:
        mm = abs(a - b)
        if mm < m:
            m = mm
            y = a

    print(x, y)


main()


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

    A = sorted(A)
    x = A[-1]
    del A[-1]
    b = x / 2

    m = 10**9
    y = A[0]
    for a in A:
        mm = abs(a - b)
        if mm < m:
            m = mm
            y = a

    print(x, y)


main()
Buggy code:
n = int(input())
a = list(map(int,input().split()))
dis = [abs(max(a)/2 - a[i]) for i in range(n-1)]
r = a[dis.index(min(dis))]
print(max(a),r)

Fixed code:
n = int(input())
a = list(map(int,input().split()))
m = max(a)
del a[a.index(m)]
dis = [abs(m/2 - a[i]) for i in range(n-1)]
r = a[dis.index(min(dis))]
print(m,r)
Buggy code:
n = int(input())
a = list(map(int,input().split()))
a.sort()
dis = [abs(a[-1]//2 - a[i]) for i in range(n-1)]
r = a[a.index(min(a))]
print(a[-1],a[a.index(min(a))])

Fixed code:
n = int(input())
a = list(map(int,input().split()))
a.sort()
dis = [abs(a[-1]/2 - a[i]) for i in range(n-1)]
r = a[dis.index(min(dis))]
print(a[-1],r)
Buggy code:
n = int(input())
A = list(map(int,input().split()))
ans1 = max(A)
ans2 = 0
minid = 10**9
for a in A:
    if abs(ans1/2-a) < minid:
        minid = ans1/2-a
        ans2 = a
print(ans1, ans2)

Fixed code:
n = int(input())
A = list(map(int,input().split()))
ans1 = max(A)
ans2 = 0
minid = 10**9+1
for a in A:
    if abs(ans1/2-a) <= minid:
        minid = abs(ans1/2-a)
        ans2 = a
print(ans1, ans2)
Buggy code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
c=a[n-1]
if c%2==0:
  p=c//2
  o=10**9
  for i in range(n):
    if abs(p-a[i])<=o:
      o=abs(p-a[i])
      ans=a[i]
else:
  p=c//2
  q=c//2+1
  o=10**9
  for i in range(n):
    if abs(p-a[i])<abs(q-a[i]):
      if abs(p-a[i])<o:
        o=abs(p-a[i])
        ans=a[i]
    else:
      if abs(q-a[i])<o:
        o=abs(q-a[i])
        ans=a[i]
print(c,ans)

Fixed code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
c=a[n-1]
if n==2:
  print(a[1],a[0])
  exit()
if c%2==0:
  p=c//2
  o=10**9
  for i in range(n):
    if abs(p-a[i])<=o:
      o=abs(p-a[i])
      ans=a[i]
else:
  p=c//2
  q=c//2+1
  o=10**9
  for i in range(n):
    if abs(p-a[i])<abs(q-a[i]):
      if abs(p-a[i])<o:
        o=abs(p-a[i])
        ans=a[i]
    else:
      if abs(q-a[i])<o:
        o=abs(q-a[i])
        ans=a[i]
print(c,ans)
Buggy code:
import sys
input = sys.stdin.readline

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

ans = [-1, 0, 0]

import bisect

i = a[-1]
idx = [bisect.bisect_left(a, i // 2), bisect.bisect_left(a, i // 2) - 1]

if abs(i // 2 - a[idx[0]]) < abs(i // 2 - a[idx[1]]):
    print(i, a[idx[0]])    
else:
    print(i, a[idx[1]])


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

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

ans = [-1, 0, 0]

import bisect

i = a[-1]
idx = [bisect.bisect_left(a, i / 2), bisect.bisect_left(a, i / 2) - 1]

if abs(i / 2 - a[idx[0]]) < abs(i // 2 - a[idx[1]]):
    print(i, a[idx[0]])    
else:
    print(i, a[idx[1]])
Buggy code:
n = int(input())
a = list(map(int, input().split()))
m = max(a)
ans = ' '.join((
    str(m),
    str(max(a, key=lambda x: min(x, m - x)))
))
print(ans)


Fixed code:
n = int(input())
a = list(map(int, input().split()))
m = max(a)
ans = ' '.join((
    str(m),
    str(max(sorted(a), key=lambda x: min(x, m - x)))
))
print(ans)
Buggy code:
from bisect import bisect_left

N = int(input())
data = list(map(int, input().split(' ')))
sorteddata = sorted(data)

def takeClosest(myList, myNumber):
    pos = bisect_left(myList, myNumber)
    if pos == 0:
        return myList[0]
    if pos == len(myList):
        return myList[-1]
    before = myList[pos - 1]
    after = myList[pos]
    if after - myNumber < myNumber - before:
       return after
    else:
       return before

ans = takeClosest(sorteddata, sorteddata[-1] / 2)
print(sorteddata[-1] + ' ' + ans)

Fixed code:
from bisect import bisect_left

N = int(input())
data = list(map(int, input().split(' ')))
sorteddata = sorted(data)

def takeClosest(myList, myNumber):
    pos = bisect_left(myList, myNumber)
    if pos == 0:
        return myList[0]
    if pos == len(myList):
        return myList[-1]
    before = myList[pos - 1]
    after = myList[pos]
    if after - myNumber < myNumber - before:
       return after
    else:
       return before

ans = takeClosest(sorteddata, sorteddata[-1] / 2)
print(str(sorteddata[-1]) + ' ' + str(ans))
Buggy code:
n = int(input())
x = list(map(int, input().split()))
a = max(x)
b = a
for i in x:
    if abs(a/2 - i) < abs(a/2-b):
        b = i
print(a, b)

Fixed code:
n = int(input())
x = list(map(int, input().split()))
a = max(x)
b = a
for i in x:
    if abs(a/2 - i) <= abs(a/2 - b):
        b = i
print(a, b)
Buggy code:
n=int(input())
l=sorted(list(map(int,input().split())))
ans=l[0]
for i in range(n-1):
  if abs(l[-1]-ans)>abs(l[-1]-l[i]):
    ans=l[i]
print(l[-1],ans)

Fixed code:
n=int(input())
l=sorted(list(map(int,input().split())))
ans=l[0]
for i in range(n-1):
  if abs(l[-1]/2-ans)>abs(l[-1]/2-l[i]):
    ans=l[i]
print(l[-1],ans)
Buggy code:
n = int(input())
a  = list(map(int,input().split()))
N = max(a)
res = 10**9
K = 0
for i in range(n):
    
    if abs(a[i]-N/2) < res:
        res = abs(a[i] -N/2)
        K = i
print(N,a[K])


Fixed code:
n = int(input())
a  = list(map(int,input().split()))
N = max(a)
res = 10**10
k = 0
for i in range(n):
    
    if abs(a[i]-N/2) <= res:
        res = abs(a[i] -N/2)
        k = i

print(N,a[k])
Buggy code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy,bisect
from operator import itemgetter
#from heapq import heappush, heappop
#import numpy as np
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
#from scipy.sparse import csr_matrix
#from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
nf = lambda: float(ns())
na = lambda: list(map(int, stdin.readline().split()))
nb = lambda: list(map(float, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
a = na()
a.sort(reverse=True)
ans = -1
t = a[0]
target = (a[0] + (2 - 1)) // 2
#print(target)
pre = inf
for i in range(1, n):
    #print(pre)
    dif = abs(target - a[i])
    if pre < dif:
        print(t, a[i-1])
        sys.exit()
    else:
        pre = dif


Fixed code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy,bisect
from operator import itemgetter
#from heapq import heappush, heappop
#import numpy as np
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
#from scipy.sparse import csr_matrix
#from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
nf = lambda: float(ns())
na = lambda: list(map(int, stdin.readline().split()))
nb = lambda: list(map(float, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
a = na()
a.sort(reverse=True)
ans = -1
t = a[0]
target = (a[0] + (2 - 1)) // 2
#print(target)
pre = inf
if n == 2:
    print(max(a), min(a))
    sys.exit()
for i in range(1, n):
    #print(pre)
    dif = abs(target - a[i])
    if pre < dif:
        print(t, a[i-1])
        sys.exit()
    else:
        pre = dif
Buggy code:
import sys
import math
import numpy as np
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10**9)
INF = 10**9
mod = 10**9+7

def gnv(list, num):

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

N = i()
a = l()
m = max(a)
print(m,gnv(a,m/2))

Fixed code:
import sys
import math
import numpy as np
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10**9)
INF = 10**9
mod = 10**9+7

def gnv(list, num):

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

N = i()
a = l()
m = max(a)
if N == 2:
    print(m,min(a))
else:
    print(m,gnv(a,m/2))
Buggy code:
n=int(input())
a=list(map(int,input().split()))

MAX=max(a)
Harf=MAX/2

cnt=10**20
ans=0
for i in range(n):
    if abs(Harf-a[i])<cnt:
        ans=a[i]
        cnt=abs(Harf-a[i])
print(MAX,ans)

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

MAX=max(a)
Harf=MAX/2

cnt=10**20
ans=0
for i in range(n):
    if MAX==a[i]:
        continue
    elif abs(Harf-a[i])<cnt:
        ans=a[i]
        cnt=abs(Harf-a[i])
print(MAX,ans)
Buggy code:
# 1.input
n = int(input())
a = list(map(int, input().split()))

#2. choose maximum number as a_i and remove
ai = max(a)
a.remove(ai)

# 3. choose the nearest number from (a_i/2) as a_j
abs_dist = [abs(a_temp-(ai/2)) for a_temp in a]
chosen_temp = min(abs_dist)
aj = int(chosen_temp + (ai/2))

print("{} {}".format(ai, aj))

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

#2. choose maximum number as a_i and remove
ai = max(a)
a.remove(ai)

# 3. choose the nearest number from (a_i/2) as a_j
abs_dist = [abs(a_temp-(ai/2)) for a_temp in a]
chosen_temp = min(abs_dist)
aj = a[abs_dist.index(chosen_temp)]

print("{} {}".format(ai, aj))
Buggy code:
N = int(input())
a = tuple(int(x) for x in input().split())

def hoge(n, r):
 return n * (min(n-r, r))

n = max(a)
ans = (n, a[0])
for i in a[1:]:
 ans = (n, i) if hoge(*ans) < hoge(n, i) else ans
print(*ans)

Fixed code:
N = int(input())
a = sorted(int(x) for x in input().split())

def hoge(n, r):
 return n * (min(n-r, r))

n = max(a)
ans = (n, a[0])
for i in a[1:]:
 ans = (n, i) if hoge(*ans) < hoge(n, i) else ans
print(*ans)
Buggy code:
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)

max_a = max(a)
da = [abs(ai - max_a / 2) for ai in a]
med_i = da.index(min(da))

print("%d %d" % (max_a, a[med_i]))


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

max_a = max(a)
a.remove(max_a)
da = [abs(ai - max_a / 2) for ai in a]
med_i = da.index(min(da))

print("%d %d" % (max_a, a[med_i]))
Buggy code:
def main():
  n = int(input())
  a = list(map(int, input().split()))
  a.sort()
  
  r = 0
  c = n / 2
  for i in range(n-1):
    if abs(c-r) > abs(c-a[i]):
      r = a[i]
  ans = "{} {}".format(a[-1], r)
  print(ans)

  
if __name__ == "__main__":
  main()


Fixed code:
def main():
  n = int(input())
  a = list(map(int, input().split()))
  a.sort()
  
  r = 0
  c = a[-1] / 2
  for i in range(n-1):
    if abs(c-r) > abs(c-a[i]):
      r = a[i]
  ans = "{} {}".format(a[-1], r)
  print(ans)

  
if __name__ == "__main__":
  main()
Buggy code:
n = int(input())
a = list(map(int,input().split()))

import bisect
a.sort()

center = a[-1]//2

index = bisect.bisect_left(a,center)

if a[index] != center:
    if index > 0 and center - a[index-1] < a[index] - center:
        index -= 1
        
if index == N-1:
    index -= 1
    
print(a[-1],a[index])

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

import bisect
a.sort()

center = a[-1]//2

index = bisect.bisect_left(a,center)

if a[index] != center:
    if index > 0 and center - a[index-1] < a[index] - center:
        index -= 1
        
if index == n-1:
    index -= 1
    
print(a[-1],a[index])
Buggy code:
n = int(input())
A = list(map(int, input().split()))
p = max(A)
q = p
for a in A:
    if abs(p/2-a) < abs(p/2-q): q = a
print(p, q)

Fixed code:
n = int(input())
A = list(map(int, input().split()))
p = max(A)
q = 0
for a in A:
    if abs(p/2-a) < abs(p/2-q): q = a
print(p, q)
Buggy code:
n = int(input())
A = list(map(int, input().split()))

if len(A) == 2:
    print(A[1], A[0])
else:
    A.sort()

    a = A[-1]

    k = a / 2
    B = [a for a in A if a <  k]
    C = [a for a in A if a >= k]

    if k - B[-1] > C[0] - k:
        print(a, C[0])
    else:
        print(a, B[-1])


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

A.sort()

if len(A) == 2:
    print(A[1], A[0])
else:
    a = A[-1]
    k = a / 2
    B = [a for a in A if a <  k]
    C = [a for a in A if a >= k]

    if k - B[-1] > C[0] - k:
        print(a, C[0])
    else:
        print(a, B[-1])
Buggy code:
n = map(int, input().split())
alist = list(map(int, input().split()))
m = max(alist)
sbn = 10**10
for a in alist:
    if m/2 - a < sbn:
        ans = a
        sbn = m/2 - a
print(m, ans)


Fixed code:
n = map(int, input().split())
alist = list(map(int, input().split()))
m = max(alist)
sbn = 10**10
for a in alist:
    if abs(m/2 - a) < sbn and a != m:
        ans = a
        sbn = abs(m/2 - a)
print(m, ans)
Buggy code:
import bisect as bi

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

A.sort()

n=A[nn-1]
ki=bi.bisect_right(A,float(n/2))
if abs(float(n/2)-A[ki]) <= abs(float(n/2)-A[min(ki-1,0)]) :
    k=A[ki]
else :
    k=A[ki-1]

print("{} {}".format(n,k))


Fixed code:
import bisect as bi

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

A.sort()

n=A[nn-1]

ki=bi.bisect_right(A[:nn-1],float(n/2))
#print(ki)
if abs(float(n/2)-A[:nn-1][min(ki,nn-2)]) <= abs(float(n/2)-A[:nn-1][max(ki-1,0)]) :
    k=A[min(ki,nn-2)]
else :
    k=A[max(ki-1,0)]

print("{} {}".format(n,k))
Buggy code:
# -*- coding: utf-8 -*-
n = int(input())
an = list(map(int, input().split()))

ai = max(an)
tmpdiff = 10**9
aj = 0
for a in an:
    if abs(ai/2-a) < tmpdiff:
        tmpdiff = abs(ai/2-a)
        aj = a

print(ai,aj)


Fixed code:
# -*- coding: utf-8 -*-
n = int(input())
an = list(map(int, input().split()))

ai = max(an)
tmpdiff = 10**9
aj = 0
for a in an:
    if ai > a and abs(ai/2-a) < tmpdiff:
        tmpdiff = abs(ai/2-a)
        aj = a

print(ai,aj)