Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
S=input()
Q=int(input())
query=[list(map(str,input().split())) for _ in range(Q)]
flag=0
#print(query)
s=S
s2=""
for i in range(Q):
    if len(query[i])==1:
        flag=(flag+1)%2 #反転フラグをひっくり返す
    else:
        if flag==0:
            if query[i][1]=="1":
                s="".join((query[i][2],s))
            else:
                s = "".join((s,query[i][2]))
        else:
            if query[i][1]=="2":
                s="".join((query[i][2],s))
            else:
                s = "".join((s,query[i][2]))
if flag==0:
    print(s)
else:
    for i in range(len(s)):
        s2="".join(())
    print(s[::-1])

Fixed submission:
from collections import deque
d=deque()
S=list(input())
Q=int(input())
query=[list(map(str,input().split())) for _ in range(Q)]
flag=0  #反転なし
#print(query)
s=S
s2=""
d.extend(S)
#print(d)
for i in range(Q):
    #print(i,len(d))
    if (len(query[i])==1):
        if len(d)>1:
            flag=(flag+1)%2 #反転フラグをひっくり返す
    else:
        if flag==0:
            if query[i][1]=="1":
                d.appendleft(query[i][2])
            else:
                d.append(query[i][2])
        else:
            if query[i][1]=="2":
                d.appendleft(query[i][2])
            else:
                d.append(query[i][2])
    #print(d)
if flag==0:
    print("".join(list(d)))
else:
    d.reverse()
    print("".join(list(d)))

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
Q=int(input())
query=[list(map(str,input().split())) for _ in range(Q)]
flag=0
#print(query)
s=S
for i in range(Q):
    if len(query[i])==1:
        flag=(flag+1)%2 #反転フラグをひっくり返す
    else:
        if flag==0:
            if query[i][1]=="1":
                s="".join((query[i][2],s))
            else:
                s = "".join((s,query[i][2]))
        else:
            if query[i][1]=="2":
                s="".join((query[i][2],s))
            else:
                s = "".join((s,query[i][2]))
if flag==0:
    print(s)
else:
    print(s[::-1])

Fixed submission:
from collections import deque
d=deque()
S=list(input())
Q=int(input())
query=[list(map(str,input().split())) for _ in range(Q)]
flag=0  #反転なし
#print(query)
s=S
s2=""
d.extend(S)
#print(d)
for i in range(Q):
    #print(i,len(d))
    if (len(query[i])==1):
        if len(d)>1:
            flag=(flag+1)%2 #反転フラグをひっくり返す
    else:
        if flag==0:
            if query[i][1]=="1":
                d.appendleft(query[i][2])
            else:
                d.append(query[i][2])
        else:
            if query[i][1]=="2":
                d.appendleft(query[i][2])
            else:
                d.append(query[i][2])
    #print(d)
if flag==0:
    print("".join(list(d)))
else:
    d.reverse()
    print("".join(list(d)))
Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
rest=[[] for _ in range(N)]
r2=[]
end=0
flag=0
buf=""
ans=float("inf")
end=0
for i in range(M):
    s,c=map(int,input().split())
    if len(rest[s-1])==0:
        rest[s-1].append(c)
    elif rest[s-1].count(c)==0:
        end=1
        break
#print(rest)

if N == 1:
    l=range(0,10**N,1)
else:
    l=range(10**(N-1),10**N,1)

if end!=1:
    for i in l:
        buf=str(i)
        #print(i)
        for j in range(N):
            if len(rest[j])==1:
                if buf[j]!=str(rest[j][0]):
                    fail=1
                    break
        if fail==0:
            ans=i
            flag=1
            break
        fail=0
if (flag==1):
    print(ans)
else:
    print("-1")

Fixed submission:
import collections

N,M=map(int,input().split())
#if not(M==0):
s=[list(map(int,input().split())) for _ in range(M)]
flag=1
l=[[i+1,-1] for i in range(N)]
ns=""
#print(l)
"""
if M==0:
    for i in range(M):
        if i==0:
            l[i][1]=1
        else:
            l[i][1]=0
        ns="".join((ns,str(l[i][1])))
    print(ns)
"""
#else:
for i in range(M):
    #print(l)
    if l[s[i][0]-1][1]==-1:
        l[s[i][0]-1][1]=s[i][1]
    else:
        if not(l[s[i][0]-1][1]==s[i][1]):
            flag=0
if (not(N==1) and (l[0][1]==0)):
    flag=0
if flag==1:
    for i in range(N):
        if not(N==1):
            if (l[i][1]==-1):
                if i==0:
                    l[i][1]=1
                else:
                    l[i][1]=0
        else:
            if (l[i][1]==-1):
                l[i][1]=0
        ns="".join((ns,str(l[i][1])))
    print(ns)
else:
    print("-1")
Buggy python submission (verdict: Time Limit Exceeded):

N=input()
cnt=0
bit=0
bitflag=0
cur=0
inf=1001001001

Nd="".join(("0",N))


dp=[[inf for _ in range(2)] for _ in range(1000005)]
dp[0][0]=0
print(dp)
for i in range(0,len(Nd),1):
    for j in range(2):
        x=int(Nd[len(Nd)-1-i])
        #print(x)
        x=x+j
        for a in range(0,10,1):
            ni=i+1
            nj=0
            b=a-x
            if b<0:
                nj=1
                b=b+10
            dp[ni][nj]=min(dp[ni][nj],dp[i][j]+a+b)

print(dp[len(Nd)][0])






Fixed submission:

N=input()
cnt=0
bit=0
bitflag=0
cur=0
inf=float("inf")

Nd="".join(("0",N))


dp=[[inf for _ in range(2)] for _ in range(1000005)]
dp[0][0]=0
#print(dp)
for i in range(0,len(Nd),1):
    for j in range(2):
        x=int(Nd[len(Nd)-1-i])
        #print(x)
        x=x+j
        for a in range(0,10,1):
            ni=i+1
            nj=0
            b=a-x
            if b<0:
                nj=1
                b=b+10
            dp[ni][nj]=min(dp[ni][nj],dp[i][j]+a+b)

print(dp[len(Nd)][0])

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N=input()
cnt=0
bit=0
bitflag=0
cur=0
inf=1001001001
dp=np.zeros((1000005,2)) #dp[N][2]
dp=dp.tolist()
Nd="".join(("0",N))
#print(Nd)
for i in range(0,len(Nd)+1,1):
    for j in range(2):
        dp[i][j]=inf
dp[0][0]=0
for i in range(0,len(Nd),1):
    for j in range(2):
        x=int(Nd[len(Nd)-1-i])
        #print(x)
        x=x+j
        for a in range(0,10,1):
            ni=i+1
            nj=0
            b=a-x
            if b<0:
                nj=1
                b=b+10
            dp[ni][nj]=min(dp[ni][nj],dp[i][j]+a+b)

print(dp[len(Nd)][0])






Fixed submission:

N=input()
cnt=0
bit=0
bitflag=0
cur=0
inf=float("inf")

Nd="".join(("0",N))


dp=[[inf for _ in range(2)] for _ in range(1000005)]
dp[0][0]=0
#print(dp)
for i in range(0,len(Nd),1):
    for j in range(2):
        x=int(Nd[len(Nd)-1-i])
        #print(x)
        x=x+j
        for a in range(0,10,1):
            ni=i+1
            nj=0
            b=a-x
            if b<0:
                nj=1
                b=b+10
            dp[ni][nj]=min(dp[ni][nj],dp[i][j]+a+b)

print(dp[len(Nd)][0])
Buggy python submission (verdict: Runtime Error):
def modpow(a,n,p):
    if n==0:
        return 1
    x=modpow(a,n//2,p)
    x=(x*x)%p
    if (n%2)==1:
        x=(x*a)%p
    return x%p
def modinv(a,p):
    return modpow(a,p-2,p)

r1,c1,r2,c2=map(int,input().split())
n1=r2+c2+2
n2=r2+c1+1
n3=r1+c2+1
n4=r1+c1
l=[r2+1,r2+1,r1,r1]
p=10**9+7
buf=1
cnt=0
l=[0]*(10**6+10)
l2=[0]*20
inv=[0]*(10**6+10)
for i in range(2,n1+3,1):#n1+1
    l[i]=(l[i-1]*i)%p
print((((l[n1]*modinv(l[r2+1],p)*modinv(l[n1-r2-1],p))%p)-(l[n2]*modinv(l[r2+1],p)*modinv(l[n2-r2-1],p))-(l[n3]*modinv(l[r1],p)*modinv(l[n3-r1],p))+(l[n4]*modinv(l[r1],p)*modinv(l[n4-r1],p)))%p)

Fixed submission:

import numpy as np

N=input()
K=input()
dp=np.zeros((len(str(N))+10,len(str(N))+10,2))
dp=dp.tolist()


x0=int(N[0])
dp[0][0][0]=1


for i in range(0,len(N),1):
    for j in range(0,4,1):
        for k in range(0,2,1):
            nd=int(N[i])
            for d in range(0,10,1):
                ni=i+1
                nj=j
                nk=k
                if not(d==0):
                    nj=nj+1
                if ((k==0)and(d<nd)):
                    nk=1
                if (not(nj>int(K)))and(not((k==0)and(d>nd))):
                    dp[ni][nj][nk]=dp[ni][nj][nk]+dp[i][j][k]


print(int(dp[len(N)][int(K)][0]+dp[len(N)][int(K)][1]))
Buggy python submission (verdict: Time Limit Exceeded):

import numpy as np

H,N=map(int,input().split())
weights=[list(map(int,input().split())) for _ in range(N)]
INF=100100101
#print(weight)
#print(value)

#print(weights)
dp=[INF for i in range(H+1)]
for i in range(H+1):
    if i==0:
        dp[i]=0
    else:
        for j in range(len(weights)):
            a=weights[j][0]
            b=weights[j][1]
            piv=max(0,i-a)  #use i-a's dp[] value as a pivot (if not exits(i-a<0), return dp[0])
            dp[i]=min(dp[i],dp[piv]+b) #the part which forcely treated as piv=0, returns min([weights]), other is treated as normal dp
    #print(dp)

print(dp[H])


Fixed submission:

#import numpy as np

H,N=map(int,input().split())
weights=[list(map(int,input().split())) for _ in range(N)]
INF=100100101
#print(weight)
#print(value)

#print(weights)
dp=[INF]*(H+1)
for i in range(H+1):
    if i==0:
        dp[i]=0
    else:
        for j in weights:
            a=j[0]
            b=j[1]
            piv=max(0,i-a)  #use i-a's dp[] value as a pivot (if not exits(i-a<0), return dp[0])
            dp[i]=min(dp[i],dp[piv]+b) #the part which forcely treated as piv=0, returns min([weights]), other is treated as normal dp
    #print(dp)

print(dp[H])

Buggy python submission (verdict: Time Limit Exceeded):


H,N=map(int,input().split())
weight=[]
value=[]
for i in range(N):
    Ai,Bi=map(int,input().split())
    weight.append(Ai)
    value.append(Bi)
INF=100000001
#print(weight)
#print(value)


dp=[INF for i in range(H+1)]
dp[0]=0
for i in range(N):
    a=weight[i]
    b=value[i]
    for j in range(H+1):
        nj=min(j+a,H)
        dp[nj]=min(dp[nj],dp[j]+b)
print(dp[H])


Fixed submission:

#import numpy as np

H,N=map(int,input().split())
weights=[list(map(int,input().split())) for _ in range(N)]
INF=100100101
#print(weight)
#print(value)

#print(weights)
dp=[INF]*(H+1)
for i in range(H+1):
    if i==0:
        dp[i]=0
    else:
        for j in weights:
            a=j[0]
            b=j[1]
            piv=max(0,i-a)  #use i-a's dp[] value as a pivot (if not exits(i-a<0), return dp[0])
            dp[i]=min(dp[i],dp[piv]+b) #the part which forcely treated as piv=0, returns min([weights]), other is treated as normal dp
    #print(dp)

print(dp[H])
Buggy python submission (verdict: Time Limit Exceeded):
lis=[]
N=int(input())
P=map(int, input().split())
count=0
P=list(P)
for i in range(N):
    lis=P[:i]
    lis.sort()
    #print(lis) 
    if (len(lis)==0):
        count=count+1
    elif (int(lis[0])>=int(P[i])):
        count=count+1
    lis=[]
print(count)

Fixed submission:
lis=[]
N=int(input())
P=map(int, input().split())
count=1
P=list(P)
Min=P[0]
for i in range(N-1):
    if P[i+1]<Min:
        count=count+1
    if Min>P[i+1]:
        Min=P[i+1]
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
A,B,K=map(int, input().split())
count=0
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())
count=0
if (A-K)<0:
    B=B+A-K
    A=0
    if B<0:
        B=0
else:
    A=A-K
print(A,B)
Buggy python submission (verdict: Runtime Error):


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

print(str(6-A-B))

Fixed submission:


A=int(input())
B=int(input())

print(str(6-A-B))
Buggy python submission (verdict: Time Limit Exceeded):
import pprint
import copy
N=int(input())
S=input()
dig=[[] for i in range(10)]
chkigid=[0]*10
ansdigid=[0]*10
#print(dig)
cnt=0
for i in range(N):
    dig[int(S[i])].append([int(S[i]),chkigid[int(S[i])],i])#dig[int(S[i])][chkigid[int(S[i])]][2]=i
    chkigid[int(S[i])]=chkigid[int(S[i])]+1
    #pprint.pprint(dig)
    #pprint.pprint(chkigid)
    #input()
for i in range(10):
    for j in range(10):
        dig2=copy.deepcopy(dig)
        v1 = float("inf")
        if len(dig2[i])!=0:
            v1 = dig2[i][0][2]
            dig2[i].pop(0)#pop(dig2[i][0])
        v2 = float("inf")
        for k in range(len(dig2[j])):
            #print(dig2[j][len(dig2[j])-1- k])
            if len(dig2[j])!=0:
                v2=dig2[j][len(dig2[j])-1-k][2]
                dig2[j].pop(len(dig2[j])-1-k)
                break
        if (v1<v2)and(v1!=float("inf"))and(v2!=float("inf")):
            for k in range(10):
                for l in range(len(dig2[k])):
                    if v1<dig2[k][l][2]<v2:
                        #print(dig2[k][l][0])
                        cnt=cnt+1
                        break
        #pprint.pprint(dig2)
        #print(i,v1,j,v2,cnt)
        #input()
print(cnt)




Fixed submission:
import pprint
import copy
N=int(input())
S=input()
dig=[[] for i in range(10)]
chkigid=[0]*10
ansdigid=[0]*10
#print(dig)
cnt=0
for i in range(N):
    dig[int(S[i])].append(i)#dig[int(S[i])][chkigid[int(S[i])]][2]=i
    chkigid[int(S[i])]=chkigid[int(S[i])]+1
    #pprint.pprint(dig)
    #pprint.pprint(chkigid)
    #input()
#print(dig)
for i in range(10):
    for j in range(10):
        #dig2=copy.deepcopy(dig)
        v1 = float("inf")
        if len(dig[i])!=0:
            v1 = dig[i][0]
        v2 = float("inf")
        if len(dig[j])!=0:
            v2= dig[j][len(dig[j])-1]
        if (v1<v2)and(v1!=float("inf"))and(v2!=float("inf")):
            for k in range(10):
                for l in range(len(dig[k])):
                    if v1<dig[k][l]<v2:
                        #print(dig2[k][l][0])
                        cnt=cnt+1
                        break
        #pprint.pprint(dig)
        #print(i,v1,j,v2,cnt)
        #input()
print(cnt)
Buggy python submission (verdict: Runtime Error):
#from math import *
N=int(input())
A=list(map(int,input().split()))
l=[0 for _ in range(3)]
ans=1
p=10**9+7
for i in range(N):
    cnt=0
    piv=A[i]
    ind=[]
    for j in range(3):
        if l[j]==piv:
            cnt=cnt+1
            ind.append(j)
    l[ind[0]]=l[ind[0]]+1
    ans=(ans*cnt)%p
    #print(l,ans)
    #input()
print(ans%p)




Fixed submission:
N=int(input())
A=list(map(int,input().split()))
l=[[] for _ in range(3)]
ans=1
p=10**9+7
flag=1
for i in range(N):
    cnt=0
    piv=A[i]
    ind=[]
    for j in range(3):
        if len(l[j])==piv:
            cnt=cnt+1
            ind.append(j)
    if len(ind)==0:
        flag=0
        break
    l[ind[0]].append(piv)
    ans=(ans*cnt)%p
    #print(l,ans)
    #input()
if flag==1:
    print(ans%p)
else:
    print(flag)

Buggy python submission (verdict: Runtime Error):
#from math import *
N=int(input())
A=list(map(int,input().split()))
l=[[],[],[]]
ans=1
p=10**9+7
for i in range(N):
    cnt=0
    piv=A[i]
    ind=[]
    for j in range(3):
        if len(l[j])==piv:
            cnt=cnt+1
            ind.append(j)
    l[ind[0]].append(piv)
    ans=(ans*cnt)%p
    #print(l,ans)
    #input()
print(ans)




Fixed submission:
N=int(input())
A=list(map(int,input().split()))
l=[[] for _ in range(3)]
ans=1
p=10**9+7
flag=1
for i in range(N):
    cnt=0
    piv=A[i]
    ind=[]
    for j in range(3):
        if len(l[j])==piv:
            cnt=cnt+1
            ind.append(j)
    if len(ind)==0:
        flag=0
        break
    l[ind[0]].append(piv)
    ans=(ans*cnt)%p
    #print(l,ans)
    #input()
if flag==1:
    print(ans%p)
else:
    print(flag)

Buggy python submission (verdict: Runtime Error):
from math import *
N=int(input())
A=list(map(int,input().split()))
l=[[],[],[]]
ans=1
p=10**9+7
for i in range(N):
    cnt=0
    piv=A[i]
    ind=[]
    for j in range(3):
        if len(l[j])==piv:
            cnt=cnt+1
            ind.append(j)
    l[ind[0]].append(piv)
    ans=(ans*cnt)%p
    #print(l,ans)
    #input()
print(ans)




Fixed submission:
N=int(input())
A=list(map(int,input().split()))
l=[[] for _ in range(3)]
ans=1
p=10**9+7
flag=1
for i in range(N):
    cnt=0
    piv=A[i]
    ind=[]
    for j in range(3):
        if len(l[j])==piv:
            cnt=cnt+1
            ind.append(j)
    if len(ind)==0:
        flag=0
        break
    l[ind[0]].append(piv)
    ans=(ans*cnt)%p
    #print(l,ans)
    #input()
if flag==1:
    print(ans%p)
else:
    print(flag)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N=int(input())
tree=[[] for _ in range(N)]
dirtree=[[] for _ in range(N)]
paths=[]
for i in range(N-1):
    a,b=map(int,input().split())
    tree[a-1].append(b-1)
    tree[b-1].append(a-1)
    paths.append([a-1,b-1,i,0])
paths=sorted(paths,key=lambda x:x[1])
paths.sort(key=lambda x:x[0])
#print(paths)
v=0
d=deque()
d.append(v)
seen=[0]*N
col=[-1]*N
path=[]
dirtree = [[] for _ in range(N)]
while len(d)>0:
    v=d.popleft()
    seen[v]=1
    for j in tree[v]:
        if seen[j]==0:
            d.append(j)
            dirtree[v].append(j)
#print(dirtree)
v=0
d.append(v)
col[v]=0
while len(d)>0:
    v=d.popleft()
    seen[v]=0
    c=0
    for j in dirtree[v]:
        if seen[j]==1:
            d.append(j)
            c=c+1
            if c==col[v]:
                c=c+1
                path.append([min(j,v),max(j,v),c])
            else:
                path.append([min(j, v), max(j, v), c])
            col[j]=c
    path = sorted(path, key=lambda x: x[1])
    path.sort(key=lambda x: x[0])
    #print(path)
    #input()
for i in range(N-1):
    paths[i][3]=path[i][2]
paths.sort(key=lambda x:x[2])
path.sort(key=lambda x:x[2],reverse=True)
print(path[0][2])
for i in range(N-1):
    print(paths[i][3])

Fixed submission:
from collections import deque
N=int(input())
tree=[[] for _ in range(N)]
dirtree=[[] for _ in range(N)]
paths=[]
for i in range(N-1):
    a,b=map(int,input().split())
    tree[a-1].append(b-1)
    tree[b-1].append(a-1)
    paths.append([a-1,b-1,i,0])
paths=sorted(paths,key=lambda x:x[1])
paths.sort(key=lambda x:x[0])
#print(paths)
v=0
d=deque()
d.append(v)
seen=[0]*N
col=[-1]*N
path=[]
dirtree = [[] for _ in range(N)]
while len(d)>0:
    v=d.popleft()
    seen[v]=1
    for j in tree[v]:
        if seen[j]==0:
            d.append(j)
            dirtree[v].append(j)
#print(dirtree)
v=0
d.append(v)
col[v]=0
while len(d)>0:
    v=d.popleft()
    seen[v]=0
    c=0
    for j in dirtree[v]:
        if seen[j]==1:
            d.append(j)
            c=c+1
            if c==col[v]:
                c=c+1
                path.append([min(j,v),max(j,v),c])
            else:
                path.append([min(j, v), max(j, v), c])
            col[j]=c
path = sorted(path, key=lambda x: x[1])
path.sort(key=lambda x: x[0])
    #print(path)
    #input()
for i in range(N-1):
    paths[i][3]=path[i][2]
paths.sort(key=lambda x:x[2])
path.sort(key=lambda x:x[2],reverse=True)
print(path[0][2])
for i in range(N-1):
    print(paths[i][3])
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
c=0
A1=[]
A2=[]
s1=0
s2=0
c=float("inf")
for i in range(N-1):
    A1=A[:i+1]
    A2=A[i+1:]
    s1=sum(A1)
    s2=sum(A2)
    if abs(s1-s2)<c:
        c=abs(s1-s2)
print(c)


Fixed submission:
N=int(input())
A=list(map(int,input().split()))
c=0
all=sum(A)
buf=all
A1=[]
A2=[]
s1=0
s2=0
c=float("inf")
for i in range(N-1):
    buf=buf-A[i]
    if c>abs((all-buf)-buf):
        c=abs((all-buf)-buf)
    else:
        break
print(c)
Buggy python submission (verdict: Time Limit Exceeded):
import math
import collections
N,K,Q=map(int,input().split())
A=[int(input()) for _ in range(Q)]
for i in range(N):
 if K+A.count(i+1)-Q>0:
  print("Yes")
 else:
  print("No")

Fixed submission:
import math
import collections
N,K,Q=map(int,input().split())
A=[int(input()) for _ in range(Q)]
c=collections.Counter(A)
for i in range(N):
 if K+c[i+1]-Q>0:
  print("Yes")
 else:
  print("No")
Buggy python submission (verdict: Runtime Error):
import math
N,M=map(int,input().split())
A=list(map(int,input().split()))
A.sort(reverse=True)
logof2=[0]*N
mi=0
#print(A)
for i in range(N):
    logof2[i]=math.log2(A[i])
#print(logof2)
for i in range(M):
    if logof2[0]<0:
        break
    else:
        logof2[0]=logof2[0]-1
        logof2.sort(reverse=True)
    #print(logof2)
for i in range(N):
    mi=mi+math.floor(pow(2,logof2[i]))

print(mi)


Fixed submission:
import heapq
import math
N,M=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
logof2=[0]*N
mi=0
buf=0
#print(A)
for i in range(N):
    A[i]=-A[i]
heapq.heapify(A)
for i in range(M):
    buf=heapq.heappop(A)
    buf=(-buf)//2
    buf=-buf
    heapq.heappush(A,buf)
    #print(A)
for i in range(N):
    mi=mi-math.floor(A[i])

print(mi)
Buggy python submission (verdict: Time Limit Exceeded):
import copy
N=int(input())
A=[int(input()) for _ in range(N)]
l=[]
for i in range(N):
    Ad = copy.deepcopy(A)
    del Ad[i]
    Ad.sort(reverse=True)
    print(Ad[0])


Fixed submission:
import copy
N=int(input())
A=[int(input()) for _ in range(N)]
l=[]
for i in range(N):
    l.append([A[i],i])
l.sort(key=lambda x:x[0],reverse=True)
#print(l)
excep=l[0][1]

for i in range(N):
    if i==excep:
        print(l[1][0])
    else:
        print(l[0][0])
Buggy python submission (verdict: Runtime Error):
import collections
N=int(input())
a=list(map(int,input().split()))
l=[]
if max(a)==0:
    print("Yes")
elif (N%3)==0:
    c=collections.Counter(a)
    values = list(c.values())  # aのCollectionのvalue値のリスト(n_1こ、n_2こ…)
    key = list(c.keys())  # 先のvalue値に相当する要素のリスト(要素1,要素2,…)
    for i in range(len(key)):
        l.append([key[i], values[i]])  # lは[要素i,n_i]の情報を詰めたmatrix
    l.sort(key=lambda x:x[1],reverse=True)
    #print(l)
    if ((len(l)==3)and(l[0][1]==l[0][2]==l[0][3])and(l[0]^l[1]==l[2])):
        print("Yes")
    elif (len(l)==2)and(l[0][1]==2*l[1][1])and(l[1][0]==0):
        print("Yes")
    else:
        print("No")
else:
    print("No")

Fixed submission:
import collections
N=int(input())
a=list(map(int,input().split()))
l=[]
if max(a)==0:
    print("Yes")
elif (N%3)==0:
    c=collections.Counter(a)
    values = list(c.values())  # aのCollectionのvalue値のリスト(n_1こ、n_2こ…)
    key = list(c.keys())  # 先のvalue値に相当する要素のリスト(要素1,要素2,…)
    for i in range(len(key)):
        l.append([key[i], values[i]])  # lは[要素i,n_i]の情報を詰めたmatrix
    l.sort(key=lambda x:x[1],reverse=True)
    #print(l)
    if (len(l)==3)and(l[0][1]==l[1][1]==l[2][1])and(l[0][0]^l[1][0]==l[2][0]):
        print("Yes")
    elif (len(l)==2)and(l[0][1]==2*l[1][1])and(l[1][0]==0):
        print("Yes")
    else:
        print("No")
else:
    print("No")

Buggy python submission (verdict: Runtime Error):
N=int(input())
a=list(map(int,input().split()))
if N==3:
    if a[0]^a[1]==a[2]:
        print("Yes")
    else:
        print("No")
    input()
else:
    if max(a)==0:
        print("Yes")
    else:
        print("No")

Fixed submission:
import collections
N=int(input())
a=list(map(int,input().split()))
l=[]
if max(a)==0:
    print("Yes")
elif (N%3)==0:
    c=collections.Counter(a)
    values = list(c.values())  # aのCollectionのvalue値のリスト(n_1こ、n_2こ…)
    key = list(c.keys())  # 先のvalue値に相当する要素のリスト(要素1,要素2,…)
    for i in range(len(key)):
        l.append([key[i], values[i]])  # lは[要素i,n_i]の情報を詰めたmatrix
    l.sort(key=lambda x:x[1],reverse=True)
    #print(l)
    if (len(l)==3)and(l[0][1]==l[1][1]==l[2][1])and(l[0][0]^l[1][0]==l[2][0]):
        print("Yes")
    elif (len(l)==2)and(l[0][1]==2*l[1][1])and(l[1][0]==0):
        print("Yes")
    else:
        print("No")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N=int(input()) 
A=list(map(int,input().split()))
count=0
allcount=0
matrix=[]
ans=[0]*N
for i in range(N):
    buf=[0]*N
    if i==N-1:
        buf[0]=1
        buf[N-1]=1
    else:
        buf[i]=1
        buf[i+1]=1
    matrix.append(buf)
matrix=np.matrix(matrix)
A=np.array(A)
A=np.reshape(A,(1,N))
right=A.T
#print(right)
#print(matrix)
#print(np.linalg.inv(matrix))
rev=np.linalg.inv(matrix)
B=rev*right
#print(B)
B=np.reshape(B,(1,N))
B=B.tolist()
#print(B)
for i in range(N):
    ans[i]=int(2*B[0][i])
print(*ans,sep=" ")

Fixed submission:
#N%2==1なので
#a1=S-2((a2+a3)+(a4+a5)+...+(aN-1+aN))
#=S-2(A2+A4+...+AN-1)よりa1を求め
#ai+ai+1=2Ai<=>ai+1=2Ai-aiより再帰的にa2以降を求める
N=int(input())
A=list(map(int,input().split()))
count=0
allcount=0
matrix=[]
ans=[0]*N
allsum=0
a1=0
for i in range(N):
    allsum=allsum+A[i]
a1=allsum
for i in range(N):
    if i%2==1:
        a1=a1-2*A[i]
ans[0]=a1
for i in range(0,N-1,1):
    ans[i+1]=2*A[i]-ans[i]
print(*ans,sep=" ")