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-----
3 4
2 2 4

-----Sample Output-----
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))

Difficulty: MEDIUM_HARD

Solutions:
import numpy as np
import sys
sys.setrecursionlimit(10 ** 9)

def mi():
	return map(int, input().split())

def ii():
	return int(input())

def isp():
	return input().split()

def deb(text):
	print('-------\n{}\n-------'.format(text))

class Polynomial:

	def __init__(self, dim=0, const=1):
		self.values = [(dim, const)]

	def __add__(self, other):
		return self.values + other.values

class PolySolver:

	def __init__(self, size, init_val=1):
		self.size = size
		self.f = np.zeros(size, np.int64)
		self.f[0] = init_val

	def multiple(self, polynomial, MOD):
		new_F = np.zeros(self.size, np.int64)
		for (dim, const) in polynomial:
			if dim != 0:
				g = np.zeros(self.size, np.int64)
				g[dim:] += self.f[:-dim]
			else:
				g = const * self.f.copy()
			new_F += g
		self.f = new_F
		self.f %= MOD

	def add(self, polynomial, MOD):
		for (dim, const) in polynomial:
			self.f[dim] += const
			self.f %= MOD

	def get_coefficient(self, dim):
		return self.f[dim]
INF = 10 ** 20

def main():
	(N, S) = mi()
	A = list(mi())
	MOD = 998244353
	F = PolySolver(3010, init_val=0)
	ans = 0
	for i in range(N):
		f = Polynomial(dim=A[i]) + Polynomial(const=1)
		F.add(Polynomial(const=1).values, MOD)
		F.multiple(f, MOD)
		ans += F.get_coefficient(S)
	print(ans % MOD)

def __starting_point():
	main()
__starting_point()


import sys
input = sys.stdin.readline
inf = 100000000000000000
mod = 998244353
(n, s) = map(int, input().split())
A = list(map(int, input().split()))
dp = [0] * (s + 1)
ans = 0
for i in range(n):
	dp[0] += 1
	for j in range(s, A[i] - 1, -1):
		dp[j] += dp[j - A[i]]
		dp[j] %= mod
	ans += dp[s]
	ans %= mod
print(ans)


def main():
	MOD = 998244353
	(N, S) = map(int, input().split())
	A = list(map(int, input().split()))
	dp = [0] * (S + 1)
	ans = 0
	for i in range(N):
		dp[0] += 1
		dp2 = [0] * (S + 1)
		for j in range(S + 1):
			dp2[j] += dp[j]
			if j + A[i] <= S:
				dp2[j + A[i]] += dp[j]
				dp2[j + A[i]] %= MOD
		dp = dp2
		ans += dp[S]
		ans %= MOD
	print(ans)
main()


(n, s) = map(int, input().split())
a = list(map(int, input().split()))
c = [0] * (s + 1)
ans = 0
mod = 998244353
for i in range(n):
	c_ = c.copy()
	if a[i] <= s:
		for j in range(a[i], s + 1):
			c[j] += c_[j - a[i]]
		c[a[i]] += i + 1
	ans += c[s]
	ans %= mod
print(ans)


(n, s) = map(int, input().split())
t = [0] * (s + 1)
m = 998244353
a = list(map(int, input().split()))
ans = 0
for i in range(n):
	d = t.copy()
	if a[i] <= s:
		for j in range(a[i], s + 1):
			t[j] += d[j - a[i]]
		t[a[i]] += i + 1
	ans += t[-1]
	ans %= m
print(int(ans))


from heapq import *
import sys
from collections import *
from itertools import *
from decimal import *
import copy
from bisect import *
import math
sys.setrecursionlimit(4100000)

def gcd(a, b):
	if a % b == 0:
		return b
	return gcd(b, a % b)
input = lambda : sys.stdin.readline().rstrip()
(N, S) = map(int, input().split())
A = list(map(int, input().split()))
mod = 998244353
dp = [0 for n in range(3001)]
c = 0
for n in range(N):
	a = A[n]
	for s in range(0, S + 1)[::-1]:
		if s + a <= S:
			dp[s + a] += dp[s]
			dp[s + a] %= mod
	dp[a] += n + 1
	dp[a] %= mod
	c += dp[S]
	c %= mod
print(c)


(n, s) = list(map(int, input().split()))
arr = list(map(int, input().split()))
mod = 998244353
ans = 0
dp = [0] * (s + 1)
for i in range(n):
	dp[0] += 1
	tmp = arr[i]
	for j in range(s, tmp - 1, -1):
		dp[j] += dp[j - tmp]
	ans += dp[s]
	ans %= mod
print(ans)


(N, S) = map(int, input().split())
A = list(map(int, input().split()))
mod = 998244353
ans = 0
q = [0] * (S + 1)
for i in range(N):
	q2 = q.copy()
	if A[i] <= S:
		for j in range(A[i], S + 1):
			q[j] += q2[j - A[i]]
		q[A[i]] += i + 1
	ans += q[S]
	ans %= mod
print(ans)


(n, s) = map(int, input().split())
A = [int(i) for i in input().split()]
mod = 998244353
dp = [0 for i in range(s + 1)]
ans = 0
for i in range(n):
	now = A[i]
	for q in range(s - now, -1, -1):
		dp[q + now] += dp[q] % mod
	if A[i] <= s:
		dp[A[i]] += i + 1
	ans += dp[s]
	ans = ans % mod
print(ans)


(N, S) = map(int, input().split())
A = list(map(int, input().split()))
mod = 998244353
f = [0] * (1 + S)
ans = 0
for i in range(N):
	g = [0] * (1 + S)
	f[0] += 1
	for j in range(1 + S):
		if j - A[i] < 0:
			g[j] = f[j]
		else:
			g[j] = f[j] + f[j - A[i]]
	ans += g[S]
	ans %= mod
	f = g
print(ans)


(n, s, *a) = map(int, open(0).read().split())
ans = 0
mod = 998244353
dp = [0] * (s + 1)
for i in range(n):
	dp[0] += 1
	if a[i] > s:
		continue
	ans += dp[s - a[i]] * (n - i)
	ans %= mod
	for j in range(s, a[i] - 1, -1):
		dp[j] += dp[j - a[i]]
		dp[j] %= mod
print(ans)


(n, s) = map(int, input().split())
a = list(map(int, input().split()))
MOD = 998244353
ptn = [0] * (s + 1)
ptn[0] = 1
ans = 0
for i in range(n):
	for j in range(s + 1)[::-1]:
		if j + a[i] > s:
			continue
		ptn[j + a[i]] += ptn[j]
	ans += ptn[s]
	ans %= MOD
	ptn[0] += 1
print(ans)


import sys
input = sys.stdin.readline
(n, s) = map(int, input().split())
A = list(map(int, input().split()))
mod = 998244353
ans = 0
B = [0] * (s + 1)
for i in range(n):
	for j in range(s, -1, -1):
		if j - A[i] >= 0:
			B[j] = (B[j] + B[j - A[i]]) % mod
	if A[i] < len(B):
		B[A[i]] += i + 1
	ans = (ans + B[s]) % mod
print(ans)


MOD = 998244353
(N, S) = map(int, input().split())
A = list(map(int, input().split()))
F = [0 for _ in range(S + 1)]
res = 0
for i in range(N):
	F[0] += 1
	for j in range(S + 1)[::-1]:
		if j - A[i] >= 0:
			F[j] += F[j - A[i]]
	res += F[S]
	res %= MOD
print(res)