#include #include #include using i32 = std::int32_t; using u32 = std::uint32_t; using i64 = std::int64_t; using u64 = std::uint64_t; using i128 = __int128_t; using u128 = __uint128_t; using isize = std::ptrdiff_t; using usize = std::size_t; class rep { struct Iter { usize itr; constexpr Iter(const usize pos) noexcept : itr(pos) {} constexpr void operator++() noexcept { ++itr; } constexpr bool operator!=(const Iter& other) const noexcept { return itr != other.itr; } constexpr usize operator*() const noexcept { return itr; } }; const Iter first, last; public: explicit constexpr rep(const usize first, const usize last) noexcept : first(first), last(std::max(first, last)) {} constexpr Iter begin() const noexcept { return first; } constexpr Iter end() const noexcept { return last; } }; class revrep { struct Iter { usize itr; constexpr Iter(const usize pos) noexcept : itr(pos) {} constexpr void operator++() noexcept { --itr; } constexpr bool operator!=(const Iter& other) const noexcept { return itr != other.itr; } constexpr usize operator*() const noexcept { return itr; } }; const Iter first, last; public: explicit constexpr revrep(const usize first, const usize last) noexcept : first(last - 1), last(std::min(first, last) - 1) {} constexpr Iter begin() const noexcept { return first; } constexpr Iter end() const noexcept { return last; } }; template using Vec = std::vector; using Fp = atcoder::modint998244353; const auto INV2 = Fp(1) / Fp(2); void main_() { usize N; std::cin >> N; Vec A(N); for (auto& x : A) { u32 y; std::cin >> y; x = y; } Vec C(N); { Vec more(N); more[N - 1] = Fp(1); for (const auto i : revrep(1, N)) { more[i - 1] = more[i] * Fp(i); } Vec pow2(2 * N); pow2[0] = 1; for (const auto i : rep(1, 2 * N)) { pow2[i] = pow2[i - 1] * 2; } Fp sum; for (const auto i : rep(0, N - 1)) { sum += (more[i] - more[i + 1] * INV2) * pow2[2 * ((N - 1) - i) + i]; C[i] = sum; } for (const auto i : rep(0, N)) { C[N - 1] += more[i] * pow2[2 * ((N - 1) - i) + i]; } } A.resize(2 * N); C.resize(2 * N); for (const auto i : rep(0, N)) { A[2 * N - i - 1] = A[i]; C[2 * N - i - 1] = C[i]; } const auto N2 = 2 * N; std::reverse(C.begin(), C.end()); auto F = atcoder::convolution(A, C); for (const auto i : rep(N2, F.size())) { F[i - N2] += F[i]; } F.resize(N2); std::reverse(F.begin(), F.end()); const usize K = std::min(N2, (usize)(7.5 * std::sqrt(N))); Vec> D_base(K + 1); D_base[0] = {Fp(1)}; for (const auto i : rep(1, K + 1)) { D_base[i].resize(D_base[i - 1].size() + 2); for (const auto j : rep(0, D_base[i - 1].size())) { D_base[i][j] += D_base[i - 1][j]; D_base[i][j + 1] += D_base[i - 1][j] * Fp((isize)N - 3); D_base[i][j + 2] += D_base[i - 1][j]; } } Vec::const_iterator> D(K); for (const auto i : rep(0, K)) { D[i] = D_base[i].cbegin() + (D_base[i].size() / 2); } for (const auto i : rep(0, N + 1)) { if (i % K == 0 and i != 0) { const auto tmp = atcoder::convolution(F, D_base[K]); F.assign(N2, 0); for (const auto i : rep(0, tmp.size())) { F[(i + N2 - K) % N2] += tmp[i]; } } Fp ans; const isize width = i % K; for (isize i = -width; i <= width; i += 1) { ans += F[i < 0 ? i + N2 : i] * D[width][i]; } std::cout << (ans * INV2).val() << '\n'; } } int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); main_(); return 0; }