Buggy python submission (verdict: Runtime Error):
import numpy as np

k, q = map(int, input().split())
d = np.array(input().split(), dtype=np.int)
for _ in range(q):
  n, x, m = map(int, input().split())
  quot = (n-1) // k
  rest = (n-1) % k
  dmod = d % m
  same = (k - dmod.count_nonzero()) * quot + rest - dmod[:rest].count_nonzero()
  a_last = x % m + dmod.sum() * quot + dmod[:rest].sum()
  beyond = a_last // m
  print(n - 1 - same - beyond)

Fixed submission:
import numpy as np

k, q = map(int, input().split())
d = np.array(input().split(), dtype=np.int)
for _ in range(q):
  n, x, m = map(int, input().split())
  quot = (n-1) // k
  rest = (n-1) % k
  dmod = d % m
  same = (k - np.count_nonzero(dmod)) * quot + rest - np.count_nonzero(dmod[:rest])
  a_last = x % m + dmod.sum() * quot + dmod[:rest].sum()
  beyond = a_last // m
  print(n - 1 - same - beyond)

Buggy python submission (verdict: Time Limit Exceeded):
k, q = map(int, input().split())
d = list(map(int, input().split()))
for _ in range(q):
  n, x, m = map(int, input().split())
  x %= m
  dmod = [di % m for di in d]
  quot = (n-1) // k
  rest = (n-1) % k
  same = dmod.count(0) * quot + dmod[:rest].count(0)
  a_last = x + sum(dmod) * quot + sum(dmod[:rest])
  beyond = a_last // m
  print(n - 1 - same - beyond)

Fixed submission:
import numpy as np

k, q = map(int, input().split())
d = np.array(input().split(), dtype=np.int)
for _ in range(q):
  n, x, m = map(int, input().split())
  quot = (n-1) // k
  rest = (n-1) % k
  dmod = d % m
  same = (k - np.count_nonzero(dmod)) * quot + rest - np.count_nonzero(dmod[:rest])
  a_last = x % m + dmod.sum() * quot + dmod[:rest].sum()
  beyond = a_last // m
  print(n - 1 - same - beyond)

Buggy python submission (verdict: Time Limit Exceeded):
k, q = map(int, input().split())
d = list(map(int, input().split()))
for _ in range(q):
  n, x, m = map(int, input().split())
  dmod = [di % m for di in d]
  same = dmod.count(0) * ((n-1) // k) + dmod[: (n-1) % k].count(0)
  a_last = x + sum(dmod) * ((n-1) // k) + sum(dmod[: (n-1) % k])
  beyond = a_last // m - x // m
  print(n - 1 - same - beyond)

Fixed submission:
import numpy as np

k, q = map(int, input().split())
d = np.array(input().split(), dtype=np.int)
for _ in range(q):
  n, x, m = map(int, input().split())
  quot = (n-1) // k
  rest = (n-1) % k
  dmod = d % m
  same = (k - np.count_nonzero(dmod)) * quot + rest - np.count_nonzero(dmod[:rest])
  a_last = x % m + dmod.sum() * quot + dmod[:rest].sum()
  beyond = a_last // m
  print(n - 1 - same - beyond)

Buggy python submission (verdict: Time Limit Exceeded):
k, q = map(int, input().split())
d = list(map(int, input().split()))
for _ in range(q):
  n, x, m = map(int, input().split())
  dmod = [di % m for di in d]
  same = dmod.count(0) * ((n-1) // k) + dmod[: (n-1) % k].count(0)
  a_last = x + sum(dmod) * ((n-1) // k) + sum(dmod[: (n-1) % k])
  beyond = a_last // m - x // m
  print(n - 1 - same - beyond)

Fixed submission:
import numpy as np

k, q = map(int, input().split())
d = np.array(input().split(), dtype=np.int)
for _ in range(q):
  n, x, m = map(int, input().split())
  quot = (n-1) // k
  rest = (n-1) % k
  dmod = d % m
  same = (k - np.count_nonzero(dmod)) * quot + rest - np.count_nonzero(dmod[:rest])
  a_last = x % m + dmod.sum() * quot + dmod[:rest].sum()
  beyond = a_last // m
  print(n - 1 - same - beyond)