#include #include using namespace std; const long long MOD = 998244353; long long modpow(long long a, long long b){ long long ans = 1; while (b > 0){ if (b % 2 == 1){ ans *= a; ans %= MOD; } a *= a; a %= MOD; b /= 2; } return ans; } long long modinv(long long a){ return modpow(a, MOD - 2); } vector diff(vector A){ int N = A.size(); vector B(N - 1); for (int i = 1; i < N; i++){ B[i - 1] = A[i] * i % MOD; } return B; } vector polynomial_inverse(vector f){ int N = f.size(); vector ans(1); ans[0] = modinv(f[0]); for (int i = 1; i < N * 2; i *= 2){ vector ans2 = ans; ans2.resize(i * 4); int N2 = min(N, i * 2); vector f2(i * 4, 0); for (int j = 0; j < N2; j++){ f2[j] = f[j]; } ans2 = atcoder::convolution(ans2, ans2); ans2.resize(i * 2); ans2 = atcoder::convolution(ans2, f2); ans2.resize(i * 2); for (int j = 0; j < i; j++){ ans2[j] = MOD - ans2[j] + ans[j] * 2; ans2[j] %= MOD; } swap(ans, ans2); } ans.resize(N); return ans; } vector polynomial_quotient(vector f, vector g){ int N = f.size(), M = g.size(); if (N < M){ return {0}; } reverse(g.begin(), g.end()); g.resize(N - M + 1); vector t = polynomial_inverse(g); reverse(f.begin(), f.end()); vector q = atcoder::convolution(f, t); q.resize(N - M + 1); reverse(q.begin(), q.end()); return q; } vector polynomial_remainder(vector f, vector g){ int N = f.size(); int M = g.size(); if (M <= 100){ for (int i = N - M; i >= 0; i--){ long long q = f[i + M - 1] * modinv(g[M - 1]) % MOD; for (int j = 0; j < M; j++){ f[i + j] += MOD - q * g[j] % MOD; f[i + j] %= MOD; } f.pop_back(); } return f; } else { vector q = polynomial_quotient(f, g); vector b = atcoder::convolution(g, q); for (int i = 0; i < N; i++){ f[i] += MOD - b[i]; f[i] %= MOD; } f.resize(M - 1); return f; } } vector multipoint_evaluation(vector f, vector x){ int M = x.size(); vector> g(M * 2 - 1, {1}); for (int i = 0; i < M; i++){ g[M - 1 + i] = vector{MOD - x[i], 1}; } for (int i = M - 2; i >= 0; i--){ g[i] = atcoder::convolution(g[i * 2 + 1], g[i * 2 + 2]); } g[0] = polynomial_remainder(f, g[0]); for (int i = 1; i < M * 2 - 1; i++){ g[i] = polynomial_remainder(g[(i - 1) / 2], g[i]); } vector ans(M); for (int i = 0; i < M; i++){ ans[i] = g[M - 1 + i][0]; } return ans; } int main(){ int N; cin >> N; vector A(N); for (int i = 0; i < N; i++){ cin >> A[i]; } long long ans = 1; auto dfs = [&](auto dfs, int L, int R) -> vector { if (R - L == 1){ return vector{MOD - A[L], 1}; } int m = (L + R) / 2; vector fL = dfs(dfs, L, m); vector fR = dfs(dfs, m, R); vector x(R - m); for (int i = 0; i < R - m; i++){ x[i] = A[m + i]; } vector y = multipoint_evaluation(fL, x); for (int i = 0; i < R - m; i++){ ans *= y[i]; ans %= MOD; } vector f = atcoder::convolution(fL, fR); return f; }; dfs(dfs, 0, N); if ((long long) N * (N - 1) / 2 % 2 == 1){ ans = (MOD - ans) % MOD; } cout << ans << endl; }