Polynomial and Queries

Evaluate a degree-N polynomial with integer coefficients at K given points, all modulo the prime 786433, with N and K up to 250000.

Hard9Number theoryDivide and conquerMathImplementationNo attempts yetTime limit10sMemory limit512 MB

Problem

You are given a polynomial f(x)=a0+a1x+a2x2++aNxNf(x) = a_0 + a_1 x + a_2 x^2 + \cdots + a_N x^N of degree NN with integer coefficients.

Given the integers x1,x2,,xKx_1, x_2, \ldots, x_K, write a program that computes f(xj)f(x_j) modulo 786433 for every jj.

Input

The first line contains the degree NN of the polynomial. (0N2500000 \le N \le 250000)

The second line contains N+1N+1 integers. The ii-th integer is the coefficient ai1a_{i-1}. (0ai<7864330 \le a_i < 786433)

The third line contains the number of integers KK. (1K2500001 \le K \le 250000)

The fourth line contains x1,x2,,xKx_1, x_2, \ldots, x_K. (0xj<7864330 \le x_j < 786433)

Output

Print KK lines. The ii-th line contains f(xi)f(x_i) modulo 786433.