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:
/*
#![allow(bare_trait_objects)]
#![allow(unused_imports)]
#![allow(dead_code)]

extern crate rust_procon_lib;
use rust_procon_lib::scanner::*;

use std::ops::*;

pub const MOD: u64 = 998244353;

#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub struct ModInt(u64);

impl std::fmt::Display for ModInt {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.0)
    }
}

impl ModInt {
    pub fn inv(&self) -> Self {
        Self::from(1) / *self
    }

    pub fn pow<T: Into<i64>>(&self, y: T) -> Self {
        let y = y.into();
        if y < 0 {
            return ModInt::from(1) / self.pow(-y);
        }

        let mut y = y as u64;
        let mut res = ModInt::from(1);
        let mut x = self.clone();
        while y > 0 {
            if y % 2 == 1 {
                res *= x;
            }
            y /= 2;
            x *= x;
        }
        res
    }
}

// impl<T: Into<i64>> From<T> for ModInt {
//     fn from(v: T) -> Self {
//         ModInt((MOD + (v.into() % (MOD as i64)) as u64) % MOD)
//     }
// }

impl From<i64> for ModInt {
    fn from(v: i64) -> Self {
        ModInt((MOD + (v as i64 % (MOD as i64)) as u64) % MOD)
    }
}

macro_rules! from_impl {
    ($($t:ty)*) => {
        $(
            impl From<$t> for ModInt {
                fn from(v: $t) -> Self {
                    ModInt::from(v as i64)
                }
            }
        )*
    };
}

macro_rules! ops_impl {
    ($($t:ty)*) => {
        $(
            impl AddAssign<$t> for ModInt {
                fn add_assign(&mut self, rhs: $t) {
                    *self += ModInt::from(rhs);
                }
            }

            impl Add<$t> for ModInt {
                type Output = Self;
                fn add(mut self, rhs: $t) -> Self {
                    self += rhs;
                    self
                }
            }
            impl SubAssign<$t> for ModInt {
                fn sub_assign(&mut self, rhs: $t) {
                    self.0 = round_mod(self.0 + MOD - ModInt::from(rhs).0);
                }
            }
            impl Sub<$t> for ModInt {
                type Output = Self;
                fn sub(mut self, rhs: $t) -> Self {
                    self -= rhs;
                    self
                }
            }

            impl MulAssign<$t> for ModInt {
                fn mul_assign(&mut self, rhs: $t) {
                    self.0 = self.0 * ModInt::from(rhs).0 % MOD;
                }
            }

            impl Mul<$t> for ModInt {
                type Output = Self;
                fn mul(mut self, rhs: $t) -> Self {
                    self *= rhs;
                    self
                }
            }

            impl DivAssign<$t> for ModInt {
                fn div_assign(&mut self, rhs: $t) {
                    self.0 = self.0 * ModInt::from(rhs).pow(MOD as i64 - 2).0 % MOD;
                }
            }

            impl Div<$t> for ModInt {
                type Output = Self;
                fn div(mut self, rhs: $t) -> Self {
                    self /= rhs;
                    self
                }
            }

        )*
    };
}

from_impl!(usize u8 u16 u32 u64 isize i8 i16 i32);
ops_impl!(usize u8 u16 u32 u64 isize i8 i16 i32 i64);

// impl From<usize> for ModInt {
//     fn from(v: usize) -> Self {
//         ModInt::from(v as i64)
//     }
// }

fn round_mod(mut v: u64) -> u64 {
    if v >= MOD {
        v -= MOD;
    }
    v
}

impl AddAssign for ModInt {
    fn add_assign(&mut self, rhs: Self) {
        self.0 = round_mod(self.0 + rhs.0);
    }
}

impl Add for ModInt {
    type Output = Self;
    fn add(mut self, rhs: Self) -> Self {
        self += rhs;
        self
    }
}

impl SubAssign for ModInt {
    fn sub_assign(&mut self, rhs: Self) {
        self.0 = round_mod(self.0 + MOD - rhs.0);
    }
}

impl Sub for ModInt {
    type Output = Self;
    fn sub(mut self, rhs: Self) -> Self {
        self -= rhs;
        self
    }
}

impl MulAssign for ModInt {
    fn mul_assign(&mut self, rhs: Self) {
        self.0 = self.0 * rhs.0 % MOD;
    }
}

impl Mul for ModInt {
    type Output = Self;
    fn mul(mut self, rhs: Self) -> Self {
        self *= rhs;
        self
    }
}

impl DivAssign for ModInt {
    fn div_assign(&mut self, rhs: Self) {
        self.0 = self.0 * rhs.pow(MOD as i64 - 2).0 % MOD;
    }
}

impl Div for ModInt {
    type Output = Self;
    fn div(mut self, rhs: Self) -> Self {
        self /= rhs;
        self
    }
}

fn main() {
    let mut sc = Scanner::from_stdin();
    let n = sc.usize();
    let s = sc.usize();
    let a = sc.vec_usize(n);

    // dp[sum] := left sum
    let mut dp = vec![ModInt::from(0); 3001];
    let mut ans: ModInt = 0.into();
    for i in 0..n {
        for j in (0..=3000-a[i]).rev() {
            let v = dp[j];
            dp[j+a[i]] += v;
        }
        dp[a[i]] += ModInt::from(i + 1);
        ans += dp[s] * ModInt::from(n - i);
        dp[s] = 0.into();
    }

    println!("{}", ans);
}
*/

fn main() {
    let exe = "/tmp/bin03248EA4";
    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>";