Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))
summ = 0
answer = 0
for i in range(N):
    for l in range(i):
        summ += A[l] * A[i]
answer = summ % 1000000007
print(answer)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
summ1 = 0
answer = 0
temp = 0
summ2 = 0
summ3 = 0
for i in range(N):
    summ1 += A[i]
for l in range(N):
    summ3 += A[l]
    summ2 += A[l]*(summ1-summ3)
answer = summ2 % 1000000007
print(answer)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))
summ = 0
answer = 0
for i in range(N):
    for l in range(i):
        summ += A[l] * A[i]
answer = summ % 1000000007
print(answer)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
summ1 = 0
answer = 0
temp = 0
summ2 = 0
summ3 = 0
for i in range(N):
    summ1 += A[i]
for l in range(N):
    summ3 += A[l]
    summ2 += A[l]*(summ1-summ3)
answer = summ2 % 1000000007
print(answer)
Buggy python submission (verdict: Runtime Error):
N = input()
if N % 9 == 0:
  print('yes')
else:
  print('no')

Fixed submission:
N=int(input())
if N%9 == 0:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
a,b=map(int(input()).split())
if a==1:
    print(1)
elif a==2 and b<=1:
    print(1)
elif a==2 and b>=2:
    print(2)
elif a==3 and b<=2:
    print(2)
elif a==3 and b>=3:
    print(3)
elif a==4 and b<=3:
    print(3)
elif a==4 and b>=4:
    print(4)
elif a==5 and b<=4:
    print(4)
elif a==5 and b>=5:
    print(5)
elif a==6 and b<=5:
    print(5)
elif a==6 and b>=6:
    print(6)
elif a==7 and b<=6:
    print(6)
elif a==7 and b>=7:
    print(7)
elif a==8 and b<=7:
    print(7)
elif a==8 and b>=8:
    print(8)
elif a==9 and b<=8:
    print(8)
elif a==9 and b>=9:
    print(9)
elif a==10 and b<=9:
    print(9)
elif a==10 and b>=10:
    print(10)
elif a==11 and b<=10:
    print(10)
elif a==11 and b>=11:
    print(11)
elif a==12 and b<=11:
    print(11)
else:
    print(12)

Fixed submission:
a,b=map(int, input().split())
if a==1:
    print(1)
elif a==2 and b<=1:
    print(1)
elif a==2 and b>=2:
    print(2)
elif a==3 and b<=2:
    print(2)
elif a==3 and b>=3:
    print(3)
elif a==4 and b<=3:
    print(3)
elif a==4 and b>=4:
    print(4)
elif a==5 and b<=4:
    print(4)
elif a==5 and b>=5:
    print(5)
elif a==6 and b<=5:
    print(5)
elif a==6 and b>=6:
    print(6)
elif a==7 and b<=6:
    print(6)
elif a==7 and b>=7:
    print(7)
elif a==8 and b<=7:
    print(7)
elif a==8 and b>=8:
    print(8)
elif a==9 and b<=8:
    print(8)
elif a==9 and b>=9:
    print(9)
elif a==10 and b<=9:
    print(9)
elif a==10 and b>=10:
    print(10)
elif a==11 and b<=10:
    print(10)
elif a==11 and b>=11:
    print(11)
elif a==12 and b<=11:
    print(11)
else:
    print(12)
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3


def count_pins(n, s):
    k = 3
    if n < k or n < 1 or k < 1:
        return 0
    elif n == k:
        return 1
    v1 = [0 for _ in range(n)]
    v2 = [0 for _ in range(n)]
    v3 = [0 for _ in range(n)]
    v2[n - 1] = 1
    v3[s[n - 1] - 1] = 1
    for i in range(n - 1)[::-1]:
        v2[i] = v2[i + 1]
        if v3[s[i] - 1] == 0:
            v2[i] += 1
            v3[s[i] - 1] = 1
    for j in range(1, k):
        v3 = [0 for _ in range(n)]
        v1[n - 1] = 0
        for i in range(n - 1)[::-1]:
            v1[i] = v1[i + 1]
            v1[i] = v1[i] + v2[i + 1]
            v1[i] = v1[i] - v3[s[i] - 1]
            v3[s[i] - 1] = v2[i + 1]
        v2 = v1[:]
    return v1[0]


def main():
    n = int(input())
    s = [int(c) for c in input()]
    res = count_pins(n, s)
    print(res)


if __name__ == "__main__":
    main()


Fixed submission:
#!/usr/bin/env python3


def count_pins(n, s):
    k = 3
    if n < k or n < 1 or k < 1:
        return 0
    elif n == k:
        return 1
    v1 = [0 for _ in range(n)]
    v2 = [0 for _ in range(n)]
    v3 = [0 for _ in range(10)]
    v2[n - 1] = 1
    v3[s[n - 1] - 1] = 1
    for i in range(n - 1)[::-1]:
        v2[i] = v2[i + 1]
        if v3[s[i] - 1] == 0:
            v2[i] += 1
            v3[s[i] - 1] = 1
    for j in range(1, k):
        v3 = [0 for _ in range(10)]
        v1[n - 1] = 0
        for i in range(n - 1)[::-1]:
            v1[i] = v1[i + 1]
            v1[i] += v2[i + 1]
            v1[i] -= v3[s[i] - 1]
            v3[s[i] - 1] = v2[i + 1]
        v2 = v1[:]
    return v1[0]


def main():
    n = int(input())
    s = [int(c) for c in input()]
    res = count_pins(n, s)
    print(res)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env pypy3


M = 10 ** 9 + 7


def naive_inv_num(xs):
    n = len(xs)
    res = 0
    for i in range(n - 1):
        for j in range(i + 1, n):
            if xs[i] > xs[j]:
                res += 1
    return res


def rep_inv_num(k, xs, mod=M):
    c1 = naive_inv_num(xs)
    c2 = naive_inv_num(xs * 2)
    c3 = naive_inv_num(xs * 3)
    d1 = c2 - c1
    f = c3 - 2 * c2 + c1
    res = c1
    res += (k - 1) * d1
    res %= mod
    res += f * (k - 1) * k // 2
    res %= mod
    res -= f * (k - 1)
    res %= mod
    return res


def main():
    _, k = (int(z) for z in input().split())
    xs = [int(x) for x in input().split()]
    res = rep_inv_num(k, xs)
    print(res)


if __name__ == "__main__":
    main()


Fixed submission:
#!/usr/bin/env pypy3


M = 10 ** 9 + 7


def naive_inv_num(xs):
    n = len(xs)
    res = 0
    for i in range(n - 1):
        for j in range(i + 1, n):
            if xs[i] > xs[j]:
                res += 1
    return res


def rep_inv_num(k, xs, mod=M):
    c1 = naive_inv_num(xs)
    c2 = naive_inv_num(xs * 2)
    c3 = naive_inv_num(xs * 3)
    d1 = c2 - c1
    f = c3 - 2 * c2 + c1
    res = c1
    res += (k - 1) * d1
    res %= mod
    res += f * (k - 1) * k // 2
    res %= mod
    res -= f * (k - 1)
    res %= mod
    return res


def main():
    _, k = (int(z) for z in input().split())
    xs = [int(x) for x in input().split()]
    res = rep_inv_num(k, xs)
    print(res)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import math


def nontrivial_divisors(x):
	for i in range(1, math.floor(math.sqrt(x)) + 1):
		d, m = divmod(x, i)
		if m == 0:
			if i != x:
				yield i
			if d != x:
				yield d


def solve(n, qs):
	ps = [0] # sent.
	ps.extend(qs)
	balls = [0] * (n + 1)
	vals = [0] * (n + 1)
	divs = [set(nontrivial_divisors(i)) for i in range(n + 1)]
	first = n // 2 + 1
	last = n
	while True:
		for i in range(first, last + 1):
			if vals[i] % 2 != ps[i]:
				balls[i] += 1
				vals[i] += 1
				for j in divs[i]:
					vals[j] += 1
		if first == 1:
			break
		last = first - 1
		first = last // 2 + 1
	for i in range(1, n + 1):
		if vals[i] % 2 != ps[i]:
			return None
	else:
		bs = [b for b in range(1, n + 1) if balls[b]]
		m = len(bs)
		return m, bs
	

def main():
	n = int(input())
	qs = [int(q) for q in input().split()]
	res = solve(n, qs)
	if res is None:
		print(-1)
	else:
		m, bs = res
		print(m)
		print(*bs)


if __name__ == "__main__":
	main()

Fixed submission:
import math
import sys


def nontrivial_divisors(x):
	for i in range(1, math.floor(math.sqrt(x)) + 1):
		d, m = divmod(x, i)
		if m == 0:
			if i != x:
				yield i
			if d != x:
				yield d


def solve(n, qs):
	ps = [0] # sent.
	ps.extend(qs)
	balls = [0] * (n + 1)
	vals = [0] * (n + 1)
	divs = [set() for _ in range(n + 1)]
	for i in range(1, n // 2 + 1):
		for j in range(2, n // i + 1):
			divs[i * j].add(i)
	# print(divs, file=sys.stderr)
	first = n // 2 + 1
	last = n
	while True:
		for i in range(first, last + 1):
			if vals[i] % 2 != ps[i]:
				balls[i] += 1
				vals[i] += 1
				for j in divs[i]:
					vals[j] += 1
		if first == 1:
			break
		last = first - 1
		first = last // 2 + 1
	for i in range(1, n + 1):
		if vals[i] % 2 != ps[i]:
			return None
	else:
		bs = [b for b in range(1, n + 1) if balls[b]]
		m = len(bs)
		return m, bs
	

def main():
	n = int(input())
	qs = [int(q) for q in input().split()]
	res = solve(n, qs)
	if res is None:
		print(-1)
	else:
		m, bs = res
		print(m)
		print(*bs)


if __name__ == "__main__":
	main()
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env pypy3

import collections
import math


def solve(n, xs):
    divisors = collections.Counter()
    for x in xs:
        for y in range(1, math.floor(math.sqrt(x)) + 1):
            d, m = divmod(x, y)
            if m == 0:
                divisors[y] += 1
                if y != d:
                    divisors[d] += 1
    for i in range(1, max(xs) + 1)[::-1]:
        if divisors[i] >= n - 1:
            return i


def main():
    n = int(input())
    xs = [int(x) for x in input().split()]
    print(solve(n, xs))


if __name__ == "__main__":
    main()

Fixed submission:
#!/usr/bin/env python3

import itertools
try:
    from math import gcd
except ImportError:
    from fractions import gcd


class Cumulative(object):

    def __init__(self, seq, op):
        self.cumul_array = [0]
        self.cumul_array.extend(itertools.accumulate(seq, op))


def solve(n, xs):
    left_cumul = Cumulative(xs, gcd)
    right_cumul = Cumulative(reversed(xs), gcd)
    res = 1
    for i in range(n):
        left_gcd = left_cumul.cumul_array[i]
        right_gcd = right_cumul.cumul_array[n - i - 1]
        cand = gcd(left_gcd, right_gcd)
        if cand > res:
            res = cand
    return res


def main():
    n = int(input())
    xs = [int(x) for x in input().split()]
    res = solve(n, xs)
    print(res)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env pypy3

import collections
import math


def solve(n, xs):
    divisors = collections.Counter()
    for x in xs:
        for y in range(1, math.floor(math.sqrt(x)) + 1):
            d, m = divmod(x, y)
            if m == 0:
                divisors[y] += 1
                if y != d:
                    divisors[d] += 1
    for i in range(1, max(xs) + 1)[::-1]:
        if divisors[i] >= n - 1:
            return i


def main():
    n = int(input())
    xs = [int(x) for x in input().split()]
    print(solve(n, xs))


if __name__ == "__main__":
    main()

Fixed submission:
#!/usr/bin/env python3

import itertools
try:
    from math import gcd
except ImportError:
    from fractions import gcd


class Cumulative(object):

    def __init__(self, seq, op):
        self.cumul_array = [0]
        self.cumul_array.extend(itertools.accumulate(seq, op))


def solve(n, xs):
    left_cumul = Cumulative(xs, gcd)
    right_cumul = Cumulative(reversed(xs), gcd)
    res = 1
    for i in range(n):
        left_gcd = left_cumul.cumul_array[i]
        right_gcd = right_cumul.cumul_array[n - i - 1]
        cand = gcd(left_gcd, right_gcd)
        if cand > res:
            res = cand
    return res


def main():
    n = int(input())
    xs = [int(x) for x in input().split()]
    res = solve(n, xs)
    print(res)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3

import itertools
import sys


DELTAS = [(0, 1), (1, 0), (0, -1), (-1, 0)]


def in_stage(h, w, r, c):
    return 0 <= r < h and 0 <= c < w


def in_place_solve(h, w, stage):
    ops = []
    for r0, c0 in itertools.product(range(h), range(w)):
        tr, tc = None, None
        if stage[r0][c0] % 2 == 0:
            continue
        for dr, dc in DELTAS:
            r, c = r0 + dr, c0 + dc
            if in_stage(h, w, r, c) and stage[r][c] % 2 == 1:
                tr, tc = r, c
                break
        else:
            for dr, dc in DELTAS:
                r, c = r0 + dr, c0 + dc
                if in_stage(h, w, r, c):
                    tr, tc = r, c
                    break
        ops.append((r0 + 1, c0 + 1, tr + 1, tc + 1))
        stage[r0][c0] -= 1
        stage[tr][tc] += 1
    return ops


def main():
    h, w = (int(x) for x in input().split())
    stage = [[int(x) for x in input().split()] for _ in range(h)]
    # print("Before: ", file=sys.stderr)
    # print(*stage, sep="\n", file=sys.stderr)
    ops = in_place_solve(h, w, stage)
    # print("After: ", file=sys.stderr)
    # print(*stage, sep="\n", file=sys.stderr)
    print(len(ops))
    for y0, x0, y, x in ops:
        print(y0, x0, y, x)


if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3

import itertools
import sys


DELTAS = [(0, 1), (1, 0), (0, -1), (-1, 0)]


def in_stage(h, w, r, c):
    return 0 <= r < h and 0 <= c < w


def in_place_solve(h, w, stage):
    ops = []
    for r0, c0 in itertools.product(range(h), range(w)):
        tr, tc = None, None
        if stage[r0][c0] % 2 == 0:
            continue
        for dr, dc in DELTAS:
            r, c = r0 + dr, c0 + dc
            if in_stage(h, w, r, c) and stage[r][c] % 2 == 1:
                tr, tc = r, c
                break
        else:
            for dr, dc in DELTAS:
                r, c = r0 + dr, c0 + dc
                if in_stage(h, w, r, c):
                    tr, tc = r, c
                    break
        if tr is None or tc is None:
            continue
        ops.append((r0 + 1, c0 + 1, tr + 1, tc + 1))
        stage[r0][c0] -= 1
        stage[tr][tc] += 1
    return ops


def main():
    h, w = (int(x) for x in input().split())
    stage = [[int(x) for x in input().split()] for _ in range(h)]
    # print("Before: ", file=sys.stderr)
    # print(*stage, sep="\n", file=sys.stderr)
    ops = in_place_solve(h, w, stage)
    # print("After: ", file=sys.stderr)
    # print(*stage, sep="\n", file=sys.stderr)
    print(len(ops))
    for y0, x0, y, x in ops:
        print(y0, x0, y, x)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3

import sys


# 再帰深度の制限
REC_LIMIT = 10000

# 頂点の色
UNDEF = 0
WHITE = 1
BLACK = -WHITE


# 所与のグラフが二部グラフならば，(True, color[])を返す
# さもなければ，(False, None)を返す
# 参考：『プログラミングコンテストチャレンジブック』（第2版）p.94
def is_bipartite_graph(adj_list):
    n = len(adj_list)  # 頂点数
    color = [UNDEF] * n

    # 頂点をWHITEとBLACKで塗っていく
    def dfs(v, c):
        color[v] = c
        for u in adj_list[v]:
            if color[u] == c:
                # 隣接頂点が同色で塗られていたら不可
                return False
            if color[u] == UNDEF and not dfs(u, -c):
                # 隣接頂点が未彩色なら，反対の色で塗れるか
                return False
        return True  # すべて色を塗れた
    for i in range(n):
        if color[i] == 0:
            # 未彩色なら，WHITEで塗ってみる
            if not dfs(i, WHITE):
                return (False, None)
    return (True, color)


def compute_max_additional_edges(n, m, adj_list):
    is_bi, color = is_bipartite_graph(adj_list)
    if not is_bi:
        # 二部グラフではない場合
        return n * (n - 1) // 2 - m
    else:
        # 二部グラフである場合
        w = sum(c == WHITE for c in color)
        b = sum(c == BLACK for c in color)
        return w * b - m


def main():
    # 最大再帰深度の再設定
    sys.setrecursionlimit(REC_LIMIT)
    # 入力の読み込み
    n, m = (int(x) for x in input().split())
    adj_list = [set() for _ in range(n)]
    for _ in range(m):
        a, b = (int(x) - 1 for x in input().split())
        adj_list[a].add(b)
        adj_list[b].add(a)
    res = compute_max_additional_edges(n, m, adj_list)
    print(res)


if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3

import sys


# 再帰深度の制限
REC_LIMIT = 100000

# 頂点の色
UNDEF = 0
WHITE = 1
BLACK = -WHITE


# 所与のグラフが二部グラフならば，(True, color[])を返す
# さもなければ，(False, None)を返す
# 参考：『プログラミングコンテストチャレンジブック』（第2版）p.94
def is_bipartite_graph(adj_list):
    n = len(adj_list)  # 頂点数
    color = [UNDEF] * n

    # 頂点をWHITEとBLACKで塗っていく
    def dfs(v, c):
        color[v] = c
        for u in adj_list[v]:
            if color[u] == c:
                # 隣接頂点が同色で塗られていたら不可
                return False
            if color[u] == UNDEF and not dfs(u, -c):
                # 隣接頂点が未彩色なら，反対の色で塗れるか
                return False
        return True  # すべて色を塗れた
    for i in range(n):
        if color[i] == 0:
            # 未彩色なら，WHITEで塗ってみる
            if not dfs(i, WHITE):
                return (False, None)
    return (True, color)


def compute_max_additional_edges(n, m, adj_list):
    is_bi, color = is_bipartite_graph(adj_list)
    if not is_bi:
        # 二部グラフではない場合
        return n * (n - 1) // 2 - m
    else:
        # 二部グラフである場合
        w = sum(c == WHITE for c in color)
        b = sum(c == BLACK for c in color)
        return w * b - m


def main():
    # 最大再帰深度の再設定
    sys.setrecursionlimit(REC_LIMIT)
    # 入力の読み込み
    n, m = (int(x) for x in input().split())
    adj_list = [set() for _ in range(n)]
    for _ in range(m):
        a, b = (int(x) - 1 for x in input().split())
        adj_list[a].add(b)
        adj_list[b].add(a)
    res = compute_max_additional_edges(n, m, adj_list)
    print(res)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3


def div_pairs(n):
    for i in range(1, n):
        if i * i > n:
            break
        d, m = divmod(n, i)
        if m == 0:
            yield (i, d)


def f(a, b):
    return max(len(str(a)), len(str(b)))


def solve(n):
    return min(f(a, b) for a, b in div_pairs(n))


def main():
    print(solve(int(input())))


if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3


def div_pairs(n):
    for i in range(1, n + 1):
        if i * i > n:
            break
        d, m = divmod(n, i)
        if m == 0:
            yield (i, d)


def f(a, b):
    return max(len(str(a)), len(str(b)))


def solve(n):
    return min(f(a, b) for a, b in div_pairs(n))


def main():
    print(solve(int(input())))


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env pypy3


def div_ceil(a, b):
    return (a + b - 1) // b


def solve(n, xs, ys):
    ctr = 0
    for i in range(n)[::-1]:
        diff = div_ceil(xs[i], ys[i]) * ys[i] - xs[i]
        ctr += diff
        for j in range(i + 1):
            xs[j] += diff
    return ctr


def main():
    n = int(input())
    data = (tuple(int(x) for x in input().split()) for _ in range(n))
    xs, ys = (list(line) for line in zip(*data))
    print(solve(n, xs, ys))


if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env pypy3


def div_ceil(a, b):
    return (a + b - 1) // b


def solve(n, xs, ys):
    ctr = 0
    for i in range(n)[::-1]:
        xs[i] += ctr
        diff = div_ceil(xs[i], ys[i]) * ys[i] - xs[i]
        ctr += diff
    return ctr


def main():
    n = int(input())
    data = (tuple(int(x) for x in input().split()) for _ in range(n))
    xs, ys = (list(line) for line in zip(*data))
    print(solve(n, xs, ys))


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3


def div_ceil(a, b):
    return (a + b - 1) // b


def solve(n, xs, ys):
    ctr = 0
    for i in range(n)[::-1]:
        diff = div_ceil(xs[i], ys[i]) * ys[i] - xs[i]
        ctr += diff
        for j in range(i + 1):
            xs[j] += diff
    return ctr


def main():
    n = int(input())
    data = (tuple(int(x) for x in input().split()) for _ in range(n))
    xs, ys = (list(line) for line in zip(*data))
    print(solve(n, xs, ys))


if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env pypy3


def div_ceil(a, b):
    return (a + b - 1) // b


def solve(n, xs, ys):
    ctr = 0
    for i in range(n)[::-1]:
        xs[i] += ctr
        diff = div_ceil(xs[i], ys[i]) * ys[i] - xs[i]
        ctr += diff
    return ctr


def main():
    n = int(input())
    data = (tuple(int(x) for x in input().split()) for _ in range(n))
    xs, ys = (list(line) for line in zip(*data))
    print(solve(n, xs, ys))


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env pypy3


class UnionFind(object):

    def __init__(self, number_of_nodes):
        self.par = list(range(number_of_nodes))
        self.rank = [0] * number_of_nodes

    def root(self, node):
        if self.par[node] == node:
            return node
        else:
            r = self.root(self.par[node])
            self.par[node] = r
            return r

    def in_the_same_set(self, node1, node2):
        return self.root(node1) == self.root(node2)

    def unite(self, node1, node2):
        x = self.root(node1)
        y = self.root(node2)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1


def main():
    n, k, l = (int(x) for x in input().split())
    uf_roads = UnionFind(n)
    for _ in range(k):
        p, q = (int(x) - 1 for x in input().split())
        uf_roads.unite(p, q)
    uf_rails = UnionFind(n)
    for _ in range(l):
        r, s = (int(x) - 1 for x in input().split())
        uf_rails.unite(r, s)
    ans = [sum(1 for y in range(n) if
               uf_roads.in_the_same_set(x, y) and
               uf_rails.in_the_same_set(x, y)) for x in range(n)]
    print(" ".join(str(z) for z in ans))


if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env pypy3

import collections


class UnionFind(object):

    def __init__(self, number_of_nodes):
        self.par = list(range(number_of_nodes))
        self.rank = [0] * number_of_nodes

    def root(self, node):
        if self.par[node] == node:
            return node
        else:
            r = self.root(self.par[node])
            self.par[node] = r
            return r

    def in_the_same_set(self, node1, node2):
        return self.root(node1) == self.root(node2)

    def unite(self, node1, node2):
        x = self.root(node1)
        y = self.root(node2)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1


def main():
    n, k, l = (int(x) for x in input().split())
    uf_roads = UnionFind(n)
    for _ in range(k):
        p, q = (int(x) - 1 for x in input().split())
        uf_roads.unite(p, q)
    uf_rails = UnionFind(n)
    for _ in range(l):
        r, s = (int(x) - 1 for x in input().split())
        uf_rails.unite(r, s)
    ctr = collections.Counter((uf_roads.root(i), uf_rails.root(i))
                              for i in range(n))
    ans = [ctr[(uf_roads.root(i), uf_rails.root(i))] for i in range(n)]
    print(" ".join(str(a) for a in ans))

if __name__ == '__main__':
    main()