Problem:
Score : 600 points

Problem Statement

Given are a sequence of N integers A_1, A_2, \ldots, A_N and a positive integer S.

For a pair of integers (L, R) such that 1\leq L \leq R \leq N, let us define f(L, R) as follows:

f(L, R) is the number of sequences of integers (x_1, x_2, \ldots , x_k) such that L \leq x_1 < x_2 < \cdots < x_k \leq R and A_{x_1}+A_{x_2}+\cdots +A_{x_k} = S.

Find the sum of f(L, R) over all pairs of integers (L, R) such that 1\leq L \leq R\leq N. Since this sum can be enormous, print it modulo 998244353.

Constraints

All values in input are integers.

1 \leq N \leq 3000

1 \leq S \leq 3000

1 \leq A_i \leq 3000

Input

Input is given from Standard Input in the following format:

N S
A_1 A_2 ... A_N

Output

Print the sum of f(L, R), modulo 998244353.

Sample Input 1

3 4
2 2 4

Sample Output 1

5

The value of f(L, R) for each pair is as follows, for a total of 5.

f(1,1) = 0

f(1,2) = 1 (for the sequence (1, 2))

f(1,3) = 2 (for (1, 2) and (3))

f(2,2) = 0

f(2,3) = 1 (for (3))

f(3,3) = 1 (for (3))

Sample Input 2

5 8
9 9 9 9 9

Sample Output 2

0

Sample Input 3

10 10
3 1 4 1 5 9 2 6 5 3

Sample Output 3

152

Solution in Rust (1.15.1) (judge verdict: Accepted)

// This code is generated by [cargo-atcoder](https://github.com/tanakh/cargo-atcoder)
// Original source code:
/*
use proconio::input;

const MOD: u32 = 998244353;
struct S {
    n: usize,
    s: usize,
    aa: Vec<usize>,
    dp: Vec<Vec<Vec<u32>>>,
}

impl S {
    fn new(n: usize, s: usize, aa: Vec<usize>) -> Self {
        let mut dp = vec![vec![vec![0, 0, 0]; s + 1]; n + 1];
        dp[0][0][0] = 1;
        S {
            n: n,
            s: s,
            aa: aa,
            dp: dp,
        }
    }

    fn flatten(self: &mut Self) {
        for i in 0..self.n {
            for j in 0..(self.s + 1) {
                self.dp[i + 1][j][0] += self.dp[i][j][0];
                self.dp[i + 1][j][0] %= MOD;

                self.dp[i + 1][j][1] += self.dp[i][j][0] + self.dp[i][j][1];
                self.dp[i + 1][j][1] %= MOD;

                self.dp[i + 1][j][2] += self.dp[i][j][0] + self.dp[i][j][1] + self.dp[i][j][2];
                self.dp[i + 1][j][2] %= MOD;

                let next_s = j + self.aa[i];
                if next_s <= self.s {
                    self.dp[i + 1][next_s][1] += self.dp[i][j][0] + self.dp[i][j][1];
                    self.dp[i + 1][next_s][1] %= MOD;
                    self.dp[i + 1][next_s][2] += self.dp[i][j][0] + self.dp[i][j][1];
                    self.dp[i + 1][next_s][2] %= MOD;
                }
            }
        }
    }
}

fn main() {
    input!(n: usize, s: usize);
    input!(aa: [usize; n]);

    let mut solver = S::new(n, s, aa);
    solver.flatten();

    println!("{}", solver.dp[n][s][2]);
}
*/

fn main() {
    let exe = "/tmp/binC5CAB66C";
    std::io::Write::write_all(&mut std::fs::File::create(exe).unwrap(), &decode(BIN)).unwrap();
    std::fs::set_permissions(exe, std::os::unix::fs::PermissionsExt::from_mode(0o755)).unwrap();
    std::process::exit(std::process::Command::new(exe).status().unwrap().code().unwrap())
}

fn decode(v: &str) -> Vec<u8> {
    let mut ret = vec![];
    let mut buf = 0;
    let mut tbl = vec![64; 256];
    for i in 0..64 { tbl[TBL[i] as usize] = i as u8; }
    for (i, c) in v.bytes().filter_map(|c| { let c = tbl[c as usize]; if c < 64 { Some(c) } else { None } }).enumerate() {
        match i % 4 {
            0 => buf = c << 2,
            1 => { ret.push(buf | c >> 4); buf = c << 4; }
            2 => { ret.push(buf | c >> 2); buf = c << 6; }
            3 => ret.push(buf | c),
            _ => unreachable!(),
        }
    }
    ret
}

const TBL: &'static [u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
const BIN: &'static str = "<base64-encoded ELF executable removed>";