#include <algorithm> #include <bits/stdc++.h> #ifdef SHO_LOCAL #include "debug.h" #else #define debug(...) \ {} #endif using namespace std; constexpr const long long _mod = 998244353; struct mint; static vector<mint> inv_memo; static vector<mint> fact_memo; struct mint { using ll = long long; ll raw_val; mint(ll x = 0) { raw_val = (x % _mod + _mod) % _mod; } inline mint operator-() const { return mint(-raw_val); } inline mint &operator+=(const mint a) { if ((raw_val += a.raw_val) >= _mod) raw_val -= _mod; return *this; } inline mint &operator-=(const mint a) { if ((raw_val += _mod - a.raw_val) >= _mod) raw_val -= _mod; return *this; } inline mint &operator*=(const mint a) { (raw_val *= a.raw_val) %= _mod; return *this; } inline mint operator+(const mint a) const { return mint(*this) += a; } inline mint operator-(const mint a) const { return mint(*this) -= a; } inline mint operator*(const mint a) const { return mint(*this) *= a; } inline mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } inline mint inv() const { if ((int)inv_memo.size() > raw_val) { return inv_memo[raw_val]; } return pow(_mod - 2); } inline mint &operator/=(const mint a) { return *this *= a.inv(); } inline mint operator/(const mint a) const { return mint(*this) /= a; } }; static inline mint factorial(int n) { mint res(1); for (int i = 2; i <= n; i++) { res *= i; } return res; } struct mcombination { vector<mint> f, invf; mcombination(const int n) : f(n + 1), invf(n + 1) { f[0] = 1; for (int i = 1; i <= n; ++i) f[i] = f[i - 1] * i; invf[n] = f[n].inv(); for (int i = n; i >= 1; --i) invf[i - 1] = invf[i] * i; } inline mint _c(const int n, const int k) const { if (k < 0 || k > n) return 0; return f[n] * invf[k] * invf[n - k]; } inline mint operator()(const int n, const int k) const { return _c(n, k); } inline mint h(const int n, const int r) const { return _c(n + r - 1, r); } }; static inline istream &operator>>(istream &is, mint &a) { return is >> a.raw_val; } static inline ostream &operator<<(ostream &os, const mint &a) { return os << a.raw_val; } int main() { iostream::sync_with_stdio(0), cin.tie(0), cout.tie(0); int n; cin >> n; vector<int> A(n); for (int i = 0; i < n; i++) { cin >> A[i]; } mint ans; for (int i = 0; i < n; i++) { int a = A[i]; if (i < n - 1) ans += (mint(2).pow(n - i - 1) - 1) * a; ans -= (mint(2).pow(i) - 1) * a; } cout << ans << '\n'; return 0; }