Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

k,q = map(int,input().split())
d_array = list(map(int,input().split()))

ans_array = []
for _ in range(q):
    n, x, m = map(int,input().split())
    d_mod_array = [d % m for d in d_array]
    d_sum = sum(d_mod_array)
    mod_total = x % m + d_sum * ((n-1) // k) + sum(d_mod_array[:(n-1)%k])
    reduce_total = mod_total // m

    zero_count = d_mod_array.count(0)
    zero_total = zero_count * ((n-1) // k) + d_mod_array[:(n-1)%k].count(0)
    ans = (n-1) - reduce_total - zero_total
    ans_array.append(str(ans))

print("\n".join(ans_array))



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

k,q = map(int,input().split())
d_array = list(map(int,input().split()))

ans_array = []
for _ in range(q):
    n, x, m = map(int,input().split())
    d_mod_array = [d % m for d in d_array]
    d_sum = 0
    d_part = 0
    zero_count = 0
    zero_part = 0
    part = (n-1) % k
    for i,d in enumerate(d_mod_array):
        d_sum += d
        if i < part:
            d_part += d
        if d == 0:
            zero_count += 1
            if i < part:
                zero_part += 1
    mod_total = x % m + d_sum * ((n-1) // k) + d_part
    reduce_total = mod_total // m

    zero_total = zero_count * ((n-1) // k) + zero_part
    ans = (n-1) - reduce_total - zero_total
    ans_array.append(str(ans))

print("\n".join(ans_array))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

k,q = map(int,input().split())
d_array = list(map(int,input().split()))

for _ in range(q):
    n, x, m = map(int,input().split())
    d_mod_array = [d % m for d in d_array]
    d_sum = sum(d_mod_array)
    mod_total = x % m + d_sum * ((n-1) // k) + sum(d_mod_array[:(n-1)%k])
    reduce_total = mod_total // m

    zero_count = d_mod_array.count(0)
    zero_total = zero_count * ((n-1) // k) + d_mod_array[:(n-1)%k].count(0)
    ans = (n-1) - reduce_total - zero_total
    print(ans)

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

k,q = map(int,input().split())
d_array = list(map(int,input().split()))

ans_array = []
for _ in range(q):
    n, x, m = map(int,input().split())
    d_mod_array = [d % m for d in d_array]
    d_sum = 0
    d_part = 0
    zero_count = 0
    zero_part = 0
    part = (n-1) % k
    for i,d in enumerate(d_mod_array):
        d_sum += d
        if i < part:
            d_part += d
        if d == 0:
            zero_count += 1
            if i < part:
                zero_part += 1
    mod_total = x % m + d_sum * ((n-1) // k) + d_part
    reduce_total = mod_total // m

    zero_total = zero_count * ((n-1) // k) + zero_part
    ans = (n-1) - reduce_total - zero_total
    ans_array.append(str(ans))

print("\n".join(ans_array))

Buggy python submission (verdict: Time Limit Exceeded):
k,q = map(int,input().split())
d_array = list(map(int,input().split()))

nxm_array = [list(map(int,input().split())) for _ in range(q)]

for nxm in nxm_array:
    n, x, m = nxm
    d_mod_array = [d % m for d in d_array]
    d_sum = sum(d_mod_array)
    mod_total = x % m + d_sum * ((n-1) // k) + sum(d_mod_array[:(n-1)%k])
    reduce_total = mod_total // m

    zero_count = d_mod_array.count(0)
    zero_total = zero_count * ((n-1) // k) + d_mod_array[:(n-1)%k].count(0)
    ans = (n-1) - reduce_total - zero_total
    print(ans)


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

k,q = map(int,input().split())
d_array = list(map(int,input().split()))

ans_array = []
for _ in range(q):
    n, x, m = map(int,input().split())
    d_mod_array = [d % m for d in d_array]
    d_sum = 0
    d_part = 0
    zero_count = 0
    zero_part = 0
    part = (n-1) % k
    for i,d in enumerate(d_mod_array):
        d_sum += d
        if i < part:
            d_part += d
        if d == 0:
            zero_count += 1
            if i < part:
                zero_part += 1
    mod_total = x % m + d_sum * ((n-1) // k) + d_part
    reduce_total = mod_total // m

    zero_total = zero_count * ((n-1) // k) + zero_part
    ans = (n-1) - reduce_total - zero_total
    ans_array.append(str(ans))

print("\n".join(ans_array))