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

Fixed submission:
P=998244353
N,K=map(int, input().split())
LR=[list(map(int, input().split())) for _ in range(K)]

s=[0 for _ in range(N+1)]
s[1]=1
for i in range(1,N):
  s[i+1] = s[i]
  for l,r in LR:
    s[i+1]+=(s[max(0,i-l+1)]-s[max(0,i-r)])%P
    s[i+1]%=P
print((s[N]-s[N-1])%P)

Buggy submission (verdict: Runtime Error):
import numpy as np
P=998244353
N,K=map(int,input().split())
LR=[]
for _ in range(K):
  l,r=map(int,input().split())
  LR+=range(l,r+1)
LR=list(set(LR))
LR=np.array(LR)
c=[0]*N
c[0]=1
for k in range(N):
  S=list(LR[LR<=k])
  while len(S):
    c[k]+=c[k-S[-1]]%P
    S.pop()
print(c[-1]%P)
Problem p02891 (python)

Fixed submission:
s=list(input())
k=int(input())

if len(set(s))==1:
  print((len(s)*k)//2)
  exit()

t=[1]
for i in range(1,len(s)):
  if s[i-1]==s[i]:
    t[-1]+=1
  else:
    t.append(1)
    
ans=0
for i in t:
  ans+=(i//2)*k

if s[0]==s[-1]:
  ans+= ((t[0]+t[-1])//2 - (t[0]//2+t[-1]//2))*(k-1)

print(ans)

Buggy submission (verdict: Runtime Error):
SR=S+[S[0]]
cnt=0
for i in range(len(S)-1):
  if SR[i]==SR[i+1]==SR[i+2]:
    SR[i+1]=0
    cnt+=1

for i in range(len(S)):
  if SR[i]==SR[i+1]:
    SR[i]=0
    cnt+=1
    
if SR[-2]==0 and S[-1]!=S[-2]:
  ans = cnt*K-1
else:
  ans = cnt*K
print(ans)
Problem p02935 (python)

Fixed submission:
N = int(input())
v = list(map(int,input().split()))
v.sort(reverse = True)

while len(v) > 1:
  x = v.pop()
  v[-1] = (x + v[-1]) /2
      
print(v[0])

Buggy submission (verdict: Runtime Error):
N = int(input())
v = list(map(int,input().split()))
while len(v) > 2:
  temp = []
  for i in range(len(v)//2):
    temp.append((v[2*i] + v[2*i + 1])/2)
  if n % 2 == 0:
    v = temp
  else:
    temp.append(v[-1])
    v = temp
      
print(v[0])

Buggy submission (verdict: Runtime Error):
N = int(input())
v = list(map(int,input().split()))
while len(v) > 1:
  x = v.pop()
  v[-1] = (v[-1] + x)/2

print(v[0])
Problem p02948 (python)

Fixed submission:
import heapq
n,m=map(int,input().split())
ab=[[] for _ in range(m+1)]
for i in range(n):
  a,b=map(int,input().split())
  if a<=m:
    ab[a].append(-b)

cand=[]
heapq.heapify(cand)
ans=0
for i in range(1,m+1):
  for j in range(len(ab[i])):
    heapq.heappush(cand,ab[i][j])
  if len(cand)>0:
    ans-=heapq.heappop(cand)

print(ans)

Buggy submission (verdict: Runtime Error):
import heapq
n,m=map(int,input().split())
ab=[[] for _ in range(m+1)]
for i in range(n):
  a,b=map(int,input().split())
  if a<=m:
    a[i].append(-b)

cand=[]
heapq.heapify(cand)
ans=0
for i in range(1,m+1):
  for j in range(len(ab[i])):
    heapq.heappush(cand,ab[i][j])
  if len(cand)>0:
    ans-=heapq.heappop(cand)

print(ans)
Problem p02984 (python)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
b=[sum(a)-2*sum(a[1:n-1:2])]
for i in range(1,n):
  b.append(2*a[i-1]-b[-1])
print(*b)

Buggy submission (verdict: Runtime Error):
import numpy as np
n=int(input())
y=list(map(int,input().split()))
y=list(map(lambda x: x*2,y))
A=np.zeros((n,n),dtype='int')
for i in range(n-1):
  for j in range(i,i+2):
    A[i][j]=1
A[n-1][0],A[n-1][n-1]=1,1
b=np.linalg.solve(A,y)
print(*b)

Buggy submission (verdict: Runtime Error):
import numpy as np
n=int(input())
y=list(map(int,input().split()))
y=list(map(lambda x: x*2,y))
A=np.zeros((n,n),dtype='int')
for i in range(n-1):
  for j in range(i,i+2):
    A[i][j]=1
A[n-1][0],A[n-1][n-1]=1,1
b=list(map(int,np.linalg.solve(A,y)))
print(*b)
Problem p02987 (python)

Fixed submission:
s = list(input())
t = list(set(s))
if len(t) == 2 and s.count(t[0]) == s.count(t[1]):
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
s = list(input())
t = list(set(s))
if s.count(t[0]) == s.count(t[1]):
  print("Yes")
else:
  print("No")
Problem p03013 (python)

Fixed submission:
N,M = map(int,input().split())
a = [int(input()) for _ in range(M)]
a.sort(reverse=True)

if 1 in a:
  a.pop()
  fibs = [1,0]
else:
  fibs = [1,1]

for i in range(2,N+1):
  if len(a) > 0 and i == a[-1]:
    a.pop()
    fibs[0] = fibs[1]
    fibs[1] = 0
  else:
    next = fibs[1] + fibs[0]
    if next > 1000000007:
      next -= 1000000007
    fibs[0] = fibs[1]
    fibs[1] = next

print(fibs[-1])

Buggy submission (verdict: Runtime Error):
from functools import lru_cache
MOD=10**9+7
n,m=map(int,input().split())
a=[int(input()) for _ in range(m)]
if n==1:
  print(1)
  exit()
if 1 in a and 2 in a:
  print(0)
  exit()
elif 1 in a:
  ans=[0,0,1]
elif 2 in a:
  ans=[0,1,0]
else:
  ans=[0,1,2]

@lru_cache(maxsize=None)
def cnt(x):
  if x<3:
    return ans[x]
  if x in a:
    return 0
  else:
    return (cnt(x-1)+cnt(x-2))%MOD

print(cnt(n))

Buggy submission (verdict: Runtime Error):
MOD=10**9+7
n,m=map(int,input().split())
a=[int(input()) for _ in range(m)]
if 1 in a and 2 in a:
  print(0)
  exit()
elif 1 in a:
  ans=[0,1]
elif 2 in a:
  ans=[1,0]

for i in range(2,n):
  if i+1 in a:
    ans.append(0)
  else:
    s=(ans[-1]+ans[-2])%MOD
    ans.append(s)
print(ans[-1]%MOD)

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
a = [int(input()) for _ in range(M)]

def fib(n):  
    if (n==0 or n==1):return 1
    if n in a:
      return 0
    elif fib(n-1) + fib(n-2) < 1000000007:
      return (fib(n-1) + fib(n-2))
    else:
      return (fib(n-1) + fib(n-2)) % 1000000007

print(fib(N))
Problem p03108 (python)

Fixed submission:
from sys import setrecursionlimit

def find(parent, i):
  t = parent[i]
  if t < 0:
    return i
  t = find(parent, t)
  parent[i] = t
  return t

def unite(parent, i, j):
  i = find(parent, i)
  j = find(parent, j)
  if i == j:
    return
  parent[j] += parent[i]
  parent[i] = j

setrecursionlimit(10**6)

N, M = map(int, input().split())
AB = [[int(c) - 1 for c in input().split()] for _ in range(M)]

parent = [-1]*N
inconvenience = N*(N-1) // 2
result = []
for a, b in AB[::-1]:
  result.append(inconvenience)
  pa, pb = find(parent, a), find(parent, b)
  if pa != pb:
    inconvenience -= parent[pa] * parent[pb]
  unite(parent, a, b)

for i in range(len(result)-1,-1,-1):
  print(result[i])

Buggy submission (verdict: Runtime Error):
from sys import setrecursionlimit

def find(parent, i):
  t = parent[i]
  if t < 0:
    return i
  t = find(parent, t)
  parent[i] = t
  return t

def unite(parent, i, j):
  i = find(parent, i)
  j = find(parent, j)
  if i == j:
    return
  parent[j] += parent[i]
  parent[i] = j

setrecursionlimit(10**6)

N, M = map(int, input().split())
AB = [[int(c) - 1 for c in input().split()] for _ in range(M)]

parent = [-1]*N
inconvenience = N*(N-1) // 2
result = []
for a, b in AB[::-1]:
  result.append(inconvenience)
  pa, pb = find(parent, a), find(parent, b)
  if pa != pb:
    inconvenience -= parent[pa] * parent[pb]
  unite(parent, a, b)

for i in range(N,-1,-1):
  print(result[i])
Problem p03137 (python)

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

if N >= M:
  print(0)
  exit()
  
X = list(map(int,input().split()))
X.sort()

dif = {}
for i in range(M-1):
  dif[i] = X[i+1]-X[i]
  
sorted_dif = sorted(dif.items(), key=lambda x:x[1], reverse=True)
difs = 0
for i in range(N-1):
  difs += sorted_dif[i][1]

print(X[-1]-X[0]-difs)

Buggy submission (verdict: Runtime Error):
N, M = map(int,input().split())
if M == 1:
  print(0)
  exit()
X = list(map(int,input().split()))
X.sort()
dif = {}
for i in range(M-1):
  dif[i] = X[i+1]-X[i]
  
sorted_dif = sorted(dif.items(), key=lambda x:x[1], reverse=True)
difs = 0
for i in range(N-1):
  difs += sorted_dif[i][1]

print(X[-1]-X[0]-difs)
Problem p03209 (python)

Fixed submission:
N, X = map(int, input().split())
a,p=[1],[1]
for i in range(N):
  a.append(a[i] * 2 + 3) 
  p.append(p[i] * 2 + 1)

def f(N,X):
  if N == 0:
    return 0 if X <= 0 else 1 
  elif X <= 1 + a[N-1]:
    return f(N-1, X-1) 
  else:
    return p[N-1] + 1 + f(N-1, X-2-a[N-1])

print(f(N, X))

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
S = [tuple(map(int, input().split())) for _ in range(N)]

S.sort(key=lambda x: -x[1])
st = set()
first_acc, other_acc = [0], [0]
for t, d in S:
  if t in st:
    other_acc.append(other_acc[-1] + d)
  else:
    st.add(t)
    first_acc.append(first_acc[-1] + d)

ans = 0
for i in range(K + 1):
  if len(first_acc) <= i or len(other_acc) <= K - i:
    continue
  ans = max(ans, first_acc[i] + other_acc[K - i] + i * i)

print(ans)
Problem p03252 (python)

Fixed submission:
S = input()
T = input()
al = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

setS = []
cnt = 0
for i in range(len(S)):
  if S[i] not in setS:
    S = S.replace(S[i],al[cnt])
    cnt += 1
    setS.append(S[i])

setT = []
cnt = 0
for i in range(len(T)):
  if T[i] not in setT:
    T = T.replace(T[i],al[cnt])
    cnt += 1
    setT.append(T[i])

if S == T:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
S = input()
T = input()
al = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

setS = []
for i in range(len(S)):
  if S[i] not in setS:
    S = S.replace(S[i],al[i])
    setS.append(S[i])

setT = []
for i in range(len(T)):
  if T[i] not in setT:
    T = T.replace(T[i],al[i])
    setT.append(T[i])

if S == T:
  print('Yes')
else:
  print('No')
Problem p03253 (python)

Fixed submission:
N,M=map(int,input().split())
MOD=10**9+7
 
def cmb(n, r, p):
  numerator = 1
  for i in range(n-r+1, n+1):
    numerator = numerator * i % p
  denominator = 1
  for j in range(1, r+1):
    denominator = denominator * j % p
  denominator = pow(denominator, p-2, p)
  return (numerator * denominator)%p
 
def factorization(n):
  l = []
  t = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if t%i==0:
      cnt=0
      while t%i==0:
        cnt+=1
        t //= i
      l.append([i, cnt])
  if t!=1:
    l.append([t, 1])
  if l==[]:
    l.append([n, 1])
  return l
 
ans=1
F=factorization(M)
for i in range(len(F)):
  f=F[i][1]
  ans*=cmb(f+N-1,f,MOD)
  ans%=MOD

if M==1:
  print(1)
else:
  print(ans)

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
MOD=10**9+7
 
def cmb(n, r, p):
  numerator = 1
  for i in range(n-r+1, n+1):
    numerator = numerator * i % p
  denominator = 1
  for j in range(1, r+1):
    denominator = denominator * j % p
  denominator = pow(denominator, p-2, p)
  return (numerator * denominator)%p
 
def factorization(n):
  l = []
  t = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if t%i==0:
      cnt=0
      while t%i==0:
        cnt+=1
        t //= i
      l.append([i, cnt])
  if t!=1:
    l.append([temp, 1])
  if l==[]:
    l.append([n, 1])
  return l
 
ans=1
F=factorization(M)
for i in range(len(F)):
  f=F[i][1]
  ans*=cmb(f+N-1,f,MOD)
  ans%=MOD

if M==1:
  print(1)
else:
  print(ans)
Problem p03426 (python)

Fixed submission:
H,W,D=map(int,input().split())
A=[list(map(int,input().split())) for _ in range(H)]
Q=int(input())
LR=[tuple(map(int,input().split())) for _ in range(Q)]

pos=[None]*(H*W)
for i in range(H):
  for j in range(W):
    pos[A[i][j]-1] = (i, j)

d=[0]*(H*W)
for i in range(D, H*W):
  px,py = pos[i-D]
  x, y = pos[i]
  d[i]=d[i-D] + abs(x-px) + abs(y-py)

for l, r in LR:
  print(d[r-1]-d[l-1])

Buggy submission (verdict: Runtime Error):
H,W,D=map(int,input().split())
A=[list(map(int,input().split())) for _ in range(H)]
Q=int(input())
LR=[list(map(int,input().split())) for _ in range(Q)]

c=[None]*(H*W)
for i in range(H):
  for j in range(W):
    c[A[i][j]-1] = (i, j)

d=[0]*(H*W)
for i in range(D, H*W):
  px,py = c[i-D]
  x, y = c[i]
  d[i]=d[i-D] + abs(x-px) + abs(y-py)
for l, r in LR:
  print(d[r]-d[l])
Problem p03776 (python)

Fixed submission:
N,A,B=map(int,input().split())
v=list(map(int,input().split()))
v.sort(reverse=True)
a=v[:A]
b=v[:B]
avg=sum(a)/A
print(avg)
c=[[0]*51 for _ in range(51)]
c[0][0]=1
for i in range(50):
  c[i+1][0]=1
  c[i+1][i+1]=1
  for j in range(i):
    c[i+1][j+1]=c[i][j]+c[i][j+1]
if a[0]==a[-1]:
  ans=0
  x=v.count(a[0])
  for i in range(A,B+1):
    if i<=x:
      ans+=c[x][i]
else:
  x=v.count(a[-1])
  y=a.count(a[-1])
  ans=c[x][y]
print(ans)

Buggy submission (verdict: Runtime Error):
N,A,B=map(int,input().split())
v=list(map(int,input().split()))
v.sort(reverse=True)
a=v[:A]
b=v[:B]
avg=sum(a)/A
print(avg)
c=[[0]*51 for _ in range(51)]
c[0][0]=1
for i in range(50):
  c[i+1][0]=1
  c[i+1][i+1]=1
  for j in range(i):
    c[i+1][j+1]=c[i][j]+c[i][j+1]
if a[0]==a[-1]:
  ans=0
  x=v.count(a[0])
  for i in range(A,B+1):
    if i<=x:
      ans+=C[x][i]
else:
  x=v.count(a[-1])
  y=a.count(a[-1])
  ans=c[x][y]
print(ans)
Problem p03208 (python)

Fixed submission:
N, K = map(int,input().split())
H = []
for i in range(N):
    h = int(input())
    H.append(h)

H.sort()
l = 0
r = K-1
ans = 10**10
while r <= N-1:
    sub = H[r] - H[l]
    ans = min(ans, sub)
    r += 1
    l += 1

print(ans)

Buggy submission (verdict: Runtime Error):
    N, K = map(int,input().split())
    H = []
    for i in range(N):
        h = int(input())
        H.append(h)
     
    H.sort()
    l = 0
    r = K-1
    from math import inf
    ans = inf
    while r <= N-1:
        sub = H[r] - H[l]
        ans = min(ans, sub)
        r += 1
        l += 1
     
    print(ans)

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

H.sort()
l = 0
r = K-1
from math import inf
ans = inf
while r <= N-1:
    sub = H[r] - H[l]
    ans = min(ans, sub)
    r += 1
    l += 1

print(ans)
Problem p03242 (python)

Fixed submission:
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**7) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())



a = str(input())
ans=''
for c in a:
    if c=='1':
        ans = ans + '9'
    elif c=='9':
        ans = ans + '1'
    else:
        ans = ans + c

print(ans)

Buggy submission (verdict: Runtime Error):
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**7) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())
 
# h,w = li()
# ss = [ns() for _ in range(h)]

n = int(input())

vs = li()
v_odd = []
v_even = []

i=0
for v in vs:
    if i % 2 == 0:
        v_even.append(v)
    else:
        v_odd.append(v)
    i = i + 1

max_count_odd = 0

m_odd = 0
m_even = 0
for ss in set(v_odd):
    count = v_odd.count(ss)
    if count > max_count_odd:
        max_count_odd = count
        m_odd = ss
# import pdb;pdb.set_trace() 
max_count_even = 0
for ss in set(v_even):
    count = v_even.count(ss)
    if count > max_count_even:
        max_count_even = count
        m_even = ss
# import pdb;pdb.set_trace() 
ans = len(v_even)-max_count_even  +  len(v_odd)-max_count_odd

m2_oddmax = 0
m2_evenmax = 0
import copy
# import pdb;pdb.set_trace()
if(m_even==m_odd):
    temp = set(v_odd)
    temp.remove(m_odd)
    m2_odd = 0
    # import pdb;pdb.set_trace()
    for ss in temp:
        count = v_odd.count(ss)
        if count > m2_oddmax:
            m2_oddmax = count
            m2_odd = ss
    temp = set(v_even)
    temp.remove(m_even)
    m2_even = 0
    for ss in temp:
        count = v_even.count(ss)
        if count > m2_evenmax:
            m2_evenmax = count
            m2_even = ss
    if m2_evenmax > m2_oddmax:
        # import pdb;pdb.set_trace()
        ans = len(v_even)-m2_evenmax + len(v_odd)-max_count_odd
    elif m2_evenmax <= m2_oddmax:
        # import pdb;pdb.set_trace()
        ans = len(v_even)-max_count_even + len(v_odd)-m2_oddmax
    if m2_even == 0 and m2_odd == 0:
        ans = int(n/2)
    # import pdb;pdb.set_trace()


print(ans)
Problem p02699 (python)

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

if W >= S:
  print("unsafe")
else:
  print("safe")

Buggy submission (verdict: Runtime Error):
W, S = input()

if W >= S:
  print("unsafe")
else:
  print("safe")
Problem p02701 (python)

Fixed submission:
N = int(input())
A = [input() for _ in range(N)]
print(len(list(set(A))))

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [int(input()) for _ in range(N)]
already = []
for a in A:
  if a not in already:
    already.append(a)
print(len(already))
Problem p02598 (python)

Fixed submission:
import math

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

A=list(map(int,input().split()))

low=1
high=max(A)

while low!=high:
    mid=(low+high)//2
    s=0
    for i in range(n):
        s+=math.ceil(A[i]/mid)-1
    if s>k:
        low=mid+1
    else:
        high=mid


print(low)

Buggy submission (verdict: Runtime Error):
import math

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

A=list(map(int,input().split()))

low=0
high=max(A)

while low!=high:
    mid=(low+high)//2
    s=0
    for i in range(n):
        s+=math.ceil(A[i]/mid)-1
    if s>k:
        low=mid+1
    else:
        high=mid


print(low)
Problem p02693 (python)

Fixed submission:
k=int(input())
a,b=map(int,input().split())

c=0
for i in range(a,b+1):
    if i%k==0:
        c+=1

if c==0:
    print("NG")
else:print("OK")

Buggy submission (verdict: Runtime Error):
import itertools

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

lis=[]
for i in range(q):
    lis.append(list(map(int,input().split())))

Alist=[]

for l in itertools.combinations(range(1,n+m),n):
    ll=list(l)
    a=[]
    for i in range(n):
        a.append(ll[i]-i)
    Alist.append(a)

slist=[]
for i in range(len(Alist)):
    s=0
    for j in range(q):
        aj=lis[j][0]
        bj=lis[j][1]
        cj=lis[j][2]
        dj=lis[j][3]
        if Alist[i][bj-1]-Alist[i][aj-1]==cj:
            s+=dj
    slist.append(s)

print(max(slist))
Problem p02695 (python)

Fixed submission:
import itertools

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

lis=[]
for i in range(q):
    lis.append(list(map(int,input().split())))

M=0
for l in map(list,itertools.combinations(range(1,n+m),n)):
    s=0
    for j in range(q):
        aj=lis[j][0]
        bj=lis[j][1]
        cj=lis[j][2]
        dj=lis[j][3]
        if l[bj-1]-bj-l[aj-1]+aj==cj:
            s+=dj
    M=max(M,s)
print(M)

Buggy submission (verdict: Runtime Error):
import itertools

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

lis=[]
for i in range(q):
    lis.append(list(map(int,input().split())))

Alist=[]

for l in itertools.combinations(range(1,n+m-1),n):
    ll=list(l)
    a=[]
    for i in range(n):
        a.append(ll[i]-i)
    Alist.append(a)
slist=[]
for i in range(len(Alist)):
    s=0
    for j in range(q):
        aj=lis[j][0]
        bj=lis[j][1]
        cj=lis[j][2]
        dj=lis[j][3]
        if Alist[i][bj-1]-Alist[i][aj-1]==cj:
            s+=dj
    slist.append(s)

print(max(slist))
Problem p02753 (python)

Fixed submission:
seq=input()
a=0
b=0
for i in range(3):
    if seq[i]=="A":
        a+=1
    else:
        b+=1
if a>=1 and b>=1:
    print("Yes")
else:
    print("No")

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

count=0
if p==2:
    for i in range(n):
        if int(s[i])%2==0:
            count+=i+1
elif p==5:
    for i in range(n):
        if int(s[i])%5==0:
            count+=i+1
else:
    u=[]
    num=0
    for i in range(n):
        u.append(int(s[i:n]%p))
    u.append(0)
    for i in range(n):
        for j in range(i,n):
            if (u[i]-u[j+1])%p==0:
                count+=1
print(count)
Problem p02757 (python)

Fixed submission:
n,p=map(int,input().split())
s=input()

count=0
if p==2:
    for i in range(n):
        if int(s[i])%2==0:
            count+=i+1
elif p==5:
    for i in range(n):
        if int(s[i])%5==0:
            count+=i+1
else:
    lis=[1]
    for i in range(n-1):
        lis.append((lis[i]*10)%p)
    lis.reverse()
    for i in range(n):
        lis[i]=(int(s[i])*lis[i])%p
    unum=[1]
    for i in range(p-1):
        unum.append(0)
    num=0
    for i in range(n):
        num=(num+lis[n-i-1])%p
        unum[num]+=1
    for i in range(p):
        unumi=unum[i]
        count+=(unumi*(unumi-1))*0.5
print(round(count))

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

count=0
if p==2:
    for i in range(n):
        if int(s[i])%2==0:
            count+=i+1
elif p==5:
    for i in range(n):
        if int(s[i])%5==0:
            count+=i+1
else:
    u=[]
    num=0
    for i in range(n):
        u.append(int(s[i:n]%p))
    u.append(0)
    for i in range(n):
        for j in range(i,n):
            if (u[i]-u[j+1])%p==0:
                count+=1
print(count)
Problem p02762 (python)

Fixed submission:
import sys

sys.setrecursionlimit(10**7)

def dfs(x):
    if seen[x-1]==0:
        uni[cnt].add(x)
        seen[x-1]=1
        for i in fri[x-1]:
            dfs(i)
    

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

fri=[[] for i in range(n)]
blk=[[] for i in range(n)]

for i in range(m):
    a,b=map(int,input().split())
    fri[a-1].append(b)
    fri[b-1].append(a)

for i in range(k):
    c,d=map(int,input().split())
    blk[c-1].append(d)
    blk[d-1].append(c)


seen=[0 for i in range(n)]

uni=[]
cnt=0
for i in range(1,n+1):
    if seen[i-1]==0:
        uni.append(set())
        dfs(i)
        cnt+=1

seq=[0 for i in range(n)]

for unii in uni:
    for j in unii:
        cj=len(unii)-len(fri[j-1])-len(unii&set(blk[j-1]))-1
        seq[j-1]=cj

print(*seq)

Buggy submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(10**7)

def dfs(x):
    if seen[x-1]==0:
        uni[cnt].append(x)
        seen[x-1]=1
        for i in fri[x-1]:
            dfs(i)
    

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

fri=[[] for i in range(n)]
blk=[[] for i in range(n)]

for i in range(m):
    a,b=map(int,input().split())
    fri[a-1].append(b)
    fri[b-1].append(a)

for i in range(k):
    c,d=map(int,input().split())
    blk[c-1].append(d)
    blk[d-1].append(c)


seen=[0 for i in range(n)]

uni=[]
cnt=0
for i in range(1,n+1):
    if seen[i-1]==0:
        uni.append([])
        dfs(i)
        cnt+=1

seq=[0 for i in range(n)]

for unii in uni:
    for j in unii:
        cj=len(unii)-len(fri[j-1])-len(set(unii)&set(blk[j-1])-1
        seq[j-1]=cj

print(*seq)
Problem p02572 (python)

Fixed submission:
def resolve():
    n = int(input())
    A = list(map(int, input().split()))
    sm = sum(A) % (10**9 + 7)

    ans = 0
    for a in A:
        sm -= a
        ans += sm * a
        ans %= (10**9 + 7)
    print(ans)

resolve()

Buggy submission (verdict: Runtime Error):
import decimal


def resolve():
    n = int(input())
    A = list(map(decimal.Decimal, input().split()))
    A_sum = sum(A)
    ind_sum = 0
    for a in A:
        ind_sum += a**2

    print((A_sum**2 - ind_sum)//2 % (10**9 + 7))

resolve()

Buggy submission (verdict: Runtime Error):
def resolve():
    import itertools
    import numpy as np

    n = int(input())
    A = np.asarray(list(map(int, input().split())))
    s = sum(A)
    print((s**2 - sum(A**2))//2 % (10**9 + 7))

resolve()
Problem p02624 (python)

Fixed submission:
N = int(input())
ans = 0
l = [0] * (10 ** 7 + 1)
for i in range(1, N + 1):
    for j in range(i, N + 1, i):
        l[j] += 1

for i in range(1, N + 1):
    ans += i * l[i]
print(ans)

Buggy submission (verdict: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
	int k;
	cin >> k;
    int ans = 0;
	
	for (int i = 1; i <= k; ++i) {
		for (int j = i; j <= k; j += i) {
			ans += i;
		}
	}
	cout << ans << '\n';
	
	return 0;
}

Buggy submission (verdict: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
	int k;
	cin >> k;
    ans = 0
	
	for (int i = 1; i <= k; ++i) {
		for (int j = i; j <= k; j += i) {
			ans += i;
		}
	}
	cout << ans << '\n';
	
	return 0;
}