Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
def dfs(G,v,p):
    for nv,nw in G[v]:
        if(nv==p):
            continue
        if(nw%2==0):
            color[nv]=color[v]
        else:
            color[nv]=int(not color[v])
        dfs(G,nv,v)
N=int(input())
G=[[] for i in range(N)]
color=[-1]*N
for i in range(N-1):
    u,v,w=map(int,input().split())
    u,v=u-1,v-1
    G[u].append((v,w))
    G[v].append((u,w))
color[0]=0
dfs(G,0,-1)
print(*color,sep='\n')

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
def dfs(G,v,p):
    for nv,nw in G[v]:
        if(nv==p):
            continue
        if(nw%2==0):
            color[nv]=color[v]
        else:
            color[nv]=int(not color[v])
        dfs(G,nv,v)
N=int(input())
G=[[] for i in range(N)]
color=[-1]*N
for i in range(N-1):
    u,v,w=map(int,input().split())
    u,v=u-1,v-1
    G[u].append((v,w))
    G[v].append((u,w))
color[0]=0
dfs(G,0,-1)
print(*color,sep='\n')
Buggy python submission (verdict: Runtime Error):
def update(v):
    for nv in con[v]:
        if seen[nv]:
            continue
        seen[nv]=1
        update(nv)

N,M=map(int,input().split())
seen=[0]*N
con=[[] for i in range(N)]
cnt=[[i,0] for i in range(N)]
for i in range(M):
    X,Y,Z=map(int,input().split())
    X,Y=X-1,Y-1
    con[X].append(Y)
    con[Y].append(X)
    cnt[X][1]+=1
    cnt[Y][1]+=1
cnt.sort(key=lambda x:x[1],reverse=True)
ans=0
for i,a in cnt:
    if(seen[i]):
        continue
    ans+=1
    seen[i]=1
    update(i)
print(ans)

Fixed submission:
import sys
sys.setrecursionlimit(10**7)

def update(v):
    for nv in con[v]:
        if seen[nv]:
            continue
        seen[nv]=1
        update(nv)

N,M=map(int,input().split())
seen=[0]*N
con=[[] for i in range(N)]
cnt=[[i,0] for i in range(N)]
for i in range(M):
    X,Y,Z=map(int,input().split())
    X,Y=X-1,Y-1
    con[X].append(Y)
    con[Y].append(X)
    cnt[X][1]+=1
    cnt[Y][1]+=1
cnt.sort(key=lambda x:x[1],reverse=True)
ans=0
for i,a in cnt:
    if(seen[i]):
        continue
    ans+=1
    seen[i]=1
    update(i)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
def mbfs(S,H,W,d):
    dx=[1,0,-1,0]
    dy=[0,1,0,-1]
    while(len(d)!=0):
        h=d[0][0]
        w=d[0][1]
        x=d[0][2]
        d.popleft()
        for di in range(4):
            nh=h+dx[di]
            nw=w+dy[di]
            if(nh>H-1 or nh<0 or nw>W-1 or nw<0):
                continue
            if(S[nh][nw]=='#'):
                continue
            S[nh][nw]='#'
            d.append([nh,nw,x+1])
    return x
H,W=map(int,input().split())
A=[list(input()) for i in range(H)]
d=deque()
for i in range(H):
    for j in range(W):
        if(A[i][j]=='#'):
            d.append([i,j,0])
print(mbfs(A,H,W,d))

Fixed submission:
from collections import deque
def mbfs(S,H,W):
    dxy=[[1,0],[0,1],[-1,0],[0,-1]]
    while(len(d)!=0):
        h,w,x=d.popleft()
        for t,y in dxy:
            if(0<=h+t<=H-1 and 0<=w+y<=W-1 and S[h+t][w+y]!='#'):
                S[h+t][w+y]='#'
                d.append([h+t,w+y,x+1])
    return x
H,W=map(int,input().split())
A=[list(input()) for i in range(H)]
d=deque()
for i in range(H):
    for j in range(W):
        if(A[i][j]=='#'):
            d.append([i,j,0])
print(mbfs(A,H,W))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
def mbfs(S,H,W,sh,sw):
    dist[sh][sw]=0
    d=deque()
    d.append([sh,sw])
    dx=[1,0,-1,0]
    dy=[0,1,0,-1]
    while(len(d)!=0):
        h=d[0][0]
        w=d[0][1]
        d.popleft()
        for di in range(4):
            nh=h+dx[di]
            nw=w+dy[di]
            if(nh>H-1 or nh<0 or nw>W-1 or nw<0):
                continue
            if((dist[nh][nw]!=-1 and dist[nh][nw]<dist[h][w]+1) or S[nh][nw]=='#'):
                continue
            dist[nh][nw]=dist[h][w]+1
            d.append([nh,nw])
H,W=map(int,input().split())
A=[list(input()) for i in range(H)]
dist=[[-1]*W for i in range(H)]
for i in range(H):
    for j in range(W):
        if(A[i][j]=='#'):
            mbfs(A,H,W,i,j)
print(max(max(dist[i]) for i in range(H)))

Fixed submission:
from collections import deque
def mbfs(S,H,W):
    dxy=[[1,0],[0,1],[-1,0],[0,-1]]
    while(len(d)!=0):
        h,w,x=d.popleft()
        for t,y in dxy:
            if(0<=h+t<=H-1 and 0<=w+y<=W-1 and S[h+t][w+y]!='#'):
                S[h+t][w+y]='#'
                d.append([h+t,w+y,x+1])
    return x
H,W=map(int,input().split())
A=[list(input()) for i in range(H)]
d=deque()
for i in range(H):
    for j in range(W):
        if(A[i][j]=='#'):
            d.append([i,j,0])
print(mbfs(A,H,W))
Buggy python submission (verdict: Runtime Error):
from math import gcd
A,B,K=map(int,input().split())
g=gcd(A,B)
li=[]
for i in range(1,g+1):
    if(g%i==0):
        li.append(i)
print(li[-K])

Fixed submission:
A,B,K=map(int,input().split())
A,B=min(A,B),max(A,B)
cnt=0
for i in reversed(range(1,A+1)):
    if A%i==0 and B%i==0:
        cnt+=1
    if(cnt==K):
        print(i)
        exit()
Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())

#Union-Find

par=[i for i in range(N)]
siz=[1 for _ in range(N)]
rank=[0 for _ in range(N)]
root=set()

def find(x):
    if(par[x]==x):
        return x
    else:
        par[x]=find(par[x])
        return par[x]

def union(a,b):
    a=find(a)
    b=find(b)
    if(a==b):
        return 0
    else:
        if rank[a]>rank[b]:
            par[b]=a
            if b in root:
                root.remove(b)
            root.add(a)
            siz[a]+=siz[b]
        else:
            par[a]=b
            if a in root:
                root.remove(a)
            root.add(b)
            siz[b]+=siz[a]
            if rank[a]==rank[b]:
                rank[b]+=1
            
def size(a):
    return siz[find(a)]

def same(a,b):
    return find(a)==find(b)
p=N*(N-1)//2
edge=[]
for i in range(M):
    a,b=map(lambda x:int(x)-1,input().split())
    edge.append([a,b])
ans=[p]
for i in reversed(range(1,M)):
    res=0
    union(edge[i][0],edge[i][1])
    for x in root:
        s=size(x)
        res+=s*(s-1)//2
    ans.append(max(p-res,0))
print(*ans[::-1],sep='\n')

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

#Union-Find

par=[i for i in range(N)]
siz=[1 for _ in range(N)]
rank=[0 for _ in range(N)]
root=set()

def find(x):
    if(par[x]==x):
        return x
    else:
        par[x]=find(par[x])
        return par[x]

def union(a,b):
    a=find(a)
    b=find(b)
    if(a==b):
        return 0
    else:
        if rank[a]>rank[b]:
            par[b]=a
            if b in root:
                root.remove(b)
            root.add(a)
            siz[a]+=siz[b]
        else:
            par[a]=b
            if a in root:
                root.remove(a)
            root.add(b)
            siz[b]+=siz[a]
            if rank[a]==rank[b]:
                rank[b]+=1
def size(a):
    return siz[find(a)]

def same(a,b):
    return find(a)==find(b)
    
edge=[]
for i in range(M):
    a,b=map(lambda x:int(x)-1,input().split())
    edge.append([a,b])
p=N*(N-1)//2
res=[p]
for i in reversed(range(1,M)):
    if(not same(edge[i][0],edge[i][1])):
        p=p-size(edge[i][0])*size(edge[i][1])
        union(edge[i][0],edge[i][1])
    res.append(p)
print(*res[::-1],sep='\n')
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**7)

def dfs(v,p):
    if res_v[v]!=-1:
        return res_v[v]
    size[v]=len(G[v])
    dp[v]=[0]*size[v]
    res=1
    for i in range(size[v]):
        nv=G[v][i]
        if nv==p:
            p_i[v]=i
            continue
        R=dfs(nv,v)
        dp[v][i]=R
        res=res*(R+1)%MOD
    return res
    
def reroot(v,res_p,p):
    if p!=-1:
        dp[v][p_i[v]]=res_p
    for i in range(size[v]):
        ans[v]=ans[v]*(dp[v][i]+1)%MOD
    dp_L=[1]*(size[v]+1)
    dp_R=[1]*(size[v]+1)
    for i in range(size[v]):
        dp_L[i+1]=dp_L[i]*(dp[v][i]+1)%MOD
    for i in reversed(range(size[v])):
        dp_R[i]=dp_R[i+1]*(dp[v][i]+1)%MOD
        
    for i in range(size[v]):
        nv=G[v][i]
        if nv==p:
            continue
        reroot(nv,dp_L[i]*dp_R[i+1]%MOD,v)

N,MOD=map(int,input().split())
G=[[] for i in range(N)]
for i in range(N-1):
    x,y=map(lambda x:int(x)-1,input().split())
    G[x].append(y)
    G[y].append(x)
res_v=[-1]*N
dp=[[] for i in range(N)]
size=[-1]*N
p_i=[-1]*N
dp_L=[[] for i in range(N)]
dp_R=[[] for i in range(N)]
ans=[1]*N

z_root=dfs(0,-1)
res_v[0]=z_root
reroot(0,0,-1)
print(*ans,sep='\n')

Fixed submission:
N=int(input())
h=list(map(int,input().split()))
dp=[0,abs(h[1]-h[0])]
for i in range(2,N):
    dp.append(min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1])))
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
N,K=map(int,input().split())
h=list(map(int,input().split()))
dp=[0]*N
for i in range(1,N):
    dp[i]=min(dp[j]+abs(h[j]-h[i]) for j in range(max(i-K,0),i))
print(dp[N-1])

Fixed submission:
N=int(input())
h=list(map(int,input().split()))
dp=[0,abs(h[1]-h[0])]
for i in range(2,N):
    dp.append(min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1])))
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
N=int(input())
h=list(map(int,input().split()))
dp=[0,abs(h[1]-h[0])]
for i in range(2,N):
    dp.append(min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1])))
print(dp[i])

Fixed submission:
N=int(input())
h=list(map(int,input().split()))
dp=[0,abs(h[1]-h[0])]
for i in range(2,N):
    dp.append(min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1])))
print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
INF=100000000
N,K=map(int,input().split())
h=list(map(int,input().split()))
dp=[0]*N
for i in range(1,N):
    dp[i]=min(dp[j]+abs(h[j]-h[i]) for j in range(max(i-K,0),i))
print(dp[N-1])

Fixed submission:
INF=100000000
N,K=map(int,input().split())
h=list(map(int,input().split()))
dp=[0]*N
for i in range(1,N):
    dp[i]=min(dp[j]+abs(h[j]-h[i]) for j in range(max(i-K,0),i))
print(dp[N-1])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**6)
def rec(i,j):
    res=0
    if(dp[i][j]>=0):
        return dp[i][j]
    if(i==n):
        res=0
    elif(j<w[i]):
        res=rec(i+1,j)
    else:
        res=max(rec(i+1,j),rec(i+1,j-w[i])+v[i])
    dp[i][j]=res
    return res
n,x=map(int,input().split())
dp=[[-1]*(x+10) for i in range(n+10)]
w,v=[],[]
for i in range(n):
    a,b=map(int,input().split())
    w.append(a);v.append(b)
print(rec(0,x))

Fixed submission:
N,W=map(int,input().split())
weight=[0]*N
value=[0]*N
for i in range(N):
    weight[i],value[i]=map(int,input().split())
dp=[[0]*(W+1) for i in range(N+1)]
for i in range(N):
    for j in range(W+1):
        if(j>=weight[i]):
            dp[i+1][j]=max(dp[i][j-weight[i]]+value[i],dp[i][j])
        else:
            dp[i+1][j]=dp[i][j]
print(dp[N][W])

Buggy python submission (verdict: Time Limit Exceeded):
N,W=map(int,input().split())
weight=[0]*N
value=[0]*N
for i in range(N):
    weight[i],value[i]=map(int,input().split())
dp=[[0]*(W+1) for i in range(N+1)]
for i in range(N):
    for j in range(W+1):
        if(j>=weight[i]):
            dp[i+1][j]=max(dp[i][j-weight[i]]+value[i],dp[i][j])
        else:
            dp[i+1][j]=dp[i][j]
print(dp[N][W])

Fixed submission:
N,W=map(int,input().split())
weight=[0]*N
value=[0]*N
for i in range(N):
    weight[i],value[i]=map(int,input().split())
dp=[[0]*(W+1) for i in range(N+1)]
for i in range(N):
    for j in range(W+1):
        if(j>=weight[i]):
            dp[i+1][j]=max(dp[i][j-weight[i]]+value[i],dp[i][j])
        else:
            dp[i+1][j]=dp[i][j]
print(dp[N][W])
Buggy python submission (verdict: Runtime Error):
def solve(X,Y):
    res=''
    n,m=len(X),len(Y)
    dp=[[0]*(m+1) for i in range(m+1)]
    for i in range(n):
        for j in range(m):
            if(X[i]==Y[j]):
                dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]+1)
            dp[i+1][j+1]=max([dp[i+1][j+1],dp[i][j+1],dp[i+1][j]])
    i,j=i+1,j+1
    while(i>0 and j>0):
        if(dp[i][j]==dp[i-1][j]):
            i-=1
        elif(dp[i][j]==dp[i][j-1]):
            j-=1
        else:
            i-=1;j-=1
            res+=X[i]
    return res[::-1]

def main():
    X=input()
    Y=input()
    print(solve(X,Y))

if __name__=='__main__':
    main()

Fixed submission:
def solve(X,Y):
    res=''
    n,m=len(X),len(Y)
    dp=[[0]*(m+1) for i in range(n+1)]
    for i in range(n):
        for j in range(m):
            if(X[i]==Y[j]):
                dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]+1)
            dp[i+1][j+1]=max([dp[i+1][j+1],dp[i][j+1],dp[i+1][j]])
    i,j=i+1,j+1
    while(i>0 and j>0):
        if(dp[i][j]==dp[i-1][j]):
            i-=1
        elif(dp[i][j]==dp[i][j-1]):
            j-=1
        else:
            i-=1;j-=1
            res+=X[i]
    return res[::-1]

def main():
    X=input()
    Y=input()
    print(solve(X,Y))

if __name__=='__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**6)
MOD=10**9+7
def dfs(v,p):
    if seen[v]:
        return dp[v]
    seen[v]=1
    b,w=1,1
    for nv in G[v]:
        if(nv==p):
            continue
        bw=dfs(nv,v)
        w*=sum(bw);w%=MOD
        b*=bw[1];b%=MOD
    dp[v]=(b,w)
    return (b,w)
    
N=int(input())
G,dp,seen=[],[],[]
for i in range(N):
    G.append([]);dp.append([0,0]);seen.append(0)
for i in range(N-1):
    x,y=map(lambda x:int(x)-1,input().split())
    G[x].append(y)
    G[y].append(x)
print(sum(dfs(0,-1))%MOD)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
MOD=10**9+7
def dfs(v,p):
    if seen[v]:
        return dp[v]
    seen[v]=1
    b,w=1,1
    for nv in G[v]:
        if(nv==p):
            continue
        bw=dfs(nv,v)
        w*=sum(bw);w%=MOD
        b*=bw[1];b%=MOD
    dp[v]=(b,w)
    return (b,w)
    
N=int(input())
G,dp,seen=[],[],[]
for i in range(N):
    G.append([]);dp.append([0,0]);seen.append(0)
for i in range(N-1):
    x,y=map(lambda x:int(x)-1,input().split())
    G[x].append(y)
    G[y].append(x)
print(sum(dfs(0,-1))%MOD)
Buggy python submission (verdict: Runtime Error):
N,K=map(int,input().split())
a=list(map(int,input().split()))
cum=[0]*(N+1)
for i in range(N):
    cum[i+1]=cum[i]+a[i]
beau=[]
for i in range(N+1):
    for j in range(i):
        beau.append(cum[i]-cum[j])
beau.sort()
bit=[0]*30
for x in beau:
    j=0
    while((x>>j)>0):
        bit[j]+=x>>j&1
        j+=1
ans=0
for i in range(len(beau)-K+1):
    res=1023
    for j in range(i,i+K):
        res&=beau[j]
    ans=max(ans,res)
print(ans)

Fixed submission:
N,K=map(int,input().split())
a=list(map(int,input().split()))
cum=[0]*(N+1)
for i in range(N):
    cum[i+1]=cum[i]+a[i]
A=[]
for i in range(N+1):
    for j in range(i):
        A.append(cum[i]-cum[j])
L=len(A)
ans=0
for j in reversed(range(46)):
    li=[]
    for i in range(L):
        if A[i]>>j&1:
            li.append(A[i])
    if len(li)<K:
        continue
    ans+=1<<j
    A=li
    L=len(A)
print(ans)
Buggy python submission (verdict: Runtime Error):
INF=10**20
N=int(input())
x=[];y=[];h=[]
for i in range(N):
    X,Y,H=map(int,input().split())
    x.append(X);y.append(Y);h.append(H)
for i in range(101):#Cx
    for j in range(101):#Cy
        res=-INF
        T=True
        mli=[]
        for k in range(N):
            tmp=h[k]+abs(x[k]-i)+abs(y[k]-j)
            if(h[k]>0):
                if(res==-INF):
                    res=tmp
                elif(res!=tmp):
                    T=not T
                    break
            elif(h[k]==0):
                mli.append(tmp)
        for x in mli:
            if(x<res):
                T=not T
                break
        if T:
            print(i,j,res)
            exit()

Fixed submission:
INF=10**20
N=int(input())
xyh=[list(map(int,input().split())) for i in range(N)]
xyh=sorted(xyh,key=lambda xyh:xyh[2],reverse=True)
for i in range(101):
    for j in range(101):
        res=-INF
        T=True
        for k in range(N):
            tmp=xyh[k][2]+abs(xyh[k][0]-i)+abs(xyh[k][1]-j)
            if(xyh[k][2]>0):
                if(res==-INF):
                    res=tmp
                elif(res!=tmp):
                    T=not T
                    break
            elif(xyh[k][2]==0):
                if(tmp<res):
                    T=not T
                    break
        if T:
            print(i,j,res)
            exit()
Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
c=[list(map(int,input().split())) for i in range(N)]

bit=[[] for i in range(2**3)]
for k in range(N):
    for i in range(2**3):
        t=c[k].copy()
        for j in range(3):
            if(i>>j&1):
                t[j]*=-1
        bit[i].append(t)
for i in range(2**3):
    bit[i].sort(key=lambda x:(x[0],x[1],x[2]),reverse=True)
res=0
for i in range(2**3):
    p=[1,1,1]
    for j in range(3):
        if(i>>j&1):
            p[j]*=-1
    z,o,t=0,0,0
    for k in range(M):
        z+=bit[i][k][0]*p[0]
        o+=bit[i][k][1]*p[1]
        t+=bit[i][k][2]*p[2]
    res=max(res,abs(z)+abs(o)+abs(t))
print(res)

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

bit=[[] for i in range(2**3)]
for k in range(N):
    for i in range(2**3):
        t=c[k].copy()
        for j in range(3):
            if(i>>j&1):
                t[j]*=-1
        bit[i].append(t)
for i in range(2**3):
    bit[i].sort(key=lambda x:(x[0]+x[1]+x[2]),reverse=True)
res=0
for i in range(2**3):
    p=[1,1,1]
    for j in range(3):
        if(i>>j&1):
            p[j]*=-1
    z,o,t=0,0,0
    for k in range(M):
        z+=bit[i][k][0]*p[0]
        o+=bit[i][k][1]*p[1]
        t+=bit[i][k][2]*p[2]
    res=max(res,abs(z)+abs(o)+abs(t))
print(res)
Buggy python submission (verdict: Time Limit Exceeded):
def isok(a):
    for j in range(21):
        if(a>>j&1):
            if(bit[j]>0):
                return False
    return True
def bitplus(a):
    for j in range(21):
        if(a>>j&1):
            bit[j]+=1
def bitdif(a):
    for j in range(21):
        if(a>>j&1):
            bit[j]-=a>>j&1

N=int(input())
A=list(map(int,input().split()))
left=0
ans=0
bit=[0]*21
right=0
while(left<N):
    while(right<N and isok(A[right])):
        bitplus(A[right])
        right+=1
    ans+=right-left
    if right==left:
        right+=1
    else:
        bitdif(A[left])
    left+=1
print(ans)

Fixed submission:
def isok(a):
    for j in range(21):
        if(a>>j&1):
            if(bit[j]>0):
                return False
    return True
def bitplus(a):
    for j in range(21):
        if(a>>j&1):
            bit[j]+=1
def bitdif(a):
    for j in range(21):
        if(a>>j&1):
            bit[j]-=a>>j&1

N=int(input())
A=list(map(int,input().split()))
left=0
ans=0
bit=[0]*21
right=0
while(left<N):
    while(right<N and isok(A[right])):
        bitplus(A[right])
        right+=1
    ans+=right-left
    if right==left:
        right+=1
    else:
        bitdif(A[left])
    left+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=[]
for i in range(N):
    A.append(int(input()))
ans=1
li=[A[0]]
for i in range(1,N):
    ans+=1 if li.count(A[i])%2==0 else -1
    li.append(A[i])
print(ans)


Fixed submission:
N=input()
for i in N:
    if(i=='9'):
        print("Yes")
        exit()
print('No')
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=[]
for i in range(N):
    A.append(int(input()))
ans=1
li=[A[0]]
for i in range(1,N):
    ans+=1 if li.count(A[i])%2==0 else -1
    li.append(A[i])
print(ans)

Fixed submission:
N=int(input())
A=[]
for i in range(N):
    A.append(int(input()))
B=sorted(A)
ans=0
tmp=B[0]
cnt=1
for i in range(1,N):
    if(tmp==B[i]):
        cnt+=1
    else:
        ans+=(cnt%2)
        cnt=1
        tmp=B[i]
ans+=cnt%2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=[]
for i in range(N):
    A.append(int(input()))
ans=1
li=[A[0]]
for i in range(1,N):
    ans+=1 if li.count(A[i])%2==0 else -1
    li.append(A[i])
print(ans)

Fixed submission:
N=int(input())
A=[]
for i in range(N):
    A.append(int(input()))
B=sorted(A)
ans=0
tmp=B[0]
cnt=1
for i in range(1,N):
    if(tmp==B[i]):
        cnt+=1
    else:
        ans+=(cnt%2)
        cnt=1
        tmp=B[i]
ans+=cnt%2
print(ans)
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
i=0
cnt=0
while(i<N):
    if(A[i]==i+1):
        A[i],A[i+1]=A[i+1],A[i]
        cnt+=1
        i+=2
        continue
    i+=1
print(cnt)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
i=0
cnt=0
while(i<N):
    if(A[i]==i+1):
        if(i!=N-1):
            A[i],A[i+1]=A[i+1],A[i]
        cnt+=1
        i+=2
        continue
    i+=1
print(cnt)
Buggy python submission (verdict: Runtime Error):
from collections import Counter
n=int(input())
a=list(map(int,input().split()))

c=Counter(a)
m=c.most_common()
tmp=[]
for i in range(len(m)):
    if(m[i][1]>=2):
        tmp.append(m[i])
d=sorted(tmp,key=lambda tmp:tmp[1])

if(d[0][1]>=4):
    print(d[0][0]**2)
elif(len(d)>=2):
    print(d[0][0]*d[1][0])
else:
    print(0)

Fixed submission:
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
c=Counter(a)
m=c.most_common()
t=sorted(m,key=lambda m:m[0],reverse=True)
w=0
b=0
for i in range(len(t)):
    if(t[i][1]>=4):
        if(w==b==0):
            w=t[i][0]
            b=t[i][0]
        elif(w==0):
            w=t[i][0]
        elif(b==0):
            b=t[i][0]
    elif(t[i][1]>=2):
        if(w==0):
            w=t[i][0]
        elif(b==0):
            b=t[i][0]
print(w*b)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
b=[]
for i in range(n):
    if(i%2==0):
        b.append(a[i])
    else:
        b.insert(0,a[i])

for i in range(n) if n%2==0 else (reversed(range(n))):
    print(b[i],end=' ')

Fixed submission:
from collections import deque
n=int(input())
a=list(map(int,input().split()))
b=deque()
for i in range(n):
    if(i%2==0):
        b.append(a[i])
    else:
        b.appendleft(a[i])

for i in range(n) if n%2==0 else (reversed(range(n))):
    print(b[i],end=' ')