Given are integer sequence of length N, A = (A_1, A_2, \cdots, A_N), and an integer K.
For each X such that 1 \le X \le K, find the following value:
\left(\displaystyle \sum_{L=1}^{N-1} \sum_{R=L+1}^{N} (A_L+A_R)^X\right) \bmod 998244353

-----Constraints-----
 - All values in input are integers.
 -  2 \le N \le 2 \times 10^5
 -  1 \le K \le 300 
 -  1 \le A_i \le 10^8 

-----Input-----
Input is given from Standard Input in the following format:
N K
A_1 A_2 \cdots A_N

-----Output-----
Print K lines.
The X-th line should contain the value \left(\displaystyle \sum_{L=1}^{N-1} \sum_{R=L+1}^{N} (A_L+A_R)^X \right) \bmod 998244353.

-----Sample Input-----
3 3
1 2 3

-----Sample Output-----
12
50
216

In the 1-st line, we should print (1+2)^1 + (1+3)^1 + (2+3)^1 = 3 + 4 + 5 = 12.
In the 2-nd line, we should print (1+2)^2 + (1+3)^2 + (2+3)^2 = 9 + 16 + 25 = 50.
In the 3-rd line, we should print (1+2)^3 + (1+3)^3 + (2+3)^3 = 27 + 64 + 125 = 216.

Difficulty: competition

Starter code:

Solutions:

import numpy as np
N,K = list(map(int,input().split()))
A=np.array(list(map(int,input().split())))
mod = 998244353

fact = [1]*(K+1)
for i in range(1,K+1):
    fact[i]=i*fact[i-1]%mod
inv_fact = [pow(f,mod-2,mod) for f in fact]

# r = [sum(pow(aa,t,mod) for aa in A)%mod for t in range(K+1)]##遅い
r = [0]*(K+1)
r[0] = N
temp = np.ones(N,dtype="int32")
for i in range(1,K+1):
    temp = temp*A%mod
    r[i] = int(np.sum(temp))%mod

inv2 = pow(2,mod-2,mod)
for x in range(1,K+1):
    ans = sum((fact[x]*inv_fact[t]*inv_fact[x-t] *r[x-t]*r[t]) %mod 
               for t in range(x+1))%mod
    ans-= r[x]*pow(2,x,mod) %mod
    print(((ans*inv2)%mod))



import sys

readline = sys.stdin.readline
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    import numpy as np

    def combmoddp():
        n = 400
        comb = np.array([[0] * (n + 1) for _ in range(n + 1)])
        comb[0][0] = 1

        for i in range(1, n + 1):
            comb[i][0] = 1
            for j in range(1, i + 1):
                comb[i][j] = (comb[i - 1][j - 1] + comb[i - 1][j]) % MOD

        return comb

    MOD = 998244353
    N, K = list(map(int, readline().split()))
    A = np.array(list(map(int, readline().split())), np.int64)

    s = np.array([0] * (K + 1), np.int64)
    t = np.array([1] * N, np.int64)
    for i in range(K + 1):
        s[i] = np.sum(t) % MOD
        t = t * A
        t = np.remainder(t, MOD)

    comb = combmoddp()
    d = np.array([1] * N, np.int64)

    inv2 = pow(2, MOD - 2, MOD)
    for x in range(1, K + 1):
        ans = 0
        for i in range(x + 1):
            t = (s[i] * s[x - i]) % MOD
            t = (t * comb[x][i]) % MOD
            ans += t
        ans %= MOD

        d = 2 * A * d
        d = np.remainder(d, MOD)
        ans -= np.sum(d)
        ans %= MOD
        ans *= inv2
        ans %= MOD
        print(ans)


def __starting_point():
    main()

__starting_point()

import numpy as np
MOD = 998244353
inv2 = pow(2, MOD - 2, MOD)

factorial = [1]*301
for n in range(1, 301):
   factorial[n] = n * factorial[n - 1] % MOD
   
N, K = map(int, input().split())
A = np.array(list(map(int, input().split())))

S = [0]*(K + 1)
S[0] = N
temp = np.array([1]*N)
for x in range(1, K + 1):
   temp = temp * A % MOD
   S[x] = int(np.sum(temp))
   
for X in range(1, K + 1):
   ans = 0
   for x in range(X + 1):
       comb = factorial[X] * pow(factorial[x], MOD - 2, MOD) * pow(factorial[X - x], MOD - 2, MOD) % MOD
       ans += comb * S[x] * S[X - x] % MOD
   ans -= pow(2, X, MOD) * S[X] % MOD
   ans *= inv2
   ans %= MOD
   print(ans)



import numpy as np
N,K = list(map(int,input().split()))
A=np.array(list(map(int,input().split())))
#A=list(map(int,input().split()))
mod = 998244353

fact = [1]*(K+1)
for i in range(1,K+1):
    fact[i]=i*fact[i-1]%mod
inv_fact = [pow(f,mod-2,mod) for f in fact]

# r = [sum(pow(aa,t,mod) for aa in A)%mod for t in range(K+1)]
r = [0]*(K+1)
r[0] = N
temp = np.ones(N,dtype="int32")
for i in range(1,K+1):
    temp = temp*A%mod
    r[i] = int(np.sum(temp))%mod

inv2 = pow(2,mod-2,mod)
for x in range(1,K+1):
    
#     ans = sum((fact[x]*inv_fact[t]*inv_fact[x-t] *r[x-t]*r[t]) %mod 
#                for t in range(x+1))%mod
    
#    ans-= r[x]*pow(2,x,mod) %mod

    ans = 0
    for t in range(x+1):
        comb = fact[x]*inv_fact[t]*inv_fact[x-t] %mod
        #comb = fact[x]* pow(fact[t],mod-2,mod)*pow(fact[x-t],mod-2,mod) %mod
        ans += comb * r[x-t] * r[t] %mod
    ans-= r[x]*pow(2,x,mod) %mod
    print(((ans*inv2)%mod))