Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03164 (python)

Fixed submission:
N,W = map(int,input().split())
K = 10**5
dp = [[10**100 for i in range(K+1)] for j in range(N+1)]
dp[0][0] = 0
for i in range(1,N+1):
    w,v = map(int,input().split())
    for j in range(K+1):
        dp[i][j] = dp[i-1][j]
        if j < v:
            continue
        else:
            dp[i][j] = min(dp[i-1][j-v] + w,dp[i-1][j])
for i in range(K+1):
    x = dp[N][-i-1]
    if x <= W:
        print(K-i)
        quit()

Buggy submission (verdict: Runtime Error):
N,W = map(int,input().split())
K = 10**5
dp = [[10**100 for i in range(K+1)] for j in range(N)]
dp[0][0] = 0
for i in range(1,N+1):
    w,v = map(int,input().split())
    for j in range(K+1):
        if j < v:
            continue
        else:
            dp[i][j] = min(dp[i-1][j-v] + W,dp[i][j])
for i in range(K+1):
    x = dp[N][-i-1]
    if x <= W:
        print(K-i)
        quit()
Problem p03214 (python)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
ave = sum(A)/N
ans = 0
sa = 10**9
for i in range(N):
    x = max(A[i]-ave,ave-A[i])
    if x < sa:
        sa = x
        ans = i
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
ave = A/N
ans = 0
sa = 10**9
for i in range(N):
    t = i+1
    x = max(A[i]-ave,ave-A[i])
    if x < sa:
        sa = x
        ans = t
print(ans)
Problem p03244 (python)

Fixed submission:
n = int(input())
v = list(map(int,input().split()))
v_odd = []
v_even = []
d_odd = {}
d_even = {}
o = []
e = []
for i in range(n//2):
    a = v[2*i]
    b = v[2*i+1]
    if a in d_odd:
        d_odd[a] += 1
    else:
        d_odd[a] = 1
        o.append(a)
    if b in d_even:
        d_even[b] += 1
    else:
        d_even[b] = 1
        e.append(b)
O = 0
E = 0
o_max = 0
o_second = 0
e_max = 0
e_second = 0
for i in o:
    x = d_odd[i]
    if x >= o_max:
        O = i
        o_max = x
d_odd.pop(O)
o.remove(O)
for i in o:
    x = d_odd[i]
    if x >= o_second:
        o_second = x
for i in e:
    y = d_even[i]
    if y >= e_max:
        E = i
        e_max = y
d_even.pop(E)
e.remove(E)
for i in e:
    y = d_even[i]
    if y >= e_second:
        e_second = y
if O == E:
    m = max(o_max+e_second,e_max+o_second)
else:
    m = o_max + e_max
print(n-m)

Buggy submission (verdict: Runtime Error):
n = int(input())
v = list(map(int,input().split()))
v_odd = []
v_even = []
for i in range(n//2):
    v_odd.append()
    v_even.append()
p1 = 0
p2 = 0
q1 = 0
q2 = 0
o_max = -1
e_max = -1
for i in range(n//2):
    a = v_odd[i]
    b = v_even[i]
    x = v_odd.count(a)
    y = v_even.count(b)
    if p1 <= x:
        if o_max != a:
            o_max = a
            p2 = p1
            p1 = x
    else:
        if x > p2:
            p2 = x
    if q1 <= y:
        if e_max != b:
            e_max = b
            q2 = q1
            q1 = y
    else:
        if y > q2:
            q2 = y
s = p1 + q1
if p1 == q1:
    if o_max == e_max:
        s = max(p2,q2) + p1
elif p1 > q2:
    if o_max == e_max:
        s = p1 + q2
else: 
    if o_max == e_max:
        s = p2 + q1
ans = n - s
print(ans)
Problem p03289 (python)

Fixed submission:
S = input()
n = len(S)
p = 0
if S[0] == 'A':
    p = 1
s = []
for i in range(2,n-1):
    s.append(S[i])
q = 0
if s.count('C') == 1:
    q = 1
if 'C' in s:
    s.remove('C')
s.append(S[1])
s.append(S[n-1])
r = 1
for i in range(n-2):
    x = s[i]
    t = ord(x)-97
    if 0<= t <= 25:
        continue
    else:
        r = 0
        break
ans = 'WA'
if p*q*r == 1:
    ans = 'AC'
print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
n = len(S)
p = 0
if S[0] == 'A':
    p = 1
s = []
for i in range(2,n-1):
    s.append(S[i])
q = 0
if s.count('C') == 1:
    q = 1
s.remove('C')
s.append(S[1])
s.append(S[n-1])
r = 1
for i in range(n-2):
    x = s[i]
    t = ord(x)-97
    if 0<= t <= 25:
        continue
    else:
        r = 0
        break
ans = 'WA'
if p*q*r == 1:
    ans = 'AC'
print(ans)
Problem p03290 (python)

Fixed submission:
D,G = map(int,input().split())
P = [0]*D
C = [0]*D
for i in range(D):
    P[i], C[i] = map(int,input().split())
s = sum(P)

#dp[i][j] = i問目まででj枚使った時の点数のmax#
dp = [[0 for i in range(s+1)] for j in range(D+1)]
for i in range(D):
    p = P[i]
    c = C[i]
    t = 100*(i+1)
    for j in range(s+1):
        for k in range(p+1):
            if k == p:
                if j >= k:
                    dp[i+1][j] = max(dp[i+1][j],dp[i][j-k]+c+t*k)
            else:
                if j >= k:
                    dp[i+1][j] = max(dp[i][j-k]+t*k,dp[i+1][j])
                else:
                    break
for i in range(s+1):
    if dp[D][i] >= G:
        ans = i
        break
print(ans)

Buggy submission (verdict: Runtime Error):
D,G = map(int,input().split())
P = []
C = []
for i in range(D):
    p, c = map(int,input().split())
    P.append(p)
    C.append(C)
    s += p

#dp[i][j] = i問目まででj枚使った時の点数のmax
dp = [[0 for in range(s+1)] for j in range(D+1)]
for i in range(D):
    p = P[i]
    c = C[i]
    t = 100*i
    for j in range(s+1):
        for k in range(p+1):
            if k = p:
                if j >= k:
                dp[i+1][j] = max(dp[i+1][j],dp[i][j-k]+c)
            else:
                if j >= k:
                    d[i+1][j] = max(dp[i][j-k]+t*k,dp[i+1][j])
                else:
                    break
for i in range(s+1):
    if d[N][i] >= G:
        ans = i
print(ans)
Problem p03351 (python)

Fixed submission:
a,b,c,d = map(int,input().split())
ans = 'No'
if -d <= a-c <= d:
    ans = 'Yes'
if -d <= a-b <= d:
    if -d <= b-c <= d:
        ans = 'Yes'
print(ans)

Buggy submission (verdict: Runtime Error):
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())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N, M = map(int,input().split())
P = list(map(int,input().split()))
uf = UnionFind(N)
for i in range(M):
    a, b = map(int,input().split())
    uf.union(a-1,b-1)
A = list(uf.all_group_members().values())
a = len(A)
B =[[] for i in range(a)]
import bisect
ans = 0
for i in range(a):
    S = A[i]
    for j in range(len(S)):
        s = S[j]
        insert_index = bisect.bisect_left(B[i],P[s]-1)
        B[i].insert(insert_index,P[s]-1)
    for k in range(len(S)):
        s = S[k]
        if B[i].count(s) == 1:
            ans += 1
print(ans)
Problem p03353 (python)

Fixed submission:
s = input()
K = int(input())
n = len(s)
A =[]
import bisect
for i in range(n):
    for j in range(1,K+1):
        sub = s[i:i+j]  
        if sub not in A:
            x = bisect.bisect_left(A,sub)
            A.insert(x,sub)
            if len(A) > K:
                A.pop(K)

print(A[K-1])

Buggy submission (verdict: Runtime Error):
s = input()
K = int(input())
n = len(s)
A =[]
for i in range(n):
    for j in range(i+1,n):
        sub = s[i:j]  
        if sub in A:
            continue
        else:
            if len(A) <= K:
                A.append(sub)
            else:
                A.append(sub)
                A.sort()
                A.pop(K)
print(A[K-1])
Problem p03394 (python)

Fixed submission:
N = int(input())
ans = []
n = N//2
if N == 3:
    ans = [2,5,63]
elif 4 <= N <= 15000:
    for i in range(1,n):
        ans.append(2*i)
        x = 30000 - 2*i
        ans.append(x)
    if N % 2 == 1:
        ans.append(30000)
    ans.append(3)
    ans.append(9)
else:
    for i in range(1,15000):
        ans.append(2*i)
    x = N - 14999
    for j in range(x-1):
        y = 6*j + 3
        ans.append(y)
    if x % 2 == 1:
        ans.append(30000)
    else:
        ans.append(6*x - 3)
print(*ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
ans = []
n = N//2
if N <= 15000:
    for i in range(1,n):
        ans.append(2*i)
        x = 30000 - 2*i
        ans.append(x)
    if N % 2 == 0:
        ans.append(30000)
    ans.append(3)
    ans.append(9)
else:
    for i in range(1,15000):
        ans.append(2*i)
    x = N - 14999
    for j in range(x):
        y = 6*x + 3
        if y <= 30000:
            ans.append(y)
    if N = 20000:
        ans.append(30000)
print(*ans)
Problem p03469 (python)

Fixed submission:
S = input()
ans = '2018/'
for i in range(5,10):
    ans += S[i]
print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
S[3] = '8'
print(S)
Problem p03545 (python)

Fixed submission:
abcd = input()
s = 0
i = 0
for i in range(8):
    a = abcd[0]
    for j in range(3):
        if (i >> j) & 1:
            a += '+'
        else:
            a += '-'
        a += abcd[j+1]
    s = eval(a)
    if s == 7:
        ans = a + '=' + '7'
        break
print(ans)

Buggy submission (verdict: Runtime Error):
abcd = input()
s = 0
i = 0
for i in range(8):
    a = abcd[0]
    for j in range(3):
        if (i >> j) & 1:
            a += '+'
        else:
            a += '-'
    s = eval(a)
    if s == 7:
        ans = a + '=' + '7'
        break
print(ans)
Problem p03606 (python)

Fixed submission:
N = int(input())
ans = N
for i in range(N):
    a,b = map(int,input().split())
    ans += b - a
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
ans = N
for i in range(N):
    a,b = map(int,input())
    ans += b - a
print(ans)
Problem p03651 (python)

Fixed submission:
N,K = map(int,input().split())
A = list(map(int,input().split()))
g = A[0]
import fractions
for i in range(1,N):
    g = fractions.gcd(g,A[i])
if K % g == 0:
    if K <= max(A):
        print('POSSIBLE')
    else:
        print('IMPOSSIBLE')
else:
    print('IMPOSSIBLE')

Buggy submission (verdict: Runtime Error):
N,K = map(int(input().split()))
A = list(map(int,input().split())))
g = A[0]
import fractions
for i in range(1,N):
    g = fractions.gcd(g,A[i])
if K % g == 0:
    if K <= M:
        print('POSSIBLE')
    else:
        print('IMPOSSIBLE')
else:
    print('IMPOSSIBLE')
Problem p03715 (python)

Fixed submission:
W,H = map(int,input().split())
ans = 10**30
for i in range(1,W):
    a = H*i
    w = W - i
    b = max((w//2)*H,w*(H//2))
    c = w*H - b
    x = max(a,b,c) - min(a,b,c)
    ans = min(ans,x)
for i in range(1,H):
    a = W*i
    h = H - i
    b = max((W//2)*h,W*(h//2))
    c = h*W - b
    x = max(a,b,c) - min(a,b,c)
    ans = min(ans,x)
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
S = []
P = A[:N]
Q = A[2*N:]
for i in range(N):
    Q[i] *= -1
R = A[N:2*N]
p = [0]*(N+1)
q = [0]*(N+1)
import heapq
heapq.heapify(P)
heapq.heapify(Q)
sp = sum(P)
sq = sum(Q)
p[0] = sp
q[0] = sq

for i in range(1,N+1):
    heapq.heappush(P,R[i-1])
    x = heapq.heappop(P)
    heapq.heappush(Q,-R[-i])
    y = heapq.heappop(Q)
    sp = sp + R[i-1] - x
    sq = sq - R[-i] - y
    p[i] = sp
    q[i] = sq
ans = -(10**100)
for k in range(N+1):
    ans = max(ans,p[k] + q[N-k])
    
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
S = []
P = A[:N]
Q = A[2*N:]
for i in range(N):
    Q[i] *= -1
R = A[N:2*N]
p = [0]*(N+1)
q = [0]*(N+1)
import heapq
heapq.heapify(P)
heapq.heapify(Q)
sp = sum(P)
sq = sum(Q)
p[0] = sp
q[0] = sq

for i in range(1,N+1):
    heapq.heappush(P,R[i-1])
    heapq.heappop(P)
    sp = sum(P)
    p[i] = sum(Q)
for i in range(1,N+1):
    heapq.heappush(Q,-R[-i])
    heapq.heappop(Q)
    sq = sum(Q)
    q[i] = sq

ans = -(10**100)
for k in range(N+1):
    ans = max(ans,p[k] + q[N-k])
    
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
S = []
import heapq
for i in range(N+1):
    P = A[:(N+i)]
    Q = A[(N+i):]
    for l in range(len(Q)):
        Q[l] *= -1
    heapq.heapify(P)
    heapq.heapify(Q)
    j = 0
    k = 0
    while j < i:
        heapq.heappop(P)
        j += 1
    while k < N-i:
        heapq.heappop(Q)
        k += 1
    s = sum(P) + sum(Q)
    S.append(s)
ans = max(S)
print(ans)
Problem p03716 (python)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
S = []
P = A[:N]
Q = A[2*N:]
for i in range(N):
    Q[i] *= -1
R = A[N:2*N]
p = [0]*(N+1)
q = [0]*(N+1)
import heapq
heapq.heapify(P)
heapq.heapify(Q)
sp = sum(P)
sq = sum(Q)
p[0] = sp
q[0] = sq

for i in range(1,N+1):
    heapq.heappush(P,R[i-1])
    x = heapq.heappop(P)
    heapq.heappush(Q,-R[-i])
    y = heapq.heappop(Q)
    sp = sp + R[i-1] - x
    sq = sq - R[-i] - y
    p[i] = sp
    q[i] = sq
ans = -(10**100)
for k in range(N+1):
    ans = max(ans,p[k] + q[N-k])
    
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
S = []
for i in range(N+1):
    P = A[:(N+i)]
    Q = A[(N+i):]
    for l in range(len(Q)):
        Q[l] *= -1
    heapq.heapify(P)
    heapq.heapify(Q)
    j = 0
    k = 0
    while j < i:
        heapq.heappop(P)
    while k < N-i:
        heapq.heappop(Q)
    s = sum(P) + sum(Q)
    S.append(s)
ans = min(S)
print(ans)
Problem p03732 (python)

Fixed submission:
N,W = map(int,input().split())
w1,v1 = map(int,input().split())
d = [[-v1],[],[],[]]
for i in range(N-1):
    w,v = map(int,input().split())
    x = w - w1
    d[x].append(-v)
d[0].sort()
n0 = len(d[0])
d[1].sort()
n1 = len(d[1])
d[2].sort()
n2 = len(d[2])
d[3].sort()
n3 = len(d[3])
s0 = [0]
s1 = [0]
s2 = [0]
s3 = [0]
for i in range(n0):
    x = s0[-1] + d[0][i]
    s0.append(x)
for i in range(n1):
    x = s1[-1] + d[1][i]
    s1.append(x)
for i in range(n2):
    x = s2[-1] + d[2][i]
    s2.append(x)
for i in range(n3):
    x = s3[-1] + d[3][i]
    s3.append(x)
d = [[[[0 for i in range(n3+1)] for j in range(n2+1)] for k in range(n1+1)] for l in range(n0+1)]
for i in range(n0+1):
    for j in range(n1+1):
        for k in range(n2+1):
            for l in range(n3+1):
                s = s0[i] + s1[j] + s2[k] + s3[l]
                s = -s
                x = w1*(i+j+k+l) + j + 2*k + 3*l
                if x <= W:
                    d[i][j][k][l] = s
ans = 0
for i in range(n0+1):
    for j in range(n1+1):
        for k in range(n2+1):
            for l in range(n3+1):
                x = d[i][j][k][l]
                ans = max(ans,x)
print(ans)

Buggy submission (verdict: Runtime Error):
N,W = map(int,input().split())
w1,v = map(int,input().split())
d = [[-v],[],[],[]]
for i in range(N-1):
    w,v = map(int,input().split())
    x = w - w1
    d[x].append(-v)
d[0].sort()
n0 = len(d[0])
d[1].sort()
n1 = len(d[1])
d[2].sort()
n2 = len(d[2])
d[3].sort()
n3 = len(d[3])
d = [[[[0 for i in range(n3+1)] for j in range(n2+1)] for k in range(n1+1)] for l in range(n0+1)]
for i in range(n0):
    s = sum(d[0][:i])
    for j in range(n1):
        s += sum(d[1][:j])
        for k in range(n2):
            s += sum(d[2][:k])
            for l in range(n3):
                s += sum(d[3][:l])
                s = -s
                x = w1*(i+j+k+l) + j + 2*k + 3*l
                if x <= W:
                    d[i][j][k][l] = s
ans = 0
for i in range(n0):
    for j in range(n1):
        for k in range(n2):
            for l in range(n3):
                x = d[i][j][k][l]
                ans = max(ans,x)
print(ans)
Problem p03797 (python)

Fixed submission:
N,M = map(int,input().split())
a = M - 2*N
if a <= 0:
    ans = M//2
else:
    a = a//4
    ans = N + a
print(ans)

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
a = M - 2*N
if a <= 0:
    ans = C//2
else:
    a = a//4
    ans = N + a
print(ans)
Problem p03845 (python)

Fixed submission:
N = int(input())
T = list(map(int,input().split()))
ans = sum(T)
M = int(input())
for i in range(M):
    P,X = map(int,input().split())
    t = T[P-1] - X
    print(ans-t)

Buggy submission (verdict: Runtime Error):
N = int(input())
T = list(map(int,input().split()))
ans = sum(T)
M = int(input())
for i in range(M):
    P,X = map(int,input().split())
    t = A[P-1] - X
    print(ans-t)
Problem p03846 (python)

Fixed submission:
N = int(input())
d = {}
if N % 2 == 0:
    for i in range(N//2):
        d[2*i+1] = 0
else:
    for i in range(N//2+1):
        d[2*i] = 0
A = list(map(int,input().split()))
x = 1
for i in range(N):
    if A[i] in d:
        if d[A[i]] >= 2:
            x = 0
            break
        else:
            d[A[i]] += 1
    else:
        x = 0
        break
y = 1
if N % 2 == 1:
    if d[0] != 1:
        y = 0
e = 10**9 + 7
ans = (2**(N//2))*x*y%e
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
d = {}
if N % 2 == 0:
    for i in range(N//2):
        d[2*i+1] = 0
else:
    for i in range(N//2+1):
        d[2*i] = 0
A = list(map(int,input().split()))
x = 1
for i in range(N):
    if d[A[i]] >= 2:
        x = 0
        break
    else:
        d[A[i]] += 1
y = 1
if N % 2 == 1:
    if d[0] != 1:
        y = 0
ans = (2**(N//2))*x*y
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
d = {}
if N % 2 == 0:
    for i in range(N//2):
        d[2*i+1] = 0
else:
    for i in range(N//2+1):
        d[2*i] = 1
A = list(map(int,input()))
x = 1
for i in range(A):
    if d[A[i]] >= 2:
        x = 0
        break
    else:
        d[A[i]] += 1
y = 1
if N % 2 == 1:
    if d[0] != 1:
        y = 0
ans = (2**(N//2))*x*y
print(ans)
Problem p03854 (python)

Fixed submission:
T = input()
S = ''
p,q,r,s = 'maerd','esare','remaerd','resare'
for i in range(len(T)):
    S += T[len(T)-i-1]
while len(S) >= 5:
    x = S[:5]
    y = S[:6]
    z = S[:7]
    if x == p or x == q:
        if len(S) > 5:
            S = S[5:]
        else:
            S = ''
    elif y == s:
        if len(S) > 6:
            S = S[6:]
        else:
            S = ''
    elif z == r:
        if len(S) > 7:
            S = S[7:]
        else:
            S = ''
    else:
        break
ans = 'NO'
if len(S) == 0:
    ans = 'YES'
print(ans)

Buggy submission (verdict: Runtime Error):
T = input()
S = ''
p,q,r,s = 'maerd','esare','remaerd','resare'
for i in range(len(T)):
    S += T[len(T)-i]
while len(S) >= 7:
    x = S[:5]
    y = S[:6]
    z = S[:7]
    if x == p or x == q:
        if len(S) > 5:
            S = S[5:]
        else:
            S = ''
    elif y == s:
        if len(S) > 6:
            S = S[6:]
        else:
            S = ''
    elif z == r:
        if len(S) > 7:
            S = S[7:]
        else:
            S = ''
    else:
        break
ans = 'NO'
if len(S) == 0:
    ans = 'YES'
print(ans)

Buggy submission (verdict: Runtime Error):
T = input()
S = ''
p,q,r,s = 'maerd','esare','remaerd','resare'
for i in range(len(T)):
    S += T[len(T)-i]
while len(S) >= 7:
    x = S[:5]
    y = S[:6]
    z = S[:7]
    if x == p or x == q:
        if len(S) > 5:
            S = S[5:]
        else:
            S = ''
    elif y == s:
        if len(S) > 6:
            S = S[6:]
        else:
            S = ''
    elif z == r:
        if len(S) > 7:
            S = S[7:]
        else:
            S = ''
    else:
        break
ans = 'NO'
if len(S) == 0:
    ans = 'YES'
Problem p03855 (python)

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())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r,self.members(r)) for r in self.roots())
N,K,L = map(int,input().split())
ufK = UnionFind(N)
ufL = UnionFind(N)
ans = [1]*(N)
for i in range(K):
    p,q = map(int,input().split())
    ufK.union(p-1,q-1)
for i in range(L):
    r,s = map(int,input().split())
    ufL.union(r-1,s-1)
from collections import defaultdict
ar=[(ufK.find(i),ufL.find(i)) for i in range(N)]
dic=defaultdict(int)
 
for i in ar:
    dic[i]+=1
ans=[]
for i in range(N):
    ans.append(dic[ar[i]])
print(*ans)

Buggy submission (verdict: Runtime Error):
UnionFind木
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())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r,self.members(r)) for r in self.roots())
N,K,L = map(int,input().split())
uf = UnionFind(N)
ans = 0
for i in range(K):
    p,q = map(int,input().split())
    uf.union(p,q)
for i in range(L):
    r,s = map(int,input().split())
    if uf.same(r,s):
        ans += 1
Problem p03860 (python)

Fixed submission:
a,b,c = map(str,input().split())
ans = 'A' + b[0] + 'C'
print(ans)

Buggy submission (verdict: Runtime Error):
a,b,c = map(input().split())
ans = 'A' + b[0] + 'C'
print(ans)
Problem p03861 (python)

Fixed submission:
a,b,x = map(int,input().split())
def f(p):
    q = p//x
    return q
ans = f(b) - f(a-1)
print(ans)

Buggy submission (verdict: Runtime Error):
a,b,x = map(int,input().split())
def f(p):
    q = p//x
ans = f(b) - f(a-1)
print(ans)
Problem p03946 (python)

Fixed submission:
n,t = map(int,input().split())
A = list(map(int,input().split()))
m = 10**9+1 
M = -1
ans = 1
for i in range(n):
    x = A[i]
    m = min(x,m)
    p = x-m
    if p > M:
        ans = 1
        M = p
    elif p == M:
        ans += 1
if M <= 0:
    ans = 0
print(ans)

Buggy submission (verdict: Runtime Error):
n,t = map(int,input())
A = list(map(int,input().split()))
m = 10**9+1 
M = -1
ans = 0
for i in range(n):
    x = A[i]
    m = min(x)
    p = x-A
    if p > M:
        ans = 0
        M = p
    elif p == M:
        ans += 1
print(ans)
Problem p03962 (python)

Fixed submission:
a,b,c = map(int,input().split())
i,j,k,l = 0,0,0,0
if a == b:
    i = 1
if b == c:
    j = 1
if c == a:
    k = 1
if a == b & b == c:
    l = -1
print(3-(i+j+k+l))

Buggy submission (verdict: Runtime Error):
a,b,c = map(int,input().split())
if a == b:
    i = 1
if b == c:
    j = 1
if c == a:
    k = 1
if a == b & b == c:
    l = -1
print(3-(i+j+k+l))