Under construction

Still being built. Things may change

Game with Polynomials 2

Time limit5sMemory limit512 MB

Summary
Given the coefficients of a polynomial modulo 998244353 and q query points, print the polynomial's value at each point.
Level

Medium5 of 10

Topics
Math, Number theory, Implementation
Solved
No attempts yet

Problem

In this problem:

  • For convenience, let 00=10^0 = 1.
  • Fix p=998244353p = 998244353. This number is prime.

Kipa wanted to set the following interactive problem.

You can call the following function:

  • evaluate(x): substitute x into the polynomial Q(x)Q(x) and return the remainder modulo pp.

You can call the evaluate function at most qq times. Your program receives nn as input and must output the coefficients of Q(x)Q(x) modulo pp.

While preparing the test cases, however, Kipa realized that evaluating a degree-nn polynomial at up to qq points in the straightforward way is O(qn)O(qn)! To avoid taking shortcuts as in last year's problem, Kipa asked Kyaryunha, a talented PSer, to somehow write a fast interactor for this problem.

Kyaryunha, in a bind, asks you for help. Let us write the interactor for Kyaryunha!

Input

The first line gives nn and qq.

The second line gives (n+1)(n+1) integers an,an−1,…,a1,a0a_n, a_{n-1}, \ldots, a_1, a_0, separated by spaces.

From the third line, qq lines give integers b1,…,bqb_1, \ldots, b_q.

Every integer from the second line onward is between 00 and p−1p-1.

Output

Print one integer per line, for a total of qq lines. The integer printed on the ii-th line must be

∑k=0nakbik mod p\sum_{k=0}^{n} a_k b_i^k \bmod p

Examples1

  1. Example 1

    Input
    1 2
    743644169 77606192
    1204
    981204
    
    Expected output
    1027
    980318