#include #include #include using namespace std; using namespace atcoder; using mint = modint998244353; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf32 1000000001 #define Inf64 1000000000000000001 int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); int n; cin>>n; vector a(n); rep(i,n)cin>>a[i]; vector dp(6,0); dp[0] = 1; rep(i,n){ vector ndp(6,0); ndp[0] += dp[0]; ndp[1] += dp[0] + dp[1]; ndp[3] += dp[3] + (dp[0] + dp[1] + dp[2]) * a[i]; ndp[4] += dp[3] + dp[4]; rep(j,6)ndp[j] += dp[j]; ndp[2] = 0; swap(dp,ndp); } mint ans = dp[3] + dp[4] + dp[5]; cout<