Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from collections import deque

n, m = map(int, input().split())

nodes = [ [] for i in range(m+1)]

# グラフ生成
for i in range(1, m + 1):
    a, b = map(int, input().split())
    nodes[a].append(b)
    nodes[b].append(a)

ans = [0] * (n+1)

# キュー作成
stk = deque([1])

# BFS 幅優先探索
while stk:
    v = stk.pop()
    for s in nodes[v]:
        # 未到達ノードであれば、キューに追加
        if ans[s] == 0:
            # ひとつ前のノードを記録
            ans[s] = v
            # キューに要素を追加
            stk.appendleft(s)

ans = ans[2:]
 
if 0 in ans:
    print("No")
else:
    print("Yes")
    for i in ans:
        print(i)

Fixed submission:
from collections import deque

n, m = map(int, input().split())
G = [[]for i in range(n+1)]

# グラフ生成
for i in range(m):
    a, b = map(int, input().split())
    G[a].append(b)
    G[b].append(a)
 
ans = [0]*(n+1)
 
stk = deque([1])
 
# BFS 幅優先探索
while stk:
    v = stk.pop()
    for s in G[v]:
        # 未到達ノードであれば、キューに追加
        if ans[s] == 0:
            ans[s] = v
            stk.appendleft(s)
ans = ans[2:]
 
if 0 in ans:
    print("No")
else:
    print("Yes")
    for i in ans:
        print(i)

Buggy python submission (verdict: Runtime Error):
from collections import deque

n, m = map(int, input().split())

nodes = [ [] for i in range(m+1)]

# グラフ生成
for i in range(1, m + 1):
    a, b = map(int, input().split())
    nodes[a].append(b)
    nodes[b].append(a)

ans = [0] * (n+1)

# キュー作成
stk = deque([1])

# BFS 幅優先探索
while stk:
    v = stk.pop()
    for s in nodes[v]:
        # 未到達ノードであれば、キューに追加
        if ans[s] == 0:
            # ひとつ前のノードを記録
            ans[s] = v
            # キューに要素を追加
            stk.appendleft(s)

ans = ans[2:]
 
if 0 in ans:
    print("No")
else:
    print("Yes")
    for i in ans:
        print(i)


Fixed submission:
from collections import deque

n, m = map(int, input().split())
G = [[]for i in range(n+1)]

# グラフ生成
for i in range(m):
    a, b = map(int, input().split())
    G[a].append(b)
    G[b].append(a)
 
ans = [0]*(n+1)
 
stk = deque([1])
 
# BFS 幅優先探索
while stk:
    v = stk.pop()
    for s in G[v]:
        # 未到達ノードであれば、キューに追加
        if ans[s] == 0:
            ans[s] = v
            stk.appendleft(s)
ans = ans[2:]
 
if 0 in ans:
    print("No")
else:
    print("Yes")
    for i in ans:
        print(i)
Buggy python submission (verdict: Runtime Error):
import itertools
import numpy as np

n, m, x = map(int, input().split())
san = []
for i in range(n):
    san.append(list(map(int, input().split())))

result = []
adds = []
for j in range(1,n+1):
     for conb in itertools.combinations(san, j):
        result.append(list(conb)) #タプルをリスト型に変換

for i in result:
    t = np.zeros([m+1], dtype=int)
    for j in i:
        t = t + np.array(j)

    adds.append(t)

price = -1
ans = 0
for num, i in enumerate(adds):
    use = True
    for j in range(1,m+1):
        if i[j] < 10:
            # print(i)
            use = False
            break

    if use:
        # print(i)
        # print(result[num])
        if price == -1 or price > i[0]:
        # if price > i[0]:
            price = i[0]
            ans = num

print(price)

Fixed submission:
import itertools
import numpy as np

n, m, x = map(int, input().split())
san = []
for i in range(n):
    san.append(list(map(int, input().split())))

result = []
adds = []
for j in range(1,n+1):
     for conb in itertools.combinations(san, j):
        result.append(list(conb)) #タプルをリスト型に変換

for i in result:
    t = np.zeros([m+1], dtype=int)
    for j in i:
        t = t + np.array(j)

    adds.append(t)

price = -1
ans = 0
for num, i in enumerate(adds):
    use = True
    for j in range(1,m+1):
        if i[j] < x:
            # print(i)
            use = False
            break

    if use:
        # print(i)
        # print(result[num])
        if price == -1 or price > i[0]:
        # if price > i[0]:
            price = i[0]
            ans = num

print(price)
Buggy python submission (verdict: Time Limit Exceeded):

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

buka = []


for i in range(N):
    b = 0
    for j in range(N-1):
        if (i+1) == A[j]:
            b += 1

    buka.append(b)
    
# 出力
for i in range(N):
    print(buka[i])



Fixed submission:

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

buka = [0] * N

for i in range(N-1):
    buka[A[i]-1] += 1
    
# 出力
for i in range(N):
    print(buka[i])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

def gcd(p, q):
  if p % q == 0:
    return q
  return gcd(q, p % q)

ans = 0
for x in range(1,N+1):
  for y in range(1,N+1):
    for z in range(1,N+1):
      ans += gcd(gcd(x, y), z)
print(ans)

Fixed submission:
N = int(input())

def gcd(p, q):
  if p % q == 0:
    return q
  return gcd(q, p % q)

ans = 0
for x in range(1,N+1):
  for y in range(1,N+1):
    for z in range(1,N+1):
      ans += gcd(gcd(x, y), z)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

mod = (10**9)+7
goukei = 0

for i in range(N-1):
  Ai = A[i]
  AJ = A[i+1:]
  goukei += sum(AJ)*Ai
  goukei = goukei%mod

print(goukei)

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

def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a, x0, y0

def modinv(a, m):
    g, x, y = xgcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m

mod = (10**9)+7
sumA = sum(A)%mod
sumSq = sum([(i*i)%mod for i in A])%mod
r = (((sumA*sumA)%mod)-sumSq) * modinv(2, mod)
print(r%mod)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BC = []
for b in range(Q):
  BC.append(list(map(int, input().split())))

T = [0]*100000
#T[i] = A中の数値iの数

for i in A:
  T[i]+=1
S = sum(A)
for i in BC:
  b,c = i
  n = int(T[b])
  sa = c*n - b*n
  S = S + c*n - b*n
  print(S)
  T[b]=0
  T[c]+=n
  #print(S, [b,T[b], 0],[c,T[c],T[c]+T[b]], sa, S+sa)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BC = []
for b in range(Q):
  BC.append(list(map(int, input().split())))

T = [0]*200000
#T[i] = A中の数値iの数

for i in A:
  T[i]+=1
S = sum(A)
for i in BC:
  b,c = i
  n = int(T[b])
  sa = c*n - b*n
  S = S + c*n - b*n
  print(S)
  T[b]=0
  T[c]+=n
  #print(S, [b,T[b], 0],[c,T[c],T[c]+T[b]], sa, S+sa)
Buggy python submission (verdict: Time Limit Exceeded):
NK = list(map(int, input().split()))
N = NK[0]
K = NK[1]
A = list(map(int, input().split()))

done = [1]
now = 1
for i in range(1,N+1):
    nexttown = A[now-1]
    #print(now, "->", nexttown)
    if nexttown not in done:
        done.append(nexttown)
        now = nexttown
    else:
        break

start = done.index(nexttown)
end = len(done)-1
before = start #ループに入るまでの転移数
loop = done[start:]

if K < before:
    saisyuu = done[K]
else:
    nokori = K-before
    n_loop = int(nokori/len(loop))
    hasuu = nokori%len(loop)
    loopfirst = A[done[-1]-1]
    saisyuu = loop[hasuu]
    #print("1から",before,"回転移して",loopfirst,"に到着した後、大きさ",loop,"のループを",n_loop,"回転移して",loopfirst,"にいます。")
    #print("その後、",hasuu,"回の転移をして",saisyuu,"に到着します。")
print(saisyuu)


Fixed submission:
NK = list(map(int, input().split()))
N = NK[0]
K = NK[1]
A = list(map(int, input().split()))

done = [1]
donedic = {}
donedic[1] = 1
now = 1
for i in range(1,N+1):
    nexttown = A[now-1]
    #print(now, "->", nexttown)
    try:
        a = donedic[nexttown]
    except:
        donedic[nexttown] = 1
        done.append(nexttown)
        now = nexttown
    else:
        break

start = done.index(nexttown)
end = len(done)-1
before = start #ループに入るまでの転移数
loop = done[start:]

if K < before:
    saisyuu = done[K]
else:
    nokori = K-before
    n_loop = int(nokori/len(loop))
    loopfirst = done[start]
    hasuu = nokori%len(loop)
    saisyuu = loop[hasuu]
    #print("1から",before,"回転移して",loopfirst,"に到着します。")
    #print("その後、大きさ",len(loop),"のループを",n_loop,"回転移して",loopfirst,"にいます。")
    #print("その後、",hasuu,"回の転移をして",saisyuu,"に到着します。")
print(saisyuu)
Buggy python submission (verdict: Runtime Error):
for i in range(100):
    plus_abs=X+i
    minus_abs=X-i

    for j in range(N):
        if plus_abs == int(list2[j]):
           plus_abs=1000


    for k in range(N):
        if minus_abs == int(list2[k]):
            minus_abs=1000

    if plus_abs !=1000 or minus_abs!=1000:
        if plus_abs >= minus_abs:
            result = minus_abs
        else:
            result = plus_abs

        print(result)
        break

Fixed submission:
list1= input().split(" ")
list2= input().split(" ")
X=int(list1[0])
N=int(list1[1])
plus_abs =1000
minus_abs=1000
result=0

for i in range(100):
    plus_abs=X+i
    minus_abs=X-i

    for j in range(N):
        if plus_abs == int(list2[j]):
           plus_abs=1000


    for k in range(N):
        if minus_abs == int(list2[k]):
            minus_abs=1000

    if plus_abs !=1000 or minus_abs!=1000:
        if plus_abs >= minus_abs:
            result = minus_abs
        else:
            result = plus_abs

        print(result)
        break
Buggy python submission (verdict: Runtime Error):
import numpy as np

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

ans = int(0)
if(A[0] == 0):
    ans = 0
else:
    ans = np.prod(A)

if ans >= 1e18:
    print('-1')
else:
    print(f'{ans}')

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
MAX = 1e18

A.sort()

ans = 1
for i in A:
    ans *= i
    if ans > MAX:
        ans = -1
        break

print(ans)

Buggy python submission (verdict: Runtime Error):
import numpy as np

N = int(input())
A = [map(int, input().split())]
A.sort()

ans = 0
if(A[0] == 0):
    ans = 0
else:
    ans = np.prod(x)

if ans >= 1e18:
    print('-1')
else:
    print(f'{ans}')

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
MAX = 1e18

A.sort()

ans = 1
for i in A:
    ans *= i
    if ans > MAX:
        ans = -1
        break

print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [map(int, input().split())]
ans = int(0)
for i in A:
  ans *= i
  if ans >= 1e18:
    ans = -1
    break

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
MAX = 1e18

A.sort()

ans = 1
for i in A:
    ans *= i
    if ans > MAX:
        ans = -1
        break

print(ans)
Buggy python submission (verdict: Runtime Error):
A, B = map(float, input().split())
ans = A * B
print(int(ans)

Fixed submission:
A, B = input().split()
A = int(A)
B = int(B.replace('.',''))

print(A*B // 100)
Buggy python submission (verdict: Runtime Error):
from sys import stdin

N = map(int, stdin.readline().rstrip().split())
hon = {2,4,5,7,9}
pon = {0,1,6,8}
bon = {3}

N = N % 10

if N in hon:
    print('hon')
elif N in pon:
    print('pon')
else:
    print('bon')

Fixed submission:
from sys import stdin

N = int(input()) 
hon = {2,4,5,7,9}
pon = {0,1,6,8}
bon = {3}

N = N % 10

if N in hon:
    print('hon')
elif N in pon:
    print('pon')
else:
    print('bon')
Buggy python submission (verdict: Runtime Error):
from sys import stdin

K = int(inpu())
S = input()

if len(S) <= K:
    print(S)
else:
    print(S[:K],'...',sep='')

Fixed submission:
from sys import stdin

K = int(input())
S = input()

if len(S) <= K:
    print(S)
else:
    print(S[:K],'...',sep='')
Buggy python submission (verdict: Runtime Error):
from sys import stdin
import re
import bisect
import numpy as np

n, k = map(int(), stdin.readline().rstrip().split())
data = np.zeros((n,k),dtype=bool)
for i in range(k):
    _ = stdin.readline()
    line = map(int(), stdin.readline().rstrip().split())
    for j in line:
        data[i][j] = True

count = int(0)
for i in range(n):
    if (data.T[n]).all() == True:
        count += 1
print(count)

Fixed submission:
from sys import stdin
import re
import bisect
import numpy as np

N, K = map(int, stdin.readline().rstrip().split())
frag = np.zeros((K,N), dtype=bool)
for i in range(K):
    _ = stdin.readline()
    line = map(int, stdin.readline().rstrip().split())
    for j in line:
        j -= 1
        frag[i][j] = True
        
count = int(0)
frag = frag.T
for i in range(N):
    if np.count_nonzero(frag[i] == 1) == 0:
        count += 1
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
c=10**9+7
a = [-1]
for i in range(1, m+1):
    a = a + [int(input())]
a =a+[n+1] 
for i in range(m+1):
    a[i]=a[i+1] - a[i]-1
b=[0]
b=b+[1]
for i in range(2, max(a)+1):
    b=b+[(b[i-1] + b[i-2])%c]
s=1
for i in range(m+1):
    s=(s*b[a[i]])%c
print(s)

Fixed submission:
n,m = map(int,input().split())
c=10**9+7
a = [-1 for _ in range(m + 1)]
for i in range(1, m+1):
    a[i] = int(input())
a =a+[n+1] 
for i in range(m+1):
    a[i]=a[i+1] - a[i]-1
b=[0 for _ in range(max(a) + 1)]
b[1]=1
for i in range(2, max(a)+1):
    b[i] = (b[i-1] + b[i-2])%c
s=1
for i in range(m+1):
    s=(s*b[a[i]])%c
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
a = [-1]
for i in range(1, m+1):
    a = a + [int(input())]
a =a+[n+1] 
for i in range(m+1):
    a[i]=a[i+1] - a[i]-1
b=[0]
b=b+[1]
for i in range(2, max(a)+1):
    b=b+[(b[i-1] + b[i-2])%(10**9+7)]
s=1
for i in range(m+1):
    s=(s*b[a[i]])%(10**9+7)
print(s)

Fixed submission:
n,m = map(int,input().split())
c=10**9+7
a = [-1 for _ in range(m + 1)]
for i in range(1, m+1):
    a[i] = int(input())
a =a+[n+1] 
for i in range(m+1):
    a[i]=a[i+1] - a[i]-1
b=[0 for _ in range(max(a) + 1)]
b[1]=1
for i in range(2, max(a)+1):
    b[i] = (b[i-1] + b[i-2])%c
s=1
for i in range(m+1):
    s=(s*b[a[i]])%c
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
a = [-1]
for i in range(1, m+1):
    a = a + [0]
    a[i] = int(input())
a =a+[n+1] 
for i in range(m+1):
    a[i]=a[i+1] - a[i]-1
b=[0]
b=b+[1]
for i in range(2, max(a)+1):
    b=b+[0]
    b[i] = (b[i-1] + b[i-2])%(10**9+7)
s=1
for i in range(m+1):
    s=(s*b[a[i]])%(10**9+7)
print(s)

Fixed submission:
n,m = map(int,input().split())
c=10**9+7
a = [-1 for _ in range(m + 1)]
for i in range(1, m+1):
    a[i] = int(input())
a =a+[n+1] 
for i in range(m+1):
    a[i]=a[i+1] - a[i]-1
b=[0 for _ in range(max(a) + 1)]
b[1]=1
for i in range(2, max(a)+1):
    b[i] = (b[i-1] + b[i-2])%c
s=1
for i in range(m+1):
    s=(s*b[a[i]])%c
print(s)
Buggy python submission (verdict: Time Limit Exceeded):
input_ = input()
a = int(input_.split(' ')[0])
b = int(input_.split(' ')[1])
c = int(input_.split(' ')[2])
k = int(input())
count = 0
ans = "No"
while count < k:
  if a > b:
    b *= 2
    count += 1
  elif b > c:
    c *= 2
    count += 1
  if a < b and b < c:
    ans = "Yes"

print(ans)


Fixed submission:
input_ = input()
a = int(input_.split(' ')[0])
b = int(input_.split(' ')[1])
c = int(input_.split(' ')[2])
k = int(input())
count = 0
ans = "No"
while count < k:
  if a >= b:
    b *= 2
    count += 1
  elif b >= c:
    c *= 2
    count += 1
  if a < b and b < c:
    ans = "Yes"
    break

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input_ = input()
n = int(input_.split(' ')[0])
k = int(input_.split(' ')[1])
input_ = input()
a = [0] * n
for i in range(n):
  a[i] = int(input_.split(' ')[i])

for i in range(n-k):
  if a[i+k] > a[i]:
    print("Yes")
  else:
    print("No")

Fixed submission:
import sys
input_ = input()
n = int(input_.split(' ')[0])
k = int(input_.split(' ')[1])
a = list(map(int, input().split()))

for i in range(n-k):
  if a[i+k] > a[i]:
    print("Yes")
  else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
from typing import List
import math


def solution(K: int) -> int:
    ans: int = 0
    x: int = 7
    while True:
        # print(x)
        # print()
        ans += 1
        # K が偶数の時
        if K % 2 == 0:
            return -1
        # x が K より小さい時
        if x < int(K):
            x: int = int(str(x) + str(7))
            continue
        if x % K == 0:
            return ans
        if K < ans:
            return -1
        x: int = int(str(x) + str(7))
    return ans


K: int = int(input())

print(solution(K))


Fixed submission:
def solution(K: int) -> int:
    sevens: int = 0
    for i in range(1, K + 1):
        sevens = (sevens*10 + 7) % K
        if sevens == 0:
            return i
    return -1


K: int = int(input())

print(solution(K))
Buggy python submission (verdict: Runtime Error):
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())

if ((B-A)/(V-W)) <= T:
  print("Yes")
else:
  print("No")

Fixed submission:
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())

if V-W <= 0:
  print("NO")
else:
  if (abs(B-A)/(V-W)) <= T:
      print("YES")
  else:
    print("NO")
Buggy python submission (verdict: Runtime Error):
S = input()

if S[3] == S[4]:
  if S[5] == S[6]:
    print("Yes")
  else:
    print("No")
else:
  print("No")


Fixed submission:
S = input()

if S[2] == S[3]:
  if S[4] == S[5]:
    print("Yes")
  else:
    print("No")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
N = int(input())
S = input()

moji_list = []
for i in range(N):
  if (ord(S[i])+N) <= 90:
    moji_list.append(chr(ord(S[i]) + N))
  else:
    moji_list.append(chr(ord(S[i]) + N - 26))
    
  
print("".join(moji_list))

Fixed submission:
# -*- coding: utf-8 -*-
N = int(input())
S = input()

moji_list = []

q, mod = divmod(N, 26)
for i in range(len(S)):
  if (ord(S[i])+mod) <= 90:
    moji_list.append(chr(ord(S[i]) + mod))
  else:
    moji_list.append(chr(ord(S[i]) + mod - 26))
    
  
print("".join(moji_list))

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
N = int(input())
S = input()

moji_list = []
for i in range(N):
  moji_list.append(chr(ord(S[i]) + N))
  
print("".join(moji_list))

Fixed submission:
# -*- coding: utf-8 -*-
N = int(input())
S = input()

moji_list = []

q, mod = divmod(N, 26)
for i in range(len(S)):
  if (ord(S[i])+mod) <= 90:
    moji_list.append(chr(ord(S[i]) + mod))
  else:
    moji_list.append(chr(ord(S[i]) + mod - 26))
    
  
print("".join(moji_list))
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import collections

N, M = map(int,input().split())
A = list(map(int,input().split()))
sort_A = sorted(A, reverse=True)
L = []
for i in range(N):
  L.append(len(bin(sort_A[i])))

count_discount = [0]*M
for i in range(M):
  index = L.index(max(L))
  L[index] = L[index] -1
  count_discount[index] += 1

sum = 0
for i in range(N):
  if count_discount[i] >= 1:
    q, mod = divmod(sort_A[i], (2*count_discount[i]))
    sum += q
  else:
    sum += sort_A[i]
print(sum)

Fixed submission:
import heapq
n,m = map(int, input().split())
a = list(map(lambda x: int(x)*(-1), input().split()))
heapq.heapify(a)
 
for i in range(m):
	target = heapq.heappop(a)
	heapq.heappush(a, (-1)*(-target//2))
	
print(-sum(a))
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
N = int(input())
H = list(map(int,input().split()))

sum = 0
L = []

for i in range(len(H)):
  if i == 0:
    sum = 0
  elif i == N-1:
    if H[i] <= H[i-1]:
      sum += 1
      L.append(sum)
    else:
      L.append(sum)
  else:
    if H[i] <= H[i-1]:
      sum += 1
    else:
      L.append(sum)
      sum = 0
    
print(max(L))

Fixed submission:
# -*- coding: utf-8 -*-
N = int(input())
H = list(map(int,input().split()))

sum = 0
L = []

for i in range(len(H)):
  if i == 0:
    sum = 0
    L.append(sum)
  elif i == N-1:
    if H[i] <= H[i-1]:
      sum += 1
      L.append(sum)
    else:
      L.append(sum)
  else:
    if H[i] <= H[i-1]:
      sum += 1
    else:
      L.append(sum)
      sum = 0
    
print(max(L))
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
N = int(input())
A = [int(input()) for _ in range(N)]
setA = set(A)
tempA = list(setA)
R = sorted(tempA, reverse=True)
max_v = R[0]
if len(R) >= 1:
  max_v2 = R[1]
  signal = 1
else:
  max_v2 = R[0]

for i in range(N):
  if A[i] == max_v:
    print(max_v2)
  else:
    print(max_v)

Fixed submission:
# -*- coding: utf-8 -*-
N = int(input())
A = [int(input()) for _ in range(N)]
setA = set(A)
tempA = list(setA)
R = sorted(tempA, reverse=True)
max_v = R[0]
if len(R) >= 2:
  max_v2 = R[1]
else:
  max_v2 = R[0]
R2 = sorted(A, reverse=True)
if R2[0] == R2[1]:
  signal = 1
else:
  signal = 0
  
for i in range(N):
  if A[i] == max_v and signal == 0:
    print(max_v2)
  else:
    print(max_v)

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
N = int(input())
A = [int(input()) for _ in range(N)]
setA = set(A)
tempA = list(setA)
R = sorted(tempA, reverse=True)
max_v = R[0]
max_v2 = R[1]

for i in range(N):
  if A[i] == max_v:
    print(max_v2)
  else:
    print(max_v)


Fixed submission:
# -*- coding: utf-8 -*-
N = int(input())
A = [int(input()) for _ in range(N)]
setA = set(A)
tempA = list(setA)
R = sorted(tempA, reverse=True)
max_v = R[0]
if len(R) >= 2:
  max_v2 = R[1]
else:
  max_v2 = R[0]
R2 = sorted(A, reverse=True)
if R2[0] == R2[1]:
  signal = 1
else:
  signal = 0
  
for i in range(N):
  if A[i] == max_v and signal == 0:
    print(max_v2)
  else:
    print(max_v)

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
N = int(input())
A = [int(input()) for _ in range(N)]
setA = set(A)
tempA = list(setA)
R = sorted(tempA, reverse=True)
max_v = R[0]
max_v2 = R[1]

for i in range(N):
  if A[i] == R[0]:
    print(R[0])
  else:
    print(R[1])


Fixed submission:
# -*- coding: utf-8 -*-
N = int(input())
A = [int(input()) for _ in range(N)]
setA = set(A)
tempA = list(setA)
R = sorted(tempA, reverse=True)
max_v = R[0]
if len(R) >= 2:
  max_v2 = R[1]
else:
  max_v2 = R[0]
R2 = sorted(A, reverse=True)
if R2[0] == R2[1]:
  signal = 1
else:
  signal = 0
  
for i in range(N):
  if A[i] == max_v and signal == 0:
    print(max_v2)
  else:
    print(max_v)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
N = int(input())
A = [int(input()) for _ in range(N)]

for i in range(N):
  L = A[:]
  L.remove(A[i])
  print(max(L))

Fixed submission:
# -*- coding: utf-8 -*-
N = int(input())
A = [int(input()) for _ in range(N)]
setA = set(A)
tempA = list(setA)
R = sorted(tempA, reverse=True)
max_v = R[0]
if len(R) >= 2:
  max_v2 = R[1]
else:
  max_v2 = R[0]
R2 = sorted(A, reverse=True)
if R2[0] == R2[1]:
  signal = 1
else:
  signal = 0
  
for i in range(N):
  if A[i] == max_v and signal == 0:
    print(max_v2)
  else:
    print(max_v)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N = int(input())
A_list = sorted(list(map(int, input().split())), reverse=True)

edge_list = [A_list[0]]
score = 0
for i, a in enumerate(A_list[1:]):
    maxidx = np.argmax(edge_list)
    if edge_list[maxidx] == 1:
        break
    score += edge_list[maxidx]
    #print(edge_list, maxidx, score)
    edge_list[maxidx] = a
    edge_list.insert(maxidx, a)
    #print(edge_list)
else:
    print(score)
    exit()
score += N - i - 1
print(score)


Fixed submission:
import queue

N = int(input())
A_list = sorted(list(map(int, input().split())), reverse=True)

edge_que = queue.Queue()
edge_que.put(A_list[0])
score = 0
for i, a in enumerate(A_list[1:]):
    score += edge_que.get()
    edge_que.put(a)
    edge_que.put(a)
print(score)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N = int(input())
A_list = sorted(list(map(int, input().split())), reverse=True)

ar_list = [A_list[0]]
edge_list = [A_list[0]]
score = 0
for a in A_list[1:]:
    maxidx = np.argmax(edge_list)
    score += edge_list[maxidx]
    #print(edge_list, maxidx, score)
    edge_list[maxidx] = a
    edge_list.insert(maxidx, a)
    #print(edge_list)

print(score)
    

Fixed submission:
import queue

N = int(input())
A_list = sorted(list(map(int, input().split())), reverse=True)

edge_que = queue.Queue()
edge_que.put(A_list[0])
score = 0
for i, a in enumerate(A_list[1:]):
    score += edge_que.get()
    edge_que.put(a)
    edge_que.put(a)
print(score)