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

Fixed submission:
N = int(input())
ball = list(map(int, input().split()))
ball.sort(reverse = True)
ok = {}
for x in ball:
    if x in ok:
        ok[x] += 1
    else:
        ok[x] = 1
ans = 0
for x in ball:
    if ok[x] != 0:
        y = 2**(x.bit_length()) - x
        if y in ok:
            if ok[y] != 0:
                if y == x and ok[y] == 1: 
                    continue
                ans += 1
                ok[x] -= 1
                ok[y] -= 1
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
ball = list(map(int, input().split()))
ball.sort(reverse = True)
ok = {}
for x in ball:
    if x in ok:
        dic[x] += 1
    else:
        dic[x] = 1
ans = 0
for x in ball:
    if ok[x] != 0:
        y = 2**(x.bit_length()) - x
        if ok[y] != 0:
            if y == x and ok[y] == 1: 
                continue
            ans += 1
            dic[x] -= 1
            dic[y] -= 1
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
ball = list(map(int, input().split()))
ball.sort(reverse = True)
dic = {}
for x in ball:
    dic[x] = 1

ans = 0
for x in ball:
    dic[x] = 0
    y = 2**(x.bit_length()) - x
    if dic[y] == 1:
        ans += 1
        dic[y] = 0
print(ans)
Problem p02627 (python)

Fixed submission:
a=input()
print('a' if a.islower() else 'A')

Buggy submission (verdict: Runtime Error):
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
	char a;
	cin >> a;
	if (isupper(a))cout << 'A';
	else
		cout << 'a';
}
Problem p02753 (python)

Fixed submission:
S = input()
if len(set(S)) == 2:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
S = list(input())
Q = int(input())
for i in range(Q):
    query = input().split()
    if int(query[0]) == 1:
        S.reverse()
    else:
        if int(query[1]) == 1:
            S.insert(0, query[2])
        else:
            S.append(query[2])
print("".join(S))
Problem p02833 (python)

Fixed submission:
N = int(input())  
if N%2==0: 
  r = 0 
  for i in range(99): 
    r += N // 10 // 5 ** i 
  print(r) 
else: 
  print(0)

Buggy submission (verdict: Runtime Error):
N = int(input())
print(N // 10 + sum[N // (50 ** i) for i in range(100)])

Buggy submission (verdict: Runtime Error):
N = int(input())
print(N // 10 + sum[N // (50 ** i) for i in range(100)])
Problem p02699 (python)

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

if S>W:
  print('safe')
else:
  print('unsafe')

Buggy submission (verdict: Runtime Error):
a,b,c,d=map(int,input().split())
while True:
  c-=b
  if c<=0:
    print('Yes')
    break
  a-=d
  if a<=0:
    print('No')
    break
Problem p02711 (python)

Fixed submission:
N=input()
if '7' in N:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
N=input()
if '7' in N:
  print('Yes')
else:
  print(No)
Problem p02627 (python)

Fixed submission:
x = input()

if x.isupper():
	print("A")
else:
  	print("a")

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

data = list(map(int, input().split() ))
data.sort()
print(sum(data[0:k]))
Problem p02753 (python)

Fixed submission:
s = input()
if s[0]==s[1] and s[1]==s[2]:
  print("No")
else:
  print("Yes")

Buggy submission (verdict: Runtime Error):
s=input()
if s[0]=s[1] and s[1]=s[2]:
  print("Yes"
else:
  print("No"

Buggy submission (verdict: Runtime Error):
s = input()
if s = "AAA" or "BBB":
	print("No")
else:
	print("Yer")
Problem p02754 (python)

Fixed submission:
n,a,b = map(int, input().split())
if a==0 and b==0:
  	print(0)
else:
	set = n//(a+b)
	rem = n % (a+b)
	if rem >= a:
		print( set * a + a)
	else:
		print( set * a + rem)

Buggy submission (verdict: Runtime Error):
a,b,n = input().split()
set = n//(a+b)
rem = n % (a+b)
if rem <= a:
	return set * (a+b) + a
else:
	return set * (a+b) + rem
Problem p02819 (python)

Fixed submission:
n = int(input())
 
flag = 0
 
while flag==0:
#check if n is prime or not
	tst = 2
	while n % tst != 0:
		tst = tst + 1
	if tst==n: 
		flag=1
	else:
		n=n+1
print(n)

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

flag = 0

while flag==0:
#check if n is prime or not
	tst = 2
	while n % tst != 0:
    	tst = tst + 1
    if tst==n: 
		flag=1
	else:
		n=n+1
print(n)
Problem p02831 (python)

Fixed submission:
a,b = map(int, input().split())
 
com = 1
for i in reversed(range(2,a+1)):
	if a % i ==0 and b % i == 0:
		a = a//i
		b = b//i
		com = com*i
#		print(i)
print(a*b*com)

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

ans = a * b
for i in range(a)
if ans % i**2:
	ans = ans // i
print(ans)
Problem p02959 (python)

Fixed submission:
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
 
score = 0
for i in range(n):
	if B[i] >= A[i] + A[i+1]:
		score = score + A[i] + A[i+1]
		A[i+1] = 0
	elif B[i] <= A[i]:
		score = score + B[i]
	else:
		score = score + B[i]
		A[i+1] = A[i+1] + A[i] - B[i]
print(score)

Buggy submission (verdict: Runtime Error):
n = input()
A = list(map(int, input().split()))
B = list(map(int, input().split()))

score = 0
for i in range(n):
	if B[i] >= A[i] + A[i+1]:
		score = score + A[i] + A[i+1]
        A[i+1] = 0
	elif B[i] <= A[i]:
		score = score + B[i]
	else:
		score = score + B[i]
		A[i+1] = A[i+1] + A[i] - B[i]
print(score)
Problem p03041 (python)

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

S = input()

SL = list(S)
SL[K-1] = SL[K-1].lower()
ans = "".join(SL)

print(ans)

Buggy submission (verdict: Runtime Error):
N, K = map(int,input().split())

S = input()

SL = list(S)
SL[K] = SL[K].lower()
ans = "".join(SL)

print(ans)

Buggy submission (verdict: Runtime Error):
N, K = map(int,input().split())

S = input()

SL = list(S)
SL[K] = SL[K].lower()
ans = "".join(SL)

print(ans)
Problem p03207 (python)

Fixed submission:
n = int(input())
max = 0
sum = 0

#print ("START")
for i in range(n):
	data = input()
#	print("aaa")
	data = int(data)
#	print(data)
	if max < data:
		max = data
	sum = sum + data
print(sum - max//2)

Buggy submission (verdict: Runtime Error):
n = int(input())
max = 0
sum = 0

#print ("START")
for i in range(n):
	data = (input()
#	print("aaa")
	data = int(data)
#	print(data)
	if max < data:
		max = data
	sum = sum + data
print(sum - max//2)

Buggy submission (verdict: Runtime Error):
n = int(input())
 
max = 0
sum = 0
for i in range(n):
	data = int(input())
 	if max < data:
    	max = data
    sum = sum + data
   
print(sum - max//2)

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

max = 0
sum = 0
for i in range(n)
	data = int(input())
 	if max < data:
    	max = data
    sum = sum + data
   
print(sum - max//2)
Problem p02627 (python)

Fixed submission:
c = input()

if c.isupper():
	print("A")
else:
	print("a")

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

while N > 0:
	N -= 1
	ans += chr(ord('a') + N % 26)
	N //= 26

print(ans[::-1])

Buggy submission (verdict: Runtime Error):
num = int(input())
res = ""

while num != 0:
	num -= 1
	rem = num % 26
	res += chr(ord('a') + rem)
	num //= 26

print(res)
Problem p02629 (python)

Fixed submission:
N = int(input())
ans = ""

while N > 0:
	N -= 1
	ans += chr(ord('a') + N % 26)
	N //= 26

print(ans[::-1])

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

while num > 0:
	N -= 1
	ans += chr(ord('a') + N % 26)
	N //= 26

print(ans)

Buggy submission (verdict: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

int main() {
	int a;
	cin>>a;
	string res;

	while (a != 0) {
		int rem=a%26;
		a/=26;
		char asciiChar=rem+97-1;
		res+=asciiChar;
	}

	reverse(res.begin(),res.end());
	cout<<res;
}

Buggy submission (verdict: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

// ios::sync_with_stdio(0);
// cin.tie(0);

//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);

int main() {
	int a;
	cin>>a;
	string res;

	while (a != 0) {
		int rem=a%26;
		a/=26;
		char asciiChar=rem+97-1;
		res+=asciiChar;
	}

	reverse(res.begin(),res.end());
	cout<<res;
}
Problem p02723 (python)

Fixed submission:
x=input()
if(x[2]==x[3] and x[4]==x[5]):print('Yes')
else:print('No')

Buggy submission (verdict: Runtime Error):
x=[x for x in input()]
if(x[3]==x[4] and x[5]==x[6]):
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
x=input()
if(x[3]==x[4] and x[5]==x[6]):
    print('Yes')
else:
    print('No')
Problem p02831 (python)

Fixed submission:
from fractions import gcd
A, B = map(int, input().split())
print((A*B)//gcd(A, B))

Buggy submission (verdict: Runtime Error):
A, B = map(int, input().split())
def fun(A, B, n=1):
  if n%B == 0: return n
  return fun(A, B, n+1)
print(fun(A, B))

Buggy submission (verdict: Runtime Error):
def fun(A, B, n=1):
  if n%B == 0: return n
  return fun(A, B, n+1)
print(fun(*map(int, input().split())))

Buggy submission (verdict: Runtime Error):
import numpy as np
A, B = map(int, input().split())
print(np.lcm(A, B))

Buggy submission (verdict: Runtime Error):
import numpy as np
A, B = map(int, input().split())
print(np.gcd(A, B))
Problem p02880 (python)

Fixed submission:
n = float(input())
print('Yes' if any([n/i in range(1, 10) and (n/i).is_integer() for i in range(1, 10)]) else 'No')

Buggy submission (verdict: Runtime Error):
print('Yes' if any([n/i in range(1, 10) and (n/i).is_integer() for i in range(1, 10)]) else 'No')
Problem p02627 (python)

Fixed submission:
s=input()
TF=s.isupper()
if TF == True:
  print('A')
else:
  print('a')

Buggy submission (verdict: Runtime Error):
N,K=map(int,input().split())
P=list(map(int,input().split()))

P.sort()
price=0
for i in range(K):
  price+=P[i]
  
print(price)
Problem p02779 (python)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
A.sort()
for i in range(N-1):
  if A[i]==A[i+1]:
    print('NO')
    break
else:
  print('YES')

Buggy submission (verdict: Runtime Error):
N=int(input())
A=list(map(it,input().split()))
A.sort()
for i in range(N-1):
  if A[i]==A[i+1]:
    print('NO')
    break
else:
  print('YES')

Buggy submission (verdict: Runtime Error):
N=int(input())
A=list(map(it,input().split()))
A.sort()
for i in range(N-1):
  if A[i]=A[i+1]:
    print('NO')
    break
else:
  print('YES')
Problem p02829 (python)

Fixed submission:
A=int(input())
print(6-A-int(input()))

Buggy submission (verdict: Runtime Error):
A=int(input())
print(6-A-int(input())
Problem p02831 (python)

Fixed submission:
import fractions as fr
A,B=map(int,input().split())
print(A*B//fr.gcd(A,B))

Buggy submission (verdict: Runtime Error):
import fractions as fr
A,B=map(int,input().split())
print(A*B//fr.gcd(A,B)
Problem p02836 (python)

Fixed submission:
S=input()
num=0
for i in range(len(S)//2):
  if S[i]!=S[-(i+1)]:
    num+=1
print(num)

Buggy submission (verdict: Runtime Error):
S=int(input())
num=0
for i in range(len(S)//2):
  if S[i]!=S[-i]:
    num+=1
print(num)
Problem p02860 (python)

Fixed submission:
N=int(input())
S=input()
X=int(N/2)
T=S[:X]+S[:X]
if N%2 !=0:
  print("No")
elif S==T:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
N=int(input())
S=input()
if N%2 !=0:
  print("No")
elif S[:N/2]==S[N/2:]:
  print("Yes")
else:
  print("No")
Problem p02627 (python)

Fixed submission:
a = input()
if a.islower():
  print('a')
if a.isupper():
  print('A')

Buggy submission (verdict: Runtime Error):
a = input()
if 0 <= ord(a) - ord('a') <= 26:
  return 'a'
if 0 <= ord(a) - ord('A') <= 26:
  return 'A'

Buggy submission (verdict: Runtime Error):
a = int(input())
if 0 <= ord(a) - ord('a') <= 26:
  return 'a'
if 0 <= ord(a) - ord('A') <= 26:
  return 'A'
Problem p02777 (python)

Fixed submission:
S,T=input().split()
A,B=map(int,input().split())
U=input()
 
if U==S:
  print(A-1)
  print(B)
else:
  print(A)
  print(B-1)

Buggy submission (verdict: Runtime Error):
S,T=map(input().split())
A,B=map(int,input().split())
U=input()

if U==S:
  print(A-1)
  print(B)
else:
  print(A)
  print(B-1)
Problem p02627 (python)

Fixed submission:
i=input()
if i.islower():
    print("a")
elif i.isupper():
    print("A")

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
N=int(input())
A=list(map(int,input().split()))
Q=int(input())
Adic={}
B=0

for i in A:
    Adic[i]=0

for i in A:
    Adic[i]+=1

for i in range(Q):
    b,c=map(int,input().split())
    
    if b not in Adic:
        for k,v in Adic.items():
            B+=k*v
        print(B)
        B=0
    else:
        
        if c in Adic:
            Adic[c]+=Adic[b]
            Adic[b]=0
        elif c not in Adic:
            Adic[c]=0
            Adic[c]+=Adic[b]
            Adic[b]=0
            
        for k,v in Adic.items():
            B+=k*v
        print(B)
        B=0
Problem p02627 (python)

Fixed submission:
ch = input()
if(ch>='A' and ch <='Z'):
    print('A')
else:
  print('a')

Buggy submission (verdict: Runtime Error):
ch = input()
if(ch>='A' && ch <='Z'):
  print('A')
 else:
  print('a')
Problem p02679 (python)

Fixed submission:
n = int(input())

abl = [map(int, input().split()) for _ in range(n)]

from collections import defaultdict
dic = defaultdict(int)

# a,bの最大公約数
def gcd(a, b):
   while b:
       a, b = b, a % b
   return a

ab0 = 0
a0 = 0
b0 = 0
for a,b in abl:
    if a == 0 and b == 0:
        ab0 += 1
        continue
    elif a == 0:
        a0 += 1
        continue
    elif b == 0:
        b0 += 1
        continue
    gc = abs(gcd(a,b))
    if a < 0:
        a, b = -a // gc, -b // gc
    else:
        a, b = a // gc, b // gc
    dic[(a,b)] += 1
MOD = 1000000007
ans = 1
used = defaultdict(int)
for (a,b) in dic:
    if b > 0:
        target = (b, -a)
    else:
        target = (-b, a)
    if target in dic:
        if used[target] == 0:
            ans *= pow(2, dic[(a,b)], MOD) + pow(2, dic[target], MOD) - 1
            used[(a,b)] = 1
    else:
        ans *= pow(2, dic[(a,b)], MOD)
    ans %= 1000000007

ans *= pow(2, a0, MOD) + pow(2, b0, MOD) - 1
ans %= 1000000007

print((ans - 1 + ab0) % MOD)

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

abl = [map(int, input().split()) for _ in range(n)]

from collections import defaultdict
dic = defaultdict(int)

# a,bの最大公約数
def gcd(a, b):
   while b:
       a, b = b, a % b
   return a

for a,b in abl:
    gc = abs(gcd(a,b))
    if a < 0:
        a, b = -a // gc, -b // gc
    else:
        a, b = a // gc, b // gc
    dic[(a,b)] += 1
MOD = 1000000007
ans = 1
used = defaultdict(int)
for (a,b) in dic:
    if b > 0:
        target = (b, -a)
    else:
        target = (-b, a)
    if target in dic:
        if used[target] == 0:
            ans *= pow(2, dic[(a,b)], MOD) + pow(2, dic[target], MOD) - 1
            used[(a,b)] = 1
    else:
        ans *= (dic[(a,b)] + 1)
    ans %= 1000000007


print(ans - 1)

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

abl = [map(int, input().split()) for _ in range(n)]

from collections import defaultdict
dic = defaultdict(int)

for a,b in abl:
    dic[b / a] += 1
MOD = 1000000007
ans = 1
used = defaultdict(int)
for d in dic:
    if -(1/d) in dic:
        if used[-(1/d)] == 0:
            ans *= pow(2, dic[d], MOD) + pow(2, dic[-(1/d)], MOD)  - 1
            used[d] = 1
    else:
        ans *= (dic[d] + 1)
    ans %= 1000000007


print(ans - 1)
Problem p02757 (python)

Fixed submission:
N, P = map(int, input().split())
S = input()
if P == 2:
    counter = 0
    for i in range(len(S)):
        if S[i] in ['2', '4', '6', '8', '0']:
            counter += i + 1
    print(counter)
elif P == 5:
    counter = 0
    for i in range(len(S)):
        if S[i] in ['5', '0']:
            counter += i + 1
    print(counter)
else:
    list_a = [0] * P
    list_a[0] += 1
    counter = 0
    temp = 0
    power = 1
    for i in range(N):
        power *= 10
        power %= P
        temp += power * int(S[N-i-1])
        temp %= P
        counter += list_a[temp]
        list_a[temp] += 1
    print(counter)

Buggy submission (verdict: Runtime Error):
N, P = map(int, input().split())
S = input()
if P == 2:
    counter = 0
    for i in range(len(S)):
        if S[i] in ['2', '4', '6', '8', '0']:
            counter += i + 1
    print(counter)
elif P == 5:
    counter = 0
    for i in range(len(S)):
        if S[i] in ['5', '0']:
            counter += i + 1
    print(counter)
else:
    list_a = [0] * P
    list_a[0] += 1
    counter = 0
    temp = 0
    power = 1
    for i in range(N):
        temp += pow(10, i, mod=P) * int(S[N-i-1])
        temp %= P
        counter += list_a[temp]
        list_a[temp] += 1
    print(counter)
Problem p02990 (python)

Fixed submission:
# coding: utf-8
# Your code here!


from scipy.misc import comb
mod = 10**9 + 7

n,k = map(int,input().split())

for i in range(1,k+1):
    a = int(comb(k-1, i-1, exact=True)) % mod
    b = int(comb(n-k+1, i, exact=True)) % mod 
    print(a*b%mod)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!


from scipy.special import comb
mod = 10**9 + 7

n,k = map(int,input().split())

for i in range(1,k+1):
    a = int(comb(k-1, i-1, exact=True)) % mod
    b = int(comb(n-k+1, i, exact=True)) % mod 
    print(a*b%mod)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!


from scipy.special import comb
mod = 10**9 + 7

n,k = map(int,input().split())

for i in range(1,k+1):
    a = comb(k-1, i-1, exact=True) % mod
    b = comb(n-k+1, i, exact=True) % mod 
    print(a*b%mod)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!


from scipy.special import comb
mod = 10**9 + 7

n,k = map(int,input().split())

for i in range(1,k+1):
    a = comb(k-1, i-1, exact=True) % mod
    b = comb(n-k+1, i, exact=True) % mod 
    print(a*b%mod)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!

import math 

n,k = map(int,input().split())



for i in range(1,k+1):
    a = 1
    b = 1
    for j in range(1,i+1):
        a *= (n-k+2-j)/j
        a = int(a)
    for j in range(1,i):
        b *= (k-j)/j
        b = int(b)
    a = int(a)
    b = int(b)
    a %= 10**9+7
    b %= 10**9+7
    print(a*b%(10**9+7))

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!

import math 

n,k = map(int,input().split())



for i in range(1,k+1):
    a = 1
    b = 1
    for j in range(1,i+1):
        a *= (n-k+2-j)/j
    for j in range(1,i):
        b *= (k-j)/j
    a = int(a)
    b = int(b)
    a %= 10**9+7
    b %= 10**9+7
    print(a*b%(10**9+7))

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!

import math 

n,k = map(int,input().split())



for i in range(1,k+1):
    a = 1
    b = 1
    for j in range(1,i+1):
        a *= (n-k+2-j)/j
    for j in range(1,i):
        b *= (k-j)/j
    a %= 10**9+7
    b %= 10**9+7
    print(int(a*b)%(10**9+7))

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!

import math 

n,k = map(int,input().split())

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
    
for i in range(1,k+1):
    #　青はボールk-i,仕切りi-1
    a = combinations_count(k-1, i-1) % (10**9 + 7)
    # 赤ノボールはn-k-(i-1).仕切りi
    b = combinations_count(n-k-(i-1)+i, i) % (10**9 + 7)
    print(a*b%(10**9 + 7))
Problem p03038 (python)

Fixed submission:
import bisect
n,m = map(int,input().split())

al = list(map(int,input().split()))
al = sorted(al)


cbl = []
for _ in range(m):
    b,c = map(int,input().split())
    cbl.append((c,b))

sumal = [0]
suma = 0
for a in al:
    suma += a
    sumal.append(suma)
    
cbl = sorted(cbl, reverse=True)

topn = [0 for i in range(n)]
pos = 0
for c,b in cbl:
    for _ in range(b):
        topn[pos] = c
        pos += 1
        if pos == n:
            break
    else:
        continue
    break

sumtopn = [0]
sumtop = 0
for t in topn:
    sumtop += t
    sumtopn.append(sumtop)
ans = 0
for i in range(n+1):
    left = sumal[-1] - sumal[i]
    right = sumtopn[i]
    tmp = left + right
    if tmp > ans:
        ans = tmp
        
print(ans)

Buggy submission (verdict: Runtime Error):
import bisect
n,m = map(int,input().split())

al = list(map(int,input().split()))
al = sorted(al)


cbl = []
for _ in range(m):
    b,c = map(int,input().split())
    cbl.append((c,b))

sumal = [0]
suma = 0
for a in al:
    suma += a
    sumal.append(suma)
    
cbl = sorted(cbl, reverse=True)

topn = [0 for i in range(n)]
pos = 0
for c,b in cbl:
    for _ in range(b):
        topn[pos] = c
        pos += 1
        if pos == n-1:
            break
    else:
        continue
    break

sumtopn = [0]
sumtop = 0
for t in topn:
    sumtop += t
    sumtopn.append(sumtop)
ans = 0
for i in range(n+1):
    left = sumal[-1] - sumal[i]
    right = sumtopn[i]
    tmp = left + right
    if tmp > ans:
        ans = tmp
        
print(ans)

Buggy submission (verdict: Runtime Error):
import bisect
n,m = map(int,input().split())

al = list(map(int,input().split()))
al = sorted(al)


cbl = []
for _ in range(m):
    b,c = map(int,input().split())
    cbl.append((c,b))

sumal = [0]
suma = 0
for a in al:
    suma += a
    sumal.append(suma)
    
cbl = sorted(cbl, reverse=True)

topn = [0 for i in range(n)]
pos = 0
for c,b in cbl:
    for _ in range(b):
        topn[pos] = c
        pos += 1
        if pos == n-1:
            break
    else:
        continue
    break

sumtopn = [0]
sumtop = 0
for t in topn:
    sumtop += t
    sumtopn.append(sumtop)
ans = 0
for i in range(n):
    left = sumal[-1] - sumal[i]
    right = sumtopn[i]
    tmp = left + right
    if tmp > ans:
        ans = tmp
        
print(ans)
Problem p03045 (python)

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

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

uf = UnionFind(n)
for _ in range(m):
    x,y,z = map(int,input().split())
    uf.union(x-1, y-1)
    
print(uf.group_count())

Buggy submission (verdict: Runtime Error):


n,m = map(int,input().split())

global clasta
clasta = [-1 for i in range(n)]
path = [[] for i in range(n)]
for _ in range(m):
    x,y,z = map(int,input().split())
    path[x-1].append(y-1)
    path[y-1].append(x-1)

def dfs(now,color):
    for y in path[now]:
        if clasta[y] == -1:
            clasta[y] = color
            dfs(y,color)
ans = 0
for idx,i in enumerate(clasta):
    if i == -1:
        clasta[idx] = idx
        dfs(idx,idx)
        ans += 1

print(ans)