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

Fixed submission:
A, B, C = map(int,input().split())
if A ==B and B == C:
    print('No')
elif B == C:
    print('Yes')
elif A == C:
    print('Yes')
elif A == B:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):

A, B, C = map(int,input().split())
if A == B == C:
    print('No')
elif B == C:
    print('Yes')
elif A == C:
    print('Yes')
elif A == B:
    print('Yes')
else:
    print('No'
Problem p02834 (python)

Fixed submission:
import copy
import sys
sys.setrecursionlimit(10**9)

def dfs(G, v, p, d, depth):
    depth[v] = d
    for nv in G[v]:
        if nv == p:
            continue
        dfs(G, nv, v, d+1, depth)
    return G, depth


n, T, A = map(int,input().split())
T, A = T-1, A-1
g = [[] for _ in range(n)]
for i in range(n-1):
    x, y = map(int,input().split())
    x, y = x-1, y-1
    g[x].append(y)
    g[y].append(x)

depth = [0]*n
GT = copy.deepcopy(g)
GT[T].append(-1)
GT, dt = dfs(GT, T, -1, 0, depth)

depth = [0]*n
GA = copy.deepcopy(g)
GA[A].append(-1)
GA, da = dfs(GA, A, -1, 0, depth)

ans = 0
for t, a in zip(dt, da):
    if t <= a:
        ans = max(ans, a)
print(ans-1)

Buggy submission (verdict: Runtime Error):
import copy
import sys
sys.setrecursionlimit(10**9)

def dfs(G, v, p, d):
    depth[v] = d
    for nv in G[v]:
        if nv == p:
            continue
        dfs(G, nv, v, d+1)


n, T, A = map(int,input().split())
T -= 1
A -= 1
g = [[] for _ in range(n)]
for i in range(n-1):
    x, y = map(int,input().split())
    x -= 1
    y -= 1
    g[x].append(y)
    g[y].append(x)

depth = [0]*n
GT = copy.deepcopy(g)
GT[T].append(-1)
root = T
dfs(GT, root, -1, 0)
dt = depth.copy()

depth = [0]*n
GA = copy.deepcopy(g)
GA[A].append(-1)
root = A
dfs(GA, root, -1, 0)
da = depth.copy()

def dfs2(G, v, p):
    for nv in G[v]:
        if nv == p:
            continue
        if dt[nv] <= da[nv]:
            maxd[0] = max(maxd[0], da[nv])
        else:
            continue
        dfs2(G, nv, v)


maxd = [-float('inf')]
root = T
dfs2(GT, root, -1)
if maxd[0] == -float('inf'):
    print(0)
else:
    print(maxd[0]-1)
Problem p02862 (python)

Fixed submission:
x, y = map(int, input().split())
if (x+y)%3 != 0:
    print(0)
    exit()

a = 2*x - y
b = -x + 2*y
if a < 0 or b < 0:
    print(0)
    exit()

a //= 3
b //= 3
MOD = 10**9+7
MAX_N = 10**6
fact = [1]
fact_inv = [0]*(MAX_N+4)
for i in range(MAX_N+3):
    fact.append(fact[-1]*(i+1)%MOD)

fact_inv[-1] = pow(fact[-1],MOD-2,MOD)
for i in range(MAX_N+2,-1,-1):
    fact_inv[i] = fact_inv[i+1]*(i+1)%MOD

def mod_comb_k(n,k,MOD):
    return fact[n] * fact_inv[k] % MOD * fact_inv[n-k] %MOD


print(mod_comb_k(a+b, a, MOD))

Buggy submission (verdict: Runtime Error):
x, y = map(int, input().split())
if (x+y)%3 != 0:
    print(0)
    exit()

a = 2*x - y
b = -x + 2*y
if a < 0 or b < 0:
    print(0)
    eixt()

a //= 3
b //= 3
MOD = 10**9+7
MAX_N = 10**6
fact = [1]
fact_inv = [0]*(MAX_N+4)
for i in range(MAX_N+3):
    fact.append(fact[-1]*(i+1)%MOD)

fact_inv[-1] = pow(fact[-1],MOD-2,MOD)
for i in range(MAX_N+2,-1,-1):
    fact_inv[i] = fact_inv[i+1]*(i+1)%MOD

def mod_comb_k(n,k,MOD):
    return fact[n] * fact_inv[k] % MOD * fact_inv[n-k] %MOD


print(mod_comb_k(a+b, a, MOD))

Buggy submission (verdict: Runtime Error):
x, y = map(int, input().split())
if (x+y)%3 != 0:
    print(0)
    exit()

a = (2*x - y)//3
b = (-x + 2*y)//3
if a < 0 or b < 0:
    print(0)
    eixt()

MOD = 10**9+7
MAX_N = 10**6
fact = [1]
fact_inv = [0]*(MAX_N+4)
for i in range(MAX_N+3):
    fact.append(fact[-1]*(i+1)%MOD)

fact_inv[-1] = pow(fact[-1],MOD-2,MOD)
for i in range(MAX_N+2,-1,-1):
    fact_inv[i] = fact_inv[i+1]*(i+1)%MOD

def mod_comb_k(n,k,MOD):
    return fact[n] * fact_inv[k] % MOD * fact_inv[n-k] %MOD


print(mod_comb_k(a+b, a, MOD))
Problem p02948 (python)

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

t = []
heapq.heapify(t)
ans = 0
for i in range(m):
    for dd in d[i]:
        heapq.heappush(t, dd)
    if t:
        ans += heapq.heappop(t)*(-1)
print(ans)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
d = []
for _ in range(n):
    a, b = map(int, input().split())
    d.append((b, a))
d.sort(reverse=True)

cnt = m
ans = 0
i = 0
while i < n or cnt > 0:
    if d[i][1] <= cnt:
        ans += d[i][0]
        i += 1
        cnt -= 1
    else:
        i += 1
    if i == n-1 or cnt == 0:
        break        

print(ans)
Problem p03038 (python)

Fixed submission:
n, m = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
bc = [list(map(int,input().split())) for _ in range(m)]
bc.sort(key=lambda x:x[1], reverse=True)

ad = 0
idx = 0
for b, c in bc:
    for i in range(min(b, n-idx)):
        if a[idx+i] < c:
            continue
        else:
            ad += c*i
            idx += i
            print(ad + sum(a[idx:]))
            exit()
    ad += c*min(b, n-idx)
    idx += min(b, n-idx)
print(ad + sum(a[idx:]))

Buggy submission (verdict: Runtime Error):
n, m = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
bc = [list(map(int,input().split())) for _ in range(m)]
bc.sort(key=lambda x:x[1], reverse=True)

ad = 0
idx = 0
for b, c in bc:
    for i in range(b):
        if a[idx+i] < c:
            continue
        else:
            ad += c*i
            idx += i
            print(ad + sum(a[idx:]))
            exit()
    ad += c*b
    idx += b
print(ad + sum(a[idx:]))

Buggy submission (verdict: Runtime Error):
n, m = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
bc = [list(map(int,input().split())) for _ in range(m)]
bc.sort(key=lambda x:x[1], reverse=True)

ad = 0
idx = 0
for b, c in bc:
    for i in range(b):
        if a[idx+i] < c:
            ad += c
        else:
            idx += i
            print(ad + sum(a[idx:]))
            exit()
    else:
        idx += i+1
print(ad + sum(a[idx:]))
Problem p03137 (python)

Fixed submission:
n,m = list(map(int,input().split()))
a = list(map(int,input().split()))
a.sort(reverse=True)

if n >= m:
    print(0)
    exit()

b = []
for i in range(m-1):
    b.append(abs(a[i+1]-a[i]))
b.sort(reverse=True)

for i in range(n-1):
    b.pop(0)

print(sum(b))

Buggy submission (verdict: Runtime Error):
n,m = list(map(int,input().split()))
a = list(map(int,input().split()))
a.sort(reverse=True)

if m == 1:
    print(0)
    exit()

b = []
for i in range(m-1):
    b.append(abs(a[i+1]-a[i]))
b.sort(reverse=True)

for i in range(n-1):
    b.pop(0)

print(sum(b))
Problem p03317 (python)

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

if n == k:
    print(1)
    exit()
    
n -= k
if n % (k-1) == 0:
    n //= k-1
else:
    n //= k-1
    n += 1
print(n+1)

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

if n == k:
    print(1)
    exit()

l = 0
r = 0
one = False
for i in range(n):
    if a[i] == 1:
        one = True
        continue
    if one == False:
        l += 1
    else:
        r += 1

if k >= min(l+1,r+1):
    n -= k
    if n%(k-1) == 0:
        n //= k-1
    else:
        n //= k-1
        n += 1
    pritn(n+1)
else:
    if l % (k-1) == 0:
        l //= k-1
    else:
        l //= k-1
        l += 1
        
    if r % (k-1) == 0:
        r //= k-1
    else:
        r //= k-1
        r += 1
    print(l+r)
Problem p03426 (python)

Fixed submission:
h,w,d = map(int,input().split())
hw = [[] for _ in range(h*w+1)]
for i in range(h):
    row = list(map(int,input().split()))
    for j in range(w):
        hw[row[j]] = [i,j]
 
a = [0 for _ in range(h*w+1)]
for i in range(d+1,h*w+1):
    a[i] = a[i-d] + abs(hw[i][0] - hw[i-d][0]) + abs(hw[i][1] - hw[i-d][1])
 
q = int(input())
for i in range(q):
    L,R = map(int,input().split())
    print(a[R] - a[L])

Buggy submission (verdict: Runtime Error):
h,w,d = map(int,input().split())
hw = [[0,0] for _ in range(h*w+1)]
for i in range(h):
    row = list(map(int,input().split()))
    for j in range(w):
        hw[row[j]] = [i,j]

a = [0]*(h*w)
for i in range(d,h*w):
    a[i] = a[i-d] + abs(hw[i][0] - hw[i-d][0]) + abs(hw[i][1] - hw[i-d][1])

q = int(input())
for i in range(q):
    L,R = map(int,input().split())
    print(a[R] - a[L])
Problem p03705 (python)

Fixed submission:
n,a,b = map(int,input().split())
if a == b:
    print(1)
elif n == 1 or a > b:
    print(0)
else:
    print((a+(n-1)*b) - (a*(n-1)+b) + 1)

Buggy submission (verdict: Runtime Error):
n,a,b = map(int,input().split())
if a == b:
    print(1)
elif n == 1 or a > b:
    print(0)
else:
    print(len(list(range(a*(n-1)+b, a+(n-1)*b+1))))

Buggy submission (verdict: Runtime Error):
n,a,b = map(int,input().split())
if n == 1 and a == b:
    print(1)
elif n == 1 or a > b:
    print(0)
else:
    print(len(list(range(a*(n-1)+b, a+(n-1)*b+1))))

Buggy submission (verdict: Runtime Error):
n,a,b = map(int,input().split())
if a > b or (n == 1 and a != b):
    print(0)
else:
    print(len(list(range(a*(n-1)+b, a+(n-1)*b+1))))
Problem p03986 (python)

Fixed submission:
s = input()
ans = 0
cnt = 0
for a in s:
    if a == 'S':
        cnt += 1
    else:
        if cnt > 0:
            cnt -= 1
        else:
            ans += 1
print(ans+cnt)

Buggy submission (verdict: Runtime Error):
s = list(input())
cnt = 0
while True:
    if s[0] == 'T':
        s.pop(0)
        cnt += 1
    else:
        break
    
while True:
    if s[-1] == 'S':
        s.pop(-1)
        cnt += 1
    else:
        break

cs = 0
ct = 0
for i in range(len(s)):
    if s[i] == 'S':
        cs += 1
    else:
        ct += 1
print(cnt + abs(cs-ct))

Buggy submission (verdict: Runtime Error):
s = list(input())
cnt = 0
while True:
    if s[0] == 'T':
        s.pop(0)
        cnt += 1
    else:
        break
    
while True:
    if s[-1] == 'S':
        s.pop(-1)
        cnt += 1
    else:
        break
        
i = 0
now = 'on'
ans = 0
cs = 0
while i < len(s):
    if s[i] == 'S':
        cs += 1
        now = 'on'
        i += 1
    elif now == 'on' and s[i] == 'T':
        i += cs
        cs = 0
        now = 'off'
    elif now == 'off' and s[i] == 'T':
        cnt += 1
        i += 1
        
    if i >= len(s):
        break
print(cnt)
Problem p02572 (python)

Fixed submission:
import sys
input = sys.stdin.readline
M = 1000000007
n = int(input())
A = list(map(int, input().split()))
ans = 0
s = 0
for i in range(n):
    s += A[i]
    s %= M

for i in range(n):
    s = s - A[i]
    if s < 0:
        s += M
    ans += A[i] * s
    ans %= M
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n = int(input())
tmp = list(map(int, input().split()))
A = [a % M for a in tmp]
M = 1000000007
ans = 0
for i in range(1,n):
    ans += (A[i-1] * ((sum(A[i::])%M)))%M
print(ans%M)
Problem p02597 (python)

Fixed submission:
def alter_altar(s):
    tmp = 'R' * s.count('R') + 'W' * s.count('W')
    ans = 0
    for i in range(len(s)):
        if s[i] == tmp[i]:
            pass
        else:
            ans += 1
    return ans//2
if __name__ == "__main__":
    _ = input()
    s = input()
    print(alter_altar(s))

Buggy submission (verdict: Runtime Error):
_ = input()
s = input()

def rec(s,ans):
    l = s[:len(s)//2]
    r = s[len(s)//2:]
    rw = r.count('W')
    rr = r.count('R')
    lw = l.count('W')
    lr = l.count('R')
    if rr:
        if lw > rr:
            return ans + rr
        else:
            return ans + lw 
    else:
        rec(l)

print(rec(s,0))
Problem p02629 (python)

Fixed submission:
N = int(input())
ans = ''
for i in range(1, 99):
    if N <= 26 ** i:
        N -= 1
        for j in range(i):
            ans += chr(ord('a') + N % 26)
            N //= 26
        break
    else:
        N -= 26 ** i
print(ans[::-1])

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

N = int(input())
ans = ''
for i in range(1, 99):
    if N <= 26 ** i:
        N -= 1
        for j in range(i):
            ans += chr(ord('a') + N % 26)
            N //= 26
        break
    else:
        N -= 26 ** i
print(ans[::-1])
Problem p02577 (python)

Fixed submission:
def main():
    n = int(input())
    

    if n%9==0:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    n = input()
    

    if n%9==0:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()
Problem p02735 (python)

Fixed submission:
import math
from collections import deque
def main():
    h,w = tuple([int(t)for t in input().split()])

    s = [['.']*(w+1)]

    s.extend(([list('.'+input()) for _ in range(h)]))

    dp = [[0]*(w+1) for _ in range(h+1)]

    for i in range(h):
        if s[i+1][1] == '.':
            dp[i+1][1] = dp[i][1]
        else:
            if s[i][1]=='.':
                dp[i+1][1] = dp[i][1]+1
            else:
                dp[i+1][1] = dp[i][1]

    for j in range(w):
        if s[1][j+1] == '.':
            dp[1][j+1] = dp[1][j]
        else:
            if s[1][j]=='.':
                dp[1][j+1] = dp[1][j]+1
            else:
                dp[1][j+1] = dp[1][j]

    for i in range(1,h):
        for j in range(1,w):
            if s[i+1][j+1] == '.':
                dp[i+1][j+1] = min(dp[i][j+1],dp[i+1][j])
            else:
                if s[i][j+1] == '.':
                    if s[i+1][j] == '.':
                        dp[i+1][j+1] = min(dp[i][j+1],dp[i+1][j])+1
                    else:
                        dp[i+1][j+1] = min(dp[i][j+1]+1,dp[i+1][j])
                else:
                    if s[i+1][j] == '.':
                        dp[i+1][j+1] = min(dp[i][j+1],dp[i+1][j]+1)
                    else:
                        dp[i+1][j+1] = min(dp[i][j+1],dp[i+1][j])

    print(dp[-1][-1])
if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import math
from collections import deque
def main():
    h,w = tuple([int(t)for t in input().split()])

    s = [['.']*(w+1)]

    s.extend(([list('.'+input()) for _ in range(h)]))

    dp = [[0]*(h+1) for _ in range(w+1)]

    for i in range(h):
        if s[i+1][1] == '.':
            dp[i+1][1] = dp[i][1]
        else:
            if s[i][1]=='.':
                dp[i+1][1] = dp[i][1]+1
            else:
                dp[i+1][1] = dp[i][1]

    for j in range(w):
        if s[1][j+1] == '.':
            dp[1][j+1] = dp[1][j]
        else:
            if s[1][j]=='.':
                dp[1][j+1] = dp[1][j]+1
            else:
                dp[1][j+1] = dp[1][j]

    for i in range(1,h):
        for j in range(1,w):
            if s[i+1][j+1] == '.':
                dp[i+1][j+1] = min(dp[i][j+1],dp[i+1][j])
            else:
                if s[i][j+1] == '.':
                    if s[i+1][j] == '.':
                        dp[i+1][j+1] = min(dp[i][j+1],dp[i+1][j])+1
                    else:
                        dp[i+1][j+1] = min(dp[i][j+1]+1,dp[i+1][j])
                else:
                    if s[i+1][j] == '.':
                        dp[i+1][j+1] = min(dp[i][j+1],dp[i+1][j]+1)
                    else:
                        dp[i+1][j+1] = min(dp[i][j+1],dp[i+1][j])

    print(dp[-1][-1])
if __name__ == "__main__":
    main()
Problem p02753 (python)

Fixed submission:
import math
from collections import deque
def main():
    s = set(input())

    print("Yes" if len(s) == 2 else "No")



if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import math
from collections import deque
def main():
    n,p = tuple([int(t)for t in input().split()])
 
    s = input()[::-1]
    subs = [0]*p
    counter =0
    for i in range(0,n):
        subs[int(s[0:i+1])%p] +=1
 
    counter+=subs[0]
 
    for i in range(p//2):
        counter+= subs[i]*subs[-i-1]
 
 
    counter+=subs[0]*(subs[0]-1)//2
 
    print(counter)
 
if __name__ == "__main__":
    main()
Problem p02773 (python)

Fixed submission:
from collections import Counter
n = int(input())
s = [input() for _ in range(n)]

c = Counter(s)
ma = max(c.values())
ans = []
for k,v in c.items():
  if ma == v:
    ans.append(k)

ans = sorted(ans)

for a in ans:
  print(a)

Buggy submission (verdict: Runtime Error):
from collections import Counter
n = int(input())
s = [input() for _ in range(n)]

c = Counter(s)
ma = max(c.values())
for k,v in c:
  if ma == v:
    print(k)
Problem p02819 (python)

Fixed submission:
def primelist(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]
  
x = int(input())

list = primelist(x*2)
print(min([i for i in list if i>=x]))

Buggy submission (verdict: Runtime Error):
def primelist(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]
  
x = int(input())

list = primelist(x*10)
print(min([i for i in list if i>x])
Problem p02935 (python)

Fixed submission:
n = int(input())
a = tuple(map(int,input().split()))

a = sorted(a,reverse=True)
while len(a)>1:
  a.append((a.pop()+a.pop())/2)
print(a[0])

Buggy submission (verdict: Runtime Error):
from collections import queue
n = int(input())
a = tuple(map(int,input().split()))

a = sorted(a,reversed=True)
while len(a>1):
  a.append((a.pop()+a.pop())/2)
print(a[0])
Problem p02989 (python)

Fixed submission:
n = int(input())
a = tuple(map(int,input().split()))

a = sorted(a)

print(a[n//2]-a[n//2-1])

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

a = sorted(a)

print(a[n//2+1]-a[n//2])
Problem p02990 (python)

Fixed submission:
M = 10**9+7

def factorial(n):
    f = 1
    for i in range(1,n+1):
        f = f*i%M
    return f

def comb(n,k):
    if n==0 or k == 0:
        return 1
    if n<k:
        return 0

    return perm(n,k)*inverse(factorial(k))%M

def mcomb(n,k):
    return comb(n+k-1,k)

def perm(n,k):
    if n==0 or k == 0:
        return 1
    if n<k:
        return 0

    p = 1
    for i in range(n-k+1,n+1):
        p = p*i%M

    return p

def inverse(a):
    return pow(a,M-2,M)
  
n,k = tuple(map(int,input().split()))

for i in range(k):
  i += 1
  t = comb(k-1,i-1)
  u = comb(n-k+1,i)
  ans = t*u
  ans %= M
  print(ans)

Buggy submission (verdict: Runtime Error):
M = 10**9+7

def factorial(n):
    f = 1
    for i in range(1,n+1):
        f = f*i%M
    return f

def comb(n,k):
    if n==0 or k == 0:
        return 1
    if n<k:
        return 0

    return perm(n,k)*inverse(factorial(k))%M

def mcomb(n,k):
    return comb(n+k-1,k)

def perm(n,k):
    if n==0 or k == 0:
        return 1
    if n<k:
        return 0

    p = 1
    for i in range(n-k+1,n+1):
        p = p*i%M

    return M

def inverse(a):
    return pow(a,M-2,M)
  
n,k = tuple(main(int,input().split()))

for i in range(k):
  i += 1
  ans = comb(n-k+1,i)*comb(k-1,i-1)
  ans %= M
  print(ans)
Problem p03315 (python)

Fixed submission:
s=input()
print(s.count("+")-s.count("-"))

Buggy submission (verdict: Runtime Error):
s=input()
print(s.count("+")-s.count("-")
Problem p03723 (python)

Fixed submission:
a,b,c = tuple(map(int,input().split()))
if len(set((a,b,c)))==1 and a%2==1:
    print(0)
    exit()
ans = 0
while True:
  if len(set((a,b,c)))==1:
    print(-1)
    exit()
  if a%2==0 and b%2==0 and c%2==0:
    a,b,c = b//2+c//2,c//2+a//2,a//2+b//2
    ans+=1
  else:
    break
print(ans)

Buggy submission (verdict: Runtime Error):
a,b,c = tuple(map(int,input().split()))
if len(set((a,b,c)))<3:
  print(-1)
else:
  ans = 0
  while True:
    if a%2==0 and b%2==0 and c%2==0:
      a,b,c == b//2+c//2,c//2+a//2,a//2+b//2
      ans+=1
    else:
      break
    if len(set((a,b,c)))<3:
  print(-1)
      
  print(ans)

Buggy submission (verdict: Runtime Error):
a,b,c = tuple(map(int,input().split()))
if a==b and b==c:
  print(-1)
ans = 0
else:
  while True:
    if a%2==0 and b%2==0 and c%2==0:
      a,b,c == b//2+c//2,c//2+a//2,a//2+b//2
      ans+=1
    else:
      break
      
print(ans)
Problem p03785 (python)

Fixed submission:
n,c,k = tuple(map(int,input().split()))
t = []

for i in range(n):
  t.append(int(input()))
t = sorted(t)
t_0 = t[0]
p = 1
ans = 0
for t_i in t[1:]:
  if p<c and t_i-t_0<=k:
    p+=1
  else:
    p = 1
    t_0 = t_i
    ans+=1
    
print(ans+1)

Buggy submission (verdict: Runtime Error):
from math import ceil
 
N,C,K = map(int,input().split())
T = [int(input()) for _ in range(N)]
 
T.sort()
 
bus = 0
bus_time = T[0] + K
tmp_bus = 1
 
for i in range(1,N):
    if T[i] > bus_time:
        bus += 1
        bus_time = T[i+1] + K
        tmp_bus = 0
    else:
        tmp_bus += 1
    
    if tmp_bus == C:
        bus += 1
        bus_time = T[i+1] + K
        tmp_bus = 0
 
print(bus+1)
Problem p02891 (python)

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


def main():
    S = input()
    K = int(input())

    c = S[0]
    count = [1]
    for s in S[1:]:
        if c == s:
            count[-1] += 1
        else:
            count.append(1)
            c = s

    if S[0] != S[-1]:
        ans = sum(map(lambda x: x // 2, count))
        ans *= K
        print(ans)
        return

    if len(count) == 1:
        ans = (count[0] * K) // 2
        print(ans)
        return

    ans = 0
    for c in count:
        ans += c // 2
    count[0] += count[-1]
    ans += sum(map(lambda x: x // 2, count[:-1])) * (K - 1)
    print(ans)


main()

Buggy submission (verdict: Runtime Error):
from collections import Counter
def main():
   s = input()
   k = int(input())
   li = []
   num = 1
   for i in range(len(s)-1):
       if s[i] != s[i+1]:
           li.append(1)
       else:
           li[-1] += 1
   temp = 0
   ans = 0
   if len(list((Counter(li).keys()))) == 1:
       ans += len(s) * k // 2
   else:
       for i in li:
           temp += i//2
       if s[0] != s[-1]:
           ans = temp * k
       else:
           li[0] += li[-1]
           for i in li[:-1]:
               ans += i//2
           ans = ans * (k-1) + temp
   print(ans)
main()
Problem p03038 (python)

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

N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
amin, amax = A[0], A[N-1]

BC = {}
for _ in range(M):
    b, c = map(int, input().split())
    if c in BC:
        BC[c] += b
    else:
        BC[c] = b

BC = sorted(BC.items(), reverse=True)

b = 0
c = 0
cmax = len(BC)
for i in range(N):
    if BC[c][0] <= A[i]:
        break
    A[i] = BC[c][0]
    b += 1
    if b == BC[c][1]:
        c += 1
        b = 0
        if c == cmax:
            break

print(sum(A))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 5)

N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
amin, amax = A[0], A[N-1]

BC = {}
for _ in range(M):
    b, c = map(int, input().split())
    if c in BC:
        BC[c] += b
    else:
        BC[c] = b

BC = sorted(BC.items(), reverse=True)

b = 0
c = 0
for i in range(N):
    if BC[c][0]<=A[i]:
        break
    A[i] = BC[c][0]
    b += 1
    if b==BC[c][1]:
        c += 1
        b = 0

print(sum(A))