Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
li = list(map(int,input().split()))
ans = 1

for i in li:
    ans *= i

if ans > 10**18:
    print(-1)
else:
    print(ans)

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

n = int(input())
li = list(map(int,input().split()))
ans = 1

if li.count(0) > 0:
    print(0)
    exit()

for i in li:
    ans = ans * i
    if ans > 10**18:
        print(-1)
        exit()

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int,input().split())
li = list(map(int,input().split()))
ans = [1]

for i in range(n):
    now = ans[-1]
    nex = li[now-1]
    if ans.count(nex) > 0: #循環判定
        a = ans.index(nex) #開始点
        b = ans.index(now)-a+1 #循環周期
        break
    ans.append(li[now-1])

if k <= a:
    print(ans[k])
else:
    x = (k-a)%b
    print(ans[a+x])

Fixed submission:
n, k = map(int,input().split())
li = list(map(int,input().split()))
ans = [1]
nex = 1
f = [1]+[0]*(n-1)

for i in range(n):
    now = nex #今の場所
    nex = li[now-1] #テレポート先の場所
    #print(now,nex)
    if f[nex-1] == 1: #循環判定
        a = ans.index(nex) #開始点
        b = ans.index(now)-a+1 #循環周期
        break
    f[now-1] = 1
    ans.append(li[now-1])

#print(ans)
#print(f)
if k <= a:
    print(ans[k])
else:
    x = (k-a)%b
    print(ans[a+x])
Buggy python submission (verdict: Time Limit Exceeded):
import itertools

n, k = map(int,input().split())
ans = 0
li = list(range(n+1))

for i in range(k,n+2):
    x = list(itertools.combinations(li, i))
    y = []
    for c in x:
        y.append(sum(c))
    ans += len(set(y))

print(ans%(10**9+7))

Fixed submission:
import itertools

n, k = map(int,input().split())
ans = 0
li = list(range(n+1))

for i in range(k,n+2):
    a = int(1/2*i*(i-1))
    b = n*i-(int(1/2*i*(i-1)))
    ans += b - a + 1

print(ans%(10**9+7))
Buggy python submission (verdict: Runtime Error):
k = int(input())
i = 1 #数回す用
c = 0 #ルンルン数カウント

if k > 13000:
    i = 34454557
    c = 13000

while c < k:
  j = str(i)
  if i < 13: #13未満なら
    c = c + 1 #ルンルン数
    #print(c, i)
  else: #それ以外なら
    x = 0
    for n in range(len(j)-1): #ルンルン数判定を行う
      if abs(int(j[n]) - int(j[n+1])) > 1:#桁の差が1より大きかったら
        x = 1
        break
    if x == 0:
      c = c + 1
      #print(c, i)
  i = i + 1 #iに1を足す

print(i-1)

Fixed submission:
x, y ,z = map(int,input().split())
 
print(z, x, y)
Buggy python submission (verdict: Time Limit Exceeded):
k = int(input())
i = 1 #数回す用
c = 0 #ルンルン数カウント

if k > 13000:
    i = 34454557
    c = 13000

while c < k:
  j = str(i)
  if i < 13: #13未満なら
    c = c + 1 #ルンルン数
    #print(c, i)
  else: #それ以外なら
    x = 0
    for n in range(len(j)-1): #ルンルン数判定を行う
      if abs(int(j[n]) - int(j[n+1])) > 1:#桁の差が1より大きかったら
        x = 1
        break
    if x == 0:
      c = c + 1
      #print(c, i)
  i = i + 1 #iに1を足す

print(i-1)

Fixed submission:
k = int(input())
lunlun = [1, 2, 3, 4, 5, 6, 7, 8, 9] #ルンルン数リスト

for i in range(k):
    x = lunlun[i]
    if x%10 != 0:
        lunlun.append(x*10+x%10-1)
    lunlun.append(x*10+x%10)
    if x%10 != 9:
        lunlun.append(x*10+x%10+1)
        #print(lunlun)
print(x)

Buggy python submission (verdict: Time Limit Exceeded):
k = int(input())
ans = 0 #答え
i = 1 #数回す用
c = 0 #ルンルン数カウント

while c < k:
  j = str(i)
  if i < 13: #13未満なら
    c = c + 1 #ルンルン数
    #print(c, i)
  else: #それ以外なら
    x = 0
    for n in range(len(j)-1): #ルンルン数判定を行う
      if abs(int(j[n]) - int(j[n+1])) > 1:#桁の差が1より大きかったら
        x = 1
        break
    if x == 0:
      c = c + 1
      #print(c, i)
  i = i + 1 #iに1を足す

print(i-1)

Fixed submission:
k = int(input())
lunlun = [1, 2, 3, 4, 5, 6, 7, 8, 9] #ルンルン数リスト

for i in range(k):
    x = lunlun[i]
    if x%10 != 0:
        lunlun.append(x*10+x%10-1)
    lunlun.append(x*10+x%10)
    if x%10 != 9:
        lunlun.append(x*10+x%10+1)
        #print(lunlun)
print(x)
Buggy python submission (verdict: Runtime Error):
s = input()
n = s.size()
ans=""
 
half = s[0:(n-1)/2]
 
if s==s[::-1] and half==half[::-1]:
	ans = "Yes"
else:
	ans = "No"
  
print(ans)

Fixed submission:
s = input()
n = len(s)
ans=""
 
half = s[:int((n-1)/2)]
 
if s==s[::-1] and half==half[::-1]:
	ans = "Yes"
else:
	ans = "No"
  
print(ans)

Buggy python submission (verdict: Runtime Error):
s = input()
n = s.size()
ans=""
 
half = s[0:(n-1)/2]
 
if(s==s[::-1] && half==half[::-1]){
	ans = "Yes";
}
else
	ans = "No";
  
print(ans)
}

Fixed submission:
s = input()
n = len(s)
ans=""
 
half = s[:int((n-1)/2)]
 
if s==s[::-1] and half==half[::-1]:
	ans = "Yes"
else:
	ans = "No"
  
print(ans)
Buggy python submission (verdict: Runtime Error):
s = input()

if s = "AAA" or s = "BBB":
  print("No")
else:
  print("Yes")

Fixed submission:
s = input()
 
if s == "AAA" or s == "BBB":
  print("No")
else:
  print("Yes")
Buggy python submission (verdict: Runtime Error):
n, a, b = map(int,input().split())
 
x = int(n/(a+b)) #何周目か
y = n%(a+b)

if y > a:
    ans = (x+1) * a
else:
    x * a + y

print(ans)

Fixed submission:
n, a, b = map(int,input().split())
 
x = int(n/(a+b)) #何周目か
y = n%(a+b) #余り

if y > a:
    ans = (x+1) * a
else:
    ans = x * a + y

print(ans)
Buggy python submission (verdict: Runtime Error):
a=[]
for i in range(3):
  a.append(list(map(int,input().split())))
n = int(input())
x = 0

for i in range(n):
  b = int(input())
  for j in range(3):
    for k in range(3):
      if a[j][k] == b:
        a[j][k] = 0

print(a)

if (a[0][0] == 0 and a[2][2] == 0 and a[1][1] == 0) or (a[0][2] == 0 and a[2][0] == 0 and a[1][1] == 0): #斜めに揃っていたら
  print("Yes")
  x = 1
for i in range(3):
  if a[i][0] == 0 and a[i][1] == 0 and a[i][2] and x == 0: #横に揃っていたら
    print("Yes")
    x = 1
    break
  elif a[0][i] == 0 and a[1][i] == 0 and a[2][i] and x == 0: #縦に揃っていたら
    print("Yes")
    x = 1
    break
if x == 0:
  print("No")a=[]
for i in range(3):
  a.append(list(map(int,input().split())))
n = int(input())
x = 0

for i in range(n):
  b = int(input())
  for j in range(3):
    for k in range(3):
      if a[j][k] == b:
        a[j][k] = 0

if (a[0][0] == 0 and a[2][2] == 0 and a[1][1] == 0) or (a[0][2] == 0 and a[2][0] == 0 and a[1][1] == 0): #斜めに揃っていたら
  print("Yes")
  x = 1
for i in range(3):
  if a[i][0] == 0 and a[i][1] == 0 and a[i][2] and x == 0: #横に揃っていたら
    print("Yes")
    x = 1
    break
  elif a[0][i] == 0 and a[1][i] == 0 and a[2][i] and x == 0: #縦に揃っていたら
    print("Yes")
    x = 1
    break
if x == 0:
  print("No")

Fixed submission:
a=[]
for i in range(3):
  a.append(list(map(int,input().split())))
n = int(input())
x = 0

for i in range(n):
  b = int(input())
  for j in range(3):
    for k in range(3):
      if a[j][k] == b:
        a[j][k] = 0

if (a[0][0] == 0 and a[2][2] == 0 and a[1][1] == 0) or (a[0][2] == 0 and a[2][0] == 0 and a[1][1] == 0): #斜めに揃っていたら
  print("Yes")
  x = 1
for i in range(3):
  if a[i][0] == 0 and a[i][1] == 0 and a[i][2] == 0 and x == 0: #横に揃っていたら
    print("Yes")
    x = 1
    break
  elif a[0][i] == 0 and a[1][i] == 0 and a[2][i] == 0 and x == 0: #縦に揃っていたら
    print("Yes")
    x = 1
    break
if x == 0:
  print("No")

Buggy python submission (verdict: Runtime Error):
import itertools

A=[]
for i in range(3):
    try:
        A.append(list(map(int,input().split())))
    except:
        break;
A = list(itertools.chain.from_iterable(A))
n = int(input())
b=[int(input()) for i in range(n)]

for i in b:
    if i in A:
        
#print(A)
#print(b)

Fixed submission:
a=[]
for i in range(3):
  a.append(list(map(int,input().split())))
n = int(input())
x = 0

for i in range(n):
  b = int(input())
  for j in range(3):
    for k in range(3):
      if a[j][k] == b:
        a[j][k] = 0

if (a[0][0] == 0 and a[2][2] == 0 and a[1][1] == 0) or (a[0][2] == 0 and a[2][0] == 0 and a[1][1] == 0): #斜めに揃っていたら
  print("Yes")
  x = 1
for i in range(3):
  if a[i][0] == 0 and a[i][1] == 0 and a[i][2] == 0 and x == 0: #横に揃っていたら
    print("Yes")
    x = 1
    break
  elif a[0][i] == 0 and a[1][i] == 0 and a[2][i] == 0 and x == 0: #縦に揃っていたら
    print("Yes")
    x = 1
    break
if x == 0:
  print("No")
Buggy python submission (verdict: Time Limit Exceeded):
import collections

n = int(input())
s = [input() for i in range(n)]
l = []
s.sort()

c = collections.Counter(s)
x = c.most_common()[0][1]

for item in s:
  if c[item] == x and item not in  l:
  	l.append(item)

for item in l:
  print(item)

Fixed submission:
import collections

n = int(input())
s = [input() for i in range(n)]
c = collections.Counter(s)
x = c.most_common()[0][1]

s = list(set(s))
s.sort()

for item in s:
  if c[item] == x:
  	print(item)
Buggy python submission (verdict: Runtime Error):
import collection

n = int(input())
a = list(map(int, input().split()))
c = collections.Counter(a)

if c.most_common()[0][1] == 1:
    print("Yes")
else:
    print("No")

Fixed submission:
import collections

n = int(input())
a = list(map(int, input().split()))
c = collections.Counter(a)

if c.most_common()[0][1] == 1:
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Time Limit Exceeded):
x, y = map(int,input().split())
p = list(map(int,input().split()))
ans = 0

for i in range(x-y+1):
    z = (sum(p[i:i+y])+y)/2
    if z > ans:
        ans = z

print(ans)

Fixed submission:
x, y = map(int,input().split())
p = list(map(int,input().split()))
ans = 0

for i in range(x-y+1):
    if i == 0:
        z = sum(p[:y])
    else:
        z = z - n + p[i+y-1]
    n = p[i]
    if z > ans:
        ans = z

print((ans+y)/2)

Buggy python submission (verdict: Time Limit Exceeded):
x, y = map(int,input().split())
p = list(map(int,input().split()))
ans = 0

for i in range(x-y+1):
    z = 0
    for j in range(y):
        z += (p[i+j]+1)/2
    if z > ans:
        ans = z

print(ans)

Fixed submission:
x, y = map(int,input().split())
p = list(map(int,input().split()))
ans = 0

for i in range(x-y+1):
    if i == 0:
        z = sum(p[:y])
    else:
        z = z - n + p[i+y-1]
    n = p[i]
    if z > ans:
        ans = z

print((ans+y)/2)
Buggy python submission (verdict: Runtime Error):
from sys import stdin

x,y = [long(x) for x in stdin.readline().rstrip().split()]
li = list(map(long,stdin.readline().rstrip().split()))

z = 0
if(x<y):
    print(z)

else:
    li = li.sort(reverse=True)
    del li[0:y-1]

    z = 0
    for i in li:
        z = z + i

    print(z)

Fixed submission:
n, k = map(int,input().split())
h = list(map(int,input().split()))
h.sort(reverse=True)
ans = 0

if k > n:
  ans = 0
  
else:
  ans = sum(h) - sum(h[:k])
  
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
p = list(map(int,input().split()))
ans = 1 #i=1は常に成り立つ
 
for i in range(1, n): #i=2以降について順番に見ていく
  for j in range(0, i): #iより小さい要素について順番に見ていく
    if p[j] < p[i]: #jの方が小さかったら
      break #ダメなので抜ける
    if j == i-1: #j=i-1になったら
      ans = ans + 1 #要件を満たすので+1する
  if p[i] == 1:
    break
  
print(ans)

Fixed submission:
n = int(input())
p = list(map(int,input().split()))
mini = p[0]
ans = 1

for i in p:
    if i < mini:
        ans += 1
        mini = i

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
p = list(map(int,input().split()))
ans = 1 #i=1は常に成り立つ
 
for i in range(1, n): #i=2以降について順番に見ていく
  for j in range(0, i): #iより小さい要素について順番に見ていく
    if p[j] < p[i]: #jの方が小さかったら
      break #ダメなので抜ける
    if j == i-1: #j=i-1になったら
      ans = ans + 1 #要件を満たすので+1する
  
print(ans)

Fixed submission:
n = int(input())
p = list(map(int,input().split()))
mini = p[0]
ans = 1

for i in p:
    if i < mini:
        ans += 1
        mini = i

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#自分より左側が常に自分以上である数がいくつあるか

n = int(input())
p = list(map(int,input().split()))
ans = 1 #i=1は常に成り立つ

for i in range(1, n): #i=2以降について順番に見ていく
  for j in range(0, i+1): #iより小さい要素について順番に見ていく
    if p[j] < p[i]: #jの方が小さかったら
      break #ダメなので抜ける
    if j == i: #j=iになったら
      ans = ans + 1 #要件を満たすので+1する
  
print(ans)

Fixed submission:
n = int(input())
p = list(map(int,input().split()))
mini = p[0]
ans = 1

for i in p:
    if i < mini:
        ans += 1
        mini = i

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int,input().split())
sp = [input().split() for i in range(m)]
#print(sp)
x = [] #正解記録リスト
y = []
z = 0 #ペナルティ数カウンター

for i in range(m):
  if sp[i][1] == "AC" and int(sp[i][0]) not in x: #初正解の場合
    x.append(int(sp[i][0]))
    y.append(i)
    #print(x)

for i in range(m):
  if sp[i][1] == "WA": #不正解の場合
    if int(sp[i][0]) in x: #正解していたら
      a = x.index(int(sp[i][0]))
      if i < y[a]: #正解前だったら
        z = z + 1 #ペナルティとしてカウント

print(len(x), z)

Fixed submission:
n, m = map(int,input().split())
li = [0] * n
wa = 0
ac = 0

for i in range(m):
    p, s = map(str, input().split())
    p = int(p)

    if s == "WA" and li[p-1] >= 0: #WAかつ正解前
        li[p-1] += 1 #その問題をWAした数+1
    
    elif s == "AC" and li[p-1] >= 0: #ACかつ正解前
        wa += li[p-1] #それまでにWAした数をカウントに追加
        li[p-1] = -1 #ステータスを正解済に変更
        ac += 1 #AC+1

print(ac, wa)
Buggy python submission (verdict: Time Limit Exceeded):
a, b, k = map(int,input().split())

for i in range(k):
  if a > 0:
    a = a - 1
  elif b > 0:
    b = b - 1

print(a, b)

Fixed submission:
a, b, k = map(int,input().split())

if a >= k:
    a = a - k
else:
    b = b - k + a
    a = 0
    if b < 0:
        b = 0

print(a, b)

Buggy python submission (verdict: Runtime Error):
a, b, k = map(int,input().split())

for i in range k:
  if a > 0:
    a = a - 1
  elif b > 0
  	b = b - 1

print(a, b)

Fixed submission:
a, b, k = map(int,input().split())

if a >= k:
    a = a - k
else:
    b = b - k + a
    a = 0
    if b < 0:
        b = 0

print(a, b)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [int(input()) for i in range(n)]
j = 0
k = 0

if 1 not in a:
    print(-1)
else:   
    for i in range(1,n+1):
        if i in a[k:]:
            j = j + 1
            k = a[k:].index(i) + k
        else:
            break
    print(n-j)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
x = 1
ans = 0

for i in a:
    if i == x:
        ans += 1
        x += 1

if ans == 0:
    print(-1)
else:
    print(len(a)-ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
i = [int(input()) for i in range(n)]
j = 0
k = 0

if 1 not in a:
    print(-1)
else:   
    for i in range(1,n+1):
        if i in a[k:]:
            j = j + 1
            k = a[k:].index(i) + k
        else:
            break
    print(n-j)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
x = 1
ans = 0

for i in a:
    if i == x:
        ans += 1
        x += 1

if ans == 0:
    print(-1)
else:
    print(len(a)-ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
j = 0
k = 0

if 1 not in a:
    print(-1)
else:   
    for i in range(1,n+1):
        if i in a[k:]:
            j = j + 1
            k = a[k:].index(i) + k
        else:
            break
    print(n-j)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
x = 1
ans = 0

for i in a:
    if i == x:
        ans += 1
        x += 1

if ans == 0:
    print(-1)
else:
    print(len(a)-ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
li = list(map(int,input().split()))
ans = 100000000000000000

for i in range(1,n):
    x = sum(li[:i])
    y = sum(li[i:])
    z = abs(x-y)
    if z < ans:
        ans = z
    
print(ans)

Fixed submission:
n = int(input())
li = list(map(int,input().split()))
ans = 100000000000000000

for i in range(1,n):
    if i == 1:
        x = sum(li[:i])
        y = sum(li[i:])
    else:
        x += li[i-1]
        y -= li[i-1]
    z = abs(x-y)
    if z < ans:
        ans = z
    
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
b = [0 for j in range(n)]

for i in range(n):
    b[i] = a.index(i+1) + 1

print(*b)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
b = [0 for j in range(n)]

for i in range(n):
    b[a[i]-1] = i+1

print(*b)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
b = [0 for i in range(n)]

for i in range(1,n+1): #1~nについて
    b[i-1] = a.index(i) + 1

print(*b)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
b = [0 for j in range(n)]

for i in range(n):
    b[a[i]-1] = i+1

print(*b)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
b = [0] * n

for i in range(1,n+1): #1~nについて
    b[i-1] = a.index(i) + 1

print(*b)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
b = [0 for j in range(n)]

for i in range(n):
    b[a[i]-1] = i+1

print(*b)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
b = [0] * n

for i in range(1,n+1): #1~nについて
    b[i-1] = a.index(i) + 1

print(' '.join(map(str, b)))

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
b = [0 for j in range(n)]

for i in range(n):
    b[a[i]-1] = i+1

print(*b)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
b = []

for i in range(1,n+1):
  for j in range(n):
    if a[j] == i:
      b.append(a.index(i) + 1)
      break
      
print(' '.join(map(str, b)))

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
b = [0 for j in range(n)]

for i in range(n):
    b[a[i]-1] = i+1

print(*b)
Buggy python submission (verdict: Runtime Error):
n = int(input())
h = list(map(int,input().split()))
x = []
y = 0

for i in range(n-1):
    if h[i] < h[i+1]:
        y = 0
    else:
        y = y + 1
    x.append(y)
 
print(max(x))

Fixed submission:
n = int(input())
h = list(map(int,input().split()))
x = []
y = 0

if n == 1:
    print(0)

else:
    for i in range(n-1):
        if h[i] < h[i+1]:
            y = 0
        else:
            y = y + 1
        x.append(y)
 
    print(max(x))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(input()) for i in range(n)]
b = a
c = max(a)

for i in range(n):
    if a[i] == c:
        x = b.pop(i) #i番目の要素を削除
        print(max(b)) #その中での最大値を出力
        b.insert(i, x) #削除した要素を戻す
    else:
        print(c)

Fixed submission:
import heapq

n = int(input())
a = [int(input()) for i in range(n)]
b = heapq.nlargest(2, set(a))
c = a.count(b[0])

if len(b) == 1 or c > 1: #bの長さが1または、最大値が2回以上存在するなら
    for i in range(n):
        print(b[0]) #最大値のみを表示

else: #bの長さが2以上なら
    for i in range(n):
        if a[i] == b[0]: #i番目が最大値だったら
            print(b[1]) #2番目に大きい値を出力
        else: #そうでなければ
            print(b[0]) #最大値を出力

Buggy python submission (verdict: Runtime Error):
import heapq

n = int(input())
a = [int(input()) for i in range(n)]
b = heapq.nlargest(2, set(a))
c = [i for i, x in enumerate(a) if x == b[0]] #最大値の位置

for i in range(n):
    if a[i] == b[0]: #最大値だったら
        print(b[1]) #最大値から2番目を出力
    else: #そうでなければ
        print(b[0]) #最大値を出力

Fixed submission:
import heapq

n = int(input())
a = [int(input()) for i in range(n)]
b = heapq.nlargest(2, set(a))
c = a.count(b[0])

if len(b) == 1 or c > 1: #bの長さが1または、最大値が2回以上存在するなら
    for i in range(n):
        print(b[0]) #最大値のみを表示

else: #bの長さが2以上なら
    for i in range(n):
        if a[i] == b[0]: #i番目が最大値だったら
            print(b[1]) #2番目に大きい値を出力
        else: #そうでなければ
            print(b[0]) #最大値を出力

Buggy python submission (verdict: Runtime Error):
import heapq

n = int(input())
a = [int(input()) for i in range(n)]
b = heapq.nlargest(2, set(a))
c = [i for i, x in enumerate(a) if x == b[0]] #最大値の位置

for i in range(n):
    if i in c: #最大値だったら
        print(b[1]) #最大値から2番目を出力
    else: #そうでなければ
        print(b[0]) #最大値を出力

Fixed submission:
import heapq

n = int(input())
a = [int(input()) for i in range(n)]
b = heapq.nlargest(2, set(a))
c = a.count(b[0])

if len(b) == 1 or c > 1: #bの長さが1または、最大値が2回以上存在するなら
    for i in range(n):
        print(b[0]) #最大値のみを表示

else: #bの長さが2以上なら
    for i in range(n):
        if a[i] == b[0]: #i番目が最大値だったら
            print(b[1]) #2番目に大きい値を出力
        else: #そうでなければ
            print(b[0]) #最大値を出力

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(input()) for i in range(n)]
b = a
#print(a)
for i in range(n):
  x = b.pop(i) #i番目の要素を削除
  print(max(b)) #その中での最大値を出力
  b.insert(i, x) #削除した要素を戻す

Fixed submission:
import heapq

n = int(input())
a = [int(input()) for i in range(n)]
b = heapq.nlargest(2, set(a))
c = a.count(b[0])

if len(b) == 1 or c > 1: #bの長さが1または、最大値が2回以上存在するなら
    for i in range(n):
        print(b[0]) #最大値のみを表示

else: #bの長さが2以上なら
    for i in range(n):
        if a[i] == b[0]: #i番目が最大値だったら
            print(b[1]) #2番目に大きい値を出力
        else: #そうでなければ
            print(b[0]) #最大値を出力
Buggy python submission (verdict: Time Limit Exceeded):
i, j = map(int,input().split())
ans = 100000000

for m in range(i, j):
  for n in range(m+1, j+1):
    x = m * n % 2019
    if x < ans:
      ans = x

print(ans)

Fixed submission:
i, j = map(int,input().split())
ans = 100000000

for m in range(i, min(j, i+2019)): #高々O(2019**2)
  for n in range(m+1, min(j+1, i+2020)):
    x = m * n % 2019
    if x < ans:
      ans = x

print(ans)
Buggy python submission (verdict: Runtime Error):
n, l = map(int,input().split())
m = list(range(l, n))

if 0 in m:
  print(sum(m))
  
else:
  if m[0] < 0:
    print(sum(m)-max(m))
  else:
    print(sum(m)-min(m))

Fixed submission:
n, l = map(int,input().split())
m = list(range(l, l+n))

if 0 in m:
  print(sum(m))
  
else:
  if m[0] < 0:
    print(sum(m)-max(m))
  else:
    print(sum(m)-min(m))
Buggy python submission (verdict: Time Limit Exceeded):
a, b, c, d = map(int,input().split())
ans = 0

for i in range(a,b+1):
  if i%c != 0 and i%d != 0:
    ans = ans + 1
    
print(ans)

Fixed submission:
import fractions

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

a, b, c, d = map(int,input().split())
ans = 0
a = a-1
 
x = b - (b//c + b//d - b//lcm(c,d)) #1~bまでの該当する数
y = a - (a//c + a//d - a//lcm(c,d)) #1~a-1までの該当する数
    
print(x-y)
Buggy python submission (verdict: Runtime Error):
a, b = map(int,input().split())

if b > 12:
  print(b)
elif: b > 5:
  print(int(b/2))
else:
  print(0)

Fixed submission:
a, b = map(int,input().split())
 
if a > 12:
  print(b)
elif a > 5:
  print(int(b/2))
else:
  print(0)
Buggy python submission (verdict: Runtime Error):
n, k = map(int,input().split())
s = input()

s[k-1] = s[k-1].lower()

print(s)

Fixed submission:
n, k = map(int,input().split())
s = input()
print(s[:k-1] + s.lower()[k-1] + s[k:n])
Buggy python submission (verdict: Runtime Error):
s = input()

a = int(s[:2])
b = int(s[2:])

if a == 0 and b == 0
  print("NA")
elif a > 12 and b <= 12:
  print("YYMM")
elif a <= 12 and b > 12:
  print("MMYY")
elif a <= 12 and b <= 12: 
  print("AMBIGUOUS")
else:
  print("NA")  

Fixed submission:
s = input()

a = int(s[:2])
b = int(s[2:])

if (a == 00 or a > 12) and b <= 12 and b >= 1:
  print("YYMM")
elif a <= 12 and a >= 1 and (b == 00 or b > 12):
  print("MMYY")
elif a <= 12 and a >= 1 and b <= 12 and b >= 1:
  print("AMBIGUOUS")
else:
  print("NA")