#include #include #include using namespace std; using ll = long long; #include using mint = atcoder::modint998244353; int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); ll n,k; cin>>n>>k; vector a(n); for(int i = 0;i>a[i]; ll sum = 0; for(int i = 0;i> dp(n+1,vector(3,0)); dp[n][1] = 1; for(int i = n-1;i>=0;i--){ sum -= a[i]; if(sum==a[i]) { mint b = mint(a[i]-(-k)); dp[i][2] += b * dp[i+1][1]; dp[i][0] += dp[i+1][1]; dp[i][0] += mint(a[i]-(-k)+1) * dp[i+1][0]; dp[i][2] += mint(a[i]-(-k)+1) * dp[i+1][2]; }else if(sum==a[i]+1){ mint b = mint(a[i]-(-k)); dp[i][2] += b * dp[i+1][1]; dp[i][1] += dp[i+1][1]; dp[i][0] += mint(a[i]-(-k)+1) * dp[i+1][0]; dp[i][2] += mint(a[i]-(-k)+1) * dp[i+1][2]; }else{ mint b = mint(a[i]-(-k)); dp[i][2] += b * dp[i+1][1]; dp[i][1] += dp[i+1][1]; dp[i][1] += mint(a[i]-(-k)+1) * dp[i+1][0]; dp[i][2] += mint(a[i]-(-k)+1) * dp[i+1][2]; } } mint ans = 1; for(int i = 0;i