Harryxun/stf_run huggingface dataset:
N,K=map(int,input().split())
x=list(map(int,input().split()))
min=1000000000
for i in range(N-K+1):
    if x[i+K+1]<0:
        if min>-x[i]:
            min=-x[i]
    elif x[i]>=0:
        if min>x[i+K-1]:
            min=x[i+K-1]
    elif x[i]+x[i+K-1]>=0:
        if min>x[i+K-1]-x[i]*2:
            min=x[i+K-1]-x[i]*2
    else:
        if min>x[i+K-1]*2-x[i]:
            min=x[i+K-1]*2-x[i]
print(min)

### FIXED CODE ###

N,K=map(int,input().split())
x=list(map(int,input().split()))
tmin=1000000000
for i in range(N-K+1):
    a=x[i+K-1]
    b=x[i]
    res=a-b+min([abs(a),abs(b)])
    if tmin>res:
        tmin=res
print(tmin)
n,m=map(int,input().split())
a = [0]*m
for i in range(m):
  a[i] = int(input())-1


s=[0]*n
if 0 in a:
  s[0] = 0
  s[1] = 1
elif 1 in a:
  s[0] = 1
  s[1] = 0
else:
  s[0] = 1
  s[1] = 2
  
for i in range(2,n):
  #壊れている
  if i in a:
    s[i] = 0
  else:
    s[i] = s[i-1]+s[i-2]
print(s[n-1]%1000000007)


### FIXED CODE ###

n,m=map(int,input().split())
a = [0]*n
if n!=1:
  if m!=0:
    for i in range(m):
      a[int(input())-1] = 1

  s=[0]*n
  if a[0]==1 and a[1] == 1:
    s[0] = 0
    s[1] = 0
  elif a[0] == 1:
    s[0] = 0
    s[1] = 1
  elif a[1] == 1:
    s[0] = 1
    s[1] = 0
  else:
    s[0] = 1
    s[1] = 2

  for i in range(2,n):
    #壊れている
    if a[i] == 1:
      s[i] = 0
    else:
      s[i] = s[i-1]+s[i-2]
  print(s[n-1]%1000000007)
else:
  print(1)
N = int(input())
if N[-1] == 2 or 4 or 5 or 7 or 9:
    print("hon")
elif N[-1] == 0 or 1 or 6 or 8:
    print("pon")
elif N[-1] == 3:
    print("bon")

### FIXED CODE ###

N = input()
a = int(N[-1])

if a == 2 or a ==4or a ==7 or a == 9 or a ==5:
    print("hon")
if a == 0 or a ==1 or a==6 or a==8:
    print("pon")
if a == 3:
    print("bon")
import  copy
N, K = map(int,input().split())
p = [int(i) for i in input().split()]
P = []
P_S = []
ans_list = []
temp = 0

for i in range(N):
    P.append((p[i] + 1)/2)
    temp = temp + P[i]
    P_S.append(temp)
for i in range(N - K):
    ans_list.append(P_S[i + K] - P_S[i])

print(max(ans_list))

### FIXED CODE ###

N, K = map(int,input().split())
p = [int(i) for i in input().split()]
P = []
P_S = [0]
ans_list = []
temp = 0

for i in range(N):
    P.append((p[i] + 1)/2)
    temp = temp + P[i]
    P_S.append(temp)
for i in range(K,N+1):
    ans_list.append(P_S[i] - P_S[i - K])

print(max(ans_list))
import math
N,T1=int(input()),int(input())
for n in range(1,N):
    T2=int(input())
    T1=T1*T2/math.gcd(T1,T2)
print(int(T1))


### FIXED CODE ###

import fractions
N,T1=int(input()),int(input())
for n in range(1,N):
    T2=int(input())
    T1=(T1*T2)//fractions.gcd(T1,T2)
print(T1)
n = int(input())
d = [int(i) for i in input().split()]
d.sort()
k = [0]*10005
for i in d:
    k[i] += 1
c = 1
for i in range(d[-1]):
    c *= k[i]**k[i+1]
    c %= 998244353
if (k[0] >= 2):
    print(0)
else:
    print(c)


### FIXED CODE ###

n = int(input())
d = [int(i) for i in input().split()]
out = 0
if d[0]:
    out = 1
d.sort()
k = [0]*100005
for i in d:
    k[i] += 1
c = 1
for i in range(d[n-1]):
    for j in range(k[i+1]):
        c *= k[i]
        c %= 998244353
if (k[0] >= 2 or out):
    print(0)
else:
    print(c)
import sys
sys.setrecursionlimit(10**5)
n, m = map(int, input().split())
INF = 10**10
d = [[INF]*n for _ in range(n)]
for _ in range(m):
    a, b, c = map(int, input().split())
    d[a-1][b-1] = c
    d[b-1][a-1] = c
nxt = [[[i] for i in range(n)] for _ in range(n)]
for k in range(n):
    for i in range(n):
        for j in range(n):
            if i==j:
                continue
            if d[i][k]+d[k][j] < d[i][j]:
                d[i][j] = d[i][k]+d[k][j]
                nxt[i][j] = nxt[i][k]
            elif d[i][k]+d[k][j] == d[i][j]:
                nxt[i][j].extend(nxt[i][k])
s = set()
for start in range(n):
    for goal in range(n):
        if start==goal:
            continue
        def DFS(i):
            for j in nxt[i][goal]:
                s.add((i, j))
                if j!=goal:
                    DFS(j)
        DFS(start)
print(m-len(s)//2)

### FIXED CODE ###

n, m = map(int, input().split())
INF = 10**10
d = [[INF]*n for _ in range(n)]
for _ in range(m):
    a, b, c = map(int, input().split())
    d[a-1][b-1] = c
    d[b-1][a-1] = c
nxt = [[[i] for i in range(n)] for _ in range(n)]
for k in range(n):
    for i in range(n):
        for j in range(n):
            if i==j:
                continue
            if d[i][k]+d[k][j] < d[i][j]:
                d[i][j] = d[i][k]+d[k][j]
                nxt[i][j] = nxt[i][k][:]
            elif d[i][k]+d[k][j] == d[i][j]:
                nxt[i][j] += nxt[i][k]
s = set()
for start in range(n):
    for goal in range(n):
        if start==goal:
            continue
        def DFS(i):
            for j in nxt[i][goal]:
                s.add((i, j))
                if j!=goal:
                    DFS(j)
        DFS(start)
print(m-len(s)//2)
N = int(input())

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

C = [0] * 9

for i in range(N):
    if 1 <= A[i] <= 399:
        C[0] += 1
    elif 400 <= A[i] <= 799:
        C[1] += 1
    elif 800 <= A[i] <= 1199:
        C[2] += 1
    elif 1200 <= A[i] <= 1599:
        C[3] += 1
    elif 1600 <= A[i] <= 1999:
        C[4] += 1
    elif 2000 <= A[i] <= 2399:
        C[5] += 1
    elif 2400 <= A[i] <= 2799:
        C[6] += 1
    elif 2800 <= A[i] <= 3199:
        C[7] += 1
    else:
        C[8] += 1

blank = C[0:8].count(0)

if blank == 0:
    print("8 8")
    exit()

if C[8] == 0:
    ans = str(8 - blank)
    print(ans + " " + ans)
    exit()
elif C[8] >= 8:
    ans = str(max(8 - blank, 1))
    print(ans + " " + 8)
elif 1 <= C[8] <= 7:
    ans = str(8 - blank)
    ans2 = str(min(8, 8 - blank + C[8]))
    print(ans + " " + ans2)


### FIXED CODE ###

N = int(input())

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

C = [0] * 9

for i in range(N):
    if 1 <= A[i] <= 399:
        C[0] = 1
    elif 400 <= A[i] <= 799:
        C[1] = 1
    elif 800 <= A[i] <= 1199:
        C[2] = 1
    elif 1200 <= A[i] <= 1599:
        C[3] = 1
    elif 1600 <= A[i] <= 1999:
        C[4] = 1
    elif 2000 <= A[i] <= 2399:
        C[5] = 1
    elif 2400 <= A[i] <= 2799:
        C[6] = 1
    elif 2800 <= A[i] <= 3199:
        C[7] = 1
    else:
        C[8] += 1

num = sum(C[0:8])

ans1 = str(max(num, 1))
ans2 = str( num + C[8])
print(ans1 + " " + ans2)
a,b=map(int,input().split().replace(1,14)
print('Draw' if a==b else 'Alice' if a>b else 'Bob')

### FIXED CODE ###

a,b=map(int,input().split())
if a>1:
    a=a
else:
    a=14
if b>1:
    b=b
else:
    b=14
print('Draw' if a==b else 'Alice' if a>b else 'Bob')
n = int(input())
a = [int(input()) for i in range(n)]

switch = [False] * (n + 1)
def button(x,cnt):
    if switch[x]:
        print(-1)
        return -1
    if x == 2:
        print(cnt)
        return
    switch[x] = True
    button(a[x - 1], cnt + 1)
    return cnt

ans = button(1, 0)

### FIXED CODE ###

import sys
sys.setrecursionlimit(200000)
n = int(input())
a = [int(input()) for i in range(n)]

switch = [False] * (n + 1)
def button(x,cnt):
    if switch[x]:
        print(-1)
        return -1
    if x == 2:
        print(cnt)
        return
    switch[x] = True
    button(a[x - 1], cnt + 1)
    return cnt

ans = button(1, 0)
a, b = input().split()

ans = a+b

if ans > 24:
    ans -=24

print(ans)

### FIXED CODE ###

a, b = map(int, input().split())

ans = a+b

if ans > 23:
    ans = ans - 24

print(ans)
#!/usr/bin/env python3
import copy

def main():
    N = int(input())
    sides = [[] for _ in range(N-1)]
    
    for i in range(N-1):
        a,b = map(int, input().split())
        sides[a-1].append((b-1,i))

    ans = [[None] for _ in range(N-1)]

    def dfs(focus,parent_color):
        # if focus == N - 1:
        #     return
        color = 1
        for child,index in sides[focus]:
            if parent_color == color:
                color += 1 #もし親の色と被っていた場合はその色を飛ばす
            ans[index] = color
            if child < N -1:
                dfs(child,color)
            color += 1 #同じ親から続く次の辺の色を変更する

    dfs(0,0)

    print(max(ans))
    for color in ans:
        print(color)

if __name__ == "__main__":
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
sys.setrecursionlimit(100000)

def main():
    N = int(input())
    sides = [[] for _ in range(N-1)]
    
    for i in range(N-1):
        a,b = map(int, input().split())
        sides[a-1].append((b-1,i))

    ans = [[None] for _ in range(N-1)]

    def dfs(focus,parent_color):
        color = 1
        for child,index in sides[focus]:
            if parent_color == color:
                color += 1 #もし親の色と被っていた場合はその色を飛ばす
            ans[index] = color
            if child < N-1:
                dfs(child,color)
            color += 1 #同じ親から続く次の辺の色を変更する

    dfs(0,0)

    print(max(ans))
    for color in ans:
        print(color)


if __name__ == "__main__":
    main()
n,m=map(int,input().split())
dp=[0]*(n+1)
cnt=0
for i in range(m):
  q=input()
  if dp[int(q[i])]!="A" and q[-2]=="W":
    dp[int(q[:-3])]="W"
    cnt+=1
  elif dp[int(q[i])]!="A" and q[-2]=="A":
    dp[int(q[:-3])]="A"
print(dp.count("A"),cnt)

### FIXED CODE ###

n,m=map(int,input().split())
dp=[0]*(n+1)
charge=[0]*(n+1)
cnt=0
ans=0
for i in range(m):
  q=input()
  if dp[int(q[:-3])]!="A" and q[-2]=="W":
    dp[int(q[:-3])]="W"
    charge[int(q[:-3])]+=1
  elif dp[int(q[:-3])]!="A" and q[-2]=="A":
    dp[int(q[:-3])]="A"
    ans+=1
    cnt+=charge[int(q[:-3])]
    charge[int(q[:-3])]=0
print(ans,cnt)
N= int(input())
a = N//7
for i in range(a):
	if (N-(a-i)*7)%4 == 0:
		print("Yes")
		exit()
prin("No")

### FIXED CODE ###

N= int(input())
a=N//7
if N%7 == 0 or N%4 ==0:
	print("Yes")
	exit()
for i in range(a):
	if (N-(a-i)*7)%4 == 0:
		print("Yes")
		exit()
print("No")
s=input()
k=input()
if s[0]=='1':
    print(s[1])
else:
    print(s[0])

### FIXED CODE ###

s=input()
k=int(input())
for i in range(min(len(s),k)):
    if int(s[i])>1:
            print(s[i])
            exit()
print(1)
import sys
input = sys.stdin.redline

def main():
  s = input().strip()
  t = "abc"
  count = [0, 0, 0]
  for i in range(len(s)):
    for j in range(3):
      if s[i] == t[j]:
        count[j] += 1
  m = min(count)
  jud = count[0] - m
  jud = max(jud, count[1] - m)
  jud = max(jud, count[2] - m)
  
  if jud <= 1:
    print("YES")
  else:
    print("NO")
    
if __name__ == "__main__":
  main()

### FIXED CODE ###

import sys
input = sys.stdin.readline

def main():
  s = input().strip()
  t = "abc"
  count = [0, 0, 0]
  for i in range(len(s)):
    for j in range(3):
      if s[i] == t[j]:
        count[j] += 1
  m = min(count)
  jud = count[0] - m
  jud = max(jud, count[1] - m)
  jud = max(jud, count[2] - m)
  
  if jud <= 1:
    print("YES")
  else:
    print("NO")
    
if __name__ == "__main__":
  main()
import numpy as np

if __name__=="__main__":
    inputs_number  = lambda : [int(x) for x in input().split()]
    N, Ma, Mb = inputs_number()
    drugs = [inputs_number() for i in range(N)]
    inf = 100*N + 1
    dp = np.ones((N+1,N*10+1,N*10+1)).astype(np.int32) * inf
    dp = dp.tolist()
    dp[0][0][0] = 0.0

    for i in range(N):
	for ca in range(N*i+1):
            for cb in range(N*i+1):
                if(dp[i][ca][cb]==inf):
                    continue
                dp[i+1][ca][cb]=min([dp[i+1][ca][cb], dp[i][ca][cb]])
                dp[i+1][ca+drugs[i][0]][cb+drugs[i][1]]=min([dp[i+1][ca+drugs[i][0]][cb+drugs[i][1]], dp[i][ca][cb]+drugs[i][2]])
    ans = inf
    for ca in range(1, N*10+1):
        for cb in range(1, N*10+1):
            if(Ma*cb==Mb*ca and dp[N][ca][cb]<ans):
                ans = dp[N][ca][cb]
    if(ans==inf):
        ans = -1
    print(int(ans))

### FIXED CODE ###

import numpy as np
import copy

if __name__=="__main__":
    inputs_number  = lambda : [int(x) for x in input().split()]
    N, Ma, Mb = inputs_number()
    drugs = [inputs_number() for i in range(N)]
    inf = 100*N + 1
    dp = np.ones((2,N*10+1,N*10+1)).astype(np.int32) * inf
    dp = dp.tolist()
    dp[0][0][0] = 0.0

    for i in range(N):
        for ca in range(10*i+1):
            for cb in range(10*i+1):
                if(dp[0][ca][cb]==inf):
                    continue
                dp[1][ca][cb]=min([dp[1][ca][cb], dp[0][ca][cb]])
                dp[1][ca+drugs[i][0]][cb+drugs[i][1]]=min([dp[1][ca+drugs[i][0]][cb+drugs[i][1]], dp[0][ca][cb]+drugs[i][2]])
        dp[0] = copy.copy(dp[1])
        dp[1] = (np.ones((N*10+1,N*10+1)).astype(np.int32) * inf).tolist()
    ans = inf
    for ca in range(1, N*10+1):
        for cb in range(1, N*10+1):
            if(Ma*cb==Mb*ca and dp[0][ca][cb]<ans):
                ans = dp[0][ca][cb]
    if(ans==inf):
        ans = -1
    print(int(ans))
import collections #はい。
n=int(input()) #はい。
a=[list(map(str,input().split())) for _ in range(n)]
l = []
for i in range(len(a)):
    l += list(a[i][0])
#↑与えられる文字を全てリストにしたかった。技術が無くて回りくどいやり方になってしまったけれど…。

#以下、2回以上出てくる文字を取り出してn//2文字並べ、その文字列を反転させたものを連結させるという方針。
c = collections.Counter(l) #lに含まれる文字の統計
let,num = zip(*c.most_common()) #letは出てくる文字の種類、numはそれらの文字が何個出てくるか。
ll = list(num) #numがtuple型なのでlist型にした。
for j in range(len(ll)):
    ll[j] //= 2
#↑回文に使える文字が何組あるかというリストに置き換えている。
#例) qが3個出てくる。→1組使える。　,　wが4個出てくる。→2組使える。
    
sum = 0
for jj in range(len(ll)):
    sum += ll[jj]
#↑llのリストの数値の和を求めている。
if sum < n//2:
    print(-1) #回文に使える組数がそもそも足りないのでprint(-1)で終了。
else:
    ans = '' #ここからこのansに回文を詰め込んでいく。
    for k in range(len(let)):
        ans += str(let[k]) * ll[k] #回文に使える文字を使える個数詰め込む。
    ans = ans[:n//2] #n//2以降はいらないので捨てる。
    if n % 2 == 0:
        ans += ans[::-1] #文字数が偶数なら反転させたものを連結するだけ。
    else:
        ans += let[-1] + ans[::-1] #文字数が奇数なら適当な文字(ここではletの最後の要素)を加え、反転させたものを連結する。
    print(ans) #表示する。


### FIXED CODE ###

#import math
#=input()
#=int(input())
a,b=map(int,input().split())
#=list(map(int,input().split()))
#=[list(map(int,input().split())) for _ in range()]

print(a*b)
N,M = map(int, raw_input().split())
A = map(int, raw_input().split())

C = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]

T = [(-10**8,0)]*(N+1)
T[0] = (0, 0)
for i in range(1, N+1):
  for a in A:
    if C[a]>=0:
      T[i] = max(T[i], (T[i-C[a]][0]+1, a))

ans = ""
p = N
while p>0:
  ans += str(T[p][1])
  p -= C[T[p][1]]
print ans


### FIXED CODE ###

N,M = map(int, raw_input().split())
A = map(int, raw_input().split())

C = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]

T = [(-10**8,0)]*(N+1)
T[0] = (0, 0)
for i in range(1, N+1):
  for a in A:
    if i-C[a]>=0:
      T[i] = max(T[i], (T[i-C[a]][0]+1, a))

ans = ""
p = N
while p>0:
  ans += str(T[p][1])
  p -= C[T[p][1]]
print ans
N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]

cnt = 0
while len(xy) > 0:
  tmp = xy.pop(0)
  if len(xy) == 0:
    cnt += 1
    break
  p, q = xy[0][0] - tmp[0], xy[0][1] - tmp[1]
  for l in xy:
    if p == 0 and abs(l[1] - tmp[1]) % q == 0 or q == 0 and abs(l[0] - tmp[0]) % p == 0 or abs(l[0] - tmp[0]) % p == 0 and abs(l[1] - tmp[1]) % q == 0:
      xy.remove(l)
  cnt += 1
print(cnt)

### FIXED CODE ###

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

ans = float("inf")

if N < 3:
  ans = 1
else:   
  for i in range(N):
    x, y = xy[i][0], xy[i][1]
    for j in range(N):
      if i == j:
        continue
      p, q = xy[j][0] - x, xy[j][1] - y
      cnt = 0
      for k in range(N):
        xk, yk = xy[k][0], xy[k][1]
        for l in range(N):
          if k == l:
            continue
          if xy[l][0] - xk == p and xy[l][1] - yk == q:
            cnt += 1
      ans = min(ans, N - cnt)
print(ans)
import math

a = int(input())
b = int(input())

x = (b-1) / (a-1)

print(math.ceil(x))



### FIXED CODE ###


s = input()
t = input()

list(s)
list(t)

if s[0] == t[0] and s[1] == t[1] and s[2] == t[2]:
    print(3)

elif s[0] == t[0] and s[1] == t[1] and s[2] != t[2]:
    print(2)

elif s[0] == t[0] and s[1] != t[1] and s[2] == t[2]:
    print(2)

elif s[0] != t[0] and s[1] == t[1] and s[2] == t[2]:
    print(2)

elif s[0] == t[0] and s[1] != t[1] and s[2] != t[2]:
    print(1)

elif s[0] != t[0] and s[1] != t[1] and s[2] == t[2]:
    print(1)

elif s[0] != t[0] and s[1] == t[1] and s[2] != t[2]:
    print(1)

else:
    print(0)
# F - LIS on Tree
import bisect

INF = 10**18

n = int(input())
a = list(int(x) for x in input().split())
g = [[] for _ in range(n)]
for i in range(n-1):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    g[u].append(v)
    g[v].append(u)

def dfs(now, par):
    idx = bisect.bisect_left(dp, a[now])    
    tmp = dp[idx]
    dp[idx] = a[now]
    #print(dp)
    #print('now',now)
    # 親のLIS以上であれば、その値で更新
    if ans[par] <= idx:
        ans[now] = idx
    # そうでなければ親のLISを引き継ぐ
    else:
        ans[now] = ans[par]

    for i in g[now]:
        #print('i',i)
        if i!=par:
            # 次にみる頂点と、自分（親）の情報を渡す
            dfs(i, now)
    dp[idx] = tmp

ans = [0] * n
dp = [-INF] + [INF] * n
dfs(0,-1)
for a in ans:
    print(a)

### FIXED CODE ###

# F - LIS on Tree
import bisect
import sys
sys.setrecursionlimit(10**7)

INF = 10**18

n = int(input())
a = list(int(x) for x in input().split())
g = [[] for _ in range(n)]
for _ in range(n-1):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    g[u].append(v)
    g[v].append(u)

def dfs(now, par):
    idx = bisect.bisect_left(dp, a[now])    
    tmp = dp[idx]
    dp[idx] = a[now]
    # 親のLIS以上であれば、その値で更新
    if ans[par] <= idx:
        ans[now] = idx
    # そうでなければ親のLISを引き継ぐ
    else:
        ans[now] = ans[par]

    for i in g[now]:
        if i!=par:
            # 次にみる頂点と、自分（親）の情報を渡す
            dfs(i, now)
    dp[idx] = tmp

ans = [0] * n
dp = [-INF] + [INF] * n
dfs(0, -1)
for a in ans:
    print(a)
N = int(input())
S = input()
res = 0
for i in range(10):
    if str(i) in S:
        T = S[S.index(str(i))+1:]
        for j in range(10):
        if str(j) in T:
            U = T[T.index(str(j))+1:]
            for k in range(10):
                if str(k) in U:
                res += 1         
print(res)

### FIXED CODE ###

N = int(input())
S = input()
 
res = 0
for i in range(10):
    if str(i) in S:
        T = S[S.index(str(i))+1:]
        
        for j in range(10):
            if str(j) in T:
                U = T[T.index(str(j))+1:]
                
                for k in range(10):
                    if str(k) in U:
                        res += 1
                
print(res)
#!/usr/bin/env python3

import sys
import math
import numpy as np
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

k,q = LI()
d = LI()
nxm = [LI() for _ in range(q)]

for n,x,m in nxm:
    e = list(map(lambda x:x%m,d))
    zero = e.count(0)
    zero = zero*((n-1)//k)
    for i in range((n-1)%k):
        if e[i] == 0:
            zero += 1
    s = sum(e)*((n-1)//k)
    for i in range((n-1)%k):
        s += e[i]
    tmp = (s+x%m)//m
    print(n-1-zero-tmp)

    
    


### FIXED CODE ###

#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

k,q = LI()
d = LI()
nxm = [LI() for _ in range(q)]

for n,x,m in nxm:
    e = list(map(lambda x:(x-1)%m+1,d))
    f = list(accumulate(e))
    s = f[-1] * ((n-1)//k)
    if (n-1)%k != 0:
        s += f[(n-1)%k-1]
    tmp = (s+x%m)//m
    print(n-1-tmp)
A,B = map(int,input().sprit())
if A<=5:
  print(0)
elif A<=12:
  print(B//2)
else:
  print(B)

### FIXED CODE ###

A,B = map(int,input().split())
if A<=5:
  print(0)
elif A<=12:
  print(B//2)
else:
  print(B)
import math
n = int(input())
xy = []
for i in range(n):
    x, y = [int(item) for item in input().split()]
    if x == 0 and y == 0:
        continue
    elif x == 0:
        if y > 0:
            rad = math.pi / 2.0
        elif y < 0:
            rad = -math.pi / 2.0
    else:
        rad = math.atan2(y, x)
    deg = math.degrees(rad)
    xy.append((deg, x, y))

xy.sort()
xy2 = xy[:]
for d, x, y in xy:
    xy2.append((d+360.0, x, y))
    xy2.append((d+720.0, x, y))
xy2.sort()

l = 0; r = 1
    
ans = 0.0
while l < n:
    while xy2[r][0] - xy2[l][0] < 180.0:
        r += 1
    x = 0.0; y = 0.0
    for i in range(l, r):
        x += xy2[i][1]
        y += xy2[i][2]
    d = math.hypot(x, y)
    ans = max(ans, d)
    l += 1

print(ans)

### FIXED CODE ###

import math
n = int(input())
xy = []
for i in range(n):
    x, y = [int(item) for item in input().split()]
    if x == 0 and y == 0:
        rad = 0.0
    elif x == 0:
        if y > 0:
            rad = math.pi / 2.0
        elif y < 0:
            rad = -math.pi / 2.0
    else:
        rad = math.atan2(y, x)
    deg = math.degrees(rad)
    xy.append((deg, x, y))

xy.sort()
xy2 = xy[:]
for i, (d, x, y) in enumerate(xy):
    xy2.append((d+360.0, x, y))
    if i == 0:
        xy2.append((d+720.0, x, y))
xy2.sort()

ans = 0.0
for i in range(n):
    for j in range(i+1, i+n+1):
        x = 0.0; y = 0.0
        for k in range(i, j):
            x += xy2[k][1]
            y += xy2[k][2]
        d = math.hypot(x, y)
        ans = max(ans, d)

print(ans)
a,b=map(int,input(),split())
if a<b:
    print("0")
else:
    print("10")

### FIXED CODE ###

a,b=map(int,input().split())
if a<b:
    print("0")
else:
    print("10")
#131a
S = int(input())
if (S[0]==S[1]) or (S[1]==S[2]) or (S[2]==S[3]:
    print("Bad")
else:
    print("Good")

### FIXED CODE ###

#131a
S = str(input())
if (S[0]==S[1]) or (S[1]==S[2]) or (S[2]==S[3]):
    print("Bad")
else:
    print("Good")
# -*- coding: utf-8 -*-

n=int(input())
s=input()

async=0
for i in range(1,n):
    a=set(s[:i])
    b=set(s[i:])
    c=a&b
    if len(c)>ans:
        ans=len(c)

print(ans)


### FIXED CODE ###

# -*- coding: utf-8 -*-

n=int(input())
s=input()

ans=0
for i in range(1,n):
    a=set(s[:i])
    b=set(s[i:])
    c=a&b
    if len(c)>ans:
        ans=len(c)

print(ans)
import math

time_list = list()

for _ in range(5):
    time_list.append(int(input()))


def key_func(x):
    if x < 100:
        if x % 10 == 0:
            return 10
        return x % 10  # ex: 19の場合は9を返す
    else:
        if x % 100 == 0:
            return 10
        return x % 100  # ex: 123の場合は3を返す


time_list.sort(key=key_func, reverse=True)

print(time_list)

ans = sum
for i, time in enumerate(time_list):
    if i < len(time_list) - 1:
        ans += math.ceil(time / 10) * 10
    else:
        ans += time

print(ans)


### FIXED CODE ###

import math

time_list = list()

for _ in range(5):
    time_list.append(int(input()))

# 全探索
ans = 1e6
for i in range(len(time_list)):
    tmp = 0
    for j in range(len(time_list)):
        if i == j:
            tmp += time_list[i]
            continue
        tmp += math.ceil(time_list[j] / 10) * 10
    ans = min(tmp, ans)

print(ans)
S=str(input())

if S[2]==S[3] and S[5]==S[6]:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

S=str(input())

if S[2]==S[3] and S[4]==S[5]:
    print("Yes")
else:
    print("No")
a,b,c=map(int,input().split)
print(max(0,c-a+b))


### FIXED CODE ###

a,b,c=map(int,input().split())
print(max(0,c-a+b))
a = int(input())
b = list(map(int,input().split()))
ans = 0
x = True
while x:
  for i in range(a):
    if b[i] %2 ==1:
      x=False
      break
    b[i] = b[i] /2
    ans +=1
ans = ans//a
  

print(ans)

### FIXED CODE ###

a = list(map(int,input()))
b= sum(a)
print(b)