CodeEff/ECCO huggingface dataset:
# Original solution
import sys
input = sys.stdin.buffer.readline

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

for qi in range(q):
    n, x, m = list(map(int, input().split()))
    last = x
    eq = 0
    for i in range(k):
        num = (n-1-i+k-1)//k
        last += (d[i]%m) * num
        if d[i]%m == 0: eq += num
    ans = (n-1) - (last//m - x//m) - eq
    print(ans)

# Optimized solution
import sys
input = sys.stdin.buffer.readline

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

for qi in range(q):
    n, x, m = list(map(int, input().split()))
    last = x
    eq = 0
    for i in range(k):
        num = ((n-1-i)+(k-1))//k
        last += (d[i]%m) * num
        if d[i]%m == 0: eq += num
    ans = (n-1) - (last//m - x//m) - eq
    print(ans)
# Original solution
from itertools import accumulate

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

def sof(n, a, b, c):
    if a == 0:
        return (n + 1) * (b // c)
    if a >= c or b >= c:
        return n * (n + 1) // 2 * (a // c) + (n + 1) * (b // c) + sof(n, a % c, b % c, c)
    m = (a * n + b) // c
    return n * m - sof(m - 1, c, c - b - 1, a)

def solve():
    n, x, m = list(map(int, input().split()))
    a = [0] + list([i % m for i in accumulate(d)])
    ans = 0
    rn = (n - 1) % k
    for i in range(k):
        u = (x + a[i]) % m
        v = (x + a[i + 1]) % m
        if i < rn:
            c = (n - 1) // k + 1
        else:
            c = (n - 1) // k
        if u == v:
            continue
        elif u < v:
            ans += c - (sof(c - 1, a[-1], v, m) - sof(c - 1, a[-1], u, m))
        else:
            ans += sof(c - 1, a[-1], u, m) - sof(c - 1, a[-1], v, m)
    print(ans)

for _ in range(q):
    solve()

# Optimized solution
k, q = list(map(int, input().split()))
d = list(map(int, input().split()))

def solve():
    n, x, m = list(map(int, input().split()))
    ans = 0
    rn = (n - 1) % k
    f = x % m
    for i in range(k):
        if d[i] % m == 0:
            continue
        if i < rn:
            c = (n - 1) // k + 1
        else:
            c = (n - 1) // k
        ans += c
        f += c * (d[i] % m)
    ans -= f // m
    print(ans)

for _ in range(q):
    solve()
# Original solution
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import math

#############
# Constants #
#############

MOD = 10**9 +7
INF = float('inf')

#############
# Functions #
#############

kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

#############
# Main Code #
#############

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

def query(n,x,m):
  x %= m
  ans = n-1
  n -= 1
  s1 = 0
  t1 = 0
  for i in range(k):
    s1 += d[i] % m
    if d[i] % m == 0:
      t1 += 1
  s2 = 0
  t2 = 0
  for i in range(n%k):
    s2 += d[i] % m
    if d[i] % m == 0:
      t2 += 1
  x += s1 * (n//k) + s2
  ans -= x//m
  ans -= t1 * (n//k) + t2
  
  return ans
  
    

for _ in range(q):
  n,x,m = list(map(int, input().split()))
  print((query(n,x,m)))


# Optimized solution
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import math

#############
# Constants #
#############

MOD = 10**9 +7
INF = float('inf')

#############
# Functions #
#############

kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

#############
# Main Code #
#############

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

def query(n,x,m):
  x %= m
  ans = n-1
  n -= 1
  s1 = 0
  t1 = 0
  for i in range(k):
    s1 += d[i] % m
    if d[i] % m == 0:
      t1 += 1
  s2 = 0
  t2 = 0
  for i in range(n%k):
    s2 += d[i] % m
    if d[i] % m == 0:
      t2 += 1
  x += s1 * (n//k) + s2
  ans -= x//m
  ans -= t1 * (n//k) + t2
  
  print(ans)
  
    

for _ in range(q):
  n,x,m = list(map(int, input().split()))
  query(n,x,m)
# Original solution
from math import ceil
import sys
input=sys.stdin.readline
k,q=list(map(int,input().split()))
d=list(map(int,input().split()))
for _ in range(q):
  n,x,m=list(map(int,input().split()))
  dd=[d[i]%m for i in range(k)]
  cnt1=0
  cnt2=0
  for i in range(k):
    if dd[i]==0:
      cnt1+=ceil((n-i-1)/k)
  a=x
  for i in range(k):
    a+=ceil((n-i-1)/k)*dd[i]
  cnt2=a//m-x//m
  print((n-1-cnt1-cnt2))

# Optimized solution
import sys
input=sys.stdin.readline
k,q=list(map(int,input().split()))
d=list(map(int,input().split()))
for _ in range(q):
  n,x,m=list(map(int,input().split()))
  dd=[d[i]%m for i in range(k)]
  for i in range(k):
    if dd[i]==0:
      dd[i]=m
  s=x%m+sum(dd)*((n-1)//k)+sum(dd[:(n-1)%k])
  print((n-1-s//m))
# Original solution
import sys

input = sys.stdin.readline


def main():
    K, Q = list(map(int, input().split()))
    D = list(map(int, input().split()))

    for _ in range(Q):
        n, x, m = list(map(int, input().split()))
        md = [D[i] % m for i in range(K)]
        smda = 0
        mda0 = 0
        for i in range((n - 1) % K):
            if md[i] == 0:
                mda0 += 1
            smda += md[i]
        roop = (n - 1) // K
        res = n - 1 - (x % m + sum(md) * roop + smda) // m - md.count(0) * roop - mda0
        print(res)


main()


# Optimized solution
import sys

input = sys.stdin.readline


def main():
    K, Q = list(map(int, input().split()))
    D = list(map(int, input().split()))

    for _ in range(Q):
        n, x, m = list(map(int, input().split()))
        md = [D[i] % m for i in range(K)]
        smda = 0
        mda0 = 0
        for i in range((n - 1) % K):
            if md[i] == 0:
                mda0 += 1
            smda += md[i]
        smd = smda
        md0 = mda0
        for i in range((n - 1) % K, K):
            if md[i] == 0:
                md0 += 1
            smd += md[i]
        roop = (n - 1) // K
        res = n - 1 - (x % m + smd * roop + smda) // m - md0 * roop - mda0
        print(res)


main()
# Original solution
import sys


def main():
    K, Q = list(map(int, input().split()))
    D = list(map(int, input().split()))

    for _ in range(Q):
        n, x, m = list(map(int, input().split()))
        md = [D[i] % m for i in range(K)]
        smda = 0
        mda0 = 0
        for i in range((n - 1) % K):
            if md[i] == 0:
                mda0 += 1
            smda += md[i]
        smd = smda
        md0 = mda0
        for i in range((n - 1) % K, K):
            if md[i] == 0:
                md0 += 1
            smd += md[i]
        roop = (n - 1) // K
        res = n - 1 - (x % m + smd * roop + smda) // m - md.count(0) * roop - mda0
        print(res)


main()


# Optimized solution
import sys


def main():
    K, Q = list(map(int, input().split()))
    D = list(map(int, input().split()))

    for _ in range(Q):
        n, x, m = list(map(int, input().split()))
        md = [D[i] % m for i in range(K)]
        smda = 0
        mda0 = 0
        for i in range((n - 1) % K):
            if md[i] == 0:
                mda0 += 1
            smda += md[i]
        smd = smda
        md0 = mda0
        for i in range((n - 1) % K, K):
            if md[i] == 0:
                md0 += 1
            smd += md[i]
        roop = (n - 1) // K
        res = n - 1 - (x % m + smd * roop + smda) // m - md0 * roop - mda0
        print(res)


main()
# Original solution
import sys
input = sys.stdin.readline

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

for query in range(q):
    n,x,m=list(map(int,input().split()))

    D2=[d%m for d in  D]
    S=sum(D2)
    D0=D2.count(0)
    R=(n-1)//k
    ANS=R*(k-D0) - S//m*R-(S%m*R+x%m)//m 

    x2=(x+S%m*R)%m
    rest=n-R*k-1
    S2=sum(D2[:rest])
    DR0=D2[:rest].count(0)
    ANSR=rest - DR0 - (x2+S2)//m

    print((ANS+ANSR))

# Optimized solution
import sys
input = sys.stdin.readline

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

def sum_count(A):
    S=0
    C=0
    for a in A:
        if a==0:
            C+=1
        else:
            S+=a
    return S,C

for query in range(q):
    n,x,m=list(map(int,input().split()))

    D2=[d%m for d in  D]
    S,D0=sum_count(D2)
    R=(n-1)//k
    ANS=R*(k-D0) - (R*S+x%m)//m 
    x2=(x+S*R)%m
    rest=n-R*k-1
    S2,DR0=sum_count(D2[:rest])
    ANSR=rest - DR0 - (x2+S2)//m

    print((ANS+ANSR))
# Original solution
import sys
input=sys.stdin.readline
k,q=list(map(int,input().split()))
D=[int(i) for i in input().split()]
for _ in range(q):
  n,x,m=list(map(int,input().split()))
  DD=[d%m for d in D]
  x%=m
  ans=n-1
  u,v=(n-1)//k,(n-1)%k
  z=DD.count(0)*u
  a_n=x+sum(DD)*u
  for i in range(v):
    a_n+=DD[i]
    if DD[i]==0:
      z+=1
  ans-=z+a_n//m
  print(ans)

# Optimized solution
import sys
input=sys.stdin.readline
k,q=list(map(int,input().split()))
D=[int(i) for i in input().split()]
for _ in range(q):
  n,x,m=list(map(int,input().split()))
  DD=[d%m for d in D]
  x%=m
  ans=n-1
  u,v=(n-1)//k,(n-1)%k
  z1,z2,r,s=0,0,0,0
  for i,d in enumerate(DD):
    s+=d
    if i<v:
      r+=d
      if d==0:
        z1+=1
        z2+=1
    elif d==0:
      z2+=1
  ans-=(z2*u+z1)+(x+s*u+r)//m
  print(ans)
# Original solution
#!/usr/bin/env python3
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
s = str(readline())
answer = s.count('ABC')
print(answer)

# Optimized solution
#!/usr/bin/env python3
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
s = str(readline())
count = 0
for i in range(0,n - 2):
    if s[i] == 'A' and s[i + 1] == 'B' and s[i + 2] == 'C':
        count +=1
print(count)
# Original solution
import sys
import os
import math

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

MOD = 10 ** 9 + 7


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    S = iss()
    print((S.count('ABC')))


if __name__ == '__main__':
    main()


# Optimized solution
import sys
import os
import math

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

MOD = 10 ** 9 + 7


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    S = iss()
    ret = 0
    print((sum((S[n:n+3] == 'ABC') for n in range(N-2))))


if __name__ == '__main__':
    main()
# Original solution
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    s = str(readline().rstrip().decode('utf-8'))
    print((s.count("ABC")))


if __name__ == '__main__':
    solve()


# Optimized solution
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    print((str(readline().rstrip().decode('utf-8')).count("ABC")))


if __name__ == '__main__':
    solve()
# Original solution
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())
    S = readline().strip()

    ans = 0
    for i in range(N - 2):
        if S[i : i + 3] == 'ABC':
            ans += 1

    print(ans)
    return


if __name__ == '__main__':
    main()


# Optimized solution
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())
    S = readline().strip()
    
    print((S.count('ABC')))
    return


if __name__ == '__main__':
    main()
# Original solution
w = int(input())
n = int(input())
am = [i for i in range(w+1)]
for _ in range(n):
    a, b = map(int, input().split(','))
    am[a], am[b] = am[b], am[a]
print(*am[1:], sep="\n")


# Optimized solution
w = int(input())
n = int(input())
kuji = [i+1 for i in range(w)]
for _ in range(n):
    a, b = map(int, input().split(','))
    kuji[a-1], kuji[b-1] = kuji[b-1], kuji[a-1]
print(*kuji, sep="\n")
# Original solution
r = 1000000007
N = 100000
l = [1]*N

def egcd(a, b):
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return (lastx, lasty, a)

# ax ≡ 1 (mod m)
def modinv(a, m):
    (inv, q, gcd_val) = egcd(a, m)
    return inv % m

for i in range(1,N):
    l[i] = l[i-1]+modinv(i+1,r)

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

exp = 0
for i in range(N):
    exp += (l[i]+l[N-i-1]-1)*A[i]%r

ans = exp
for i in range(1,N+1):
    ans = ans*i%r
print(ans)

# Optimized solution
N = int(eval(input()))
A = list(map(int,input().split()))
mod = 10**9+7
def inv(n):
	n %= mod
	return pow(n,mod-2,mod)
	
H = [0]*(N+1)
for n in range(1,N+1):
	H[n] = (inv(n)+H[n-1])%mod

N_f = 1
for n in range(1,N+1):
	N_f = N_f*n%mod

ans = 0
for n in range(1,N+1):
	ans += A[n-1]*(H[N-n+1]+H[n]-1)
	ans %= mod

ans *= N_f
ans %= mod
print(ans)
# Original solution
n = int(eval(input()))
A = [int(i) for i in input().split()]

p = 10 ** 9 + 7

def fact(n, p=10**9 + 7):
    f = [1]
    for i in range(1, n+1):
        f.append(f[-1]*i%p)
    return f

def invfact(n, f, p=10**9 + 7):
    inv = [pow(f[n], p-2, p)]
    for i in range(n, 0, -1):
        inv.append(inv[-1]*i%p)
    return inv[::-1]

def get_inv(n, f, invf, p=10**9 + 7):
    inv = [0]
    for i in range(n):
        inv.append(invf[i+1] * f[i] % p)
    return inv

f = fact(30+10**5)
invf = invfact(30+10**5, f)
inv = get_inv(30+10**5, f, invf)

def comb(a, b):
    return f[a] * invf[b] * invf[a-b] % p

csum = [0]

for i in range(1, n+1):
    csum.append((csum[-1] + inv[i]) % p)

ans = 0
for i, a in enumerate(A):
    ans += (csum[i+1] + csum[n-i] - csum[1] + p) % p * a
    ans %= p

print((ans * f[n] % p))

# Optimized solution
n = int(eval(input()))
A = [int(i) for i in input().split()]

p = 10 ** 9 + 7

def fact(n, p=10**9 + 7):
    f = [1]
    for i in range(1, n+1):
        f.append(f[-1]*i%p)
    return f

def get_inv(n, p=10**9 + 7):
    inv = [0, 1]
    for i in range(2, n+1):
        inv.append(-(p//i * inv[p%i]) % p)
    return inv

f = fact(30+10**5)
inv = get_inv(30+10**5)

csum = [0]

for i in range(1, n+1):
    csum.append((csum[-1] + inv[i]) % p)

ans = 0
for i, a in enumerate(A):
    ans += (csum[i+1] + csum[n-i] - csum[1] + p) % p * a
    ans %= p

print((ans * f[n] % p))
# Original solution
n = int(eval(input()))
A = [int(i) for i in input().split()]

p = 10 ** 9 + 7

def fact(n, p=10**9 + 7):
    f = [1]
    for i in range(1, n+1):
        f.append(f[-1]*i%p)
    return f

def get_inv(n, p=10**9 + 7):
    inv = [0, 1]
    for i in range(2, n+1):
        inv.append(-(p//i * inv[p%i]) % p)
    return inv

f = fact(30+10**5)
inv = get_inv(30+10**5)

csum = [0]

for i in range(1, n+1):
    csum.append((csum[-1] + inv[i]) % p)

ans = 0
for i, a in enumerate(A):
    ans += (csum[i+1] + csum[n-i] - csum[1] + p) % p * a
    ans %= p

print((ans * f[n] % p))

# Optimized solution
n = int(eval(input()))
A = [int(i) for i in input().split()]

p = 10 ** 9 + 7

def fact(n, p=10**9 + 7):
    f = [1]
    for i in range(1, n+1):
        f.append(f[-1]*i%p)
    return f

def get_inv(n, p=10**9 + 7):
    inv = [0, 1]
    for i in range(2, n+1):
        inv.append(-(p//i * inv[p%i]) % p)
    return inv

f = fact(n)
inv = get_inv(n)

csum = [0]

for i in range(1, n+1):
    csum.append((csum[-1] + inv[i]) % p)

ans = 0
for i, a in enumerate(A):
    ans += (csum[i+1] + csum[n-i] - csum[1] + p) % p * a
    ans %= p

print((ans * f[n] % p))
# Original solution
n = int(eval(input()))
A = [int(i) for i in input().split()]

p = 10 ** 9 + 7

def fact(n, p=10**9 + 7):
    f = [1]
    for i in range(1, n+1):
        f.append(f[-1]*i%p)
    return f

def get_inv(n, p=10**9 + 7):
    inv = [0, 1]
    for i in range(2, n+1):
        inv.append(-(p//i * inv[p%i]) % p)
    return inv

f = fact(n)
inv = get_inv(n)

csum = [0]

for i in range(1, n+1):
    csum.append((csum[-1] + inv[i]) % p)

ans = 0
for i, a in enumerate(A):
    ans += (csum[i+1] + csum[n-i] - csum[1] + p) % p * a
    ans %= p

print((ans * f[n] % p))

# Optimized solution
n = int(eval(input()))
A = [int(i) for i in input().split()]

p = 10 ** 9 + 7

def fact(n, p=10**9 + 7):
    f = 1
    for i in range(1, n+1):
        f = f * i % p
    return f

def get_inv(n, p=10**9 + 7):
    inv = [0, 1]
    for i in range(2, n+1):
        inv.append(-(p//i * inv[p%i]) % p)
    return inv

f = fact(n)
inv = get_inv(n)

csum = [0]

for i in range(1, n+1):
    csum.append((csum[-1] + inv[i]) % p)

ans = 0
for i, a in enumerate(A):
    ans += (csum[i+1] + csum[n-i] - csum[1] + p) % p * a
    ans %= p

print((ans * f % p))
# Original solution
n = int(eval(input()))
A = [int(i) for i in input().split()]

p = 10 ** 9 + 7

def fact(n, p=10**9 + 7):
    f = 1
    for i in range(1, n+1):
        f *= i
        f %= p
    return f

def get_inv(n, p=10**9 + 7):
    inv = [0, 1]
    for i in range(2, n+1):
        inv.append(-(p//i * inv[p%i]) % p)
    return inv

f = fact(n)
inv = get_inv(n)

csum = [0]

for i in range(1, n+1):
    csum.append((csum[-1] + inv[i]) % p)

ans = 0
for i, a in enumerate(A):
    ans += (csum[i+1] + csum[n-i] - csum[1] + p) % p * a
    ans %= p

print((ans * f % p))

# Optimized solution
n = int(eval(input()))
A = [int(i) for i in input().split()]

p = 10 ** 9 + 7

def fact(n, p=10**9 + 7):
    f = 1
    for i in range(1, n+1):
        f *= i
        f %= p
    return f

def get_inv(n, p=10**9 + 7):
    inv = [0, 1]
    for i in range(2, n+1):
        inv.append(-(p//i * inv[p%i]) % p)
    return inv

f = fact(n)
inv = get_inv(n)

csum = [0]

for i in range(1, n+1):
    csum.append((csum[-1] + inv[i]) % p)

ans = 0
for i, a in enumerate(A):
    ans += (csum[i+1] + csum[n-i] - csum[1]) * a
    ans %= p

print((ans * f % p))
# Original solution
m=10**9+7
eval(input())
i=s=r=0
f=1
a=input().split()
for _ in a:
 s+=pow(i+1,m-2,m)
 r+=int(a[i])*~-s+int(a[~i])*s
 i+=1
 f*=i
print((r*f%m))

# Optimized solution
m=10**9+7
eval(input())
i=s=r=0
f=1
a=input().split()
for _ in a:
 s+=pow(i+1,m-2,m);r+=int(a[i])*~-s+int(a[~i])*s;i+=1;f=f*i%m
print((r*f%m))
# Original solution
from fractions import Fraction

MOD = 10 ** 9 + 7

n = int(eval(input()))
a = list(map(int, input().split()))

csum = [0]
t = 0
for i in range(1, n + 1):
    t += Fraction(1, i)
    csum.append(t)

fact = 1
t = 1
while t <= n:
    fact *= t
    fact %= MOD
    t += 1

# jが何回加算されるか
ans = 0
for j in range(n):
    coef = 0
    coef += csum[abs(j - 0) + 1]  # 左側加算
    coef += csum[abs(j - (n - 1)) + 1]  # 右側加算
    coef -= 1  # 自身を減算
    # print(coef, a[j])
    ans += coef * a[j]
    ans %= MOD

ans *= fact
ans %= MOD

print(ans)

# Optimized solution
MOD = 10 ** 9 + 7

n = int(eval(input()))
a = list(map(int, input().split()))

csum_invs = [0]
t = 0
for i in range(1, n + 1):
    t += pow(i, MOD - 2, MOD)
    t %= MOD
    csum_invs.append(t)
# print(csum_invs)

fact = []
t = 1
for i in range(1, n + 1):
    t *= i
    t %= MOD
    fact.append(t)
# print(fact)

ans = 0
for i in range(n):
    # print(i)
    t = a[i] * (csum_invs[n - i] + csum_invs[i + 1] - 1)
    t %= MOD
    ans += t

ans *= fact[-1]
ans %= MOD

print(ans)

'''
逆元の求め方: フェルマーの小定理
    a ** (-1) ≡ a ** (p - 2) (mod p)
    b / a ≡ b * a **(p - 2)
    だから、/ a をしたければ、* a ** (p -2) をすればよい
'''
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))

ret = 0
mod = int(1e9) + 7

cum = [0] * (n + 1)

for i in range(n):
    cum[i + 1] = cum[i] + a[i]


def inv(x):
    return pow(x, mod - 2, mod)


for i in range(n):
    for j in range(n):
        if i == j:
            continue
        ret += inv(abs(j - i)+1) * (a[j])
        ret %= mod
ret += cum[-1]
ret %= mod
for i in range(2, n + 1):
    ret *= i
    ret %= mod
print(ret)


# Optimized solution
n = int(eval(input()))
a = list(map(int, input().split()))

ret = 0
mod = int(1e9) + 7


def inv(x):
    return pow(x, mod - 2, mod)


inv_memo = [inv(i) for i in range(1, n+1)]
cum = [0] * (n + 1)

for i in range(n):
    cum[i + 1] = (cum[i] + inv_memo[i]) % mod

for i in range(n):
    ret += (cum[n - i] + cum[i+1] - 1) * a[i]
    ret %= mod
for i in range(2, n + 1):
    ret *= i
    ret %= mod
print(ret)
# Original solution
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
AGC028 B
"""

import itertools

n = int(eval(input()))
ali = list(map(int, input().split()))

cut = 10**9+7


def modInverse(a, b, divmod=divmod):
    r0, r1, s0, s1 = a, b, 1, 0
    while r1 != 0:
        q, rtmp = divmod(r0, r1)
        stmp = s0-q*s1
        r0, s0 = r1, s1
        r1, s1 = rtmp, stmp
    return s0 % cut


def factorial(n):
    nn = 1
    for i in range(2, n+1):
        nn = nn*i
    return(nn)


invlist = [modInverse(i, cut) for i in range(1, n+1)]
accuminv = list(itertools.accumulate(invlist, func=lambda x, y: x+y % cut))

ans = 0
nfact = factorial(n)
for i in range(n):
    sump = accuminv[i]+accuminv[n-1-i] - 1
    ans += ali[i]*sump % cut

ans = ans*nfact % cut
print(ans)




# Optimized solution
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
AGC028 B
"""

import itertools
import math

n = int(eval(input()))
ali = list(map(int, input().split()))

cut = 10**9+7


def modInverse(a, b, divmod=divmod):
    r0, r1, s0, s1 = a, b, 1, 0
    while r1 != 0:
        q, rtmp = divmod(r0, r1)
        stmp = s0-q*s1
        r0, s0 = r1, s1
        r1, s1 = rtmp, stmp
    return s0 % cut


# def factorial(n):
#     nn = 1
#     for i in range(2, n+1):
#         nn = nn*i
#     return(nn)


invlist = [modInverse(i, cut) for i in range(1, n+1)]
accuminv = list(itertools.accumulate(invlist, func=lambda x, y: x+y % cut))

ans = 0
nfact = math.factorial(n)
for i in range(n):
    sump = accuminv[i]+accuminv[n-1-i] - 1
    ans += ali[i]*sump % cut

ans = ans*nfact % cut
print(ans)