AtCoder Beginner Contest 159 - Knapsack for All Segments

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

Source: atcoder | Difficulty: MEDIUM_HARD


Solutions:
import numpy as np
(N, S) = list(map(int, input().split()))
A = [0] + list(map(int, input().split()))
dt = np.array([[0 for _ in range(S + 1)] for x in range(N + 1)])
for n in range(1, N + 1):
	if A[n] <= S:
		dt[n, A[n]] += n
	if A[n] < S:
		dt[n, A[n] + 1:] += dt[n - 1, 1:S - A[n] + 1] - dt[n - 2, 1:S - A[n] + 1]
	dt[n, :] += dt[n - 1, :] * 2 - dt[n - 2, :]
	dt[n, :] %= 998244353
print(dt[N, S] % 998244353)


def main():
	MOD = 998244353
	(N, S) = list(map(int, input().split()))
	(*a,) = list(map(int, input().split()))
	dp = [0] * (S + 1)
	ret = 0
	for (i, x) in enumerate(a):
		dp[0] += 1
		if x > S:
			continue
		ret = (ret + dp[S - x] * (N - i)) % MOD
		for k in range(S - 1, x - 1, -1):
			dp[k] = (dp[k] + dp[k - x]) % MOD
	print(ret)

def __starting_point():
	main()
__starting_point()


def main():
	MOD = 998244353
	(N, S) = map(int, input().split())
	(*A,) = map(int, input().split())
	ans = 0
	dp = [0] * (S + 1)
	for (i, a) in enumerate(A, start=1):
		dp[0] = i
		ans += dp[S]
		if S >= a:
			ans += dp[S - a]
		ans %= MOD
		for s in reversed(range(a, S + 1)):
			dp[s] += dp[s - a]
			dp[s] %= MOD
	print(ans)
main()


M = 998244353
(N, S) = map(int, input().split())
ans = 0
prev = [0] * S
for (i, a) in enumerate(map(int, input().split()), 1):
	if a > S:
		continue
	prev[0] = i
	ans += prev[S - a] * (N - i + 1) % M
	for (j, s) in enumerate(prev[:S - a], a):
		if s:
			prev[j] += s
print(ans % M)


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()


def solve():
	MOD = 998244353
	(N, S) = list(map(int, input().split()))
	As = list(map(int, input().split()))
	ans = 0
	dp = [0] * (S + 1)
	dp[0] = 1
	for A in As:
		for sm in reversed(list(range(S - A + 1))):
			dp[sm + A] += dp[sm]
			dp[sm + A] %= MOD
		ans += dp[S]
		ans %= MOD
		dp[0] += 1
		dp[0] %= MOD
	print(ans)
solve()


from numpy import *
((n, s), a, m, e) = (map(int, input().split()), list(map(int, input().split())), 998244353, 3001)
D = zeros((n, e))
D[0][a[0]] = 1
for (j, i) in enumerate(a[1:]):
	D[j + 1, i] += j + 2
	D[j + 1, i:] += D[j, :e - i]
	D[j + 1, :] = (D[j + 1, :] + D[j, :]) % m
print(int(sum(D[:, s]) % m))


import sys
input = sys.stdin.readline
(N, S) = map(int, input().split())
A = list(map(int, input().split()))
dp = [[0] * (S + 1) for _ in range(N + 1)]
dp[0][0] = 1
MOD = 998244353
for i in range(N):
	for j in range(S):
		dp[i + 1][j] += dp[i][j]
		dp[i + 1][j] %= MOD
		if j + A[i] <= S:
			if j == 0:
				dp[i + 1][j + A[i]] += dp[i][j] * (i + 1)
			else:
				dp[i + 1][j + A[i]] += dp[i][j]
			dp[i + 1][j + A[i]] %= MOD
ans = 0
for i in range(1, N + 1):
	ans += dp[i][S] * (N - i + 1)
	ans %= MOD
print(ans)


(N, S) = map(int, input().split())
A = list(map(int, input().split()))
mod = 998244353
dp = [[0 for _ in range(S + 1)] for _ in range(N)]
for j in range(0, S + 1):
	if j == A[0]:
		dp[0][j] = 1
		break
for i in range(1, N):
	for j in range(0, S + 1):
		if j > A[i]:
			dp[i][j] = (dp[i - 1][j] + dp[i - 1][j - A[i]]) % mod
		elif j == A[i]:
			dp[i][j] = (dp[i - 1][j] + (i + 1)) % mod
		else:
			dp[i][j] = dp[i - 1][j]
ans = 0
for i in range(0, N):
	ans = (ans + dp[i][S]) % mod
print(ans)


mod = 998244353
(n, s) = map(int, input().split())
a = list(map(int, input().split()))
m = 3000
DP = [0] * (m + 1)
ans = 0
for ai in a:
	DP[0] += 1
	for j in reversed(range(ai, m + 1)):
		DP[j] += DP[j - ai]
		DP[j] %= mod
	ans += DP[s]
	ans %= mod
print(ans)


import numpy as np

def main():
	(n, s) = list(map(int, input().split()))
	nums = [int(c) for c in input().split()]
	mod = 998244353
	dp = np.zeros(s + 1, dtype=np.int)
	ans = 0
	for (i, num) in enumerate(nums, 1):
		dp[0] = i
		if num <= s:
			dp[num:] = dp[num:] + dp[:-num]
		dp %= mod
		ans = (ans + dp[-1]) % mod
	print(ans)

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)


import numpy as np
(n, s) = list(map(int, input().split()))
a = list(map(int, input().split()))
mod = 998244353
dp = np.zeros((s + 1, 3), dtype=np.int64)
dp[0][0] = 1
for (i, e) in enumerate(a):
	cp = dp.copy()
	dp[:, 1] += cp[:, 0]
	dp[:, 2] += cp[:, 0] + cp[:, 1]
	dp[e:, 1] += cp[:-e, 0] + cp[:-e, 1]
	dp[e:, 2] += cp[:-e, 0] + cp[:-e, 1]
	dp %= mod
ans = dp[s][2]
print(ans)


(n, s) = map(int, input().split())
a = [int(x) for x in input().split()]
mod = 998244353
dp = [[0 for _ in range(s + 1)] for __ in range(n + 1)]
dp[0][0] = 1
for i in range(n):
	for j in range(s + 1):
		dp[i + 1][j] += dp[i][j]
		if j - a[i] == 0:
			dp[i + 1][j] += i + 1
		elif j - a[i] >= 0:
			dp[i + 1][j] += dp[i][j - a[i]]
		dp[i + 1][j] %= mod
ans = 0
for i in range(n + 1):
	ans += dp[i][s]
	ans %= mod
print(ans)


import sys
sys.setrecursionlimit(2147483647)
INF = 1 << 60
MOD = 998244353
input = lambda : sys.stdin.readline().rstrip()

def resolve():
	(n, s) = map(int, input().split())
	dp = [0] * (s + 1)
	res = 0
	for a in map(int, input().split()):
		dp[0] += 1
		for i in range(s - a, -1, -1):
			dp[i + a] += dp[i]
			if dp[i + a] >= MOD:
				dp[i + a] -= MOD
		res += dp[s]
		if res >= MOD:
			res -= MOD
	print(res)
resolve()


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


(n, s) = map(int, input().split())
a = list(map(int, input().split()))
mod = 998244353
dp = [[0] * n for _ in range(3000 + 1)]
dp[a[0]][0] = 1
for i in range(1, s + 1):
	for j in range(1, n):
		if i == a[j]:
			dp[i][j] = (dp[i][j - 1] + j + 1) % mod
		elif i - a[j] > 0:
			dp[i][j] = (dp[i][j - 1] + dp[i - a[j]][j - 1]) % mod
		else:
			dp[i][j] = dp[i][j - 1] % mod
ans = 0
for j in range(n):
	ans += dp[s][j]
print(ans % mod)


def main():
	import sys
	read = sys.stdin.buffer.read
	r = 998244353
	(U, S, *A) = map(int, read().split())
	import copy
	ans = 0
	f = [0] * 3010
	for a in A:
		c = copy.copy(f)
		f = [0] * a + c[:-a]
		f = [x + y for (x, y) in zip(f, c)]
		f[0] += 1
		f[a] += 1
		ans += f[S]
	ans %= r
	print(ans)
main()


(N, S) = map(int, input().split())
A_array = list(map(int, input().split()))
mod = 998244353
sum_array = [0] * S
ans = 0
for (i, A) in enumerate(A_array):
	if A > S:
		continue
	if A == S:
		ans = (ans + (i + 1) * (N - i)) % mod
		continue
	ans = (ans + sum_array[S - A] * (N - i)) % mod
	for j in range(S - 1, A, -1):
		sum_array[j] = (sum_array[j] + sum_array[j - A]) % mod
	sum_array[A] = (sum_array[A] + (i + 1)) % mod
print(ans)


def setM():
	k = K2 // 2
	while k:
		m = int(('1' * (K2 - k) + '0' * (K2 + k)) * 3001, 2)
		M.append((k, m, ~m, (1 << K2 + k) % P))
		k //= 2
		break

def modp(n):
	for (k, m, tm, a) in M:
		n = (n & tm) + ((n & m) >> K2 + k) * a
	return n
K = 64
K2 = K // 2
P = 998244353
mm = (1 << K * 3001) - 1
mmm = (1 << K) - 1
M = []
setM()
(N, S) = map(int, input().split())
A = [int(a) for a in input().split()]
s = 0
ans = 0
for a in A:
	s += 1
	s += s << a * K
	s &= mm
	s = modp(s)
	ans += s >> S * K & mmm
print(ans % P)


import numpy as np
from sys import stdin
(N, S) = list(map(int, input().split()))
A = np.int32(input().split())
M = 998244353
V = max(A.max(), S)
ans = 0
cs = np.zeros(V + 1, dtype=np.int64)
for (i, a) in enumerate(A):
	dp = np.zeros(V + 1, dtype=np.int64)
	dp[a] = i + 1
	dp[a + 1:S + 1] = cs[np.arange(a + 1, S + 1) - a]
	cs = (cs + dp) % M
	ans = (ans + (N - i) * dp[S]) % M
print(ans)


K = 32
P = 998244353
pa = (1 << 30) - (1 << 30) % P
M = []
(N, S) = map(int, input().split())
m = int(('1' * 2 + '0' * 30) * (S + 1), 2)
mm = (1 << K * (S + 1)) - 1
A = [int(a) for a in input().split()]
s = 0
ans = 0
for a in A:
	s += 1
	s += s << a * K
	s &= mm
	s -= ((s & m) >> 30) * pa
	ans += s >> S * K
print(ans % P)


(n, s) = map(int, input().split())
A = list(map(int, input().split()))
dp = [[0] * (s + 1) for _ in range(n + 1)]
mod = 998244353
dp[0][0] = 1
ans = 0
for i in range(n):
	ni = i + 1
	for j in range(s + 1):
		nj = j
		dp[ni][nj] += dp[i][j]
		dp[ni][nj] %= mod
		nj = j + A[i]
		if nj <= s:
			dp[ni][nj] += dp[i][j]
			dp[ni][nj] %= mod
	dp[ni][0] += 1
	ans += dp[ni][s]
	ans %= mod
print(ans)


import sys
input = sys.stdin.buffer.readline

def read_int_n():
	return list(map(int, input().split()))

def slv(N, S, A):
	M = 998244353
	ans = 0
	dp = [0] * (S + 1)
	for a in A:
		dp[0] += 1
		ndp = [0] * (S + 1)
		for j in range(S + 1):
			ndp[j] += dp[j]
			ndp[j] %= M
			if j + a <= S:
				ndp[j + a] += dp[j]
				ndp[j + a] %= M
		dp = ndp
		ans += dp[S]
		ans %= M
	return ans

def main():
	(N, S) = read_int_n()
	A = read_int_n()
	print(slv(N, S, A))
main()


import sys

def input():
	return sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 7)
MOD = 998244353
(N, S) = map(int, input().split())
A = list(map(int, list(input().split())))
ans = 0
dp = [[0] * (S + 1) for _ in range(N + 1)]
for i in range(N):
	dp[i][0] += 1
	for j in range(S + 1):
		dp[i + 1][j] += dp[i][j]
		dp[i + 1][j] %= MOD
		if j + A[i] <= S:
			dp[i + 1][j + A[i]] += dp[i][j]
			dp[i + 1][j + A[i]] %= MOD
	ans += dp[i + 1][S]
	ans %= MOD
print(ans)


from sys import stdin
mod = 998244353

def main():
	(N, S) = map(int, stdin.readline().split())
	a = list(map(int, stdin.readline().split()))
	dp = [0] * (S + 1)
	ans = 0
	for A in a:
		dp[0] += 1
		for i in reversed(range(A, S + 1)):
			dp[i] += dp[i - A]
			dp[i] %= mod
		ans += dp[S]
		ans %= mod
	print(ans)
main()


import numpy as np
(n, s) = map(int, input().split())
A = list(map(int, input().split()))
mod = 998244353
ans = 0
dp = np.zeros(s + 1, np.int64)
for i in A:
	dp[0] += 1
	dp[i:] += dp[:-i].copy()
	dp %= mod
	ans += dp[-1]
print(ans % mod)


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()))
mod = 998244353
c = 0
M = [[0 for t in range(S + 1)] for j in range(N)]
M[0][0] = 2
if A[0] <= S:
	M[0][A[0]] = 1
if A[0] == S:
	c += 1
for i in range(1, N):
	M[i][0] += i + 2
	for k in range(1, S + 1):
		M[i][k] += M[i - 1][k]
		M[i][k] %= mod
		if k >= A[i]:
			M[i][k] += M[i - 1][k - A[i]]
			M[i][k] %= mod
	c += M[i][S]
	c %= mod
print(c)


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


(n, s) = list(map(int, input().split()))
a = list(map(int, input().split()))
dp = [[None] * (s + 1) for _ in range(n + 1)]
M = 998244353
for j in range(s + 1):
	dp[0][j] = 0
for i in range(n + 1):
	dp[i][0] = i + 1
for i in range(1, n + 1):
	for j in range(1, s + 1):
		dp[i][j] = dp[i - 1][j]
		if j - a[i - 1] >= 0:
			dp[i][j] += dp[i - 1][j - a[i - 1]]
		dp[i][j] %= M
print(sum((dp[i][s] for i in range(n + 1))) % M)


(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)


from sys import stdin
mod = 998244353

def solveAsPolynomial():
	import numpy as np
	(N, S) = list(map(int, stdin.readline().split()))
	a = list(map(int, stdin.readline().split()))
	ans = 0
	f = np.zeros(S + 1, np.int64)
	for A in a:
		f[0] += 1
		f[A:] += f[:-A].copy()
		f %= mod
		ans += f[S]
		ans %= mod
	return ans

def main():
	ans = solveAsPolynomial()
	print(ans)

def __starting_point():
	main()
__starting_point()


(N, S) = map(int, input().split())
A = [int(a) for a in input().split()]
X = [0] * 3001
ans = 0
P = 998244353
for (i, a) in enumerate(A):
	X[0] += 1
	for j in range(S, a - 1, -1):
		X[j] = (X[j] + X[j - a]) % P
	ans += X[S]
print(ans % P)


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


(_, s, *a) = map(int, open(0).read().split())
(c, i, *d) = [0] * 6003
for a in a:
	for j in range(s, 0, -1):
		d[a + j] += d[j]
	i += 1
	d[a] += i
	c += d[s]
print(c % 998244353)


import sys
input = sys.stdin.readline
import numpy as np
MOD = 998244353
(n, s) = map(int, input().split())
A = list(map(int, input().split()))
F = np.zeros(s + 1, dtype=np.int64)
ans = 0
for a in A:
	F[0] += 1
	F[a:] += F[:-a].copy()
	F %= MOD
	ans += F[s]
	ans %= MOD
print(ans)


import sys
sr = lambda : sys.stdin.readline().rstrip()
ir = lambda : int(sr())
lr = lambda : list(map(int, sr().split()))
MOD = 998244353
(N, S) = lr()
A = lr()
dp = [0] * (S + 1)
answer = 0
for a in A:
	dp[0] += 1
	prev = dp.copy()
	for i in range(S - a + 1):
		dp[i + a] += prev[i]
	answer += dp[-1]
print(answer % MOD)


import sys
import numpy as np
sr = lambda : sys.stdin.readline().rstrip()
ir = lambda : int(sr())
lr = lambda : list(map(int, sr().split()))
MOD = 998244353
(N, S) = lr()
A = lr()
dp = np.zeros(S + 1, np.int64)
answer = 0
for a in A:
	dp[0] += 1
	prev = dp.copy()
	dp[a:] += prev[:-a]
	dp %= MOD
	answer += dp[-1]
print(answer % MOD)


(n, s) = map(int, input().split())
now = [0] * (s + 1)
(mod1, mod2) = (10 ** 9 + 7, 998244353)
mod = mod2
ans = 0
for a in map(int, input().split()):
	now[0] += 1
	for i in range(s, -1, -1):
		now[i] = (now[i] + (0 if i < a else now[i - a])) % mod
	ans = (ans + now[-1]) % mod
print(ans)


import sys
input = sys.stdin.readline
mod = 998244353
(N, S) = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
dp = [0] * (S + 1)
for i in range(1, N + 1):
	a = A[i - 1]
	for j in range(a + 1, S + 1)[::-1]:
		dp[j] += dp[j - a]
	if a <= S:
		dp[a] += i
	ans += dp[S] * (N - i + 1)
	ans %= mod
	dp[S] = 0
print(ans)


(N, S) = map(int, input().split())
A = list(map(int, input().split()))
MOD = 998244353
dp = [0] * (S + 1)
ans = 0
for a in A:
	dp[0] += 1
	for s in range(S + 1)[::-1]:
		if a + s <= S:
			dp[a + s] = (dp[a + s] + dp[s]) % MOD
	ans += dp[S]
	ans %= MOD
print(ans)


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


import sys
sys.setrecursionlimit(10 ** 6)
readline = sys.stdin.readline
read = sys.stdin.read
(n, s, *a) = [int(i) for i in read().split()]
MOD = 998244353

def mul(c, m, dp):
	for i in range(m, c - 1, -1):
		dp[i] += dp[i - c]
		dp[i] %= MOD
dp = [0] * (s + 1)
ans = 0
for c in a:
	dp[0] += 1
	mul(c, s, dp)
	ans += dp[s]
print(ans % MOD)


(n, s) = map(int, input().split())
a = [int(j) for j in input().split()]
mod = 998244353
ans = 0
import numpy as np
dp = np.zeros(3001, np.int64)
for i in a:
	dp[0] += 1
	dp[i:] += dp[:-i].copy()
	dp %= mod
	ans += dp[s]
	ans %= mod
print(ans)


(N, S) = map(int, input().split())
mod = 998244353
A = list(map(int, input().split()))
dp1 = [[0] * (S + 1) for _ in range(N + 1)]
r = 0
for i in range(1, N + 1):
	a = A[i - 1]
	dp1[i][0] = 1
	for j in range(S + 1):
		dp1[i][j] += dp1[i - 1][j]
		if j == a:
			dp1[i][j] += 1
		if j - a >= 0:
			dp1[i][j] += dp1[i - 1][j - a]
		dp1[i][j] %= mod
	r += dp1[i][S]
print(r % mod)


import sys

def input():
	return sys.stdin.readline()[:-1]
(_, S) = list(map(int, input().split()))
A = tuple(map(int, input().split()))
mod = 998244353
ans = 0
dp = [0] * (S + 1)
for a in A:
	dp[0] += 1
	for i in range(S, a - 1, -1):
		dp[i] += dp[i - a]
		dp[i] %= mod
	ans += dp[-1]
	ans %= mod
print(ans)


import numpy as np
MOD = 998244353
(N, S) = list(map(int, input().split()))
As = list(map(int, input().split()))
dp = np.zeros((N + 1, S + 1), np.int64)
dp[:, 0] = 1
dp[1, 0] = 3
if As[0] <= S:
	dp[1, As[0]] = 1
for i in range(1, N):
	A = As[i]
	dp[i + 1] += 2 * dp[i] - dp[i - 1]
	dp[i + 1, A:] += dp[i, :-A] - dp[i - 1, :-A]
	dp[i + 1] %= MOD
print(dp[N, S])


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


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


MOD = 998244353

def main():
	import sys
	input = sys.stdin.buffer.readline
	(N, S) = (int(i) for i in input().split())
	A = [int(i) for i in input().split()]
	dp = [[0] * (S + 1) for _ in range(N + 1)]
	dp[0][0] = 1
	for i in range(N):
		dp[i + 1][0] += 1
		for j in range(S + 1):
			dp[i + 1][j] += dp[i][j]
			dp[i + 1][j] %= MOD
			if j + A[i] <= S:
				dp[i + 1][j + A[i]] += dp[i][j]
				dp[i + 1][j + A[i]] %= MOD
	ans = sum((dp[i][S] for i in range(N + 1))) % MOD
	print(ans)
main()


import numpy as np
MOD = 998244353

def main():
	(n, s) = map(int, input().split())
	a = list(map(int, input().split()))
	dp = [np.zeros(s + 1, dtype=np.int64) for i in range(n + 1)]
	ans = 0
	for i in range(n):
		if a[i] <= s:
			dp[i + 1][a[i]:] = dp[i][:-a[i]]
			dp[i + 1][a[i]] += i + 1
		dp[i + 1][:s] += dp[i][:s]
		dp[i + 1][dp[i + 1] >= MOD] -= MOD
		ans += dp[i + 1][s] * (n - i)
		ans %= MOD
	print(ans)

def __starting_point():
	main()
__starting_point()


(N, S) = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
MOD = 998244353
DP = [[0 for p in range(S + 1)] for x in range(N)]
ans = N * (A[0] == S)
if A[0] <= S:
	DP[0][A[0]] = 1
for (n, a) in enumerate(A):
	if n != 0:
		for p in range(a, S + 1):
			DP[n][p] += DP[n - 1][p - a]
		for p in range(S + 1):
			DP[n][p] += DP[n - 1][p]
			DP[n][p] %= MOD
		if a <= S:
			DP[n][a] += n + 1
	ans += DP[n][S] * (N - n) % MOD
	DP[n][S] = 0
	ans %= MOD
print(ans)


(n, s) = map(int, input().split())
a = list(map(int, input().split()))
MOD = 998244353
dp = [[1] + [0] * s for _ in range(n + 1)]
ans = 0
for i in range(n):
	for j in range(s + 1):
		dp[i + 1][j] += dp[i][j]
		dp[i + 1][j] %= MOD
		if j + a[i] <= s:
			dp[i + 1][j + a[i]] += dp[i][j]
			dp[i + 1][j + a[i]] %= MOD
	ans += dp[i + 1][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))


(N, S) = map(int, input().split())
A = list(map(int, input().split()))
mod = 998244353
ans = 0
dp = [0] * S
for (i, a) in enumerate(A):
	dp[0] += 1
	if a > S:
		continue
	ans = (ans + dp[S - a] * (N - i) % mod) % mod
	for (j, x) in enumerate(dp[:S - a]):
		dp[j + a] += x
print(ans)


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


(N, S) = map(int, input().split())
A = list(map(int, input().split()))
MOD = 998244353
dp = [[0] * (S + 1) for _ in range(N + 1)]
for (i, a) in enumerate(A):
	dp[i + 1][0] = 1
	if a <= S:
		dp[i + 1][a] = 1
	for j in range(S + 1):
		dp[i + 1][j] += dp[i][j]
		dp[i + 1][j] %= MOD
	for j in range(S + 1):
		if j + a > S:
			break
		dp[i + 1][j + a] += dp[i][j]
		dp[i + 1][j + a] %= MOD
print(sum((row[-1] for row in dp)) % MOD)


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


import sys

def main():
	MOD = 998244353
	LI = lambda : [int(x) for x in sys.stdin.readline().split()]
	(N, S) = LI()
	A = LI()
	dp = [0] * (S + 1)
	ans = 0
	for i in range(N):
		dp[0] = i + 1
		for j in range(S, 0, -1):
			if A[i] > j:
				break
			dp[j] = (dp[j] + dp[j - A[i]]) % MOD
		ans = (ans + dp[-1] * (N - i)) % MOD
		dp[-1] = 0
	print(ans)
main()


def solve():
	MOD = 998244353
	(N, S) = map(int, input().split())
	As = list(map(int, input().split()))
	dp = [[0] * 3 for _ in range(S + 1)]
	dp[0][0] = 1
	for A in As:
		for sm in reversed(range(S + 1)):
			dp[sm][2] += dp[sm][1] + dp[sm][0]
			if sm - A >= 0:
				dp[sm][2] += dp[sm - A][1] + dp[sm - A][0]
			dp[sm][2] %= MOD
			dp[sm][1] += dp[sm][0]
			if sm - A >= 0:
				dp[sm][1] += dp[sm - A][1] + dp[sm - A][0]
			dp[sm][1] %= MOD
	print(dp[S][2])
solve()


def main():
	import sys
	sys.setrecursionlimit(10 ** 9)
	input = sys.stdin.readline
	import numpy as np
	mod = 998244353
	(N, S) = map(int, input().split())
	A = list(map(int, input().split()))
	polynomial = np.zeros(S + 1, int)
	ans = 0
	for i in A:
		polynomial[0] += 1
		polynomial[i:] += polynomial[:-i].copy()
		polynomial %= mod
		ans += polynomial[S]
	print(ans % mod)
main()


import numpy as np
(N, S) = list(map(int, input().split()))
A = list(map(int, input().split()))
MOD = 998244353

def add_elements(w, i):
	a = A[i]
	w[a:] += w[:-a].copy()
	if a <= S:
		w[a] += i + 1
	w %= MOD

def main():
	w = np.zeros(S + 1, dtype=int)
	ans = 0
	for i in range(N):
		add_elements(w, i)
		ans = (ans + w[S]) % MOD
	print(ans)

def __starting_point():
	main()
__starting_point()


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) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
mod = 998244353
dp = [[0] * (s + 1) for _ in range(n + 1)]
dp[0][0] = 1
for i in range(n):
	dp[i][0] = i + 1
	for j in range(1, s + 1):
		if j >= a[i]:
			dp[i + 1][j] += dp[i][j - a[i]]
		dp[i + 1][j] += dp[i][j]
		dp[i + 1][j] %= mod
ans = 0
for i in range(1, n + 1):
	ans += dp[i][-1] * 1
	ans %= mod
print(ans)


(N, S) = map(int, input().split())
A = list(map(int, input().split()))
b = [[0] * (S + 1) for _ in range(N + 1)]
b[0][0] = int(S == 0)
MOD = 998244353
for r in range(N):
	for s in range(S + 1):
		b[r + 1][s] += b[r][s]
		if s - A[r] >= 0:
			b[r + 1][s] += b[r][s - A[r]]
		if s == A[r] or s == 0:
			b[r + 1][s] += 1
		b[r + 1][s] %= MOD
ans = 0
for i in range(N):
	ans += b[i + 1][S]
	ans %= MOD
print(ans)


import math
import numpy as np
import queue
from collections import deque, defaultdict
import heapq
from sys import stdin, setrecursionlimit
ipt = stdin.readline
setrecursionlimit(10 ** 7)

def main():
	(n, s) = list(map(int, ipt().split()))
	a = [int(i) for i in ipt().split()]
	mod = 998244353
	ans = 0
	dp = np.zeros(s + 1, dtype=int)
	for j in range(n):
		dp[0] += 1
		aj = a[j]
		ndp = dp * 1
		if s >= aj:
			dp[s - aj] *= n - j
		ndp[aj:] += dp[:-aj]
		ndp %= mod
		dp = ndp
	ans = (ans + dp[s] * (n - j)) % mod
	print(ans)
	return

def __starting_point():
	main()
__starting_point()


def main():
	import sys

	def input():
		return sys.stdin.readline().rstrip()
	(n, s) = map(int, input().split())
	a = list(map(int, input().split()))
	import numpy as np
	dp = np.zeros(s + 1, dtype=int)
	mod = 998244353
	ans = 0
	for i in range(n):
		dp[0] += 1
		dp[a[i]:] += dp[:-a[i]]
		dp %= mod
		ans += dp[-1]
		ans %= mod
	print(ans)

def __starting_point():
	main()
__starting_point()


(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)


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

def __starting_point():
	main()
__starting_point()


(n, s, *a) = map(int, open(0).read().split())
d = [0] * 3001
c = 0
for (i, a) in enumerate(a):
	for j in range(s - a, 0, -1):
		d[a + j] += d[j]
	d[a] -= ~i
	c += d[s]
print(c % 998244353)


import numpy as np
(n, s) = map(int, input().split())
a = np.array(list(map(int, input().split())))
dp = np.array([[0] * 3001 for i in range(n)])
dp[0][0] = 1
dp[0][a[0]] = 1
ans = 0
mod = 998244353
for i in range(1, n):
	dp[i] += dp[i - 1]
	dp[i][a[i]:] += dp[i - 1][:-a[i]]
	dp[i][0] += 1
	dp[i][a[i]] += 1
	dp[i] %= mod
	ans += dp[i][s]
print(ans % mod)


(N, S) = map(int, input().split())
(*a,) = map(int, input().split())
mod = 998244353
dp = [[0] * (S + 1) for _ in range(N + 1)]
dp[0][0] = 0
ans = 0
for i in range(N):
	dp[i + 1][0] += 1
	if a[i] <= S:
		dp[i + 1][a[i]] += 1
	for j in range(S + 1):
		dp[i + 1][j] += dp[i][j]
		if j >= a[i]:
			dp[i + 1][j] += dp[i][j - a[i]]
		dp[i + 1][j] %= mod
	ans += dp[i + 1][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, x) in enumerate(a):
		dp[0] += 1
		if x > s:
			continue
		ans = (ans + dp[s - x] * (n - i)) % mod
		for k in range(s - 1, x - 1, -1):
			dp[k] = (dp[k] + dp[k - x]) % mod
	print(ans)
main()


def solve():
	MOD = 998244353
	(N, S) = map(int, input().split())
	As = list(map(int, input().split()))
	dp1 = [0] * (S + 1)
	dp2S = 0
	for A in As:
		dp2S += dp1[S]
		if S - A >= 0:
			dp2S += dp1[S - A]
		if S - A == 0:
			dp2S += 1
		dp2S %= MOD
		for sm in reversed(range(A + 1, S + 1)):
			dp1[sm] += dp1[sm - A]
			dp1[sm] %= MOD
		if S - A >= 0:
			dp1[A] += dp1[0] + 1
			dp1[A] %= MOD
		dp1[0] += 1
	print(dp2S)
solve()


MOD = 998244353

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


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


import numpy as np
(n, s) = list(map(int, input().split()))
aaa = list(map(int, input().split()))
fwd_acc = np.zeros((n + 1, s + 1), dtype=np.int64)
fwd_acc[0][0] = 1
ans = 0
MOD = 998244353
for (i, a) in enumerate(aaa, start=1):
	fwd_acc[i] = fwd_acc[i - 1]
	fwd_acc[i][0] = i
	if a <= s:
		fwd_acc[i][a:] = fwd_acc[i][a:] + fwd_acc[i][:-a]
	fwd_acc[i] %= MOD
	ans = (ans + fwd_acc[i][s]) % MOD
print(ans)


import sys
sys.setrecursionlimit(10000000)
MOD = 998244353
INF = 10 ** 18
import numpy as np

def main():
	(N, S) = list(map(int, input().split()))
	A = list(map(int, input().split()))
	before = np.zeros(S + 1, np.int64)
	before[0] = 1
	ans = 0
	for a in A:
		now = np.zeros(S + 1, np.int64)
		now += before
		now[a:] += before[:-a]
		ans += now[S]
		ans %= MOD
		now[0] += 1
		now = np.mod(now, MOD)
		before = now
	print(ans)

def __starting_point():
	main()
__starting_point()


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


def main():
	(n, s) = map(int, input().split())
	A = list(map(int, input().split()))
	dp = [[0 for j in range(s + 1)] for i in range(n + 1)]
	mod = 998244353
	ans = 0
	dp[0][0] = 1
	for i in range(n):
		dp[i + 1][0] = dp[i][0] + 1
		for j in range(1, s + 1):
			if j - A[i] >= 0:
				dp[i + 1][j] += dp[i][j - A[i]]
			dp[i + 1][j] = (dp[i][j] + dp[i + 1][j]) % mod
		ans = (ans + dp[i + 1][-1]) % mod
	print(ans % mod)
main()


(n, s) = map(int, input().split())
a = list(map(int, input().split()))
mod = 998244353
dp = [0 for i in range(s + 1)]
ans = 0
tmp = [0]
for (i, ai) in enumerate(a):
	dpn = []
	dp[0] = i + 1
	for j in range(s + 1):
		if j - ai >= 0 and dp[j - ai]:
			dpn.append((dp[j] + dp[j - ai]) % mod)
		else:
			dpn.append(dp[j])
	ans = (ans + dpn[s]) % mod
	dp = dpn[:]
print(ans)


def main():
	import sys
	input = sys.stdin.readline
	(N, S) = map(int, input().split())
	A = list(map(int, input().split()))
	mod = 998244353
	dp = [[0] * (S + 1) for _ in range(N + 1)]
	dp[0][0] = 1
	for i in range(N):
		a = A[i]
		for j in range(S + 1):
			dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % mod
			if j + a <= S:
				tmp = 1
				if j == 0:
					tmp *= i + 1
				if j + a == S:
					tmp *= N - i
				dp[i + 1][j + a] = (dp[i + 1][j + a] + dp[i][j] * tmp % mod) % mod
	print(dp[-1][S])
main()


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


def f_knapsack_for_all_segments(MOD=998244353):
	import numpy as np
	(N, S) = [int(i) for i in input().split()]
	A = [int(i) for i in input().split()]
	ans = 0
	f = np.zeros(S + 1, np.int64)
	for a in A:
		f[0] += 1
		f[a:] += f[:-a].copy()
		f %= MOD
		ans += f[S]
		ans %= MOD
	return ans
print(f_knapsack_for_all_segments())


import sys
from collections import defaultdict, Counter, namedtuple, deque
import itertools
import functools
import bisect
import heapq
import math
MOD = 998244353
(n, s) = map(int, input().split())
A = list(map(int, input().split()))
dp = [[0] * (s + 1) for _ in range(n + 1)]
for i in range(n + 1):
	dp[i][0] = i + 1
ans = 0
for i in range(n):
	for j in range(s + 1):
		if s > j > 0:
			dp[i + 1][j] += dp[i][j]
		if j + A[i] <= s:
			dp[i + 1][j + A[i]] += dp[i][j]
			dp[i + 1][j + A[i]] %= MOD
	ans += dp[i + 1][s] * (n - i)
	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)


import numpy as np
(n, s) = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
mod = 998244353
f = np.zeros(s + 1, int)
for i in a:
	f[0] += 1
	f[i:] += f[:-i].copy()
	f %= mod
	ans += f[s]
print(ans % mod)


import sys
input = sys.stdin.readline
mod = 998244353
(N, S) = map(int, input().split())
A = list(map(int, input().split()))
dp = [[0] * (S + 1) for _ in range(N + 1)]
dp[0][0] = 1
for (i, a) in enumerate(A):
	dp[i + 1][0] = i + 2
	for s in range(1, S + 1):
		if s - a >= 0:
			dp[i + 1][s] = (dp[i][s] + dp[i][s - a]) % mod
		else:
			dp[i + 1][s] = dp[i][s]
ans = 0
for r in range(N + 1):
	ans = (ans + dp[r][S]) % mod
print(ans)


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


from numpy import *
M = 998244353
(N, S, *A) = list(map(int, open(0).read().split()))
a = 0
f = zeros(S + 1, int)
for b in A:
	f[0] += 1
	f[b:] += f[:-b].copy()
	f %= M
	a += f[S]
print(a % M)


(n, s) = map(int, input().split())
mod = 998244353
A = list(map(int, input().split()))
dp = [0 for _ in range(s + 1)]
p = 0
F = {0}
for i in range(n):
	dp[0] += 1
	x = [[j, dp[j]] for j in F]
	for j in x:
		if j[0] + A[i] <= s:
			dp[j[0] + A[i]] += j[1]
			dp[j[0] + A[i]] %= mod
			F.add(j[0] + A[i])
	p += dp[s]
	p %= mod
print(p)


MOD = 998244353
(N, S) = map(int, input().split())
A = list(map(int, input().split()))
dp = [[0] * (S + 10) for i in range(N + 1)]
for i in range(N):
	for j in range(S + 1):
		dp[i + 1][j] = dp[i][j]
		dp[i + 1][j] += dp[i][j - A[i]] if j >= A[i] else 0
		dp[i + 1][j] += 1 if j == A[i] or j == 0 else 0
		dp[i + 1][j] %= MOD
ans = 0
for i in range(1, N + 1):
	ans = (ans + dp[i][S]) % 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)


import numpy as np
(N, S) = map(int, input().split())
A = list(map(int, input().split()))
mod = 998244353
U = 3001
ans = 0
dp = np.zeros(U, dtype=np.int64)
dp[0] = 1
for a in A:
	newDP = np.copy(dp)
	newDP[a:] += dp[:-a]
	newDP[0] += 1
	newDP %= mod
	dp = newDP
	ans += dp[S]
	ans %= mod
print(ans)


import sys
sys.setrecursionlimit(10 ** 9)
mod = 998244353
(N, S) = list(map(int, input().split()))
A = list(map(int, input().split()))
ans = 0
num = [0] * 6020
for i in range(N):
	for j in range(3010, 0, -1):
		num[A[i] + j] += num[j]
		num[A[i] + j] %= mod
	num[A[i]] += i + 1
	num[A[i]] %= mod
	ans += num[S] * (N - i)
	ans %= mod
	num[S] = 0
print(ans)


import numpy as np
(N, S) = list(map(int, input().split()))
A = list(map(int, input().split()))
MOD = 998244353
ans = 0
dp = np.zeros(S + 1, dtype=np.int64)
for a in A:
	dp[0] += 1
	dp[a:] += dp[:-a].copy()
	dp %= MOD
	ans += dp[S]
print(ans % MOD)


import numpy as np
MOD = 998244353

def solve(A, S):
	N = len(A)
	dp = np.zeros(S + 1, dtype=int)
	res = 0
	for (i, a) in enumerate(A):
		if a > S:
			continue
		res += dp[S - a] * (N - i)
		res %= MOD
		dp[a:] += dp[:-a]
		dp[a] += i + 1
		dp %= MOD
	for (i, a) in enumerate(A):
		if a == S:
			res += (i + 1) * (N - i)
			res %= MOD
	return res % MOD

def __starting_point():
	(N, S) = map(int, input().split())
	A = tuple(map(int, input().split()))
	print(solve(A, S))
__starting_point()


def main():
	(n, s) = map(int, input().split())
	a = list(map(int, input().split()))
	mod = 998244353
	dp = [[0] * 3001 for _ in [0] * n]
	dp[0][a[0]] = 1
	for (j, i) in enumerate(a[1:]):
		dp[j + 1][i] += j + 2
		for k in range(3001 - i):
			dp[j + 1][i + k] = (dp[j + 1][i + k] + dp[j][k]) % mod
		for k in range(3001):
			dp[j + 1][k] = (dp[j + 1][k] + dp[j][k]) % mod
	print(sum([dp[i][s] for i in range(n)]) % mod)
main()


import sys
input = sys.stdin.readline

def main():
	(n, s) = map(int, input().split())
	a = tuple(map(int, input().split()))
	mod = 998244353
	res = 0
	dp = [[0] * 3003 for i in range(n)]
	for i in range(n):
		if a[i] < s:
			res = (res + dp[i - 1][s - a[i]] * (n - i)) % mod
		elif a[i] == s:
			res = (res + (i + 1) * (n - i)) % mod
		for j in range(3003):
			if j < a[i]:
				dp[i][j] = dp[i - 1][j]
			else:
				dp[i][j] = (dp[i - 1][j] + dp[i - 1][j - a[i]]) % mod
		dp[i][a[i]] += i + 1
	print(res)
main()


import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.readline())

def MI():
	return map(int, sys.stdin.readline().split())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]

def main():
	md = 998244353
	(n, s) = MI()
	aa = LI()
	dp = [0] * (s + 1)
	ans = 0
	for a in aa:
		dp[0] += 1
		for i in range(s, a - 1, -1):
			dp[i] += dp[i - a]
			dp[i] %= md
		ans += dp[s]
		ans %= md
	print(ans)
main()


mod = 998244353
(n, s) = map(int, input().split())
a = list(map(int, input().split()))
dp0 = [[0] * (s + 1) for _ in range(n + 1)]
dp1 = [[0] * (s + 1) for _ in range(n + 1)]
dp2 = [[0] * (s + 1) for _ in range(n + 1)]
dp0[0][0] = 1
for i in range(n):
	for j in range(s + 1):
		dp0[i + 1][j] += dp0[i][j]
		dp1[i + 1][j] += dp0[i][j] + dp1[i][j]
		dp2[i + 1][j] += dp0[i][j] + dp1[i][j] + dp2[i][j]
		dp0[i + 1][j] %= mod
		dp1[i + 1][j] %= mod
		dp2[i + 1][j] %= mod
		if j + a[i] <= s:
			dp1[i + 1][j + a[i]] += dp1[i][j] + dp0[i][j]
			dp2[i + 1][j + a[i]] += dp1[i][j] + dp0[i][j]
			dp1[i + 1][j + a[i]] %= mod
			dp2[i + 1][j + a[i]] %= mod
print(dp2[n][s])


import sys
input = sys.stdin.readline
(N, S) = map(int, input().split())
A = list(map(int, input().split()))
mod = 998244353
DP = [0] * (S + 1)
DP[0] = 1
ANS = 0
for a in A:
	for i in range(S - a, -1, -1):
		DP[i + a] += DP[i]
	DP[0] += 1
	ANS += DP[S]
print(ANS % mod)


import numpy as np
(N, S) = map(int, input().split())
x = [int(x) for x in input().split()]
m = np.zeros((S + 1, 3))
p = np.zeros((S + 1, 3))
p[0, 0] = 1
for i in range(1, N + 1):
	m[:, 0] = p[:, 0]
	m[:, 1] = p[:, 0] + p[:, 1]
	m[:, 2] = p[:, 0] + p[:, 1] + p[:, 2]
	m[x[i - 1]:, 1] += p[:-x[i - 1], 0] + p[:-x[i - 1], 1]
	m[x[i - 1]:, 2] += p[:-x[i - 1], 0] + p[:-x[i - 1], 1]
	p[:, 0] = m[:, 0] % 998244353
	p[:, 1] = m[:, 1] % 998244353
	p[:, 2] = m[:, 2] % 998244353
print(int(p[S, 2]))


import sys
sys.setrecursionlimit(10000000)
MOD = 998244353
INF = 10 ** 15

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


(N, S) = map(int, input().split())
dp = [0] * 3001
res = 0
for (i, a) in enumerate(map(int, input().split())):
	for w in range(S - a, 0, -1):
		dp[w + a] += dp[w]
	dp[a] += i + 1
	res += dp[S]
print(res % 998244353)


(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)


mod = 998244353
(N, S, *A) = map(int, open(0).read().split())
dp = [0] * (S + 1)
ans = 0
for (i, a) in enumerate(A, 1):
	if a <= S:
		T = dp[:]
		for j in range(a, S + 1):
			dp[j] += T[j - a]
		dp[a] += i
	ans += dp[-1]
	ans %= mod
print(ans)


(n, s) = map(int, input().split())
a = list(map(int, input().split()))
dp1 = [[0 for i in range(s + 1)] for j in range(n + 1)]
dp2 = [[0 for i in range(s + 1)] for j in range(n + 1)]
mod = 998244353
dp1[0][0] = 1
for i in range(1, n + 1):
	x = a[i - 1]
	for j in range(1, s + 1):
		p = 0
		q = 0
		if j == x:
			p += i
			q += i * (n - i + 1)
		if j > x:
			dif = dp1[i - 1][j - x]
			p = dif
			q = dif * (n + 1 - i)
		p += dp1[i - 1][j]
		q += dp2[i - 1][j]
		dp1[i][j] = p % mod
		dp2[i][j] = q % mod
print(dp2[n][s])


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


(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)


MOD = 998244353
(n, s) = map(int, input().split())
A = list(map(int, input().split()))
dp = [[0] * (s + 1) for _ in range(n + 1)]
for i in range(n):
	dp[i + 1][0] = 1
	if A[i] <= s:
		dp[i + 1][A[i]] = 1
	for j in range(s + 1):
		dp[i + 1][j] += dp[i][j]
		dp[i + 1][j] %= MOD
		if j + A[i] <= s:
			dp[i + 1][j + A[i]] += dp[i][j]
			dp[i + 1][j + A[i]] %= MOD
print(sum((i[-1] for i in dp)) % MOD)


(n, s) = map(int, input().split())
(*A,) = map(int, input().split())
p = 998244353
DP = [[0 for j in range(s + 1)] for i in range(n + 1)]
for i in range(1, n + 1):
	for j in range(s + 1):
		DP[i][j] += DP[i - 1][j]
		if j >= A[i - 1]:
			DP[i][j] += DP[i - 1][j - A[i - 1]]
		if j == A[i - 1] or j == 0:
			DP[i][j] += 1
		DP[i][j] %= p
ans = 0
for i in range(1, n + 1):
	ans += DP[i][s]
	ans %= p
print(ans)


(N, S) = map(int, input().split())
A = list(map(int, input().split()))
m = 998244353
import numpy as np
dp = np.zeros((N + 1, S + 1), dtype=np.int64)
dp[:, 0] = [1] * (N + 1)
for (i, a) in enumerate(A):
	dp[i + 1] += dp[i]
	dp[i + 1, a:] = (dp[i + 1, a:] + dp[i, :-a]) % m
print(np.sum(dp[:, -1]) % m)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
import time, random
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def main():
	(n, s) = LI()
	a = LI()
	r = 0
	dp = [0] * (s + 1)
	dp[0] = 1
	for i in range(n):
		ai = a[i]
		if ai > s:
			dp[0] += 1
			continue
		dp[s] += dp[s - ai] * (n - i)
		dp[s] %= mod2
		for j in range(s - 1, ai - 1, -1):
			dp[j] += dp[j - ai]
			dp[j] %= mod2
		dp[0] += 1
	return dp[-1] % mod2
print(main())


import numpy as np
(n, s) = list(map(int, input().split()))
a = list(map(int, input().split()))
mod = 998244353
f = np.zeros(3001, int)
ans = 0
for ai in a:
	ff = np.zeros(3001, int)
	ff += f
	ff[ai:] += f[:-ai]
	ff[0] += 1
	ff[ai] += 1
	f = ff
	f %= mod
	ans += f[s]
	ans %= mod
print(ans)


import numpy as np
(n, s) = map(int, input().split())
a = list(map(int, input().split()))
dp = [np.zeros(s + 1, dtype=np.int64) for _ in range(n + 1)]
for i in range(n + 1):
	dp[i][0] = 1
ans = 0
for (i, w) in enumerate(a):
	dp[i] += dp[i - 1]
	dp[i][w:] += dp[i - 1][:-w]
	dp[i] %= 998244353
	ans += dp[i][-1]
	ans %= 998244353
print(ans)


(N, S) = map(int, input().split())
A = list(map(int, input().split()))
mod = 998244353
dp = [0] * S
dp[0] = 1
ans = 0
for i in range(N):
	h = dp[:]
	a = A[i]
	if a > S:
		continue
	if a == S:
		ans = (ans + (i + 1) * (N - i)) % mod
		continue
	h[a] = (h[a] + i + 1) % mod
	for j in range(a + 1, S):
		h[j] = (h[j] + dp[j - a]) % mod
	ans = (ans + dp[S - a] * (N - i)) % mod
	dp = h
print(ans)


(N, S) = map(int, input().split())
mod = 998244353
A = list(map(int, input().split()))
L = [0 for _ in range(S + 1)]
p = 0
F = {0}
for i in range(N):
	L[0] += 1
	X = [[j, L[j]] for j in F]
	for j in X:
		if j[0] + A[i] <= S:
			L[j[0] + A[i]] += j[1]
			L[j[0] + A[i]] %= mod
			F.add(j[0] + A[i])
	p += L[S]
	p %= mod
print(p)


import numpy as np
mod = 998244353
(N, S) = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
coef = np.zeros(3001, dtype=int)
ans = 0
for a in A:
	coef[0] += 1
	coef[a:] += coef[:-a]
	coef %= mod
	ans += coef[S]
	ans %= mod
print(ans)


import sys
input = sys.stdin.readline
(N, S) = map(int, input().split())
a = list(map(int, input().split()))
mod = 998244353
dp = [0] * (S + 1)
for l in range(N):
	r = N - l
	x = a[l]
	if x > S:
		continue
	for i in range(S, 0, -1):
		if i + x > S:
			continue
		if i + x == S:
			dp[S] += dp[i] * r
			dp[S] %= mod
		else:
			dp[i + x] += dp[i]
			dp[i + x] %= mod
	if x == S:
		dp[S] += (l + 1) * r
		dp[S] %= mod
	else:
		dp[x] += l + 1
		dp[x] %= mod
print(dp[-1])


def main():
	mod = 998244353
	(n, s) = map(int, input().split())
	A = tuple(map(int, input().split()))
	DP = [[x + 1] + [0] * s for x in range(n + 1)]
	for (i, a) in enumerate(A):
		for j in range(1, s + 1):
			if j - a < 0:
				DP[i + 1][j] = DP[i][j]
			else:
				DP[i + 1][j] = DP[i][j] + DP[i][j - a]
			DP[i + 1][j] %= mod
	ans = 0
	for dp in DP:
		ans += dp[-1]
		ans %= mod
	print(ans)
main()


(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)


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


import numpy as np
(n, s) = list(map(int, input().split()))
a = list(map(int, input().split()))
mod = 998244353
res = 0
dp = np.zeros(s + 1, dtype=int)
for i in range(n):
	dp[0] += 1
	dp[a[i]:] += dp[:-a[i]].copy()
	dp %= mod
	res += dp[s]
	res %= mod
print(res)


(n, s) = map(int, input().split())
a = list(map(int, input().split()))
dp = [[1 if _2 == 0 else 0 for _2 in range(s + 1)] for _1 in range(n + 1)]
MOD = 998244353
for (i, ai) in enumerate(a):
	for (j, v) in enumerate(dp[i]):
		dp[i + 1][j] += v
		dp[i + 1][j] %= MOD
		if j + ai <= s:
			dp[i + 1][j + ai] += v
			dp[i + 1][j + ai] %= MOD
print(sum((dp_i[s] for dp_i in dp)) % MOD)


from sys import stdin
(N, S) = map(int, stdin.readline().split())
A = list(map(int, stdin.readline().split()))
M = 998244353
V = max(max(A), S)
ans = 0
cs = [0 for _ in range(V + 1)]
for (i, a) in enumerate(A):
	dp = [0 for _ in range(V + 1)]
	dp[a] = i + 1
	for s in range(a + 1, S + 1):
		dp[s] = cs[s - a]
	cs = [(a + b) % M for (a, b) in zip(cs, dp)]
	ans = (ans + (N - i) * dp[S]) % M
print(ans)


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


(N, S) = map(int, input().split())
A = [int(i) for i in input().split()]
mod = 998244353
dp = [[0] * (S + 1) for _ in range(N + 1)]
ret = 0
for (i, a) in enumerate(A):
	if a <= S:
		dp[i + 1][a] += i + 1
	for j in range(S, -1, -1):
		dp[i + 1][j] += dp[i][j]
		if j >= a:
			dp[i + 1][j] += dp[i][j - a]
		dp[i + 1][j] %= mod
	ret += (dp[i + 1][S] - dp[i][S]) * (N - i) % mod
	ret %= mod
print(ret)


(n, s) = map(int, input().split())
a = list(map(int, input().split()))
mod = 998244353
lst = [0 for i in range(s + 1)]
dp = [lst]
for i in range(n):
	new = [0 for i in range(s + 1)]
	new[0] = 1
	if a[i] <= s:
		new[a[i]] = 1
	for j in range(s + 1):
		if j - a[i] >= 0:
			new[j] += dp[-1][j] + dp[-1][j - a[i]]
			new[j] %= mod
		else:
			new[j] += dp[-1][j]
			new[j] %= mod
	dp.append(new)
ans = 0
for i in range(n + 1):
	ans += dp[i][-1]
	ans %= mod
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()))
dp1 = [0] * (3001 * N)
dp2 = [0] * (3001 * N)
for n in range(N):
	for s in range(3000, -1, -1):
		dp2[n * N + s] = dp2[(n - 1) * N + s]
		dp1[n * N + s] = dp1[(n - 1) * N + s]
		if s > A[n]:
			dp2[n * N + s] += dp1[(n - 1) * N + s - A[n]] * (N - n)
			dp1[n * N + s] += dp1[(n - 1) * N + s - A[n]]
		elif s == A[n]:
			dp2[n * N + s] += (n + 1) * (N - n)
			dp1[n * N + s] += n + 1
		dp2[n * N + s] %= mod
		dp1[n * N + s] %= mod
print(dp2[(N - 1) * N + S])


import numpy as np
(n, s) = map(int, input().split())
A = list(map(int, input().split()))
MOD = 998244353
U = 3010
count = 0
F = np.zeros(U + 1, np.int64)
for a in A:
	F[0] += 1
	F[a:] += F[:-a].copy()
	F %= MOD
	count += F[s]
count %= MOD
print(count)


import sys
input = sys.stdin.readline
MOD = 998244353
(n, s) = map(int, input().split())
a = [int(item) for item in input().split()]
dp = [[0] * (s + 1) for _ in range(n)]
dp[0][0] = 1
if a[0] <= s:
	dp[0][a[0]] = 1
ans = 0
for (i, item) in enumerate(a[1:]):
	for j in range(s + 1):
		dp[i + 1][j] += dp[i][j]
		dp[i + 1][j] %= MOD
		if j + item <= s:
			dp[i + 1][j + item] += dp[i][j]
			dp[i + 1][j + item] %= MOD
	if item <= s:
		dp[i + 1][item] += 1
	dp[i + 1][0] += 1
	ans += dp[i + 1][s]
	ans %= MOD
print(ans)


(N, S) = map(int, input().split())
a = list(map(int, input().split()))
dp1 = [0] * (S + 1)
ans = 0
for i in range(N):
	dp1[0] += 1
	dp2 = [0] * (S + 1)
	for j in range(S + 1):
		dp2[j] += dp1[j]
		if j + a[i] <= S:
			dp2[j + a[i]] += dp1[j]
	dp1 = dp2[:]
	ans += dp1[-1]
	ans = ans % 998244353
print(ans)


import sys
stdin = sys.stdin
ns = lambda : stdin.readline().rstrip()
ni = lambda : int(stdin.readline().rstrip())
nm = lambda : map(int, stdin.readline().split())
nl = lambda : list(map(int, stdin.readline().split()))
(n, s) = nm()
a = nl()
mod = 998244353
ans = 0
dp = [[0] * (s + 1) for i in range(n + 1)]
dp[0][0] = 1
for (i, v) in enumerate(a):
	dp[i + 1][0] = 1
	for j in range(s + 1):
		dp[i + 1][j] += dp[i][j]
		if j >= v:
			dp[i + 1][j] += dp[i][j - v]
		dp[i + 1][j] %= mod
	ans += dp[i + 1][s]
print(ans % mod)


import numpy as np
mod = 998244353
(N, S) = list(map(int, input().split()))
A = [0] + list(map(int, input().split()))
dp = np.array([[0 for _ in range(S + 1)] for i in range(N + 1)])
for k in range(0, N):
	dp[k + 1, :] += (2 * dp[k, :] - dp[k - 1, :]) % mod
	if S > A[k + 1]:
		dp[k + 1, A[k + 1] + 1:] += (dp[k, 1:S - A[k + 1] + 1] - dp[k - 1, 1:S - A[k + 1] + 1]) % mod
	if A[k + 1] <= S:
		dp[k + 1, A[k + 1]] += k + 1
print(dp[N, S] % mod)


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)


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