Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
# D - Alter Altar

from collections import deque

N = int(input())
c = list(str(input()))
dw = deque()
dr = deque()

for i, c in enumerate(c, 1):
    if c == 'W':
        dw.append(i)
    else:
        dr.appendleft(i)

ans = 0
while dw:
    w = dw.popleft()
    r = dr.popleft()
    if w < r:
        ans += 1

    else:
        break
print(ans)

Fixed submission:
from collections import deque

N = int(input())
c = list(str(input()))
dw = deque()
dr = deque()

for i, c in enumerate(c, 1):
    if c == 'W':
        dw.append(i)
    else:
        dr.appendleft(i)

ans = 0
while dw and dr:
    w = dw.popleft()
    r = dr.popleft()
    if w < r:
        ans += 1

    else:
        break
print(ans)

Buggy python submission (verdict: Runtime Error):
from collections import deque

N = int(input())
c = list(str(input()))
dw = deque()
dr = deque()

for i, c in enumerate(c, 1):
    if c == 'W':
        dw.append(i)
    else:
        dr.appendleft(i)

ans = 0
while dw:
    w = dw.popleft()
    r = dr.popleft()
    print(w, r)
    if w < r:
        ans += 1

    else:
        break
print(ans)

Fixed submission:
from collections import deque

N = int(input())
c = list(str(input()))
dw = deque()
dr = deque()

for i, c in enumerate(c, 1):
    if c == 'W':
        dw.append(i)
    else:
        dr.appendleft(i)

ans = 0
while dw and dr:
    w = dw.popleft()
    r = dr.popleft()
    if w < r:
        ans += 1

    else:
        break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(int(a) for a in input().split())

B = []
tmp = 1
for i in range(N):
    tmp *= A[i]
    if i < K-1:
        continue
    if i > K-1:
        tmp //= A[i-K]
    B.append(tmp)

for i in range(N-K):
    if B[i] < B[i+1]:
        print('Yes')
    else:
        print('No')

Fixed submission:
N, K = map(int, input().split())
A = list(int(a) for a in input().split())

for i in range(N-K):
    if A[i] < A[i+K]:
        print('Yes')
    else:
        print('No')

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(int(a) for a in input().split())

B = []
tmp = 1
for i in range(N):
    tmp *= A[i]
    if i < K-1:
        continue
    if i > K-1:
        tmp //= A[i-K]
    B.append(tmp)

for i in range(N-K):
    if B[i] < B[i+1]:
        print('Yes')
    else:
        print('No')

Fixed submission:
N, K = map(int, input().split())
A = list(int(a) for a in input().split())

for i in range(N-K):
    if A[i] < A[i+K]:
        print('Yes')
    else:
        print('No')

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(int(a) for a in input().split())

Acum = [1] * (N+1)
for i in range(N):
    Acum[i+1] = Acum[i] * A[i]

for j in range(K, N):
    now = Acum[j] // Acum[j-K]
    nxt = Acum[j+1] // Acum[j+1-K]
    if now < nxt:
        print('Yes')
    else:
        print('No')

Fixed submission:
N, K = map(int, input().split())
A = list(int(a) for a in input().split())

for i in range(N-K):
    if A[i] < A[i+K]:
        print('Yes')
    else:
        print('No')
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

def make_divisors(n):
    divisors = 0
    for i in range(1, int(pow(n,0.5)+1)):
        if n%i==0:
            divisors += 1
            if i!=n//i: 
                divisors += 1
    return divisors

ans = 0
for i in range(1, N+1):
    ans += i * make_divisors(i)
print(ans)

Fixed submission:
# D - Sum of Divisors

N = int(input())

ans = 0
D = [0] * (N+1)
for i in range(1, N+1):
    for j in range(i, N+1, i):
        D[j] += 1
    ans += i*D[i]
print(ans)
Buggy python submission (verdict: Runtime Error):
# C - One Quadrillion and One Dalmatians
import bisect

N = int(input())

keta = [26 ** i for i in range(1, 12)]
keta_sum = [0] * 12
for i in range(11):
    keta_sum[i+1] = keta_sum[i] + keta[i]
k = bisect.bisect_left(keta_sum, N)
ans = ''

for i in range(k):
    n = N - keta_sum[k-i-1]
    if n > 26:
        s = n // 26
        t = n % 26
    else:
        s = n
        t = n
    if t == 0:
        t = 26
    ans = ans + chr(t+96)
    N = (n//26) + (n%26) + 26

print(ans)


Fixed submission:
# C - One Quadrillion and One Dalmatians

N = int(input())

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

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# F - Strivore

K = int(input())
S = list(str(input()))
N = len(S)
MOD = 10**9+7

fac = [1, 1]
inv = [0, 1]
finv = [1, 1]
pow25 = [1, 25]
pow26 = [1, 26]

for i in range(2, N+K+1):
    fac.append(fac[-1] * i % MOD)
    inv.append(MOD - inv[MOD%i] * (MOD//i) % MOD)
    finv.append(finv[-1] * inv[-1] % MOD)
    if i <= K+1:
        pow25.append(pow(25, i, MOD))
        pow26.append(pow(26, i, MOD))

def comb_mod(n, r, m):
    if (n<0 or r<0 or n<r): return 0
    r = min(r, n-r)
    return fac[n] * finv[n-r] * finv[r] % m


ans = 0
for i in range(K+1):
    tmp = pow25[i]
    tmp = (tmp * comb_mod(i+N-1, N-1, MOD)) % MOD
    tmp = (tmp * pow26[K-i]) % MOD
    ans += tmp
    ans %= MOD
print(ans)



Fixed submission:
# F - Strivore

K = int(input())
S = list(str(input()))
N = len(S)
MOD = 10**9+7

fac = [1, 1]
inv = [0, 1]
finv = [1, 1]

for i in range(2, N+K+1):
    fac.append(fac[-1] * i % MOD)
    inv.append(MOD - inv[MOD%i] * (MOD//i) % MOD)
    finv.append(finv[-1] * inv[-1] % MOD)

def comb_mod(n, r, m):
    if (n<0 or r<0 or n<r): return 0
    r = min(r, n-r)
    return fac[n] * finv[n-r] * finv[r] % m

ans = 0
for i in range(K+1):
    tmp = pow(25, i, MOD)
    tmp *= comb_mod(i+N-1, N-1, MOD)
    tmp *= pow(26, K-i, MOD)
    ans += tmp
    ans %= MOD
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# F - Strivore

K = int(input())
S = list(str(input()))
N = len(S)
MOD = 10**9+7

fac = [1, 1]
inv = [0, 1]
finv = [1, 1]

for i in range(2, N+K+1):
    fac.append(fac[-1] * i % MOD)
    inv.append(MOD - inv[MOD%i] * (MOD//i) % MOD)
    finv.append(finv[-1] * inv[-1] % MOD)

def comb_mod(n, r, m):
    if (n<0 or r<0 or n<r): return 0
    r = min(r, n-r)
    return fac[n] * finv[n-r] * finv[r] % m

ans = 0
for i in range(K+1):
    tmp = pow(25, i, MOD)
    tmp *= comb_mod(i+N-1, N-1, MOD)
    tmp *= pow(26, K-i, MOD)
    ans += tmp
    ans %= MOD
print(ans)



Fixed submission:
# F - Strivore

K = int(input())
S = list(str(input()))
N = len(S)
MOD = 10**9+7

fac = [1, 1]
inv = [0, 1]
finv = [1, 1]

for i in range(2, N+K+1):
    fac.append(fac[-1] * i % MOD)
    inv.append(MOD - inv[MOD%i] * (MOD//i) % MOD)
    finv.append(finv[-1] * inv[-1] % MOD)

def comb_mod(n, r, m):
    if (n<0 or r<0 or n<r): return 0
    r = min(r, n-r)
    return fac[n] * finv[n-r] * finv[r] % m

ans = 0
for i in range(K+1):
    tmp = pow(25, i, MOD)
    tmp *= comb_mod(i+N-1, N-1, MOD)
    tmp *= pow(26, K-i, MOD)
    ans += tmp
    ans %= MOD
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# D - Not Divisible
import numpy as np
from collections import Counter

N = int(input())
A = list(int(a) for a in input().split())
c = Counter(A)
dbl = set([i[0] for i in c.items() if i[1] >= 2])

A.sort()
A = np.array(A)
ans = 0
for i in range(N):
    if A[i] == 0:
        continue
    elif A[i] not in dbl:
        ans += 1
    B = A % A[i]
    B = B.astype(np.bool)
    A = A * B

print(ans)

Fixed submission:
# D - Not Divisible
from collections import Counter

N = int(input())
A = list(int(a) for a in input().split())
c = Counter(A)
ng = set([i[0] for i in c.items() if i[1] >= 2])
A.sort()

M = max(A)
primes = []
is_prime = [True] * (M+1)
for i, a in enumerate(A):
    if is_prime[a]:
        if a not in ng:
            primes.append(a)
        for j in range(a*2, M+1, a):
            is_prime[j] = False
print(len(primes))
Buggy python submission (verdict: Time Limit Exceeded):
# C - Lamps
# imos法, 累積和

N, K = map(int, input().split())
A = list(int(a) for a in input().split())

for _ in range(K):
    B = [0] * (N+1)
    for i, a in enumerate(A):
        left = max(0, i-a)
        right = min(i+a+1, N)
        B[left] += 1
        B[right] -= 1
    for i in range(N):
        B[i+1] += B[i]
    B.pop()
    if A == B:
        break
    else:
        A = B

print(' '.join(map(str, A)))


Fixed submission:
# C - Lamps
# imos法, 累積和

N, K = map(int, input().split())
A = list(int(a) for a in input().split())

for _ in range(K):
    B = [0] * (N+1)
    for i, a in enumerate(A):
        left = max(0, i-a)
        right = min(i+a+1, N)
        B[left] += 1
        B[right] -= 1
    for i in range(N):
        B[i+1] += B[i]
    B.pop()
    if A == B:
        break
    else:
        A = B

print(' '.join(map(str, A)))
Buggy python submission (verdict: Time Limit Exceeded):
# B - Multiplication 2

import sys
readline = sys.stdin.readline

N = int(readline())
A = list(int(x) for x in readline().split())

ans = 1
for a in A:
    ans *= a

if ans > 10**18:
    print(-1)
else:
    print(ans)

Fixed submission:
# B - Multiplication 2

import sys
readline = sys.stdin.readline

N = int(readline())
A = list(int(x) for x in readline().split())
A.sort()

ans = 1
for a in A:
    ans *= a
    if ans == 0:
        break
    if ans > 10**18:
        break

if ans > 10**18:
    print(-1)
else:
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
readline = sys.stdin.readline

N, S = map(int, readline().split())
A = list(int(x) for x in readline().split())
MOD = 998244353

dp = [[0] * (S+1) for _ in range(N+1)]
dp[0][0] = 1

for i in range(N):
    for j in range(S+1):
        # 1,2のケース。jが変わらない遷移が2通りある。
        dp[i+1][j] = (dp[i+1][j] + dp[i][j] * 2) % MOD
        # 3のケース。j+A[i] <= Sならば、j+A[i]に遷移する。
        if j + A[i] <= S:
            dp[i+1][j+A[i]] = (dp[i+1][j+A[i]] + dp[i][j]) % MOD
print(dp[N][S])

Fixed submission:
import sys
readline = sys.stdin.readline

N, S = map(int, readline().split())
A = list(int(x) for x in readline().split())
MOD = 998244353

dp = [[0] * (S+1) for _ in range(N+1)]
dp[0][0] = 1

for i in range(N):
    for j in range(S+1):
        # 1,2のケース。jが変わらない遷移が2通りある。
        dp[i+1][j] = (dp[i+1][j] + dp[i][j] * 2) % MOD
        # 3のケース。j+A[i] <= Sならば、j+A[i]に遷移する。
        if j + A[i] <= S:
            dp[i+1][j+A[i]] = (dp[i+1][j+A[i]] + dp[i][j]) % MOD
print(dp[N][S])

Buggy python submission (verdict: Time Limit Exceeded):
N, S = map(int, input().split())
A = list(int(x) for x in input().split())
MOD = 998244353

dp = [[0] * (S+1) for _ in range(N+1)]
dp[0][0] = 1

for i in range(N):
    for j in range(S+1):
        # 1,2のケース。jが変わらない遷移が2通りある。
        dp[i+1][j] = (dp[i+1][j] + dp[i][j] * 2) % MOD
        # 3のケース。j+A[i] <= Sならば、j+A[i]に遷移する。
        if j + A[i] <= S:
            dp[i+1][j+A[i]] = (dp[i+1][j+A[i]] + dp[i][j]) % MOD
print(dp[N][S])

Fixed submission:
import sys
readline = sys.stdin.readline

N, S = map(int, readline().split())
A = list(int(x) for x in readline().split())
MOD = 998244353

dp = [[0] * (S+1) for _ in range(N+1)]
dp[0][0] = 1

for i in range(N):
    for j in range(S+1):
        # 1,2のケース。jが変わらない遷移が2通りある。
        dp[i+1][j] = (dp[i+1][j] + dp[i][j] * 2) % MOD
        # 3のケース。j+A[i] <= Sならば、j+A[i]に遷移する。
        if j + A[i] <= S:
            dp[i+1][j+A[i]] = (dp[i+1][j+A[i]] + dp[i][j]) % MOD
print(dp[N][S])

Buggy python submission (verdict: Runtime Error):
N, S = map(int, input().split())
A = list(int(x) for x in input().split())
MOD = 998244353

dp = [[0] * (S+1) for _ in range(N+1)]
dp[0][0] = 1

for i in range(N):
    for j in range(S+1):
        print(i, j)
        # 1,2のケース。jが変わらない遷移が2通りある。
        dp[i+1][j] += dp[i][j] * 2
        # 3のケース。j+A[i] <= Sならば、j+A[i]に遷移する。
        if j + A[i] <= S:
            dp[i+1][j+A[i]] += dp[i][j]
        print(dp)
print(dp[N][S])

Fixed submission:
import sys
readline = sys.stdin.readline

N, S = map(int, readline().split())
A = list(int(x) for x in readline().split())
MOD = 998244353

dp = [[0] * (S+1) for _ in range(N+1)]
dp[0][0] = 1

for i in range(N):
    for j in range(S+1):
        # 1,2のケース。jが変わらない遷移が2通りある。
        dp[i+1][j] = (dp[i+1][j] + dp[i][j] * 2) % MOD
        # 3のケース。j+A[i] <= Sならば、j+A[i]に遷移する。
        if j + A[i] <= S:
            dp[i+1][j+A[i]] = (dp[i+1][j+A[i]] + dp[i][j]) % MOD
print(dp[N][S])
Buggy python submission (verdict: Runtime Error):
# D - .. (Double Dots)

from collections import deque
N, M = map(int, input().split())
tree = [[] for _ in range(M)]
for i in range(M):
    A, B = map(int, input().split())
    A -= 1
    B -= 1
    tree[A].append(B)
    tree[B].append(A)

ans_arr = [-1] * (N)
q = deque()
ans_arr[0] = 0 
q.append(0)

while len(q)>0:
    n = q.popleft()
    for i in tree[n]:
        if ans_arr[i] == -1:
            ans_arr[i] = n+1
            q.append(i)

ans = 'Yes'
for i in ans_arr[1:]:
    if i == -1:
        ans = 'No'
        break

if ans == 'No':
    print(ans)
else:
    print(ans)
    for i in ans_arr[1:]:
        print(i)


Fixed submission:
# D - .. (Double Dots)

from collections import deque

N, M = map(int, input().split())
tree = [[] for _ in range(N)]
for i in range(M):
    A, B = map(int, input().split())
    A -= 1
    B -= 1
    tree[A].append(B)
    tree[B].append(A)

ans_arr = [-1] * (N)
q = deque()
ans_arr[0] = 0 
q.append(0)

while len(q)>0:
    n = q.popleft()
    for i in tree[n]:
        if ans_arr[i] == -1:
            ans_arr[i] = n+1
            q.append(i)

ans = 'Yes'
for i in ans_arr[1:]:
    if i == -1:
        ans = 'No'
        break

if ans == 'No':
    print(ans)
else:
    print(ans)
    for i in ans_arr[1:]:
        print(i)
Buggy python submission (verdict: Runtime Error):
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

div = make_divisors(X)

for d in div:
    i = 1
    j = i-d
    while True:
        if pow(i,5)-pow(j,5)<X:
            i += 1
            j += 1
            continue
        if pow(i,5)-pow(j,5)==X:
            print(i,j)
            break
        elif pow(i,5)-pow(j,5)>X:
            break


Fixed submission:
# D - I hate Factorization

X = int(input())
fact = []
for i in range(300):
    fact.append(pow(i,5))

for i in range(300):
    for j in range(300):
        if fact[i]-fact[j]==X:
            print(i, j)
            break
        elif fact[i]+fact[j]==X:
            print(i, -j)
            break
    else:
        continue
    break

Buggy python submission (verdict: Time Limit Exceeded):
# D - I hate Factorization

X = int(input())
fact = []
for i in range(10**5):
    fact.append(pow(i,5))

for i in range(10**5):
    for j in range(10**5):
        if fact[i]-fact[j]==X:
            print(i, j)
            break
        elif fact[i]+fact[j]==X:
            print(i, -j)
            break
    else:
        continue
    break




Fixed submission:
# D - I hate Factorization

X = int(input())
fact = []
for i in range(300):
    fact.append(pow(i,5))

for i in range(300):
    for j in range(300):
        if fact[i]-fact[j]==X:
            print(i, j)
            break
        elif fact[i]+fact[j]==X:
            print(i, -j)
            break
    else:
        continue
    break
Buggy python submission (verdict: Time Limit Exceeded):
# E - This Message Will Self-Destruct in 5s

N = int(input())
A = list(int(x) for x in input().split())

ans = 0
for i in range(N):
    for j in range(i+A[i]+1,N):
        if j-i==A[i]+A[j]:
            ans += 1

print(ans)

Fixed submission:
# E - This Message Will Self-Destruct in 5s
from collections import defaultdict

N = int(input())
A = list(int(x) for x in input().split())

di = defaultdict(int)
for i in range(N):
    di[i+1+A[i]] += 1

dj = defaultdict(int)
for j in range(N):
    dj[j+1-A[j]] += 1

ans = 0
for k, v in di.items():
    ans += v * dj.get(k,0)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# D - Multiple of 2019

s = str(input())
ans = 0
 
for i in range(len(s)):
    for j in range(i+4, min(len(s),10000)):
        if int(s[i:j+1])%2019==0:
            ans += 1
 
print(ans)

Fixed submission:
# D - Multiple of 2019

from collections import defaultdict
d = defaultdict(int)

mod = 2019
s = str(input())[::-1]

ssum = 0
d[0] = 1
for i in range(len(s)):
    ssum = (ssum + int(s[i])*pow(10, i, mod))%mod
    d[ssum] += 1

ans = 0
for n in d.values():
    ans += n*(n-1)//2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# D - Multiple of 2019

s = str(input())
ans = 0

for i in range(len(s)):
    for j in range(i, len(s)):
        if int(s[i:j+1])%2019==0:
            ans += 1

print(ans)

Fixed submission:
# D - Multiple of 2019

from collections import defaultdict
d = defaultdict(int)

mod = 2019
s = str(input())[::-1]

ssum = 0
d[0] = 1
for i in range(len(s)):
    ssum = (ssum + int(s[i])*pow(10, i, mod))%mod
    d[ssum] += 1

ans = 0
for n in d.values():
    ans += n*(n-1)//2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# D - Multiple of 2019

s = str(input())
ans = 0

for i in range(len(s)):
    for j in range(i, len(s)):
        if int(s[i:j+1])%2019==0:
            ans += 1

print(ans)

Fixed submission:
# D - Multiple of 2019

from collections import defaultdict
d = defaultdict(int)

mod = 2019
s = str(input())[::-1]

ssum = 0
d[0] = 1
for i in range(len(s)):
    ssum = (ssum + int(s[i])*pow(10, i, mod))%mod
    d[ssum] += 1

ans = 0
for n in d.values():
    ans += n*(n-1)//2

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# E - Dividing Chocolate
import numpy as np

H, W, K = map(int, input().split())
S = np.zeros((H, W), dtype=np.int64)

ans = H*W

for i in range(H):
    S[i] = list(str(input()))

for m in range(2**(H-1)):
    wp = np.zeros((H, W), dtype=np.int64)
    wq = np.zeros((H, ), dtype=np.int64)
    wp[0] = S[0]
    h = 0
    tmp = 0
    for n in range(H-1):
        if m>>n&1:
            h += 1
            tmp += 1
        wp[h] += S[n+1]

    for j in range(W):
        wq += wp[:,j]
        if any([a > K for a in wq]):
            tmp += 1
            wq = wp[:,j]
    ans = min(ans, tmp)

print(ans)


Fixed submission:
# E - Dividing Chocolate
import numpy as np

H, W, K = map(int, input().split())
S = np.zeros((H, W), dtype=np.int64)

ans = H+W

for i in range(H):
    S[i] = list(str(input()))

for m in range(2**(H-1)):
    wp = np.zeros((H, W), dtype=np.int64)
    wq = np.zeros((H, ), dtype=np.int64)
    wp[0] = S[0]
    cut = 0
    for n in range(H-1):
        if m>>n&1:
            cut += 1
        wp[cut] += S[n+1]

    if cut >= ans or np.count_nonzero(wp > K):
        continue

    for j in range(W):
        wq += wp[:,j]
        if np.count_nonzero(wq > K):
            cut += 1
            wq = wp[:,j]
    ans = min(ans, cut)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# D - String Formation

S = str(input())
Q = int(input())

for _ in range(Q):
    q = [str(x) for x in input().split()]
    if q[0] == '1':
        S = ''.join(list(reversed(S)))
    elif q[1]=='1':
        S = q[2]+S
    else:
        S = S+q[2]

print(S)

Fixed submission:
# D - String Formation

S = str(input())
Q = int(input())

# 1の数
c = 0
l = ''
r = ''

for _ in range(Q):
    q = [str(x) for x in input().split()]
    if q[0] == '1':
        c += 1
        l, r = r, l
    elif q[1]=='1':
        l = l + q[2]
    else:
        r = r + q[2]

if c%2==1:
    S = ''.join(reversed(S))

l = ''.join(reversed(l))

print(l+S+r)
Buggy python submission (verdict: Time Limit Exceeded):
stdin = open(0)
k, q = map(int, stdin.readline().split())
d = [int(x) for x in stdin.readline().split()]

for _ in range(q):
    n, x, m = map(int, stdin.readline().split())
    z = 0
    last = x
    ans = 0
    
    for i in range(k):
        dnum = (n-1-i+(k-1))//k
        last += d[i]%m * dnum
        if d[i]%m == 0:
            z += dnum
        
    ans = (n-1) - (last//m - x//m) - z
    print(ans)

Fixed submission:
k, q = map(int, input().split())
d = [int(x) for x in input().split()]

for _ in range(q):
    n, x, m = map(int, input().split())
    z = 0
    last = x
    ans = 0

    for i in range(k):
        dnum = (n-1-i+(k-1))//k
        last += d[i]%m * dnum
        if d[i]%m == 0:
            z += dnum
        
    ans = (n-1) - (last//m - x//m) - z
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
k, q = map(int, input().split())
d = [int(x) for x in input().split()]

for _ in range(q):
    n, x, m = map(int, input().split())
    z = 0
    last = x
    ans = 0

    for i in range(k):
        dnum = (n-1-i+(k-1))//k
        last += d[i]%m * dnum
        if d[i]%m == 0:
            z += dnum
        
    ans = (n-1) - (last//m - x//m) - z
    print(ans)


Fixed submission:
k, q = map(int, input().split())
d = [int(x) for x in input().split()]

for _ in range(q):
    n, x, m = map(int, input().split())
    z = 0
    last = x
    ans = 0

    for i in range(k):
        dnum = (n-1-i+(k-1))//k
        last += d[i]%m * dnum
        if d[i]%m == 0:
            z += dnum
        
    ans = (n-1) - (last//m - x//m) - z
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# D - Dice in Line

N, K = map(int, input().split())
P = list(int(x) for x in input().split())

A = []

for i in range(K-1, N):
    A.append(sum(P[i-(K-1):i+1]))

print(0.5*(K+max(A)))

Fixed submission:
# D - Dice in Line

N, K = map(int, input().split())
P = list(int(x) for x in input().split())

S = [0] * (N+1)

for i in range(N):
    S[i+1] = S[i] + P[i]

ans = 0

for j in range(K, N+1):
    if S[j]-S[j-K]>ans:
        ans = S[j]-S[j-K]

print(0.5*(K+ans))

Buggy python submission (verdict: Time Limit Exceeded):
# D - Dice in Line

N, K = map(int, input().split())
P = list(int(x) for x in input().split())

A = [0] * K

for i in range(K-1, N):
    if sum(P[i-(K-1):i+1])>sum(A):
        A = P[i-(K-1):i+1]

ans = 0

for a in A:
    ans += 0.5*(1+a)

print(ans)

Fixed submission:
# D - Dice in Line

N, K = map(int, input().split())
P = list(int(x) for x in input().split())

S = [0] * (N+1)

for i in range(N):
    S[i+1] = S[i] + P[i]

ans = 0

for j in range(K, N+1):
    if S[j]-S[j-K]>ans:
        ans = S[j]-S[j-K]

print(0.5*(K+ans))
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    H, N = map(int, input().split())
    A = [0] * N
    B = [0] * N
    for i in range(N):
        A[i], B[i] = map(int, input().split())

    dp = [0] * (H+1)
    for x in range(1, H+1):
        dp[x] = min(dp[max(x-a, 0)] + b for a, b in zip(A, B))

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

Fixed submission:
def main():
    H, N = map(int, input().split())
    A = [0] * N
    B = [0] * N
    for i in range(N):
        A[i], B[i] = map(int, input().split())

    dp = [0] * (H+1)
    for x in range(1, H+1):
        dp[x] = min(dp[max(x-a, 0)] + b for a, b in zip(A, B))

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