#include using namespace std; #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #ifdef _RUTHEN #include #else #define show(...) true #endif #define REP(i, n) for (int i = 0; i < (n); i++) template using V = vector; constexpr int P = 258280327; V convolution(V &a, V &b, const int n) { assert(a.size() == b.size()); if (n <= 120) { V c(n + n - 1); REP(i, n) REP(j, n) c[i + j] += a[i] * b[j]; REP(i, n + n - 1) c[i] %= P; return c; } const int n0 = (n + 1) / 2; const int n1 = n - n0; V a0(n0), a1(n1), b0(n0), b1(n1); REP(i, n0) { a0[i] = a[i]; b0[i] = b[i]; } REP(i, n1) { a1[i] = a[i + n0]; b1[i] = b[i + n0]; } V a01(n0), b01(n0); REP(i, n0) { a01[i] += a0[i]; b01[i] += b0[i]; } REP(i, n1) { a01[i] += a1[i]; b01[i] += b1[i]; if (a01[i] >= P) a01[i] -= P; if (b01[i] >= P) b01[i] -= P; } auto c0 = convolution(a0, b0, n0); auto c1 = convolution(a1, b1, n1); auto c2 = convolution(a01, b01, n0); V c(n0 + n0 + n0 + n0 - 1); REP(i, n0 + n0 - 1) { c[i] += c0[i]; c[i + n0] += c2[i] - c0[i]; if (c[i + n0] < 0) c[i + n0] += P; } REP(i, n1 + n1 - 1) { c[i + n0] -= c1[i]; if (c[i + n0] < 0) c[i + n0] += P; c[i + n0 + n0] += c1[i]; } return c; } int main() { ios::sync_with_stdio(false); cin.tie(0); int N; cin >> N; N++; V a(N); REP(i, N) cin >> a[i]; int M; cin >> M; M++; V b(M); REP(i, M) cin >> b[i]; if (N == 1 and a[0] == 0) { cout << 0 << '\n'; cout << 0 << '\n'; return 0; } if (M == 1 and b[0] == 0) { cout << 0 << '\n'; cout << 0 << '\n'; return 0; } REP(i, N) a[i] %= P; REP(i, M) b[i] %= P; int K = max(N, M); while (a.size() < K) a.push_back(0); while (b.size() < K) b.push_back(0); auto c = convolution(a, b, (int)a.size()); while (c.size() > N + M - 1) c.pop_back(); cout << c.size() - 1 << '\n'; REP(i, c.size()) cout << c[i] << " \n"[i + 1 == c.size()]; return 0; }