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

Fixed submission:
n = int(raw_input())
count = 0
res = 0
ais = map(int , raw_input().split())

for i,a in enumerate(ais):
	
	if a == i +1:
		count += 1
	else:
		#flush the count
		res += (count + 1)/2# + 1
		count = 0

if count: res +=  (count+1)/2 
print res

Buggy submission (verdict: Runtime Error):
n = int(raw_input())
h = {}
for i,a in enumerate(map(int, raw_input())):
	i += 1
	if a != i:
		h[a] = i

def get(u, parent):
	if parent[u] != u:
		parent[u] = get(parent[u], parent)
	return parent[u]

parent = {u:u for u in h}
sizes = {u:1 for u in h}
for u in h:
	v = h[u]
	pu,pv = get(u, parent), get(v, parent)
	if pu != pv:
		parent[pv] = pu
		sizes[pu] += sizes[pv]
print sum([sizes[u]-1 for u in parent if parent[u] == u] or [0])
Problem p03644 (python)

Fixed submission:
import math
print 2 ** int(math.floor(math.log(int(raw_input()),2)))

Buggy submission (verdict: Runtime Error):
import math
c= 0
while(n % 2 == 0):
    n/=2
    c+=1
print c
Problem p03659 (python)

Fixed submission:
n = raw_input()
ais = map(int, raw_input().split())
c = 0
s = sum(ais)
m = +float('inf')
for a in ais[:-1]:
	c += a
	m = min(m, abs(c - s + c))
print m

Buggy submission (verdict: Runtime Error):
n = raw_input()
ais = map(int, raw_input())
c = 0
s = sum(ais)
m = +float('inf')
for a in ais:
	c += a
	m = min(m, abs(c - s + c))
print m
Problem p03680 (python)

Fixed submission:
ais = [int(raw_input()) for oo in range(int(raw_input()))]
seen = set([])
u = 0
while((u!= 1) and (u not in seen)):
	seen.add(u)
	u = ais[u] - 1

print len(seen) if u == 1 else -1

Buggy submission (verdict: Runtime Error):
ais = [int(raw_input()) for oo in range(raw_input())]#n = raw_input()
seen = set([])
u = 0
while(u!= 1 or u not in seen):
	seen.add(u)
	u = ais[u] - 1

print len(seen) if u == 1 else -1

Buggy submission (verdict: Runtime Error):
ais = [int(raw_input()) for oo in range(raw_input())]#n = raw_input()
#for
ais = map(int , raw_input().split())
seen = set([])
u = 0
while(u!= 1 or u not in seen):
	seen.add(u)
    u = ais[u] - 1

print len(seen) if u == 1 else -1
Problem p03693 (python)

Fixed submission:
r,g,b, = map(str, raw_input().split())
s = int(r+g+b)
print 'YES' if s % 4 == 0 else 'NO'

Buggy submission (verdict: Runtime Error):
r,g,b, = map(str, raw_input())
s = int(r+g+b)
print 'YES' if s % 4 == 0 else 'NO'
Problem p03695 (python)

Fixed submission:
import collections
def f(n,ais):
	cc,extra = collections.Counter(),0
	for ai in ais:
		if ai/400 < 8: cc[ai/400] +=1
		else: extra +=1
	print len(cc) + (1 if (len(cc) == 0 and extra) else 0), min(10000, len(cc) + extra)
	#print min(cc.values() or [0]), max(cc.values() or [0]) + extra
f(int(raw_input()), map(int, raw_input().split()))

Buggy submission (verdict: Runtime Error):
import collections
n = int(raw_input())


def f(ais):
	extra = 0
	cc = collections.Counter()
	for ai in ais:
		if ai/400 < 8: cc[ai/400] +=1
	else:
		extra +=1
	print min(cc.values()), max(cc.values()) + extra
f(map(int, raw_input().split()))

Buggy submission (verdict: Runtime Error):

import collections
n = int(raw_input())


def f(ais):
	extra = 0
	cc = collections.Counter()
	for ai in ais:
		if ai/400 < 8:
		cc[ai/400] +=1
	else:
		extra +=1
	print min(cc.values()), max(cc.values()) + extra
f(map(int, raw_input().split()))

Buggy submission (verdict: Runtime Error):

import collections
n = int(raw_input())


def f(ais):
	extra = 0
	cc = collections.Counter()
	for ai in ais:
		if ai/400 < 8:
		cc[ai/400] +=1
	else:
		extra +=1
	print min(cc.values()), max(cc.values()) + extra
Problem p03697 (python)

Fixed submission:
a,b= map(int, raw_input().split())
print a+b if (a+b < 10) else 'error'

Buggy submission (verdict: Runtime Error):
print sum(map(int, raw_input().split())) < 10 else 'error'
Problem p03699 (python)

Fixed submission:
n = int(raw_input()) 
ais = [int(raw_input()) for _ in range(n)]
r = 0
cumul = 0
m = +float('inf')
for i in range(0, len(ais)):
	cumul += ais[i]
	if ais[i] % 10:
		m = min(m, ais[i])

	if cumul % 10 == 0:
		r = max(r, cumul - m)
	else:
		r = max(r, cumul)

print r

Buggy submission (verdict: Runtime Error):
n = int(raw_input()) 
r,cumul, ais, m = 0, 0, [int(raw_input()) for _ in range(n)],+float('inf')
for ai in ais:# in range(0, len(ais)):
	cumul += ai
	m = min(m, ais[i] if ai % 10 else +float('inf'))
	r = max(r, cumul - (m if cumul % 10 else 0))
print r

Buggy submission (verdict: Runtime Error):
n ais = [int(raw_input())] + map(int, raw_input().split())

r = 0
cumul = 0
m = +float('inf')
for i in range(1, len(ais)):
	cumul += ais[i]
	
	if cumul % 10 == 0:

		r = max(r, cumul - m)
	else:
		m = min(m, ais[i])
		r = max(r, cumul)

print r
Problem p03773 (python)

Fixed submission:
a,b = map(int, raw_input().split())
print (a + b) % 24

Buggy submission (verdict: Runtime Error):
a,b = map(int, raw_input())
print (a + b) % 24
Problem p03777 (python)

Fixed submission:
a,b = raw_input().split()
if a == 'H':
	print b
else:
	h = {'H':'D', 'D':'H'}
	print h[b]

Buggy submission (verdict: Runtime Error):
a,b = raw_input().split()
if a == 'H':
	print b
else:
	h = {'H':'C', 'C':'H'}
	print h[b]
Problem p03815 (python)

Fixed submission:
n = int(raw_input())


c = 2 * (n / 11)
h = {0:0}
for i in range(1, 6+1):
	h[i] = 1
for i in range(7, 12):
	h[i] = 2
if n in h:
	print h[n]
else:
	print h[n % 11] + c

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


c = 2 * (n / 11) if n > 11 else 0
h = {}
for i in range(1, 6+1):
	h[i] = 1
for i in range(7, 12):
	h[i] = 2
if n in h:
	print h[n]
else:
	print h[n % 11] + c
Problem p03854 (python)

Fixed submission:
words = ['dream','dreamer', 'erase', 'eraser']
s = raw_input()
dp = [False for _ in range(len(s))]

for j in range(len(s)):
	for w in words:
		b = dp[j - len(w)] if j - len(w) -1 >= 0 else True
		b &= j-len(w) +1 >= 0 and s[j- len(w)+1:j+1] == w
		if b:
			dp[j] = True
			break
print 'YES' if dp[-1] else 'NO'

Buggy submission (verdict: Runtime Error):
words = [w[::-1] for w in ['dream','dreamer', 'erase', 'eraser']]
s = raw_input()[::-1]
while(i < len(s)):
	for w in words:
		if w == s[:len(w)]:
			i += len(w)
			break



print 'YES' if i == len(s) else 'NO'
Problem p03943 (python)

Fixed submission:
ais = sorted(map(int, raw_input().split()))
print 'Yes' if sum(ais[:2]) == ais[2] else 'No'

Buggy submission (verdict: Runtime Error):
ais = sorted(map(int, raw_input()).split())
print 'Yes' if sum(ais[:2]) == ais[2] else 'No'

Buggy submission (verdict: Runtime Error):
ais = sorted(map(int, raw_input()))
print 'Yes' if sum(ais[:2]) == ais[2] else 'No'
Problem p04045 (python)

Fixed submission:
#1000 8
#1 3 4 5 6 7 8 9
n,k = map(int, raw_input().split())
s = set(map(int, raw_input().split()))
letters = [u for u in range(10) if u not in s]
def dfs(u,n,letters):
	if u >= n:
		return u
	return min([dfs(u*10 +l,n,letters) for l in letters if u or l])

print dfs(0,n,letters)

Buggy submission (verdict: Runtime Error):

n,k = map(int, raw_input().split())
letters = [u for u in range(10) if u not in set(map(int, raw_input().split()))]
def dfs(u,n,letters):return min([dfs(u*10 +l,n,letters) for l in letters if u or l]) if u < n else u

print dfs(0,n,letters)

Buggy submission (verdict: Runtime Error):
#1000 8
#1 3 4 5 6 7 8 9
n,k = map(int, raw_input().split())
s = set(map(int, raw_input()))
letters = [u for u in range(10) if u not in s]
def dfs(u,n,letters):
	if u >= n:
		return u
	return min([dfs(u*10 +l,n,letters) for l in letters if u or l])

print dfs(0,n,letters)
Problem p02576 (python)

Fixed submission:
import math
n,x,t=map(int,input().split())
ans=math.ceil(n/x)*t
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
l = []
 
 
for i in range(len(a) - 1):
    if a[i + 1] < a[i]:
        l.append(a[i]-a[i + 1])
        a[i + 1] = a[i]
print(sum(l))
Problem p02600 (python)

Fixed submission:
x=int(input())
if x>=400 and x<=599:
    print(8)
elif x>=600 and x<=799:
    print(7)
elif x>=800 and x<=999:
    print(6)
elif x>=1000 and x<=1199:
    print(5)
elif x>=1200 and x<=1399:
    print(4)
elif x>=1400 and x<=1599:
    print(3)
elif x>=1600 and x<=1799:
    print(2)
else:
    print(1)

Buggy submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
k=int(input())
count=0
while(b<=a):
    b*=2
    count+=1
while(c<=b):
    c*=2
    count+=1
if count<=k:
    print("Yes")
else:
    print("No")
Problem p02621 (python)

Fixed submission:
n=int(input())
print(int(n+n**2+n**3))

Buggy submission (verdict: Runtime Error):
n=int(inpput())
print(int((n+n**2+n**3)))
Problem p02639 (python)

Fixed submission:
a=list(map(int,input().split()))
print(a.index(0)+1)

Buggy submission (verdict: Runtime Error):
x, n = map(int, input().split())
P = list(map(int, input().split()))
diff, ans = 1000, -1
for i in range(0, 102):
    if (P.count(i)):
        continue
    if (abs(i - x) < diff):
        diff = abs(i - x)
        ans = i
print(ans)
Problem p02675 (python)

Fixed submission:
s=input()
if int(s[-1]) == 2 or int(s[-1]) == 4 or int(s[-1]) == 5 or int(s[-1]) == 7 or int(s[-1]) ==9:
    print("hon")
elif int(s[-1]) == 0 or int(s[-1]) == 1 or int(s[-1]) == 6 or int(s[-1]) ==8:
    print("pon")
else:
    print("bon")

Buggy submission (verdict: Runtime Error):
import sys
from math import cos, radians, pi, sqrt
 
 
input = input().split()
 
A = int(input[0])
B = int(input[1])
H = int(input[2])
M = int(input[3])
 
rad = 2*pi*(H/12.0+(M/60.0)/12.0-M/60.0)
out = sqrt((pow(A,2)+pow(B,2))-(2*A*B*cos(rad)))
 
print(out)
Problem p02696 (python)

Fixed submission:
A, B, N = map(int, input().split())
from math  import floor

def f(A, B, N):
    return floor(A*N/B)-A*floor(N/B)


print(f(A, B, min(B-1, N)))

Buggy submission (verdict: Runtime Error):
n,m,q=map(int,input().split())
import math
a=[]
for i in range(1,min(m-1,q+1)):
    a.append(math.floor(n*i/m)-n*math.floor(i/m))
print(max(a))
Problem p02898 (python)

Fixed submission:
n,m=map(int,input().split())
a=list(map(int,input().split()))
ans=0
for i in range(0,len(a)):
  if a[i]>=m:
    ans+=1
print(ans)

Buggy submission (verdict: Runtime Error):
n,m=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(0,len(a)):
  if a[i]>=m:
    ans+=1
print(ans)
Problem p03161 (python)

Fixed submission:
N,K = map(int,input().split())
h = list(map(int,input().split()))
dp = [-1] * N
dp[0] = 0
 
for i in range(1, N):
    l = []
    m = min(K, i)
    for j in range(1, m+1):
        l.append(dp[i-j] + abs(h[i] - h[i-j]))
    dp[i] = min(l)
print(dp[-1])

Buggy submission (verdict: Runtime Error):
K = map(int,input().split())
h = list(map(int,input().split()))
dp = [-1] * N
dp[0] = 0
 
for i in range(1, N):
    l = []
    m = min(K, i)
    for j in range(1, m+1):
        l.append(dp[i-j] + abs(h[i] - h[i-j]))
    dp[i] = min(l)
print(dp[-1])
Problem p04029 (python)

Fixed submission:
import sys
import math

#https://atcoder.jp/contests/agc008/submissions/15248942
sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

N = ini()
print(int((N*(N+1))/2))
'''
sum = 0
for i in range(N):
    sum += (i+1)
print(sum)
'''

Buggy submission (verdict: Runtime Error):
N = ini()
print(int((N*(N+1))/2))
'''
sum = 0
for i in range(N):
    sum += (i+1)
print(sum)
'''
Problem p02536 (python)

Fixed submission:
# -*- coding: utf-8 -*-
import sys 
sys.setrecursionlimit(10**6)
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,M = map(int,readline().split())
road = [[] for _ in range(N+1)]
visit = [0]*(N+1)

for i in range(M):
    x,y = map(int,readline().split())
    road[x].append(y)
    road[y].append(x)
  
def dfs(v,prev):
    for x in road[v]:
        if x == prev:
            continue
        if visit[x] != 0:
            continue
        visit[x] = 1
        dfs(x,v)
    return 

count = 0     
for i in range(1,N+1):
    if visit[i] == 0:
        dfs(i,-1)
        count += 1

print(count-1)

Buggy submission (verdict: Runtime Error):
# -*- coding: Shift-JIS -*-
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**6)

class UnionFind:
    """素集合を木構造として管理する。"""
    def __init__(self, n):
        self.parent = [-1] * n
        self.n = n
        self.cnt = n
 
    def root(self, x):
        """要素xの代表元を求める。O(α(N))"""
        if self.parent[x] < 0:
            return x
        else:
            self.parent[x] = self.root(self.parent[x])
            return self.parent[x]
 
    def merge(self, x, y):
        """要素xを含む集合と要素yを含む集合を併合する。O(α(N))"""
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return False
        if self.parent[x] > self.parent[y]:
            x, y = y, x
        self.parent[x] += self.parent[y]
        self.parent[y] = x
        self.cnt -= 1
        return True
 
    def is_same(self, x, y):
        """要素x, yが同じ集合に属するかどうかを求める。O(α(N))"""
        return self.root(x) == self.root(y)
 
    def size(self, x):
        """要素xを含む集合の要素数を求める。O(α(N))"""
        return -self.parent[self.root(x)]
 
    def count(self):
        """集合の個数を求める。O(1)"""
        return self.cnt
 
    def groups(self):
        """集合を列挙する。list[list[int]]で返す。O(N)"""
        res = [[] for _ in range(self.n)]
        for i in range(self.n):
            res[self.root(i)].append(i)
        return [group for group in res if group]

N,Q = map(int,readline().split())
uf = UnionFind(N)

for _ in range(Q):
    x,y = map(int,readline().split())
    x-=1; y-=1
    uf.merge(x,y)

print(uf.count()-1)
Problem p02603 (python)

Fixed submission:
# -*- coding: utf-8 -*-
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N_all = int(readline())
A_all = list(map(int,readline().split()))
A = [A_all[0]]
for i in range(1,N_all):
    if A[-1] != A_all[i]:
        A.append(A_all[i])
N = len(A) 
if N == 1:
    print(1000)
    sys.exit()
money = 1000
kabu = 0 
for i in range(N):
    if i == 0:
        if A[i] > A[i+1]:
            continue
        else:
        	kabu = money // A[i]
        	money -= kabu * A[i]
    elif i == N-1:
        money += A[i]*kabu
        kabu = 0
    else:
        if A[i-1] < A[i] and A[i] > A[i+1]:
            money += A[i]*kabu
            kabu = 0
        if A[i-1] > A[i] and A[i] < A[i+1]:
            kabu = money // A[i]
            money -= kabu * A[i]
print(money)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N_all = int(readline())
A_all = list(map(int,readline().split()))
A = [A_all[0]]
for i in range(1,N_all):
    if A[-1] != A_all[i]:
        A.append(A_all[i])
N = len(A) 
money = 1000
kabu = 0 
for i in range(N):
    money += A[i]*kabu
    kabu = 0
    if i == 0:
        if A[i] < A[i+1]:
        	kabu = money // A[i]
        	money -= kabu * A[i]
    elif i == N-1:
        continue
    else:
        if A[i-1] > A[i] and A[i] < A[i+1]:
            kabu = money // A[i]
            money -= kabu * A[i]
print(money)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N_all = int(readline())
A_all = list(map(int,readline().split()))
A = [A_all[0]]
for i in range(1,N_all):
    if A[-1] != A_all[i]:
        A.append(A_all[i])
N = len(A) 
money = 1000
kabu = 0 
for i in range(N):
    money += A[i]*kabu
    kabu = 0
    if i == 0:
        if A[i] < A[i+1]:
        	kabu = money // A[i]
        	money -= kabu * A[i]
    elif A[i-1] > A[i] and A[i] < A[i+1] and i < N-1: 
        kabu = money // A[i]
        money -= kabu * A[i]
print(money)
Problem p02609 (python)

Fixed submission:
# -*- coding: utf-8 -*-
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
S = readline().decode().rstrip()
one_cnt = S.count('1')
S_rev = S[::-1]
#one_modは元のビットが立ってるとき zero_modは逆
one_mod = 0
zero_mod = 0
#Nが大きすぎるため下の桁から順に計算
for i in range(N):
    if S_rev[i] == '1' and one_cnt - 1 != 0:
        one_mod += pow(2,i,one_cnt - 1)
        one_mod %= (one_cnt - 1)
        zero_mod += pow(2,i,one_cnt + 1)
        zero_mod %= (one_cnt + 1)

cnt = [0]*(one_cnt+1)
pop_cnt = [0]* (one_cnt+1)
for i in range(1,one_cnt+1):
    pop_cnt[i] = pop_cnt[i//2] + i%2
    j = i % pop_cnt[i]
    cnt[i] = 1 + cnt[j] 

one_pow2 = [1]*(N+1)
zero_pow2 = [1]*(N+1)
for i in range(1,N):
    if one_cnt-1 != 0:
        one_pow2[i+1] = one_pow2[i]*2 % (one_cnt - 1)
    zero_pow2[i+1] = zero_pow2[i]*2 % (one_cnt + 1)

for i in range(N):
    if S[i] == '1':
        if one_cnt-1 == 0:
            print(0)
        else:
            nxt = one_mod
            nxt -= one_pow2[N-i]
            nxt %= (one_cnt - 1)
            print(1+cnt[nxt])
    else:
        nxt = zero_mod
        nxt += zero_pow2[N-i]
        nxt %= (one_cnt + 1)
        print(1+cnt[nxt])

Buggy submission (verdict: Runtime Error):
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def popcnt(n):
    c = (n & 0x5555555555555555) + ((n>>1) & 0x5555555555555555)
    c = (c & 0x3333333333333333) + ((c>>2) & 0x3333333333333333)
    c = (c & 0x0f0f0f0f0f0f0f0f) + ((c>>4) & 0x0f0f0f0f0f0f0f0f)
    c = (c & 0x00ff00ff00ff00ff) + ((c>>8) & 0x00ff00ff00ff00ff)
    c = (c & 0x0000ffff0000ffff) + ((c>>16) & 0x0000ffff0000ffff)
    c = (c & 0x00000000ffffffff) + ((c>>32) & 0x00000000ffffffff)
    return c
N = int(readline())
S = readline().decode().rstrip()
one_cnt = S.count('1')
cnt = [0]*(one_cnt+1)
for i in range(1,one_cnt+1):
    j = i % popcnt(i)
    cnt[i] = 1 + cnt[j] 
    
n = int(S, 2)
for i in range(N):
    if S[i] == '1':
        tmp = n - 2**(N-i-1)
        tmp %= (one_cnt-1)
        print(1+cnt[tmp])
    else:
        tmp = n + 2**(N-i-1) 
        tmp %= (one_cnt+1)
        print(1+cnt[tmp])
Problem p02642 (python)

Fixed submission:
import sys 
import numpy as np
from numba import jit
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


@jit(cache=True)
def solve(A):
  count = np.zeros(10**6+10)
  for x in A:
    if count[x] > 1:
      continue
    count[::x] += 1
  ans = 0
  for x in A:
    ans += count[x] == 1
  return ans

N = int(readline())
A = list(map(int,readline().split()))
A = np.array(A)
print(solve(A))

Buggy submission (verdict: Runtime Error):
import sys 
from collections import deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
A = list(map(int,readline().split()))
A = list(sorted(A))
q = deque(A)
ans = 0
while q:
  t = q.popleft()
  cnt = q.count(t)
  if t == 1:
    if cnt == 0:
      print(1)
      sys.exit()
    else:
      print(0)
      sys.exit()
  if cnt == 0:
    ans += 1
  count = 0
  for j in range(len(q)):
    if q[j] % t == 0:
      count +=1
      q.remove(q[j])
      q.appendleft(1)
    for i in range(count):
      q.remove(1)
print(ans)
Problem p02657 (python)

Fixed submission:
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

A, B = map(int, readline().split())
print(A*B)

Buggy submission (verdict: Runtime Error):
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
mod = 998244353
N,S = map(int,readline().split())
A = list(map(int,readline().split()))
dp = [[0 for _ in range(S+1)] for _ in range(N+1)]
dp[0][0] = 1
for i in range(N):
  for j in range(S+1):
    dp[i+1][j] += 2*dp[i][j]
    dp[i+1][j] %= mod
    if j + A[i] <=S:
      dp[i+1][j+A[i]] += dp[i][j]
      dp[i+1][j+A[i]] %= mod
print(dp[N][S]%mod)
Problem p02715 (python)

Fixed submission:
import sys 
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
MOD = 10 ** 9 + 7    
N, K = map(int, readline().split())
d = [0] * (K+1)
for i in range(K,0,-1):
    t = K // i
    cnt = pow(t,N,MOD)
    for j in range(2,t+1):
        cnt -= d[i*j]
        cnt %= MOD
    d[i] = cnt
ans = 0
for num,cnt in enumerate(d):
    ans += num * cnt
    ans %= MOD
print(ans)

Buggy submission (verdict: Runtime Error):
import sys 
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
MOD = 10 ** 9 + 7    
N, K = map(int, readline().split())
d = [0] * (K+1)
for i in range(K,0,-1):
    t = K // i
    cnt = pow(t,N,MOD)
    for j in range(2,t+1):
        cnt -= d[i*j]
        cnt %= mod
    d[i] = cnt
ans = 0
for num,cnt in enumerate(d):
    ans += num * cnt
    ans %= MOD
print(ans)
Problem p02727 (python)

Fixed submission:
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
X,Y,A,B,C = map(int,readline().split())
P = list(map(int,readline().split()))
Q = list(map(int,readline().split()))
R = list(map(int,readline().split()))
P = sorted(P,reverse=True)
Q = sorted(Q,reverse=True)
R = sorted(R,reverse=True)
P = P[:X]
Q = Q[:Y]
PQR = sorted(P+Q+R,reverse = True)
ans = sum(PQR[:X+Y])
print(ans)

Buggy submission (verdict: Runtime Error):
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
X,Y,A,B,C = map(int,readline().split())
P = list(map(int,readline().split()))
Q = list(map(int,readline().split()))
R = list(map(int,readline().split()))
P = sorted(P,reverse=True)
Q = sorted(Q,reverse=True)
R = sorted(R,reverse=True)
P = P[:X]
Q = Q[:Y]
PQ = sorted(P+Q,reverse = True)
XY = X+Y
total = sum(PQ)
for i in range(C):
    if R[i] < PQ[-(i+1)]:
      if i == 0:
        ans = total
      else:
        ans = total + sum(R[:i]) - sum(PQ[-i:])
      break
    if i == C-1:
      ans = total + sum(R[:i+1]) - sum(PQ[-(i+1):])
print(ans)

Buggy submission (verdict: Runtime Error):
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
X,Y,A,B,C = map(int,readline().split())
P = list(map(int,readline().split()))
Q = list(map(int,readline().split()))
R = list(map(int,readline().split()))
P = sorted(P,reverse=True)
Q = sorted(Q,reverse=True)
R = sorted(R,reverse=True)
P = P[:X]
Q = Q[:Y]
PQ = sorted(P+Q,reverse = True)
XY = X+Y
total = sum(PQ)
for i in range(C):
    if R[i] < PQ[-(i+1)]:
      if i ==0:
        ans = total
      else:
        ans = total + sum(R[:i]) - sum(PQ[-i:])
      break
    if i == max(C-1,XY-1):
      ans = total + sum(R[:i+1]) - sum(PQ[-(i+1):])
print(ans)

Buggy submission (verdict: Runtime Error):
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
X,Y,A,B,C = map(int,readline().split())
P = list(map(int,readline().split()))
Q = list(map(int,readline().split()))
R = list(map(int,readline().split()))
P = sorted(P,reverse=True)
Q = sorted(Q,reverse=True)
R = sorted(R,reverse=True)
P = P[:X]
Q = Q[:Y]
PQ = sorted(P+Q,reverse = True)
total = sum(PQ)
for i in range(C):
    if R[i] < PQ[-(i+1)]:
      if i ==0:
        ans = total
      else:
        ans = total + sum(R[:i]) - sum(PQ[-i:])
      break
    if i == C-1:
      ans = total + sum(R[:i+1]) - sum(PQ[-(i+1):])
print(ans)