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

Fixed submission:
S, W = list(map(int, input().split()))
if S <= W :
    print("unsafe")
if S > W :
    print("safe")

Buggy submission (verdict: Runtime Error):
S, W = list(map(int, input().split()))
if S < W :
    print(unsafe)
if S > W :
    print(safe)
Problem p02723 (python)

Fixed submission:
a = input()
iff3 = a[2]
iff4 = a[3]
iff5 = a[4]
iff6 = a[5]
if iff3 == iff4 :
    if iff5 == iff6 :
        print("Yes")
    else :
        print("No")
else :
    print("No")

Buggy submission (verdict: Runtime Error):
coffee = str(input())
iff3 = coffee[3]
iff4 = coffee[4]
iff5 = coffee[5]
iff6 = coffee[6]
if iff3 == iff4 :
    if iff5 == iff6 :
        print("Yes")
    if iff5 != iff6 :
        print("No")
if iff3 != iff4:
    print("No")
Problem p02829 (python)

Fixed submission:
a = int(input())
b = int(input())
if a == 1 :
    if b == 2 :
        print("3")
    if b == 3 :
        print("2")
if a == 2 :
    if b == 1 :
        print("3")
    if b == 3 :
        print("1")
if a == 3 :
    if b == 2 :
        print("1")
    if b == 1 :
        print("2")

Buggy submission (verdict: Runtime Error):
import math
a = int(input())
b = a / 2
d = 0
c = 1
b = math.ceil(b)
for i in range(b):
    c = c * a
    a = a - 2
c = str(c)
for e in range(len(c)):
    if len(c) - c[e] == "0":
        d = d + 1
    else:
        break
print(d)
Problem p02572 (python)

Fixed submission:
def main():
    mod = 10**9+7
    #n,a = get_input()
    n = int(input())
    a = [int(x) for x in input().split()]
    ans = 0
    asum = sum(a) 
    for i in range(n):
        asum = asum - a[i]
        ans = ( ans + ((a[i] * asum) % mod)) % mod
    
    print(ans)
    
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    mod = 10**9+7
    #n,a = get_input()
    n = int(input())
    a = [int(x) for x in input().split()]
    aa = [a**2 % mod for x in a]
    ans = 0
    asum = sum(a) 
    p = asum ** 2 % mod
    q = sum(aa) % mod
    ans = (p - q) % mod
    if ans < 0:
      ans += mod
    if ans % 2 == 1:
      ans += mod
    ans = ans // 2
    print(ans)
    
if __name__ == '__main__':
    main()
Problem p02596 (python)

Fixed submission:
def main():
    k = int(input())
    if (k%2==0 or k%5==0):
        print("-1")
        return

    #7(10**i-1)が9Kで割り切れるような最小の整数iを求める。

    if k%7==0:
        L=9*k//7
    else:
        L=9*k
    i=1
    for n in range(1,L+1):
        i=(10*i)%L
        if i==1:
            print(n)
            return
    print("-1")
    return

main()

Buggy submission (verdict: Runtime Error):
def main():
    k = int(input())
    if (k%2==0 or k%5==0):
        print("-1")
        return

    #7(10**i-1)が9Kで割り切れるような最小の整数iを求める。

    if k%7==0:
        L=9*k/7
    else:
        L=9*k
    i=1
    for n in range(1,L+1):
        i=(10*i)%L
        if i==1:
            print(n)
            return
    print("-1")
    return

main()

Buggy submission (verdict: Runtime Error):
def main():
    k = int(input())
    if (k%2==0 or k%5==0):
        print("-1")
        return

    #7(10**i-1)が9Kで割り切れるような最小の整数iを求める。

    if k%7==0:
        L=9*k/7
    else:
        L=9*k
    i=1
    for n in range(1,L+1):
        i=(10*i)%L
        if i==1:
            print(n)
            return
    print("-1")

main()
Problem p02598 (python)

Fixed submission:
import math

N,K = map(int,input().split())

a = list(map(int, input().split()))
l = 0
r = max(a)

x = (l+r)//2
ans = r+1
while(r>1+l):

    
    x = (l+r)//2
    if x == 0:
        break

    count = 0
    for i in range(N):
        count += math.ceil(a[i] /x)-1
    if (count <=K):
        if (ans > x):
            ans = x
        r = x
    else:
        l = x
count = 0
ans = x
if(x!= 0 and l != 0):
        
    for i in range(N):
        count += math.ceil(a[i]/l)-1

    if (count <=K):
        ans = l
    else:
        ans = r

if l==0:
    ans = r
print(ans)

Buggy submission (verdict: Runtime Error):
import math

N,K = map(int,input().split())

a = list(map(int, input().split()))
l = 0
r = max(a)

x = (l+r)//2
ans = r+1
while(r>1+l):
    
    x = (l+r)//2
    count = 0
    for i in range(N):
        count += math.ceil(a[i] /x)-1
    if (count <=K):
        if (ans > x):
            ans = x
        r = x
    else:
        l = x
count = 0
for i in range(N):
    count += math.ceil(a[i]/l)-1

if (count <=K):
    ans = l
else:
    ans = r
print(ans)

Buggy submission (verdict: Runtime Error):
import math

N,K = map(int,input().split())

a = list(map(int, input().split()))
l = 0
r = max(a)

x = (l+r)//2
ans = r+1
while(r>1+l):
    
    x = (l+r)//2
    count = 0
    for i in range(N):
        count += math.ceil(a[i] /x)-1
    if (count <=K):
        if (ans > x):
            ans = x
        r = x
    else:
        l = x

for i in range(N):
    count += math.ceil(a[i]/l)-1

if (count <=K):
    ans = l
else:
    ans = r
print(ans)

Buggy submission (verdict: Runtime Error):
import math

N,K = map(int,input().split())

a = list(map(int, input().split()))
l = 0
r = max(a)

x = (l+r)//2
ans = r+1
while(r>1+l):
    print(str(l)+":"+str(r))
    x = (l+r)//2
    count = 0
    for i in range(N):
        count += math.ceil(a[i] /x)-1
    if (count <=K):
        if (ans > x):
            ans = x
        r = x
    else:
        l = x

for i in range(N):
    count += math.ceil(a[i]/l)-1

if (count <=K):
    ans = l
else:
    ans = r
print(ans)
Problem p02970 (python)

Fixed submission:
N,D=map(int,input().split())
assined = 2*D+1
if N%assined==0:
  print(N//assined)
else:
  print(N//assined+1)

Buggy submission (verdict: Runtime Error):
/* ex4_1
  bonbonc */

#include<stdio.h>
int main(void){
	int tree, range;
	int assigned;//一人が割り当てられる木の本数の最大値

	scanf("%d %d",&tree,&range);
	assigned = 2*range+1; //自分のいる位置と左右にrange本

	if (tree%assigned==0){//木の本数がassignedで割り切れるとき
		printf("%d\n",tree/assigned);//木の本数をassignedで割った商を出力
	}else{
		printf("%d\n",tree/assigned +1);//木の本数をassignedで切り捨て除算し、1を加えて出力
	}

	
	return 0;
}
Problem p02835 (python)

Fixed submission:
x = input().split()
a, b, c =x
d = int(a)+int(b)+int(c)
if d<22:
    print("win")
else:
    print("bust")

Buggy submission (verdict: Runtime Error):
a = int(input())
b = int(input())
c = int(input())
d = int(a+b+c)
if d<22:
    print("win")
else:
    print("bust")
Problem p02596 (python)

Fixed submission:
N = int(input())
if N % 7:
    L = 9*N
else:
    L = 9*N//7
num = 1
if L % 2 and L % 5:
    i = 1
    while i <= L:
        num = (num*10) % L
        if num == 1:
            print(i)
            break

        else:

            i += 1

else:
    print(-1)

Buggy submission (verdict: Runtime Error):
N = int(input())

mod_list = []
if N % 2:
    i = 1
    while True:
        num = (7*((10**i)-1)/9) % N
        if num == 0:
            print(i)
            break
        if num in mod_list:
            print(-1)
            break
        else:
            mod_list.append()
            i += 1

else:
    print(-1)
Problem p02552 (python)

Fixed submission:
x=int(input())
if x==1:
    print(0)
else:
    print(1)

Buggy submission (verdict: Runtime Error):
x=int(input())
if x=1:
    print(0)
else:
    print(1)
Problem p02688 (python)

Fixed submission:
import collections
N,K=map(int,input().split())
sunuke=[]
for i in range(K):
    d=int(input())
    okashi=input().split()
    for i in range(d):
        sunuke.append(okashi[i])

have_okashi=collections.Counter(sunuke)
print(N-len(have_okashi))

Buggy submission (verdict: Runtime Error):
N,K=map(int,input().split())
sunuke=[]
for i in range(K):
    d=int(input())
    okashi=input().split()
    for i in range(d):
        sunuke.append(okashi[i])

have_okashi=collections.Counter(sunuke)
print(N-len(have_okashi))
Problem p03327 (python)

Fixed submission:
contest_num = int(input())

if contest_num <= 999:
    print('ABC')
elif contest_num >= 1000:
    print('ABD')

Buggy submission (verdict: Runtime Error):
if contest_num <= 999:
    print('ABC' + str(contest_num).zfill(3))
elif contest_num >= 1000:
    over_thousand_num_fix = contest_num - 999
    print('ABD' + str(over_thousand_num_fix).zfill(3))
Problem p02570 (python)

Fixed submission:
D, T, S = map(int, input().split())

print('Yes' if D <= T*S else 'No')

Buggy submission (verdict: Runtime Error):
D, T, S = map(input().split())

print('Yes' if D <T*S else 'No')
Problem p02557 (python)

Fixed submission:
n=int(input())
a=[int(_) for _ in input().split()]
b=[int(_) for _ in input().split()]

d_a={}
d_b={}

for i in range(-1,n):
    d_a[i]=0
    d_b[i]=0

for i in range(n):
    d_a[a[i]-1]+=1
    d_b[b[i]-1]+=1

diff=0
c,d=0,0
for i in range(n):
    if d_a[i]+d_b[i]>n:
        print("No")
        exit()
    c+=d_a[i]
    d+=d_b[i-1]
    diff = max(diff,c-d)
print("Yes")
# for i in range(n):
#     print(a[i],end=" ")
# print()
for i in range(n):
    print(b[(i-diff)%n],end=" ")
print()

Buggy submission (verdict: Runtime Error):
n=int(input())
a=[int(_) for _ in input().split()]
b=[int(_) for _ in input().split()]

d_a={}
d_b={}

for i in range(n):
    d_a[i]=0
    d_b[i]=0

for i in range(n):
    d_a[a[i]]+=1
    d_b[b[i]]+=1

diff=0

for i in range(n):
    if d_a[i]+d_b[i]>n:
        print("No")
        exit()
    diff = max(diff,abs(d_a[i]-d_b[(i-1)%n]))
print("Yes")
# for i in range(n):
#     print(a[i],end=" ")
# print()
for i in range(n):
    print(b[(i-diff)%n],end=" ")
print()
Problem p02597 (python)

Fixed submission:
n = int(input())
s = [_ for _ in input()]

l, r = 0, n-1
if not('R' in s):
    print(0)
    exit()

if not('W' in s):
    print('0')
    exit()

ans = 0
while 1:
    while s[l] == "R":
        l += 1
    while s[r] == "W" and l != r:
        r -= 1

    if l != r:
        s[l], s[r] = s[r], s[l]
        ans += 1
        # print(s)
    if l == r:
        break

print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = [_ for _ in input()]

l, r = 0, n-1
if not('R' in s):
    print(0)
    exit()

if not('W' in s):
    print('0')
    exit()

ans = 0
while 1:
    while s[l] == 'W':
        l += 1

    while s[r] == 'R' and l < r:
        r -= 1

    ans += 1

    if l > r:
        break

    l += 1
    r -= 1
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = [_ for _ in input()]

l, r = 0, n-1
if not('R' in s):
    print(0)
    exit()

if not('W' in s):
    print('0')
    exit()

ans = 0
while 1:
    while s[l] == 'R':
        l += 1

    while s[r] == 'R' and l < r:
        r -= 1

    ans += 1

    if l > r:
        break

    l += 1
    r -= 1
print(ans)
Problem p02623 (python)

Fixed submission:
n, m, k = [int(_) for _ in input().split()]

a = [int(_) for _ in input().split()]
b = [int(_) for _ in input().split()]

b.append(k+100)
cnt = 0
ans1, ans2 = 0, 0
for i in range(n-1):
    a[i+1] += a[i]
    if a[i+1] <= k:
        ans1 = i+2
for j in range(m-1):
    b[j+1] += b[j]
    if b[j+1] <= k:
        ans2 = j+2
# print(a, b)
ans = max(ans1, ans2)
for i in range(n):
    nokori = k-a[i]
    r, l = 0, m
    if nokori < 0:
        break
    if b[0] > nokori:
        ans = max(i+1, ans)
        continue

    while(l-r > 1):
        if b[(r+l)//2] <= nokori:
            r = (r+l)//2
        else:
            l = (r+l)//2
        # print(l, r)
    ans = max(i+l+1, ans)
    # print(i, r, l, nokori)
print(ans)

Buggy submission (verdict: Runtime Error):
n, m, k = [int(_) for _ in input().split()]

a = [int(_) for _ in input().split()]
b = [int(_) for _ in input().split()]

b.append(k)
cnt = 0
ans1, ans2 = 0, 0
for i in range(n-1):
    a[i+1] += a[i]
    if a[i] <= k:
        ans1 = i

for j in range(m):
    b[j+1] += b[j]
    if b[i] <= k:
        ans2 = j
# print(a, b)
ans = max(ans1, ans2)
for i in range(n):
    nokori = k-a[i]
    if nokori < 0:
        break
    if b[0] > nokori:
        ans = max(i+1, ans)
        continue

    r, l = 0, m

    while(l-r > 1):
        if b[(r+l)//2] <= nokori:
            r = (r+l)//2
        else:
            l = (r+l)//2
        # print(l, r)
    ans = max(i+l+1, ans)
    # print(i, r, l, nokori)
print(ans)
Problem p02699 (python)

Fixed submission:
s,w=[int(x) for x in input().split()]
 
if(s>w):
  print("safe")
else:
  print("unsafe")

Buggy submission (verdict: Runtime Error):
s,w=[int(x) for x in input().splir()]

if(s>w):
  print("safe")
else:
  print("unsafe")
Problem p02829 (python)

Fixed submission:
a=int(input())
b=int(input())
print(6-a-b)

Buggy submission (verdict: Runtime Error):
a=int(input())
b=int(input())
prit(6-a-b)
Problem p03222 (python)

Fixed submission:
H,W,K = [int(i) for i in input().split()]

DP = [[0 for i in range(W)]for j in range(2)]

t = [0 for i in range(W+10)]
t[0]  = 1
t[1] = 1
t[2] = 2
for i in range(2,W+8):
    t[i+1] = t[i] + t[i-1]

#print(t)
n = 0
DP[0][0] = 1
for i in range(H):
    if W == 1:
        break
    DP[not(n)][0] = (DP[n][0] * t[W-1] + DP[n][1] * t[W-2]) % 1000000007
    for i in range(1,W-1):
        DP[not(n)][i] =( DP[n][i-1] *(t[W-i-1] * t[i-1]) + DP[n][i] * (t[i] * t[W-i-1]) + DP[n][i+1]*(t[W-i-2] * t[i])) % 1000000007
    
    DP[not(n)][W-1] = (DP[n][W-2]*t[W-2] + DP[n][W-1] * t[W-1]) % 1000000007
    n = not(n)
print(DP[n][K-1])

Buggy submission (verdict: Runtime Error):
H,W,K = [int(i) for i in input().split()]

DP = [[0 for i in range(W)]for j in range(2)]

t = [0 for i in range(W+10)]

t[1] = 1
t[2] = 2
for i in range(2,W+8):
    t[i+1] = t[i] + t[i-1]

#print(t)
n = 0
DP[0][0] = 1
for i in range(H):
    if W == 1:
        break
    DP[not(n)][0] = (DP[n][0] * t[W-1] + DP[n][1] * t[W-2]) % 1000000007
    for i in range(1,W-1):
        DP[not(n)][i] =( DP[n][i-1] *t[W - (i+1)] + DP[n][i]*(t[i-1] + t[W-i]) + DP[n][i+1]*t[i-2] ) % 1000000007
    
    DP[not(n)][W-1] = (DP[n][W-2]*t[W-2] + DP[n][W-1] * t[W-1]) % 1000000007
    n = not(n)
print(DP[n][K])
Problem p03315 (python)

Fixed submission:
S = input()
ans =0
for i in S:
    if i=='+':
        ans +=1
    else:
        ans-=1

print(ans)

Buggy submission (verdict: Runtime Error):
N,K =[int(i) for i in input().split(' ')]

A = [int(i) for i in input().split(' ' )]
index_1 = -1

for i in range(len(A)):
    #print(index_1)
    if A[i]==1:
        index_1 = i
        break

ans = 0
if index_1%(K-1)==0:
    ans += index_1 // (K-1)
else:
    ans += index_1 //(K-1) + 1

if (N-index_1 -1)%(K-1)==0:
    ans += (N - index_1-1) // (K-1)
else:
    ans += (N - index_1 -1) //(K-1) + 1
    
print(ans)

Buggy submission (verdict: Runtime Error):
lis = input()
ans = 0
for i in lis:
  if i=='+':
    ans +=1
   else:
    ans-=1
    
print(ans)
Problem p03317 (python)

Fixed submission:
N,K =[int(i) for i in input().split(' ')]

A = [int(i) for i in input().split(' ')]
"""
index_1 = -1

for i in range(len(A)):
    #print(index_1)
    if A[i]==1:
        index_1 = i
        break

ans = 0
if index_1%(K-1)==0:
    ans += index_1 // (K-1)
else:
    ans += index_1 //(K-1) + 1

if (N-index_1 -1)%(K-1)==0:
    ans += (N - index_1-1) // (K-1)
else:
    ans += (N - index_1 -1) //(K-1) + 1
    
print(ans)
"""
ans =0
if (N-1)%(K-1) ==0:
    ans = (N-1)//(K-1)
else:
    ans = (N-1)//(K-1) +1
print(ans)

Buggy submission (verdict: Runtime Error):
N,K =[int(i) for i in input().split(' ')]

A = [int(i) for i in input().split(' ')]
"""
index_1 = -1

for i in range(len(A)):
    #print(index_1)
    if A[i]==1:
        index_1 = i
        break

ans = 0
if index_1%(K-1)==0:
    ans += index_1 // (K-1)
else:
    ans += index_1 //(K-1) + 1

if (N-index_1 -1)%(K-1)==0:
    ans += (N - index_1-1) // (K-1)
else:
    ans += (N - index_1 -1) //(K-1) + 1
    
print(ans)
"""
ans =0
if (N-1)%(k-1) ==0:
    ans = (N-1)//(k-1)
else:
    ans = (N-1)//(k-1) +1
print(ans)
Problem p03329 (python)

Fixed submission:
N = int(input())
#num = [1]
#print("a")
"""
#memo = [[ -1 for i in range(12)]for j in range(100000)]
n = 6
while True:
    num.append(n)
    n *= 6
    if n > 100000:
        break
n = 9
while True:
    num.append(n)
    n *= 9
    if n > 100000:
        break
num.sort()

ans = 0
print(num)
#while N > 6:

def DP(n , index):
    if index == 0:
        return  n
    elif n == 0:
        return 0
    min_ = 10000000
    if n < num[index]:
        #print(n,num[index])
        return DP(n,index - 1)
    can = num[index]
    #print(index)
#    print(n//can)
    for i in range(n // can+1):
        min_ = min(min_ , DP(n - i * can,index - 1) + i)
 #       print(i,n,index,DP(n - i*can,index-1))
    
     #   print(min_)
    #print(min_)
    memo[n][index] = min_
    return min_
    
print(DP(N,11))
"""

def ninep(N):
    if N <9:
        return N
    ans = 0
    while N > 0:
        ans += N % 9
        N =N // 9
    return ans


def sixp(N):
    if N <6:
        return N
    ans = 0
    while N > 0:
        ans += N % 6
        N = N // 6
    return ans


ans = 1000000
for i in range(N+1):
    ans = min(ans,ninep(i) + sixp(N - i))
#    print(ninep(i), sixp(N - i),i)

print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())

num = [1]
memo = [[ -1 for i in range(12)]for j in range(100000)]
n = 6
while True:
    num.append(n)
    n *= 6
    if n > 100000:
        break
n = 9
while True:
    num.append(n)
    n *= 9
    if n > 100000:
        break
num.sort()

ans = 0
print(num)
#while N > 6:

def DP(n , index):
    if index == 0:
        return  n
    elif n == 0:
        return 0
    min_ = 10000000
    if n < num[index]:
        #print(n,num[index])
        return DP(n,index - 1)
    can = num[index]
    #print(index)
#    print(n//can)
    for i in range(n // can+1):
        min_ = min(min_ , DP(n - i * can,index - 1) + i)
 #       print(i,n,index,DP(n - i*can,index-1))
    
     #   print(min_)
    #print(min_)
    memo[n][index] = min_
    return min_
    
print(DP(N,11))
Problem p03705 (python)

Fixed submission:
n,a,b=[int(_) for _ in input().split()]
if n==1:
  if a==b:
    print(1)
  else:
    print(0)
  exit()
print(max(0,(n-2)*(b-a)+1))

Buggy submission (verdict: Runtime Error):
n,a,b=[int(_) for_ in input().split()]
if n==1:
  if a==b:
    print(1)
  else:
    print(0)
print(max(0,(n-2)*(b-a)+1)
Problem p03774 (python)

Fixed submission:
n,m=[int(_)for _ in input().split()]

ab=[[int(_) for _ in input().split()]for i in range(n)]
cd=[[int(_) for _ in input().split()]for i in range(m)]


def dist(p1,p2):
  return abs(p1[0]-p2[0])+abs(p1[1]-p2[1])

for i in range(n):
  d=1000000000
  ans=0
  for j in range(m):
    if d>dist(ab[i],cd[j]):
      ans=j+1
      d=dist(ab[i],cd[j])
  print(ans)

Buggy submission (verdict: Runtime Error):
3 4
10 10
-10 -10
3 3
1 2
2 3
3 5
3 5
Problem p03986 (python)

Fixed submission:
s=input()
c=0
ans=0
for i in range(len(s)):
  if s[i]=='T':
    c+=1
  if s[i]=='S':
    c-=1
  ans = max(ans,c)
print(ans*2)

Buggy submission (verdict: Runtime Error):
s=input()
c=0
ans=0
for i in range(len(s)):
  if s[i]=='T':
    c+=1
  if s[i]='S':
    c-=1
  ans = max(ans,c)
print(ans*2)

Buggy submission (verdict: Runtime Error):
s=input()
c=0
ans=0
for i in range(n):
  if s[i]=='T':
    c+=1
  if s[i]='S':
    c-=1
  ans = max(ans,c)
print(ans*2)
Problem p04005 (python)

Fixed submission:
a=[int(_) for _ in input().split()]
if a[0]%2==0 or a[1]%2==0 or a[2]%2==0:
  print(0)
else:
  a.sort()
  print(a[0]*a[1])

Buggy submission (verdict: Runtime Error):
a=[int(_) for i in range(n)]
if a[0]%2==0 or a[1]%2==0 or a[2]%2==0:
  print(0)
else:
  a.sort()
  print(a[0]*a[1])
Problem p02699 (python)

Fixed submission:
S, W = map(int, input().split())
if W >= S:
    print("unsafe")
else:
    print("safe")

Buggy submission (verdict: Runtime Error):
S, W = map(int(input().split()))
if W >= S:
    print("unsafe")
else:
    print("safe")

Buggy submission (verdict: Runtime Error):
S = int(input())
W = int(input())
if W >= S:
    print("unsafe")
else:
    print("safe")
Problem p02552 (python)

Fixed submission:
x = input()
if x == "0":
  print(1)
else:
  print(0)

Buggy submission (verdict: Runtime Error):
x = input()
if x = "0":
  print(1)
elif x = "1":
  print(0)
Problem p02570 (python)

Fixed submission:
D,T,S = map(int,input().split())
if(D>T*S):
    print("No")
else:
    print("Yes")

Buggy submission (verdict: Runtime Error):
from collections import Counter

class UnionFind:
    def __init__(self,num:int):
        self.r = [-1 for i in range(num)]
    def root(self,x:int):
        if(self.r[x] < 0):
            return x
        self.r[x] = self.root(self.r[x])
        return self.r[x]
    def unite(self,x:int,y:int):
        rx = self.root(x)
        ry = self.root(y)
        if(rx == ry):
            return False
        if(self.r[rx] > self.r[ry]):
            rx,ry = ry,rx
        self.r[rx] += self.r[ry]
        self.r[ry] = rx
        return True
    def size(self,x:int):
        return -self.r[self.root(x)]

N,M = map(int,input().split())
group = UnionFind(N)
for i in range(M):
    A,B = map(int,input().split())
    group.unite(A-1,B-1)
ans = 0
for i in range(N):
    ans = max(ans,group.size(i))
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter

class UnionFind:
    def __init__(self,num:int):
        self.r = [-1 for i in range(num)]
    def root(self,x:int):
        if(self.r[x] < 0):
            return x
        self.r[x] = self.root(self.r[x])
        return self.r[x]
    def unite(self,x:int,y:int):
        rx = self.root(x)
        ry = self.root(y)
        if(rx == ry):
            return False
        if(self.r[rx] > self.r[ry]):
            rx,ry = ry,rx
        self.r[rx] += self.r[ry]
        self.r[ry] = rx
        return True
    def size(self,x:int):
        return -self.r[self.root(x)]

N,M = map(int,input().split())
group = UnionFind(N)
for i in range(M):
    A,B = map(int,input().split())
    group.unite(A-1,B-1)
ans = 0
for i in range(N):
    ans = max(ans,group.size(i))
print(group.r)
print(ans)
Problem p02862 (python)

Fixed submission:
import sys
r=sys.stdin.readline
X,Y=map(int,r().split())
#a=X-2b, b=Y-2a
if 2*X-Y<0 or (2*X-Y)%3!=0 or 2*Y-X<0 or (2*Y-X)%3!=0:
    print(0)
    exit(0)   
a=(2*Y-X)//3
b=(2*X-Y)//3
MOD=10**9+7
#ex) ab, ba --> a+bCa
def pow(a,b):
    ans=1
    while b:
        if b&1:
            ans=(ans*a)%MOD
        a=(a**2)%MOD
        b=b//2
    return ans 
N=a+b
K=a
fac=[1 for _ in range(N+1)]
for i in range(2,N+1):
    fac[i]=(fac[i-1]*i)%MOD
A=fac[N]
B=(fac[N-K]*fac[K])%MOD
print((A%MOD)*pow(B,MOD-2)%MOD)

Buggy submission (verdict: Runtime Error):
import sys
from collections import defaultdict
r=sys.stdin.readline
X,Y=map(int,r().split())
#a=X-2b, b=Y-2a
sys.setrecursionlimit(10**6)
if (X+Y)%3!=0:
    print(0)
    exit(0)   
a=(2*Y-X)//3
b=(2*X-Y)//3
MOD=10**9+7
N=10**6
#permutation with repetition
#ex) ab, ba --> a+bCa
def pow(a,b):
    ans=1
    while b:
        if b&1:
            ans=(ans*a)%MOD
        a=(a**2)%MOD
        b=b//2
    return ans 
N=a+b
K=a
fac=[1 for _ in range(N+1)]
for i in range(2,N+1):
    fac[i]=(fac[i-1]*i)%MOD
A=fac[N]
B=(fac[N-K]*fac[K])%MOD
print((A%MOD)*pow(B,MOD-2)%MOD)

Buggy submission (verdict: Runtime Error):
import sys
from collections import defaultdict
r=sys.stdin.readline
X,Y=map(int,r().split())
#a=X-2b, b=Y-2a
sys.setrecursionlimit(10**6)
if (2*Y-X)%3!=0 or (2*X-Y)%3!=0:
    print(0)
    exit(0)   
a=(2*Y-X)//3
b=(2*X-Y)//3
MOD=10**9+7
N=10**6
#permutation with repetition
#ex) ab, ba --> a+bCa
def pow(a,b):
    ans=1
    while b:
        if b&1:
            ans=(ans*a)%MOD
        a=(a**2)%MOD
        b=b//2
    return ans 
N=a+b
K=a
fac=[1 for _ in range(N+1)]
for i in range(2,N+1):
    fac[i]=(fac[i-1]*i)%MOD
A=fac[N]
B=(fac[N-K]*fac[K])%MOD
print((A%MOD)*pow(B,MOD-2)%MOD)