#pragma GCC target("avx2") #pragma GCC optimize("Ofast,unroll-loops") #include const int p = 1009; long long pow_mod(int n, long long k) { long long N, ans = 1; for (N = n; k > 0; k >>= 1, N = N * N % p) if (k & 1) ans = ans * N % p; return ans; } #define MT_N 624 #define MT_M 397 #define MT_MATRIX_A 0x9908b0dfUL #define MT_UPPER_MASK 0x80000000UL #define MT_LOWER_MASK 0x7fffffffUL static unsigned int mt[MT_N]; static int mti = MT_N + 1; void init_genrand(unsigned int s) { mt[0] = s & 0xffffffffUL; for (mti = 1; mti < MT_N; mti++) { mt[mti] = (1812433253UL * (mt[mti-1] ^ (mt[mti-1] >> 30)) + mti); mt[mti] &= 0xffffffffUL; } } unsigned int genrand() { unsigned int y; static unsigned int mag01[2] = {0x0UL, MT_MATRIX_A}; if (mti >= MT_N) { int kk; if (mti == MT_N + 1) init_genrand(5489UL); for (kk = 0; kk < MT_N - MT_M; kk++) { y = (mt[kk] & MT_UPPER_MASK) | (mt[kk+1] & MT_LOWER_MASK); mt[kk] = mt[kk+MT_M] ^ (y >> 1) ^ mag01[y&0x1UL]; } for (; kk < MT_N - 1; kk++) { y = (mt[kk] & MT_UPPER_MASK) | (mt[kk+1] & MT_LOWER_MASK); mt[kk] = mt[kk+(MT_M-MT_N)] ^ (y >> 1) ^ mag01[y&0x1UL]; } y = (mt[MT_N-1] & MT_UPPER_MASK) | (mt[0] & MT_LOWER_MASK); mt[MT_N-1] = mt[MT_M-1] ^ (y >> 1) ^ mag01[y&0x1UL]; mti = 0; } y = mt[mti++]; y ^= (y >> 11); y ^= (y << 7) & 0x9d2c5680UL; y ^= (y << 15) & 0xefc60000UL; y ^= (y >> 18); return y; } int main() { int i, M, N, K[400001], A[2001]; scanf("%d %d", &M, &N); for (i = 0; i <= M; i++) scanf("%d", &(K[i])); for (i = 0; i <= N; i++) scanf("%d", &(A[i])); // for (i = 0, K[0] = p - 1; i <= N; i++) A[i] = genrand() % p; // A[0] = 2; int j, k; long long B[1009][2001]; for (i = 1, B[0][0] = 1; i <= N; i++) B[0][i] = 0; for (i = 0; i <= N; i++) B[1][i] = A[i]; for (k = 2; k < p; k++) { for (i = 0; i <= N; i++) for (j = 0, B[k][i] = 0; j <= i; j++) B[k][i] += B[k-1][j] * A[i-j]; for (i = 0; i <= N; i++) B[k][i] %= p; } if (A[0] == 0) { for (i = M, k = 0; i >= 0 && k < p; i--) k = k * p + K[i]; if (k < p) for (i = 0; i <= N; i++) printf("%lld ", B[k][i]); else for (i = 0; i <= N; i++) printf("0 "); } else { for (i = M, k = 0; i >= 1; i--) k = (k * p + K[i]) % (p - 1); k = pow_mod(A[0], k); for (i = 0; i <= N; i++) B[0][i] = 0; B[0][0] = k; B[0][p] = A[1] * k % p; for (k = 1; k <= K[0]; k++) { for (i = 0; i <= N; i++) for (j = 0, B[k][i] = 0; j <= i; j++) B[k][i] += B[k-1][j] * A[i-j]; for (i = 0; i <= N; i++) B[k][i] %= p; } for (i = 0; i <= N; i++) printf("%lld ", B[K[0]][i]); } printf("\n"); fflush(stdout); return 0; }