Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = []
for i in range(N):
  A.append(int(input()))
B = list(A)
B.sort()
m1 = B[N-1]
m2 = B[N-2]
for i in range(N):
  if A.count(m1) >= 2:
    print(m1)
  else:
    if A[i] == m1:
      print(m2)
    else:
      print(m1)

Fixed submission:
N = int(input())
A = []
for i in range(N):
  A.append(int(input()))
B = list(A)
B.sort()
m1 = B[N-1]
m2 = B[N-2]
#a = A.count(m1)
for i in range(N):
  if A[i] == m1:
    print(m2)
  else:
    print(m1)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = []
for i in range(N):
  A.append(int(input()))
m = max(A)
for i in range(N):
  if A.count(m) >= 2:
    print(m)
  elif m == A[i]:
    B = A.pop(i)
    print(max(A))
    A.insert(i,B)
  else:
    print(m)

Fixed submission:
N = int(input())
A = []
for i in range(N):
  A.append(int(input()))
B = list(A)
B.sort()
m1 = B[N-1]
m2 = B[N-2]
#a = A.count(m1)
for i in range(N):
  if A[i] == m1:
    print(m2)
  else:
    print(m1)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = []
for i in range(N):
  A.append(int(input()))
m = max(A)
for i in range(N):
  if m == A[i]:
    B = A.pop(i)
    print(max(A))
    A.insert(i,B)
  else:
    print(m)

Fixed submission:
N = int(input())
A = []
for i in range(N):
  A.append(int(input()))
B = list(A)
B.sort()
m1 = B[N-1]
m2 = B[N-2]
#a = A.count(m1)
for i in range(N):
  if A[i] == m1:
    print(m2)
  else:
    print(m1)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = []
for i in range(N):
  A.append(int(input()))
for i in range(N):
  B = A.pop(i)
  print(max(A))
  A.insert(i,B)

Fixed submission:
N = int(input())
A = []
for i in range(N):
  A.append(int(input()))
B = list(A)
B.sort()
m1 = B[N-1]
m2 = B[N-2]
#a = A.count(m1)
for i in range(N):
  if A[i] == m1:
    print(m2)
  else:
    print(m1)
Buggy python submission (verdict: Runtime Error):
N,X = (int(x) for x in input().split())
L = [int(x) for x in input().split()]
s = 0
i = 0
while (s <= X):
  if i > N:
    print(N)
    quit()
  else:
    s = s + L[i]
    i = i + 1
print(i)



Fixed submission:
N,X = (int(x) for x in input().split())
L = [int(x) for x in input().split()]
s = 0
i = 0
while (s <= X):
  if i >= N:
    print(N+1)
    quit()
  else:
    s = s + L[i]
    i = i + 1
print(i)
Buggy python submission (verdict: Runtime Error):
N,M = (int(x) for x in input().split())
a = [0]*N  
k = []
ans = 0
for i in range(M):
  k = [int(x) for x in input().split()]
  for j in range(k[0]): #kよりつながっている電球を一個ずつ見てる
    s = k[j+1]-1
#    print(i,j,s,a[s],a)
    a[s] = a[s] | (1<<i) #aは各スイッチがつながっている電球の情報を保持
#   左端はMとつながっているかどうかを表す。
    #a[0]＝10100はスイッチ０が電球4と電球2とつながっていることを表している。
p = [int(x) for x in input().split()]
P = 0
for i in range(M):
  P |= p[i] << i　
  #Pはpの情報を全て持っている二進数。例えば、P＝10011は電球４、１、０が
  # on になっているスイッチの個数を2で割った余りが１の時点灯するを表す
  #左端がMは統一されている
for s in range(1<<N):　　#1<<N は2**nと同じ
  t = 0
  for i in range(N):
    if ((s>>i) & 1):　#スイッチオンだったら
      t ^= a[i]		
      #これはXORを使って、スイッチがonになっているスイッチの個数を２で割ったあまりを表している
  if (t == P):	#もし、t＝＝Pなら、当てはまっているので、ans++する。
    ans += 1
print(ans)

Fixed submission:
N,M = (int(x) for x in input().split())
a = [0]*N  
k = []
ans = 0
for i in range(M):
  k = [int(x) for x in input().split()]
  for j in range(k[0]): #kよりつながっている電球を一個ずつ見てる
    s = k[j+1]-1
#    print(i,j,s,a[s],a)
    a[s] = a[s] | (1<<i)
#   print(i,j,s,a[s],a)
    #二進数でi桁目が１のとき、スイッチsとi番目の電球がつながっている?
p = [int(x) for x in input().split()]
P = 0
for i in range(M):
  P |= p[i] << i
for s in range(1<<N):
  t = 0
  for i in range(N):
    if ((s>>i) & 1):
      t ^= a[i]
  if (t == P):
    ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,M = (int(x) for x in input().split())
lr = []
for i in range(1,N+1):
  lr.append(i)
l,r = (int(x) for x in input().split())
d = set(lr[l-1:r])
for i in range(1,M):
  l,r = (int(x) for x in input().split())
  d = d & set(lr[l-1:r])
print(len(d))

  

Fixed submission:
N,M = (int(x) for x in input().split())
R = N
L = 1
for i in range(M):
  l,r = (int(x) for x in input().split())
  if l > L:
    L = l
  if r < R:
    R = r
if R-L < 0:
  print(0)
else:
  print(R-L+1)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
V = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]
m = 0
for p in range(2**N):
  value = 0
  for i in range(N):
    if ((p>>i) & 1):
      value = value + V[i] - C[i]
  if value > m:
    m = value
print(m)

Fixed submission:
N = int(input())
V = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]
m = 0
for i in range(N):
  if (V[i]-C[i]) > 0:
    m = m + V[i]-C[i]
print(m)
Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    _ = input()
    an = map(int, input().split())

    ans = 1
    for a in an:
        ans *= a
    if ans > 10 ** 18:
        ans = -1
    print(ans)

if __name__ == '__main__':
    resolve()

Fixed submission:
def resolve():
    _ = input()
    an = sorted(map(int, input().split()), reverse=True)

    ans = 1
    if an[-1] == 0:
        ans = 0
    else:
        for a in an:
            ans *= a
            if ans > 10 ** 18:
                ans = -1
                break
    print(ans)
    
if __name__ == '__main__':
    resolve()

Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    _ = input()
    A = map(int, input().split())

    from functools import reduce
    ans = reduce(lambda lhs, rhs: lhs * rhs, A)

    print(ans if ans <= 10 ** 18 else -1)

if __name__ == '__main__':
    resolve()

Fixed submission:
def resolve():
    _ = input()
    an = sorted(map(int, input().split()), reverse=True)

    ans = 1
    if an[-1] == 0:
        ans = 0
    else:
        for a in an:
            ans *= a
            if ans > 10 ** 18:
                ans = -1
                break
    print(ans)
    
if __name__ == '__main__':
    resolve()
Buggy python submission (verdict: Runtime Error):
import sys
a = list(sys.stdin.read().split())
t = [[int(n[:-1] or 0), int(n[-1])] for n in a]
t = list(zip(*t))
ans = (sum(t[0]) + (len(u := list(filter(lambda n: n > 0, t[1]))) - 1)) * 10 + min(u)
print(ans)

Fixed submission:
import sys
a = list(sys.stdin.read().split())
t = list(zip(*[[int(n[:-1] or 0), int(n[-1])] for n in a]))
print((sum(t[0]) + len((u := sorted(filter(lambda n: n > 0, t[1])))[:0:-1])) * 10 + (u and u[0] or 0))

Buggy python submission (verdict: Runtime Error):
a = list(sys.stdin.read().split())
t = [[int(n[:-1] or 0), int(n[-1])] for n in a]

t = list(zip(*t))

ans = (sum(t[0]) + (len(u := list(filter(lambda n: n > 0, t[1]))) - 1)) * 10 + min(u)
print(ans)

Fixed submission:
import sys
a = list(sys.stdin.read().split())
t = list(zip(*[[int(n[:-1] or 0), int(n[-1])] for n in a]))
print((sum(t[0]) + len((u := sorted(filter(lambda n: n > 0, t[1])))[:0:-1])) * 10 + (u and u[0] or 0))

Buggy python submission (verdict: Runtime Error):
a = list(sys.stdin.read().split())
t = [[int(n[:-1] or 0), int(n[-1])] for n in a]
print((sum(t[0]) + (len(u := list(filter(lambda n: n > 0, t[1]))) - 1)) * 10 + min(u))

Fixed submission:
import sys
a = list(sys.stdin.read().split())
t = list(zip(*[[int(n[:-1] or 0), int(n[-1])] for n in a]))
print((sum(t[0]) + len((u := sorted(filter(lambda n: n > 0, t[1])))[:0:-1])) * 10 + (u and u[0] or 0))
Buggy python submission (verdict: Runtime Error):
X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

goukei = X + Y
delicious = 0
red = 0
green = 0


def max_pop(p):
    pidx = p.index(max(p))
    maxp = p.pop(pidx)
    return maxp


maxp = max_pop(p)
maxq = max_pop(q)
maxr = max_pop(r)
maxdelis = [maxp, maxq, maxr]
for i in range(goukei):
    maxdeli = max(maxdelis)
    idx = maxdelis.index(max(maxdelis))
    delicious += maxdeli
    if idx == 0:
        red += 1
        if red == X:
            maxdelis[0] = 0
        else:
            maxdelis[0] = max_pop(p)
    elif idx == 1:
        green += 1
        if green == X:
            maxdelis[1] = 0
        else:
            maxdelis[1] = max_pop(q)
    else:
        maxdelis[2] = max_pop(r)

print(delicious)


Fixed submission:
X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p = sorted(p)[-X:]
q = sorted(q)[-Y:]
pq = p + q
pq.sort()
r.sort()
N = X + Y
cnt = 0

from collections import deque
pq = deque(pq)
r = deque(r)

pq_max = pq.pop()
r_max = r.pop()
emp = deque()

for _ in range(N):
    if pq_max >= r_max:
        cnt += pq_max
        if pq == emp:
            pq_max = 0
        else:
            pq_max = pq.pop()
    else:
        cnt += r_max
        if r == emp:
            r_max = 0
        else:
            r_max = r.pop()

print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
N, A, B = list(map(int, input().split()))
char_num = 0
counter = 0
while char_num < N:
  for a in range(A):
    if char_num >= N:
      break
    counter += 1
    char_num += 1
  for b in range(B):
    if char_num >= N:
      break
    char_num += 1
print(counter)

Fixed submission:
N, A, B = list(map(int, input().split()))
a = N//(A+B)*A
amari = N%(A+B)

if amari >= A:
  print(a + A)
else:
  print(a + amari)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
cnt = 0
for i in range(q):
  query = input()
  if query == '1':
    cnt += 1
  else:
    t, f, c = query.split()
    if (f == '1' and cnt % 2 == 0) or (f == '2' and cnt % 2 == 1):
      s = c + s
    else:
      s = s + c
if cnt % 2 == 0:
  print(s)
else:
  print(s[::-1])

Fixed submission:
from collections import deque
s = deque(input())
q = int(input())
cnt = 0
for i in range(q):
  query = input()
  if query == '1':
    cnt += 1
  else:
    t, f, c = query.split()
    if (f == '1' and cnt % 2 == 0) or (f == '2' and cnt % 2 == 1):
      s.appendleft(c)
    else:
      s.append(c)
if cnt % 2 == 0:
  print(''.join(s))
else:
  s.reverse()
  print(''.join(s))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
for i in range(q):
  query = input()
  if query == '1':
    s = s[::-1]
    continue
  else:
    t, f, c = query.split()
    if f == '1':
      s = c + s
    else:
      s = s + c
print(s)

Fixed submission:
from collections import deque
s = deque(input())
q = int(input())
cnt = 0
for i in range(q):
  query = input()
  if query == '1':
    cnt += 1
  else:
    t, f, c = query.split()
    if (f == '1' and cnt % 2 == 0) or (f == '2' and cnt % 2 == 1):
      s.appendleft(c)
    else:
      s.append(c)
if cnt % 2 == 0:
  print(''.join(s))
else:
  s.reverse()
  print(''.join(s))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
for i in range(q):
  query = input()
  if query == '1':
    s = s[::-1]
  else:
    t, f, c = query.split()
    if f == '1':
      s = c + s
    else:
      s = s + c
print(s)

Fixed submission:
from collections import deque
s = deque(input())
q = int(input())
cnt = 0
for i in range(q):
  query = input()
  if query == '1':
    cnt += 1
  else:
    t, f, c = query.split()
    if (f == '1' and cnt % 2 == 0) or (f == '2' and cnt % 2 == 1):
      s.appendleft(c)
    else:
      s.append(c)
if cnt % 2 == 0:
  print(''.join(s))
else:
  s.reverse()
  print(''.join(s))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
for i in range(q):
  query = input()
  if query == '1':
    s = s[::-1]
  else:
    t, f, c = query.split()
    if f == '1':
      s = c + s
    else:
      s = s + c
print(s)

Fixed submission:
from collections import deque
s = deque(input())
q = int(input())
cnt = 0
for i in range(q):
  query = input()
  if query == '1':
    cnt += 1
  else:
    t, f, c = query.split()
    if (f == '1' and cnt % 2 == 0) or (f == '2' and cnt % 2 == 1):
      s.appendleft(c)
    else:
      s.append(c)
if cnt % 2 == 0:
  print(''.join(s))
else:
  s.reverse()
  print(''.join(s))
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
num = ['0'] * N
si = False
error = False

for i in range(M):
    s, c = input().split()
    if num[int(s)-1] in ['0', c]:
        num[int(s)-1] = c
        if s == '1':
            s1 = True
    else:
        error = True
        break

if not s1:
    num[0] = '1'
if num[0] == '0' or error:
    print(-1)
else:
    print(''.join(num))


Fixed submission:
N, M = map(int, input().split())
num = ['0'] * N
s1 = False
error = False

for i in range(M):
    s, c = input().split()
    if num[int(s)-1] in ['0', c]:
        num[int(s)-1] = c
        if s == '1':
            s1 = True
    else:
        error = True
        break

if N != 1 and not s1:
    num[0] = '1'
if (N != 1 and num[0] == '0') or error:
    print(-1)
else:
    if N != 1 and not s1:
        num[0] = '1'
    print(''.join(num))
Buggy python submission (verdict: Runtime Error):
N = int(input())
x = list(map(int, input().split()))
l = []
minx = min(x)
maxx = max(x)
for p in range(minx, maxx):
  s = 0
  for j in range(N):
    s += (x[j]-p)**2
  l.append(s)
minp = min(l)
p = l.index(minp) + 1
hp1 = 0
hp2 = 0
for i in range(N):
  hp1 += (x[i]-p)**2
  hp2 += (x[i]-p-1)**2
print(min(hp1, hp2))

Fixed submission:
N = int(input())
x = list(map(int, input().split()))
p = int(sum(x)/N)
hp1 = 0
hp2 = 0
for i in range(N):
  hp1 += (x[i]-p)**2
  hp2 += (x[i]-p-1)**2
print(min(hp1, hp2))

Buggy python submission (verdict: Runtime Error):
N = int(input())
x = list(map(int, input().split()))
l = []
minx = min(x)
maxx = max(x)
for p in range(minx, maxx):
  s = 0
  for j in range(N):
    s += (x[j]-p)**2
  l.append(s)
minp = min(l)
p = l.index(minp)
p = int(p)
hp1 = 0
hp2 = 0
for i in range(N):
  hp1 += (x[i]-p)**2
  hp2 += (x[i]-p-1)**2
print(min(hp1, hp2))

Fixed submission:
N = int(input())
x = list(map(int, input().split()))
p = int(sum(x)/N)
hp1 = 0
hp2 = 0
for i in range(N):
  hp1 += (x[i]-p)**2
  hp2 += (x[i]-p-1)**2
print(min(hp1, hp2))

Buggy python submission (verdict: Runtime Error):
N = int(input())
x = list(map(int, input().split()))
l = []
minx = min(x)
maxx = max(x)
for p in range(minx, maxx):
  s = 0
  for j in range(N):
    s += (x[j]-p)**2
  l.append(s)
minp = min(l)
p = l.index(minp)
hp1 = 0
hp2 = 0
for i in range(N):
  hp1 += (x[i]-p)**2
  hp2 += (x[i]-p-1)**2
print(min(hp1, hp2))

Fixed submission:
N = int(input())
x = list(map(int, input().split()))
p = int(sum(x)/N)
hp1 = 0
hp2 = 0
for i in range(N):
  hp1 += (x[i]-p)**2
  hp2 += (x[i]-p-1)**2
print(min(hp1, hp2))
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n, k = map(int, input().split())
    p = list(map(lambda pi: (int(pi) + 1) / 2, input().split()))
    ex = 0
    for i in range(n - k + 1):
        ex = max(ex, sum(p[i:i + k]))
    print(ex)


if __name__ == '__main__':
    main()


Fixed submission:
n, k = map(int, input().split())
p = list(map(lambda pi: (int(pi) + 1) / 2, input().split()))
ex = sum(p[:k])
mx = ex
for i in range(n - k):
    ex += p[i + k] - p[i]
    if mx < ex:
        mx = ex
print(mx)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
p = list(map(lambda pi: (int(pi) + 1) / 2, input().split()))
ex = 0
for i in range(n-k+1):
    ex = max(ex, sum(p[i:i+k]))
print(ex)

Fixed submission:
n, k = map(int, input().split())
p = list(map(lambda pi: (int(pi) + 1) / 2, input().split()))
ex = sum(p[:k])
mx = ex
for i in range(n - k):
    ex += p[i + k] - p[i]
    if mx < ex:
        mx = ex
print(mx)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
p = list(map(lambda pi: (int(pi) + 1) / 2, input().split()))
ex = []
for i in range(n-k+1):
    ex.append(sum(p[i:i+k]))
print(max(ex))

Fixed submission:
n, k = map(int, input().split())
p = list(map(lambda pi: (int(pi) + 1) / 2, input().split()))
ex = sum(p[:k])
mx = ex
for i in range(n - k):
    ex += p[i + k] - p[i]
    if mx < ex:
        mx = ex
print(mx)
Buggy python submission (verdict: Runtime Error):
import math

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


def lcm(x, y):
    return (x * y) // math.gcd(x, y)

print(lcm(a, b))


Fixed submission:
#バージョン的にfractionsにある
import fractions

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

print((a * b) // fractions.gcd(a, b))
Buggy python submission (verdict: Time Limit Exceeded):
_  = input()
A = list(map(int, input().split()))

li = list()
for i, n in enumerate(A):
    li.append((i + 1, n))

li.sort(key=lambda x: x[1])
ans = ""
for y in li:
    ans = ans.__add__(str(y[0]) + " ")

print(ans.strip())

Fixed submission:
_  = input()
A = list(map(int, input().split()))

li = sorted( enumerate(A, 1), key=lambda x: x[1])

print(" ".join([str(i[0]) for i in li]))
Buggy python submission (verdict: Time Limit Exceeded):
N,K=[int(x) for x in input().split()]
Plist=[int(p)+1 for p in input().split()]
ans=0
for i in range(N-K+1):
    ans=max(ans, sum( Plist[i:i+K] ) )
print(ans/2)

Fixed submission:
N,K=[int(x) for x in input().split()]
Plist=[int(p)+1 for p in input().split()]
tmp=sum(Plist[0:K])
ans=tmp
for i in range(K,N):
    tmp=tmp-Plist[i-K]+Plist[i]
    ans=max(ans, tmp)
print(ans/2)
Buggy python submission (verdict: Runtime Error):
import itertools

def comb(a,b):
    if a<=0:
        return 0
    if b==1:
        return a
    elif b==2:
        return a*(a-1)//2
    else:
        return a*(a-1)*(a-2)//6

def tmp(L, K):
    ret=[]
    if K==1:
        bases=itertools.combinations(range(L+1),K)    
        for b in bases:
            ret+=[ k*10**b[0] for k in range(1,10)]
    if K==2:
        bases=itertools.combinations(range(L+1),K)
        kk=list(itertools.product(range(1,10),range(1,10)))
        for b in bases:
            ret+=[ k[0]*10**b[0] + k[1]*10**b[1] for k in kk]
    return ret

Nst=input()
K=int(input())
L=len(Nst)
N1=int(Nst[0])
N2=int(Nst[1])

if K==1:
    ans=comb( L-1, K) * 9 + N1
elif K>=2:
    ans=comb( L-1, K) * 9**(K) + comb( L-1, K-1) * 9**(K-1) *(N1-1)
    lst=[ 10**(L-1)*N1 + a for a in tmp(L-1, K-1)]
    ans+=sum([x <= int(Nst) for x in lst])
print (ans)

Fixed submission:
import itertools

def comb(a,b):
    if a<=0:
        return 0
    if b==1:
        return a
    elif b==2:
        return a*(a-1)//2
    else:
        return a*(a-1)*(a-2)//6

def tmp(L, K):
    ret=[]
    if K==1:
        bases=itertools.combinations(range(L+1),K)    
        for b in bases:
            ret+=[ k*10**b[0] for k in range(1,10)]
    if K==2:
        bases=itertools.combinations(range(L+1),K)
        kk=list(itertools.product(range(1,10),range(1,10)))
        for b in bases:
            ret+=[ k[0]*10**b[0] + k[1]*10**b[1] for k in kk]
    return ret

Nst=input()
K=int(input())
L=len(Nst)
N1=int(Nst[0])

if K==1:
    ans=comb( L-1, K) * 9 + N1
elif K>=2:
    ans=comb( L-1, K) * 9**(K) + comb( L-1, K-1) * 9**(K-1) *(N1-1)
    lst=[ 10**(L-1)*N1 + a for a in tmp(L-1, K-1)]
    ans+=sum([x <= int(Nst) for x in lst])
print (ans)
Buggy python submission (verdict: Runtime Error):
import numpy as np

a,b,x=[int(x) for x in input().split()]
if x*2<=a**2*b:
    y=2*x
    theta=np.arctan2(y,b*a*b)
else:
    theta=np.arctan2(a**3, 2*(b*a**2-x) )
print(90-theta*180/np.pi)
    

Fixed submission:
import math

a,b,x=[int(x) for x in input().split()]
if x*2<=a**2*b:
    y=2*x
    theta=math.atan2(y,b*a*b)
else:
    theta=math.atan2(a**3, 2*(b*a**2-x) )
print(90-theta*180/math.pi)
Buggy python submission (verdict: Runtime Error):
N=int(input())
print N**3

Fixed submission:
N=int(input())
print (N**3)
Buggy python submission (verdict: Runtime Error):
from bisect import *

def index(a, x):
    'Locate the leftmost value exactly equal to x'
    i = bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return i
    raise ValueError

def find_lt(a, x):
    'Find rightmost value less than x'
    i = bisect_left(a, x)
    try:
        if i:
            return a[i-1]
    except:
        return -1

def find_le(a, x):
    'Find rightmost value less than or equal to x'
    i = bisect_right(a, x)
    try:
        if i:
            return a[i-1]
    except:
        return -1

def find_gt(a, x):
    'Find leftmost value greater than x'
    i = bisect_right(a, x)
    try:
        if i != len(a):
            return a[i]
    except:
        return -1

def find_ge(a, x):
    'Find leftmost item greater than or equal to x'
    i = bisect_left(a, x)
    try:
        if i != len(a):
            return a[i]
    except:
        return -1

def fun(a,b):
    if b==-1:
        return -1
    elif b==0:
        return 0
    return (b+1)*(2*a-b)/2 - b*(b+1)/2

N=int(raw_input())
X=map(int, raw_input().split())
Y=sorted(X)
ans=[-1,0,0]
if len(Y)==2:
    print Y[1],Y[0]

else:
    for y in Y[::-1]:
        qry=y/2
        tmp1=find_ge(Y, qry)
        tmp2=find_le(Y, qry)
        if ans[0]<fun(y,tmp1):
            ans=[fun(y,tmp1),y,tmp1]
        if ans[0]<fun(y,tmp2):
            ans=[fun(y,tmp2),y,tmp2]
    print ans[1], ans[2]


Fixed submission:
from bisect import *

def index(a, x):
    'Locate the leftmost value exactly equal to x'
    i = bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return i
    raise ValueError

def find_lt(a, x):
    'Find rightmost value less than x'
    i = bisect_left(a, x)
    try:
        if i:
            return a[i-1]
    except:
        return -1

def find_le(a, x):
    'Find rightmost value less than or equal to x'
    i = bisect_right(a, x)
    try:
        if i:
            return a[i-1]
        else:
            return -1
    except:
        return -1

def find_gt(a, x):
    'Find leftmost value greater than x'
    i = bisect_right(a, x)
    try:
        if i != len(a):
            return a[i]
    except:
        return -1

def find_ge(a, x):
    'Find leftmost item greater than or equal to x'
    i = bisect_left(a, x)
    try:
        if i != len(a):
            return a[i]
        else:
            return -1
    except:
        return -1

def fun(a,b):
    if b==-1:
        return -1
    elif b==0:
        return 0
    return (b+1)*(2*a-b)/2 - b*(b+1)/2

N=int(raw_input())
X=map(int, raw_input().split())
Y=sorted(X)
ans=[-1,0,0]
if len(Y)==2:
    print Y[1],Y[0]

else:
    for y in Y[::-1]:
        qry=y/2
        tmp1=find_ge(Y, qry)
        tmp2=find_le(Y, qry)
        if ans[0]<fun(y,tmp1):
            ans=[fun(y,tmp1),y,tmp1]
        if ans[0]<fun(y,tmp2):
            ans=[fun(y,tmp2),y,tmp2]
    print ans[1], ans[2]
Buggy python submission (verdict: Runtime Error):
[N,Z,W]=map(int,raw_input().split())
A=map(int,raw_input().split())

if abs(A[-1]-W)>abs(A[-1]-A[-2]):
    print abs(A[-1]-W)
else:
    print abs(A[-1]-A[-2])


Fixed submission:
[N,Z,W]=map(int,raw_input().split())
A=map(int,raw_input().split())

if len(A)==1:
    print abs(A[-1]-W)
else:
    if abs(A[-1]-W)>abs(A[-1]-A[-2]):
        print abs(A[-1]-W)
    else:
        print abs(A[-1]-A[-2])
Buggy python submission (verdict: Time Limit Exceeded):
import bisect

def index(a, x):
    'Locate the leftmost value exactly equal to x'
    i = bisect.bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return [1,i]
    return [0,0]


N=int(raw_input())
D=sorted(map(int, raw_input().split()))
M=int(raw_input())
T=sorted(map(int, raw_input().split()))

ans=["NO","YES"]
a=1

for t in T:
    [a,i]=index(D,t)
    if a==0: break
    D.pop(i)
print ans[a]


Fixed submission:
#import bisect

#def index(a, x):
#    'Locate the leftmost value exactly equal to x'
#    i = bisect.bisect_left(a, x)
#    if i != len(a) and a[i] == x:
#        return [1,i]
#    return [0,0]


N=int(raw_input())
D=sorted(map(int, raw_input().split()))
M=int(raw_input())
T=sorted(map(int, raw_input().split()))

DD={}
for d in D:
    if d not in DD:
        DD[d] = 1
    else:
        DD[d]+=1

ans=["NO","YES"]
a=1

for t in T:
    try:
        if DD[t]>0:
            DD[t]-=1
        else:
            a=0
            break
    except:
        a=0
        break
print ans[a]
Buggy python submission (verdict: Runtime Error):
[N,M,K]= map(int, raw_input().split())
ans=["No","Yes"]
f=0
for m in range(M+1):
    for n in range(N+1):
        if K== m*N+n*M-2*m*n:
            f=1
print ans[f]


Fixed submission:
S=raw_input()
if len(S)>3:
    if S[:4]=="YAKI":
        print "Yes"
    else:
        print "No"
else:
    print "No"