Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline

n,m = map(int, input().split())
link = [[] for _ in range(n)]
for i in range(m):
    tmp = list(map(int,input().split()))
    link[tmp[0]-1].append([tmp[1]-1,tmp[2]])
    link[tmp[1]-1].append([tmp[0]-1,-tmp[2]])
from collections import deque
vis=[False]*n
dist=[0]*n
for i in range(n):
    if vis[i]:
        continue
    vis[i] = True
    Q = deque()
    Q.append([i,0])
    while Q:
        now,cnt = Q.popleft()
        vis[now]=True
        for nxt,nxt_dist in link[now]:
            if dist[nxt] != cnt+nxt_dist:# NG or 0
                if vis[nxt]:
                    print("No")
                    exit()
                dist[nxt] = cnt+nxt_dist
            if not vis[nxt]:
                Q.append([nxt,cnt+nxt_dist])
print("Yes")

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

n,m = map(int, input().split())
link = [[] for _ in range(n)]
for i in range(m):
    tmp = list(map(int,input().split()))
    link[tmp[0]-1].append([tmp[1]-1,tmp[2]])
    link[tmp[1]-1].append([tmp[0]-1,-tmp[2]])
from collections import deque
INF=10**10
dist=[INF]*n
for i in range(n):
    if dist[i]!=INF:
        continue
    dist[i]=0
    Q = deque()
    Q.append([i,0])
    while Q:
        now,cnt = Q.popleft()
        for nxt,nxt_dist in link[now]:
            if dist[nxt] == INF:
                dist[nxt] = cnt+nxt_dist
                Q.append([nxt,cnt+nxt_dist])
            elif dist[nxt] != cnt+nxt_dist:
                    print("No")
                    exit()

print("Yes")

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int, input().split())
link = [[] for _ in range(n)]
for i in range(m):
    tmp = list(map(int,input().split()))
    link[tmp[0]-1].append([tmp[1]-1,tmp[2]])
    link[tmp[1]-1].append([tmp[0]-1,-tmp[2]])
from collections import deque
vis=[False]*n
dist=[0]*n
for i in range(n):
    if vis[i]:
        continue
    vis[i] = True
    Q = deque()
    Q.append([i,0])
    while Q:
        now,cnt = Q.popleft()
        vis[now]=True
        for nxt,nxt_dist in link[now]:
            if dist[nxt] != cnt+nxt_dist:# NG or 0
                if vis[nxt]:
                    print("No")
                    exit()
                dist[nxt] = cnt+nxt_dist
            if not vis[nxt]:
                Q.append([nxt,cnt+nxt_dist])
print("Yes")

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

n,m = map(int, input().split())
link = [[] for _ in range(n)]
for i in range(m):
    tmp = list(map(int,input().split()))
    link[tmp[0]-1].append([tmp[1]-1,tmp[2]])
    link[tmp[1]-1].append([tmp[0]-1,-tmp[2]])
from collections import deque
INF=10**10
dist=[INF]*n
for i in range(n):
    if dist[i]!=INF:
        continue
    dist[i]=0
    Q = deque()
    Q.append([i,0])
    while Q:
        now,cnt = Q.popleft()
        for nxt,nxt_dist in link[now]:
            if dist[nxt] == INF:
                dist[nxt] = cnt+nxt_dist
                Q.append([nxt,cnt+nxt_dist])
            elif dist[nxt] != cnt+nxt_dist:
                    print("No")
                    exit()

print("Yes")
Buggy python submission (verdict: Time Limit Exceeded):
k = int(input())
a = list(map(int, input().split()))

a.reverse()
now=[]
now.append(2)

for group in a:
    nxt_now = []
    for num in now:
        if num % group !=0:
            continue

        for i in range(group):
            nxt_now.append(num+i)
    if len(nxt_now) ==0:
        print(-1)
        exit()

    now = nxt_now
print(min(now),max(now))

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

mn,mx = 2,2
for g in a:
    mn = g * (((mn - 1) // g) + 1)
    mx = g * (mx//g) + g - 1

    if mn > mx:
        print(-1)
        exit()

print(mn,mx)
Buggy python submission (verdict: Runtime Error):
n=input()
l=[]
for i in range(n):
  l.append(int(input()))
print(len(set(l)))
        

Fixed submission:
n=int(input())
l=[]
for i in range(n):
  l.append(int(input()))
print(len(set(l)))

Buggy python submission (verdict: Runtime Error):
n=input()
l=[]
for i in range(n):
  l.apend(int(input()))
print(len(set(l)))
        

Fixed submission:
n=int(input())
l=[]
for i in range(n):
  l.append(int(input()))
print(len(set(l)))
Buggy python submission (verdict: Runtime Error):
n,a,b = map(int, input().split())

ans=0
for i in range(n):
  num=str(i+1)
  sm=0
  for j in num:
    sm+=j
  if a<=sm<=b:
    ans+=1
print(ans)
    
  

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

ans=0
for i in range(n):
  num=str(i+1)
  sm=0
  for j in num:
    sm+=int(j)
  if a<=sm<=b:
    ans+=(i+1)
print(ans)

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

ans=0
for i in range(n)
  num=str(i+1)
  sm=0
  for j in num:
    sm+=j
  if a<=sm<=b:
    ans+=1
print(ans)
    
  

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

ans=0
for i in range(n):
  num=str(i+1)
  sm=0
  for j in num:
    sm+=int(j)
  if a<=sm<=b:
    ans+=(i+1)
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
a.sort()

ans=0
lastnum=a[0]
cnt=1
for num in a[1:]:
    if num==lastnum:
        cnt+=1
    else:
        ans+=min(cnt,abs(cnt-lastnum))
        cnt=1
    tmp=lastnum
    lastnum=num

ans+=min(cnt,abs(cnt-tmp))
print(ans)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))

from collections import defaultdict
d = defaultdict(int)

for num in a:
    d[num]+=1

ans=0
for num,cnt in d.items():
    if num > cnt:
        ans+=cnt
    else:
        ans+=cnt-num
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
st=str(n)

sm = 0
for i in st:
  sm+=int(i)
if n%sm==0:
  print("Yes")
else
  print("No")

Fixed submission:
n=int(input())
st=str(n)

sm = 0
for i in st:
  sm+=int(i)
if n%sm==0:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
n = int(input())
f=[]
for i in range(n):
    tmp = list(map(int,input().split()))
    f.append(tmp)
p=[]
for i in range(n):
    tmp = list(map(int,input().split()))
    p.append(tmp)

from itertools import *
first=True
ans=-10**12
for tmp in list(product([0,1], repeat=10)):
    if first:
        first=False
        continue

    for i in range(n):
        cnt=0
        for j in range(10):
            cnt+= tmp[j] & mise[j]
        sm=0
        for i in range(n):
            sm+=p[i][cnt]
        if ans < sm:
            ans=sm
print(ans)

Fixed submission:
n = int(input())
f=[]
for i in range(n):
    tmp = list(map(int,input().split()))
    f.append(tmp)
p=[]
for i in range(n):
    tmp = list(map(int,input().split()))
    p.append(tmp)

from itertools import *
first=True
ans=-10**12
for tmp in list(product([0,1], repeat=10)):
    if first:
        first=False
        continue

    ona=[]
    for mise in f:
        cnt=0
        for j in range(10):
            cnt+= tmp[j] & mise[j]
        ona.append(cnt)

    sm=0
    for i in range(len(p)):
        sm+=p[i][ona[i]]
    if ans < sm:
        ans=sm
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
k=int(input())

now=1
for i in range(n):
  if now*2 >=k
  	now+=k
  else:
    now*=2
print(now)


Fixed submission:
n=int(input())
k=int(input())

now=1
for i in range(n):
  if now*2 >=now+k:
  	now+=k
  else:
    now*=2
print(now)
Buggy python submission (verdict: Runtime Error):
s=input()
print(s.count("1")

Fixed submission:
s=input()
print(s.count("1"))
Buggy python submission (verdict: Runtime Error):
n = int(input())
p = list(map(int, input().split()))

i=0
ans=0
while i<n-1:                                                                                     if p[i] == i+1 and p[i+1] == i+2:
        p[i],p[i+1] = p[i+1],p[i]
        ans+=1
    elif p[i] == i+1 and p[i+1] != i+2:
        p[i],p[i+1] = p[i+1],p[i]
        ans+=1
    i+=1
if p[n-1] == n and p[n-2]!=n-1:
    ans+=1
print(ans)

Fixed submission:
n = int(input())
p = list(map(int, input().split()))

i=0
ans=0
while i<n-1:
    if p[i] == i+1 and p[i+1] == i+2:
        p[i],p[i+1] = p[i+1],p[i]
        ans+=1
    elif p[i] == i+1 and p[i+1] != i+2:
        p[i],p[i+1] = p[i+1],p[i]
        ans+=1
    i+=1
if p[n-1] == n and p[n-2]!=n-1:
    ans+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
s=input()

sets=set(s)

for i in range(97,123):
  if not ord(i) in sets:
    print(ord(i))
    exit()
print("None")

Fixed submission:
s=input()

sets=set(s)

for i in range(97,123):
  if not chr(i) in sets:
    print(chr(i))
    exit()
print("None")
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = []
for _ in range(N):
    S.append(int(input()))

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

result=1
for num in S:
    result = lcm(result,num)
print(result)

Fixed submission:
N = int(input())
S = []
for _ in range(N):
    S.append(int(input()))

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

result=1
for num in S:
    result = lcm(result,num)
print(result)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
abc=[]
for i in range(n-1):
    tmp = list(map(int,input().split()))
    abc.append(tmp)
q,k = map(int, input().split())
que = []
for i in range(q):
    tmp = list(map(int,input().split()))
    que.append(tmp)

from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
from scipy.sparse import csr_matrix

arr = [[0 for i in range(n)] for j in range(n)]
for a in abc:
    arr[a[0]-1][a[1]-1] = a[2]
    arr[a[1]-1][a[0]-1] = a[2]

dist = dijkstra(csr_matrix(arr),indices=[k-1])

for tmp in que:
    print(int(dist[0][tmp[0]-1] + dist[0][tmp[1]-1]))

Fixed submission:
n = int(input())
abc=[]
for i in range(n-1):
    tmp = list(map(int,input().split()))
    abc.append(tmp)
q,k = map(int, input().split())
que = []
for i in range(q):
    tmp = list(map(int,input().split()))
    que.append(tmp)

link = [[] for _ in range(n)]
for tmp in abc:
    link[tmp[0]-1].append([tmp[1]-1,tmp[2]])
    link[tmp[1]-1].append([tmp[0]-1,tmp[2]])

dist=[-1]*n

from collections import deque
Q = deque()
Q.append([k-1,0])

while Q:
    now,now_d=Q.popleft()

    for nxt in link[now]:
        if dist[nxt[0]]!=-1:
            continue
        nxt_d =nxt[1] + now_d
        dist[nxt[0]]=nxt_d
        Q.append([nxt[0],nxt_d])

for tmp in que:
    print(dist[tmp[0]-1] + dist[tmp[1]-1])

Buggy python submission (verdict: Runtime Error):
n = int(input())
abc=[]
for i in range(n-1):
    tmp = list(map(int,input().split()))
    abc.append(tmp)
q,k = map(int, input().split())
que = []
for i in range(q):
    tmp = list(map(int,input().split()))
    que.append(tmp)

from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
from scipy.sparse import csr_matrix

arr = [[0 for i in range(n)] for j in range(n)]
for a in abc:
    arr[a[0]-1][a[1]-1] = a[2]
    arr[a[1]-1][a[0]-1] = a[2]

dist = dijkstra(csr_matrix(arr),indices=[k-1])

for tmp in que:
    print(int(dist[0][tmp[0]-1] + dist[0][tmp[1]-1]))

Fixed submission:
n = int(input())
abc=[]
for i in range(n-1):
    tmp = list(map(int,input().split()))
    abc.append(tmp)
q,k = map(int, input().split())
que = []
for i in range(q):
    tmp = list(map(int,input().split()))
    que.append(tmp)

link = [[] for _ in range(n)]
for tmp in abc:
    link[tmp[0]-1].append([tmp[1]-1,tmp[2]])
    link[tmp[1]-1].append([tmp[0]-1,tmp[2]])

dist=[-1]*n

from collections import deque
Q = deque()
Q.append([k-1,0])

while Q:
    now,now_d=Q.popleft()

    for nxt in link[now]:
        if dist[nxt[0]]!=-1:
            continue
        nxt_d =nxt[1] + now_d
        dist[nxt[0]]=nxt_d
        Q.append([nxt[0],nxt_d])

for tmp in que:
    print(dist[tmp[0]-1] + dist[tmp[1]-1])
Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int, input().split())

S = []
for _ in range(M):
    D = list(map(int, input().split()))
    S.append(D)

#S.sort(key=lambda x:x[0])
S.sort()

first = []

for tmp in S:
    if tmp[0]!=1:
        break
    first.append(tmp[1])

for tmp in S:
    if tmp[1] == N and tmp[0] in first:
        print("POSSIBLE")
        exit()
print("IMPOSSIBLE")

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

S = []
for _ in range(M):
    D = list(map(int, input().split()))
    S.append(D)

set1=set()
set2=set()

for tmp in S:
    if tmp[0]==1:
        set1.add(tmp[1])
    if tmp[1]==N:
        set2.add(tmp[0])

if len(set1&set2) == 0:
    print("IMPOSSIBLE")
else:
    print("POSSIBLE")

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int, input().split())

S = []
for _ in range(M):
    D = list(map(int, input().split()))
    S.append(D)

#S.sort(key=lambda x:x[0])
S.sort()

first = []

for tmp in S:
    if tmp[0]!=1:
        break
    first.append(tmp[1])

for tmp in S:
    if tmp[0] in first:
        if tmp[1] == N:
            print("POSSIBLE")
            exit()
print("IMPOSSIBLE")

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

S = []
for _ in range(M):
    D = list(map(int, input().split()))
    S.append(D)

set1=set()
set2=set()

for tmp in S:
    if tmp[0]==1:
        set1.add(tmp[1])
    if tmp[1]==N:
        set2.add(tmp[0])

if len(set1&set2) == 0:
    print("IMPOSSIBLE")
else:
    print("POSSIBLE")
Buggy python submission (verdict: Runtime Error):
N,P = map(int, input().split())
A = list(map(int, input().split()))

even_num=0
odd_num=0

for a in A:
    if a%2==0:
        even_num+=1
    else:
        odd_num+=1

ev_case = 2**even_num

from scipy.special import comb

res=0
for i in range(P,odd_num+1,2):
    res += comb(odd_num, i, exact=True)

print(ev_case*res)

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

even_num=0
odd_num=0

for a in A:
    if a%2==0:
        even_num+=1
    else:
        odd_num+=1

ev_case = 2**even_num


from math import factorial

res=0
for i in range(P,odd_num+1,2):                                                                   res += factorial(odd_num) / factorial(i) / factorial(odd_num - i)

print(int(ev_case*res))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

dup=[0]*n
for num in a:
    dup[num-1]+=1
    if dup[num-1]>1:
        break

A=-1
B=-1
for i in range(len(a)):
    if a[i]==num:
        if A==-1:
            A=i
        else:
            B=i
B=n-B
def find_power(n,mod=10**9+7):
    powlist=[0]*(n+1)
    powlist[0]=1
    powlist[1]=1
    for i in range(2,n+1):
        powlist[i]=powlist[i-1]*i%(mod)
    return powlist

def find_inv_power(n,mod=10**9+7):
    powlist=find_power(n)
    check=powlist[-1]
    first=1
    uselist=[0]*(n+1)
    secondlist=[0]*30
    secondlist[0]=check
    secondlist[1]=check**2
    for i in range(28):
        secondlist[i+2]=(secondlist[i+1]**2)%(10**9+7)
    a=format(10**9+5,"b")
    for j in range(30):
        if a[29-j]=="1":
            first=(first*secondlist[j])%(10**9+7)
    uselist[n]=first
    for i in range(n,0,-1):
        uselist[i-1]=(uselist[i]*i)%(10**9+7)
    return uselist

mod = 10**9+7
NUM = (10**5)+100
p_lis=find_power(NUM,mod)
ip_lis=find_inv_power(NUM,mod)
def comb(n,r,mod=10**9+7):
    if n<r:
        return 0
    elif n>=r:
        return (p_lis[n]*ip_lis[r]*ip_lis[n-r])%(mod)

print(n)
for k in range(2,n+2):
    base=comb(n+1,k)
    for i in range(k):
        j=k-i-1
        base-= comb(A,i) *comb(B,j)

    print(base)


Fixed submission:
n = int(input())
a = list(map(int, input().split()))

dup=[0]*n
for num in a:
    dup[num-1]+=1
    if dup[num-1]>1:
        break

A=-1
B=-1
for i in range(len(a)):
    if a[i]==num:
        if A==-1:
            A=i
        else:
            B=i
B=n-B

def find_power(n,mod=10**9+7):
    powlist=[0]*(n+1)
    powlist[0]=1
    powlist[1]=1
    for i in range(2,n+1):
        powlist[i]=powlist[i-1]*i%(mod)
    return powlist
  
def find_inv_power(n,mod=10**9+7):
    powlist=find_power(n)
    check=powlist[-1]
    first=1
    uselist=[0]*(n+1)
    secondlist=[0]*30
    secondlist[0]=check
    secondlist[1]=check**2
    for i in range(28):
        secondlist[i+2]=(secondlist[i+1]**2)%(10**9+7)
    a=format(10**9+5,"b")
    for j in range(30):
        if a[29-j]=="1":
            first=(first*secondlist[j])%(10**9+7)
    uselist[n]=first
    for i in range(n,0,-1):
        uselist[i-1]=(uselist[i]*i)%(10**9+7)
    return uselist

mod = 10**9+7
NUM = (10**5)+100
p_lis=find_power(NUM,mod)
ip_lis=find_inv_power(NUM,mod)

def comb(n,r,mod=10**9+7):
    if n<r:
        return 0
    elif n>=r:
        return (p_lis[n]*ip_lis[r]*ip_lis[n-r])%(mod)

print(n)
for k in range(2,n+2):
    base=comb(n+1,k) - comb(A+B,k-1)

    print(base%mod)
Buggy python submission (verdict: Runtime Error):
x,a,b=map(int, input().split())

if b<=a:
  print("delicious")
elif a+x>b:
  print("dangerous")
else:
  print("safe"

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

if b<=a:
  print("delicious")
elif a+x>=b:
  print("safe")
else:
  print("dangerous")
Buggy python submission (verdict: Runtime Error):
s=input()
import collections
c = collections.Counter(l)

for i in c.values():
  if i!=1:
    print("no")
    exit()
print("yes")

Fixed submission:
s=input()
import collections
c = collections.Counter(s)

for i in c.values():
  if i!=1:
    print("no")
    exit()
print("yes")
Buggy python submission (verdict: Runtime Error):
x,y = map(int, input().split())
if x==2 or y==2:
  print("No")
  exit()

if x==4 or x==6 or x==9 or x==11:
  if y==4 or y==6 or y==9 or y~=11:
    print("Yes")
  else:
    print("No")
else:
    print("No")
 

Fixed submission:
x,y = map(int, input().split())
if x==2 or y==2:
  print("No")
  exit()

if x==4 or x==6 or x==9 or x==11:
  if y==4 or y==6 or y==9 or y==11:
    print("Yes")
  else:
    print("No")
else:
    print("Yes")

Buggy python submission (verdict: Runtime Error):
x,y = map(int, input().split())
if x==2 or y==2:
  print("No")
  exit()

if x==4 or x==6 or x==9 or x==11:
  if y==4 or y==6 or y==9 or y~=11:
    print("Yes")
  else:
    print("No")
else:
	print("No")
  

Fixed submission:
x,y = map(int, input().split())
if x==2 or y==2:
  print("No")
  exit()

if x==4 or x==6 or x==9 or x==11:
  if y==4 or y==6 or y==9 or y==11:
    print("Yes")
  else:
    print("No")
else:
    print("Yes")
Buggy python submission (verdict: Runtime Error):
n,m = map(int, input().split())
ans=[0]*n
for i in range(n):
  a,b = list(map(int,input().split()))
  ans[a-1]+=1
  ans[b-1]+=1
for i in range(n):
  print(ans[i])
  

Fixed submission:
n,m = map(int, input().split())
ans=[0]*n
for i in range(m):
  a,b = list(map(int,input().split()))
  ans[a-1]+=1
  ans[b-1]+=1
for i in range(n):
  print(ans[i])
Buggy python submission (verdict: Runtime Error):
n= int(input())
def fact_m(n, modulus=10**9+7):
    ans=1
    if n <= modulus//2:
        for i in range(1,n+1):
            ans = (ans * i) % modulus   
    else:
        for i in range(1,modulus-n):
            ans = (ans * i) % modulus
        ans = modinv(ans, modulus)

        if n % 2 == 0:
            ans = -1*ans + modulus
    return ans % modulus
print(fact_m(m))

Fixed submission:
n= int(input())
def fact_m(n, modulus=10**9+7):
    ans=1
    if n <= modulus//2:
        for i in range(1,n+1):
            ans = (ans * i) % modulus   
    else:
        for i in range(1,modulus-n):
            ans = (ans * i) % modulus
        ans = modinv(ans, modulus)

        if n % 2 == 0:
            ans = -1*ans + modulus
    return ans % modulus
print(fact_m(n))
Buggy python submission (verdict: Time Limit Exceeded):
k, s = map(int, input().split())
cnt=0

for x in range(0,k+1):
    for y in range(0,k+1):
        for z in range(0,k+1):
            if x+y+z==s:
                cnt+=1

print(cnt)

Fixed submission:
k, s = map(int, input().split())
cnt=0

for x in range(0,k+1):
    for y in range(0,k+1):
        z = s - x - y
        if 0 <= z and z <= k:
            cnt+=1

print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    def size(self, x):
        return -self.parents[self.find(x)]
    def same(self, x, y):
        return self.find(x) == self.find(y)
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
    def group_count(self):
        return len(self.roots())
import sys
input=sys.stdin.readline
n,k,l = map(int, input().split())
uf_road = UnionFind(n)
uf_train = UnionFind(n)
for i in range(k):
    p,q=list(map(int, input().split()))
    uf_road.union(p-1, q-1)
for i in range(l):
    p,q=list(map(int, input().split()))
    uf_train.union(p-1, q-1)

ans=[0]*n
for i in range(n):
    if ans[i]!=0:
        continue
    mem1=set(uf_road.members(i))
    mem2=set(uf_train.members(i))
    inter=mem1 & mem2
    int_num=len(inter)
    for tmp in inter:
        ans[tmp]=int_num
print(*ans)

Fixed submission:
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    def size(self, x):
        return -self.parents[self.find(x)]
    def same(self, x, y):
        return self.find(x) == self.find(y)
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
    def group_count(self):
        return len(self.roots())
import sys
input=sys.stdin.readline
n,k,l = map(int, input().split())
uf_road = UnionFind(n)
uf_train = UnionFind(n)
for i in range(k):
    p,q=list(map(int, input().split()))
    uf_road.union(p-1, q-1)
for i in range(l):
    p,q=list(map(int, input().split()))
    uf_train.union(p-1, q-1)

from collections import defaultdict
d = defaultdict(int)
for i in range(n):
    d[uf_road.find(i), uf_train.find(i)] += 1
print(*(d[uf_road.find(i), uf_train.find(i)] for i in range(n)))
Buggy python submission (verdict: Runtime Error):
n = int(input())
import math

def getk(n):
    return int((1+math.sqrt(8*n-7))/2)

while(True):
    k = getk(n)
    print(k,end="")
    print(" ",end="")
    if k ==1:
        break
    n-=k

Fixed submission:
n = int(input())
import math

def getk(num):
    return int((1+math.sqrt(8*num-7))/2)

while(True):
    k = getk(n)
    print(k)
    n-=k
    if k == 1 or n<=0:
        break
Buggy python submission (verdict: Runtime Error):
s=input()
import collections
c = collections.Counter(l)

if (c["N"]!=0 and c["S"]==0) or (c["N"]==0 and c["S"]!=0) or (c["W"]!=0 and c["E"]==0) or (c["W"]==0 and c["E"]!=0):
  print("Yes")
else:
  print("No")
  
  

Fixed submission:
s=input()
import collections
c = collections.Counter(s)

if (c["N"]!=0 and c["S"]==0) or (c["N"]==0 and c["S"]!=0) or (c["W"]!=0 and c["E"]==0) or (c["W"]==0 and c["E"]!=0):
  print("No")
else:
  print("Yes")
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = []
for _ in range(n):
    a.append(int(input()))
import numpy as np
lis = np.argsort(np.array(a))

ans=0
for i in range(n):
    if i%2 != lis[i]%2:
        ans+=1
print(ans//2)

Fixed submission:
n = int(input())
a = []
for _ in range(n):
    a.append(int(input()))
import numpy as np
lis = np.argsort(np.array(a))

ans=0
for i in range(n):
    if i%2 != lis[i]%2:
        ans+=1
print(ans//2)