Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
S=str(input())
Q=int(input())

Query=[]
for i in range(Q):
    Query.append(list(input().split()))
#print(Query)

check=1
for j in range(Q):
    if len(Query[j])==1:
        check*=-1      
        #print(S)
    else:
        if Query[j][1]=='1':
            if check==1:
                S=Query[j][2]+S
            else:
                S+=Query[j][2]
            #print(S)
        else:
            if check==1:
                S+=Query[j][2]
            else:
                S=Query[j][2]+S
            #print(S)

if check==1:
    print(S)
else:
    print(S[::-1])

Fixed submission:
S=str(input())
Q=int(input())

Query=[]
for i in range(Q):
    Query.append(list(input().split()))

N=len(S)//2
S_left_reverse=S[:N+1][::-1]
S_right=S[N+1:]
#print(S_left_reverse,S_right)


check=1
for j in range(Q):
    if len(Query[j])==1:
        check*=-1
        #print(S_left_reverse,S_right)
    else:
        if Query[j][1]=='1':
            if check==1:
                S_left_reverse+=Query[j][2]
                #print(S_left_reverse,S_right)
            else:
                S_right+=Query[j][2]
                #print(S_left_reverse,S_right)
        else:
            if check==1:
                S_right+=Query[j][2]
                #print(S_left_reverse,S_right)
            else:
                S_left_reverse+=Query[j][2]
                #print(S_left_reverse,S_right)


ans=S_left_reverse[::-1]+S_right
if check==1:
    print(ans)
else:
    print(ans[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
S=str(input())
Q=int(input())

Query=[]
for i in range(Q):
    Query.append(list(input().split()))
#print(Query)

for j in range(Q):
    if len(Query[j])==1:
        S=S[::-1]
        #print(S)
    else:
        if Query[j][1]=='1':
            S=Query[j][2]+S
            #print(S)
        else:
            S+=Query[j][2]
            #print(S)

print(S)

Fixed submission:
S=str(input())
Q=int(input())

Query=[]
for i in range(Q):
    Query.append(list(input().split()))

N=len(S)//2
S_left_reverse=S[:N+1][::-1]
S_right=S[N+1:]
#print(S_left_reverse,S_right)


check=1
for j in range(Q):
    if len(Query[j])==1:
        check*=-1
        #print(S_left_reverse,S_right)
    else:
        if Query[j][1]=='1':
            if check==1:
                S_left_reverse+=Query[j][2]
                #print(S_left_reverse,S_right)
            else:
                S_right+=Query[j][2]
                #print(S_left_reverse,S_right)
        else:
            if check==1:
                S_right+=Query[j][2]
                #print(S_left_reverse,S_right)
            else:
                S_left_reverse+=Query[j][2]
                #print(S_left_reverse,S_right)


ans=S_left_reverse[::-1]+S_right
if check==1:
    print(ans)
else:
    print(ans[::-1])
Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
S=[list(map(int,input().split())) for _ in range(M)]

ans=''

S_sorted=sorted(S)
#print(S_sorted)

for j in range(M-1):
    if S_sorted[j][0]==S_sorted[j+1][0] and S_sorted[j][1]!=S_sorted[j+1][1]:
        ans='-1'

if ans!='-1':
    if S_sorted[0][0]==1 and S_sorted[0][1]==0:
        if N==1:
            ans=0
        else:
            ans='-1'

R=[1]

if ans!='-1' and ans!=0:
    for _ in range(1,N):
        R.append(0)
    
    for k in range(M):
        R[S_sorted[k][0]-1]=S_sorted[k][1]
    
    for l in range(N):
        ans+=str(R[l])
        int(ans)

#print(R)


print(ans)

Fixed submission:
N,M=map(int,input().split())
S=[list(map(int,input().split())) for _ in range(M)]



if N>=2:
    for i in range(10**(N-1),10**N):
        letter=str(i)
        for j in range(M):
            if letter[S[j][0]-1]!=str(S[j][1]):
                break
        else:
            print(i)
            break
    else:
        print('-1')
else:
    for k in range(0,10):
        letter=str(k)
        for l in range(M):
            if letter[S[l][0]-1]!=str(S[l][1]):
                break
        else:
            print(k)
            break
    else:
        print('-1')
Buggy python submission (verdict: Runtime Error):
A,B,C=map(int,input().split())

S=set(A,B,C)

if len(S)==2:
    print('Yes')
else:
    print('No')

Fixed submission:
A,B,C=map(int,input().split())

S={A,B,C}

if len(S)==2:
    print('Yes')
else:
    print('No')

Buggy python submission (verdict: Runtime Error):
A,B,C=map(int,input().split())

S=set{A,B,C}

if len(S)==2:
    print('Yes')
else:
    print('No')

Fixed submission:
A,B,C=map(int,input().split())

S={A,B,C}

if len(S)==2:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
H,N=map(int,input().split())
A=[]
B=[]
for _ in range(N):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)


inf=float('inf')
component=[0]
for i in range(H):
    component.append(inf)
DP=[]
for j in range(N+1):
    DP.append(copy.copy(component))#DPは(N+1)×(H+1)


for k in range(1,N+1):#k番目の魔法
    for l in range(1,H+1):#体力H
        DP[k][l]=min(DP[k-1][l],DP[k][max(0,l-A[k-1])]+B[k-1])

print(DP[N][H])










Fixed submission:
H,N=map(int,input().split())
A=[]
B=[]
for _ in range(N):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)


inf=float('inf')
component=[0]
for i in range(H):
    component.append(inf)
DP=[]
for j in range(N+1):
    DP.append(component)#DPは(N+1)×(H+1)


for k in range(1,N+1):#k番目の魔法
    for l in range(1,H+1):#体力H
        DP[k][l]=min(DP[k-1][l],DP[k][max(0,l-A[k-1])]+B[k-1])

print(DP[N][H])

Buggy python submission (verdict: Time Limit Exceeded):
import copy

H,N=map(int,input().split())
A=[]
B=[]
for _ in range(N):
    a,b=map(int,input().split())
    A.append(copy.copy(a))
    B.append(copy.copy(b))


inf=float('inf')
component=[0]
for i in range(H):
    component.append(inf)
DP=[]
for j in range(N+1):
    DP.append(copy.copy(component))#DPは(N+1)×(H+1)


for k in range(1,N+1):#k番目の魔法
    for l in range(1,H+1):#体力H
        DP[k][l]=min(DP[k-1][l],DP[k][max(0,l-A[k-1])]+B[k-1])

print(DP[N][H])










Fixed submission:
H,N=map(int,input().split())
A=[]
B=[]
for _ in range(N):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)


inf=float('inf')
component=[0]
for i in range(H):
    component.append(inf)
DP=[]
for j in range(N+1):
    DP.append(component)#DPは(N+1)×(H+1)


for k in range(1,N+1):#k番目の魔法
    for l in range(1,H+1):#体力H
        DP[k][l]=min(DP[k-1][l],DP[k][max(0,l-A[k-1])]+B[k-1])

print(DP[N][H])
Buggy python submission (verdict: Runtime Error):
N=int(input())
P=list(map(int,input().split()))

Min=P[0]
ans=1

for i in range(1,N):
    if Min>=P[i]:
        ans+=1
        Min=P[i]
    
print(ans)

Fixed submission:
N,M=map(str,input().split())

if M==N:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())

def func(x,y,n=N):
    R=0
    for i in range(1,n+1):
        Len=len(str(i))
        up=int(str(i)[0])
        down=int(str(i)[Len-1])
        if up==x and down==y:
            R+=1
    return R

ans=0

for j in range(10):
    for k in range(10):
        ans+=func(j,k)*func(k,j)

print(ans)

Fixed submission:
import copy

N=int(input())

def arrange(List,n=N):  #先頭がup末尾がdownの総数をList[up][down]に入れる;Listは10×10で0が入ってる
    for i in range(1,n+1):
        Len=len(str(i))
        up=int(str(i)[0])
        down=int(str(i)[Len-1])
        List[up][down]+=1
    return List

original=[]
component=[]
for x in range(10):
    component.append(0)
for y in range(10):
    original.append(copy.deepcopy(component))


L=arrange(original)

ans=0

for j in range(10):
    for k in range(10):
        ans+=L[j][k]*L[k][j]

print(ans)

Buggy python submission (verdict: Runtime Error):
N=int(input())

def add(x):
    Len=len(str(x))
    up=int(str(x)[0])
    down=int(str(x)[Len-1])
    R=0
    if down!=0:
        if up<down:
            if Len>=3:
                R+=2*((10**(Len-2)-1)//9)
        elif up>down:
            R+=2*((10**(Len-1)-1)//9)
        else:
            R+=2*(((10**(Len-1)-1)//9)+1)-1
    return int(R)

def ans(y):
    if y==1:
        return 1
    else:
        return ans(y-1)+add(y)

#for i in range(1,N+1):
    #print(i,ans(i))

print(ans(N))



Fixed submission:
import copy

N=int(input())

def arrange(List,n=N):  #先頭がup末尾がdownの総数をList[up][down]に入れる;Listは10×10で0が入ってる
    for i in range(1,n+1):
        Len=len(str(i))
        up=int(str(i)[0])
        down=int(str(i)[Len-1])
        List[up][down]+=1
    return List

original=[]
component=[]
for x in range(10):
    component.append(0)
for y in range(10):
    original.append(copy.deepcopy(component))


L=arrange(original)

ans=0

for j in range(10):
    for k in range(10):
        ans+=L[j][k]*L[k][j]

print(ans)
Buggy python submission (verdict: Runtime Error):
import copy

N,M=map(int,input().split())
L=[list(map(int,input().split())) for i in range(M)]

S=[]
component=[0,0]
for j in range(N):
    S.append(copy.deepcopy(component)

for k in range(1,M+1):
    if L[k-1][1]=='AC':
        if S[L[k-1][0]][0]==0:
            S[L[k-1][0]][0]=1
    else:
        if S[L[k-1][0]][0]==0:
            S[L[k-1][0]][1]+=1

ansAC=0
ansWA=0

for l in range(N):
    ansAC+=S[l][0]
    ansWA+=S[l][1]

print(ansAC,ansWA)




Fixed submission:
import copy

N,M=map(int,input().split())
L=[list(map(str,input().split())) for i in range(M)]

for x in range(M):
    L[x][0]=int(L[x][0])

#print(N,M)
#print(L)

S=[]
component=[0,0]
for j in range(N):
    S.append(copy.deepcopy(component))

#print(S)

for k in range(1,M+1):
    if L[k-1][1]=='AC':
        if S[L[k-1][0]-1][0]==0:
            S[L[k-1][0]-1][0]=1
    else:
        if S[L[k-1][0]-1][0]==0:
            S[L[k-1][0]-1][1]+=1
    #print(S)

ansAC=0
ansWA=0

for l in range(N):
    ansAC+=S[l][0]
    if S[l][0]==1:
        ansWA+=S[l][1]

print(ansAC,ansWA)
Buggy python submission (verdict: Runtime Error):
import copy
from collections import deque

H,W=map(int,input().split())
S=[list(input()) for _ in range(H)]


def check(tup):
    global H
    global W
    global S

    tup_x=tup[0]
    tup_y=tup[1]
    if 0<=tup_x<H and 0<=tup_y<W:
        if S[tup_x][tup_y]=='.':
            return True
    else:
        return False

def neighbor(tup):
    x=tup[0]
    y=tup[1]
    cand=[(x-1,y),(x+1,y),(x,y-1),(x,y+1)]
    List=[]
    for c in cand:
        if check(c):
            List.append(c)
    return List

def bfs(start):#startはtuple型
    global H
    global W

    deq=deque()#as queue
    Dict=[]
    component=[]
    for i in range(W):
        component.append(-1)
    for j in range(H):
        Dict.append(copy.copy(component))

    deq.append(start)
    Dict[start[0]][start[1]]=0
    while deq:
        now=deq.popleft()
        nexts=neighbor(now)
        for next in nexts:
            next_x=next[0]
            next_y=next[1]
            if Dict[next_x][next_y]>=0:
                continue
            if next in deq:
                continue
            deq.append(next)
            Dict[next_x][next_y]=Dict[now[0]][now[1]]+1

    M=[]
    for d in Dict:
        M.apeend(max(d))
    return max(M)

Ans=[]
for k in range(H):
    for l in range(W):
        Ans.append(bfs((k,l)))

print(max(Ans))




Fixed submission:
import copy
from collections import deque

H,W=map(int,input().split())
S=[list(input()) for _ in range(H)]


def check(tup):
    global H
    global W
    global S

    tup_x=tup[0]
    tup_y=tup[1]
    if 0<=tup_x<H and 0<=tup_y<W:
        if S[tup_x][tup_y]=='.':
            return True
    else:
        return False

def neighbor(tup):
    x=tup[0]
    y=tup[1]
    cand=[(x-1,y),(x+1,y),(x,y-1),(x,y+1)]
    List=[]
    for c in cand:
        if check(c):
            List.append(c)
    return List

def bfs(start):#startはtuple型
    global H
    global W

    if check(start):
        deq=deque()#as queue
        Dict=[]
        component=[]
        for i in range(W):
            component.append(-1)
        for j in range(H):
            Dict.append(copy.copy(component))

        deq.append(start)
        Dict[start[0]][start[1]]=0
        while deq:
            now=deq.popleft()
            nexts=neighbor(now)
            for next in nexts:
                next_x=next[0]
                next_y=next[1]
                if Dict[next_x][next_y]>=0:
                    continue
                if next in deq:
                    continue
                deq.append(next)
                Dict[next_x][next_y]=Dict[now[0]][now[1]]+1

        M=[]
        for d in Dict:
            M.append(max(d))
        return max(M)
    
    else:
        return 0

Ans=[]
for k in range(H):
    for l in range(W):
        Ans.append(bfs((k,l)))

print(max(Ans))
Buggy python submission (verdict: Runtime Error):
N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=str(input())

rec=[]
ans=0

def win(hand):
    if hand=='r':
        return ['p',P]
    elif hand=='s':
        return ['r',R]
    else:
        return ['s',S]

def gap(hand):
    if hand=='r':
        return 's'
    elif hand=='s':
        return 'p'
    else:
        return 'r'


for i in range(N):
    win_hand=win(T[i])[0]
    win_point=win(T[i])[1]
    same_hand=T[i]
    if 0<=i<=K-1:
        rec.append(win_hand)
        ans+=win_point
    else:
        if win_hand!=rec[i-K]:
            rec.append(win_hand)
            ans+=win_point
        else:
            if N-K<i<=N-1:
                rec.append(same_hand)#不要
            else:
                next_win_hand=win(T[i+K])[0]
                rec.append(gap(next_win_hand))

    #print(ans)

#print(rec)
print(ans)




Fixed submission:
N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=str(input())

rec=[]
ans=0

def win(hand):
    if hand=='r':
        return ['p',P]
    elif hand=='s':
        return ['r',R]
    else:
        return ['s',S]

def gap(hand):
    if hand=='r':
        return 's'
    elif hand=='s':
        return 'p'
    else:
        return 'r'


for i in range(N):
    win_hand=win(T[i])[0]
    win_point=win(T[i])[1]
    same_hand=T[i]
    if 0<=i<=K-1:
        rec.append(win_hand)
        ans+=win_point
    else:
        if win_hand!=rec[i-K]:
            rec.append(win_hand)
            ans+=win_point
        else:
            if N-K-1<i<=N-1:
                rec.append(same_hand)#不要
            else:
                next_win_hand=win(T[i+K])[0]
                rec.append(gap(next_win_hand))

    #print(ans)

#print(rec)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
P=10**9+7
count=[0]*60    #マジックナンバー

def culc(a):
    global count

    i=0
    while a>0:
        if a&1==1:
            count[i]+=1
        a=a>>1
        i+=1

def res():
    global N
    global count

    res=0
    for i in range(len(count)):
        res=(res+(2**i)*count[i]*(N-count[i]))%P

    return res

for index in range(N):
    culc(A[index])

ans=res()
print(ans)



Fixed submission:
N=int(input())
A=list(map(int,input().split()))
P=10**9+7
count=[0]*60    #マジックナンバー

def culc(a):
    global count

    i=0
    while a>0:
        if a&1==1:
            count[i]+=1
        a=a>>1
        i+=1

def res():
    global N
    global count

    res=0
    for i in range(len(count)):
        res=(res+(2**i)*count[i]*(N-count[i]))%P

    return res

for index in range(N):
    culc(A[index])

ans=res()
print(ans)
Buggy python submission (verdict: Runtime Error):
S=str(input())
L=['SUN','MON','TUE','WED','THU','FRI','SAT']
s=L.index(L)

print(7-s)



Fixed submission:
S=str(input())
L=['SUN','MON','TUE','WED','THU','FRI','SAT']
s=L.index(S)

print(7-s)
Buggy python submission (verdict: Runtime Error):
N=int(input())
S=str(input())

ans=N

for i in range(N-1):
    if S[i]=S[i+1]:
        ans-=1

print(ans)






Fixed submission:
N=int(input())
S=str(input())

ans=N

for i in range(N-1):
    if S[i]==S[i+1]:
        ans-=1

print(ans)
Buggy python submission (verdict: Runtime Error):
S=str(input())
T=str(input())

count=0
for i in range(3):
    if S[i]==S[j]:
        count+=1

print(count)

Fixed submission:
S=str(input())
T=str(input())

count=0
for i in range(3):
    if S[i]==T[i]:
        count+=1

print(count)
Buggy python submission (verdict: Runtime Error):
N=int(input())

print(int(((N-1)*N/2))

Fixed submission:
N=int(input())

print((N-1)*N//2)
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input()))

preans=0

for i in range(N):
    preans+=1/A[i]

print(1/preans)

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

preans=0

for i in range(N):
    preans+=1/A[i]

print(1/preans)
Buggy python submission (verdict: Runtime Error):
N=int(input())
V=list(map(input().split()))

V_sorted=sorted(V)

now_value=(V_sorted[0]+V_sorted[1])/2
for i in range(2,N):
    now_value=(now_value+V_sorted[i])/2

print(now_value)


    

    


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

V_sorted=sorted(V)

now_value=(V_sorted[0]+V_sorted[1])/2
for i in range(2,N):
    now_value=(now_value+V_sorted[i])/2

print(now_value)

Buggy python submission (verdict: Runtime Error):
N=int(input())
V=list(map(input().split()))

V_sorted=sorted(V)

now_value=(V_sorted[0]+V_sorted[1])/2
for i in range(2,N):
    now_value=(now_value+V_sorted[i])/2

print(now_value)


    

    


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

V_sorted=sorted(V)

now_value=(V_sorted[0]+V_sorted[1])/2
for i in range(2,N):
    now_value=(now_value+V_sorted[i])/2

print(now_value)

Buggy python submission (verdict: Runtime Error):
N=int(input())
V=list(map(input().split()))

V_sorted=sorted(V)

now_value=(V_sorted[0]+V_sorted[1])/2
for i in range(2,N):
    now_value=(new_value+V_sorted[i])/2

print(now_value)


    

    


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

V_sorted=sorted(V)

now_value=(V_sorted[0]+V_sorted[1])/2
for i in range(2,N):
    now_value=(now_value+V_sorted[i])/2

print(now_value)
Buggy python submission (verdict: Runtime Error):
A,B,C=map（int,input().split())

ans=0

if A-B<C:
    ans=C-(A-B)

print(ans)

Fixed submission:
A,B,C=map(int,input().split())

ans=0

if A-B<C:
    ans=C-(A-B)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S=list(input())
N=len(S)

T=[0 for _ in range(N)]

for i in range(N):
    if S[i]=='R':
        j=i
        while S[j]=='R':
            j+=1
        if (j-i)%2==0:
            T[j]+=1
        elif (j-i)%2==1:
            T[j-1]+=1
    else:
        j=i
        while S[j]=='L':
            j-=1
        if (i-j)%2==0:
            T[j]+=1
        elif (j-i)%2==1:
            T[j+1]+=1

ans=''
for k in range(N):
    ans+=str(T[k])+' '

print(ans)



Fixed submission:
#鈴木に教わった

S=str(input())
N=len(S)

ans=[]
for h in range(N):
    ans.append(0)
    
L=[]
count=0
for i in range(N-1):
    if S[i]==S[i+1]:
        count+=1
    else:
        L.append([S[i],count+1])
        count=0

L.append([S[N-1],count+1])

now=0
for j in range(len(L)):
    if L[j][0]=='R':
        now+=L[j][1]
        ans[now]+=L[j][1]//2
        ans[now-1]+=L[j][1]-L[j][1]//2
    else:
        ans[now-1]+=L[j][1]//2
        ans[now]+=L[j][1]-L[j][1]//2
        now+=L[j][1]

print(*ans)

Buggy python submission (verdict: Runtime Error):
S=list(input())
N=len(S)
#print(S,N)

T=[0 for _ in range(N)]

for i in range(N):
    if S[i]=='R':
        j=i
        while S[j]=='R':
            j+=1
        if (j-i)%2==0:
            T[j]+=1
        elif (j-i)%==1:
            T[j-1]+=1
    else:
        j=i
        while S[j]=='L':
            j-=1
        if (i-j)%2==0:
            T[j]+=1
        elif (j-i)%2==1:
            T[j+1]+=1

print(T)



Fixed submission:
#鈴木に教わった

S=str(input())
N=len(S)

ans=[]
for h in range(N):
    ans.append(0)
    
L=[]
count=0
for i in range(N-1):
    if S[i]==S[i+1]:
        count+=1
    else:
        L.append([S[i],count+1])
        count=0

L.append([S[N-1],count+1])

now=0
for j in range(len(L)):
    if L[j][0]=='R':
        now+=L[j][1]
        ans[now]+=L[j][1]//2
        ans[now-1]+=L[j][1]-L[j][1]//2
    else:
        ans[now-1]+=L[j][1]//2
        ans[now]+=L[j][1]-L[j][1]//2
        now+=L[j][1]

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

A,B=map(int,input().split())

if (A+B)%2==0:
    print((A+B)//2)
else:
    print('IMPOSSIBLE')

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

if (A+B)%2==0:
    print((A+B)//2)
else:
    print('IMPOSSIBLE')

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

A,B=map(int,input().split())

if (A+B)%2==0:
    print((A+B)/2)
else:
    print('impossible')

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

if (A+B)%2==0:
    print((A+B)//2)
else:
    print('IMPOSSIBLE')
Buggy python submission (verdict: Runtime Error):
import math

N,D=int(input().split())

if N%(2*D+1)==0:
    print(N//(2*D+1))
else:
    print((N//(2*D+1))+1)

Fixed submission:
import math

N,D=map(int,input().split())

if N%(2*D+1)==0:
    print(N//(2*D+1))
else:
    print((N//(2*D+1))+1)
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=[]
for i in range(N):
    A.append(int(input()))

max_value=max(A)
max_index=A.index(max_value)
second_value=A.sort()[-2]

for j in range(N):
    if j==max_index:
        print(second_value)
    else:
        print(max_value)

Fixed submission:
import copy

N=int(input())
A=[]
for _ in range(N):
    A.append(int(input()))

A_max=max(A)
ind_max=A.index(A_max)
B=copy.copy(A)
B.remove(A_max)
B_max=max(B)

for i in range(N):
    if A[i]!=A_max:
        print(A_max)
    else:
        print(B_max)

Buggy python submission (verdict: Runtime Error):
N=int(input())
A=[]
for i in range(N):
    A.append(int(input()))

max_value=max(A)
max_index=A.index(max_value)
second_value=A.sort()[-2]

for j in range(N):
    if i==max_index:
        print(second_value)
    else:
        print(max_value)

Fixed submission:
import copy

N=int(input())
A=[]
for _ in range(N):
    A.append(int(input()))

A_max=max(A)
ind_max=A.index(A_max)
B=copy.copy(A)
B.remove(A_max)
B_max=max(B)

for i in range(N):
    if A[i]!=A_max:
        print(A_max)
    else:
        print(B_max)

Buggy python submission (verdict: Time Limit Exceeded):
import heapq
import copy

N=int(input())
A=[-int(input()) for i in range(N)]
#print(N,A)

for j in range(N):
    copy_A=copy.copy(A)
    item=copy_A.pop(j)  #負
    #print(item)
    heapq.heapify(copy_A)
    #print(copy_A)
    MAX=-copy_A[0]  #正
    print(MAX)





Fixed submission:
import copy

N=int(input())
A=[]
for _ in range(N):
    A.append(int(input()))

A_max=max(A)
ind_max=A.index(A_max)
B=copy.copy(A)
B.remove(A_max)
B_max=max(B)

for i in range(N):
    if A[i]!=A_max:
        print(A_max)
    else:
        print(B_max)
Buggy python submission (verdict: Runtime Error):
L,R=map(int,input().split())

l=L%2019
r=R%2019

ans=0

if R-L<2019 and l<r:
    D=[]
    for i in range(l,r):
        for j in range(i+1,r+1):
            D.append((i*j)%2019)

ans=min(D)

print(ans)

Fixed submission:
L,R=map(int,input().split())

l=L%2019
r=R%2019

ans=0

if R-L<2019 and l<r:
    D=[]
    for i in range(l,r):
        for j in range(i+1,r+1):
            D.append((i*j)%2019)
    ans=min(D)

print(ans)
Buggy python submission (verdict: Runtime Error):
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N,K=map(int,input().split())

for i in range(1,K+1):
    x=combinations_count(K-1,i-1)
    y=combinations_count(N-K+1,i)
    print((x*y)%1000000007)




Fixed submission:
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N,K=map(int,input().split())

for i in range(1,K+1):
    x=combinations_count(K-1,i-1)
    if N-K+1>=i:
        y=combinations_count(N-K+1,i)
        print((x*y)%1000000007)
    else:
        print(0)