CodeEff/ECCO huggingface dataset:
# Original solution
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

n, k = list(map(int, readline().split()))
r, s, p = list(map(int, readline().split()))
t = read().rstrip().decode("utf-8")

hands = ['r', 's', 'p']

points = {}

player = {}
player['r'] = 'p'
player['s'] = 'r'
player['p'] = 's'
points['p'] = p
points['r'] = r
points['s'] = s

ans = 0

for i in range(k):
    t_ = t[i::k] + '.'
    myhand = ['.'] * len(t_)
    for i in range(len(t_) - 1):
        c = t_[i]
        if i < 1:
            ans += points[player[c]]
            myhand[i] = player[c]
        elif player[c] != myhand[i-1]:
            ans += points[player[c]]
            myhand[i] = player[c]
        else:
            myhand[i] = set(hands) and not player[c] and player[t_[i+1]]

print(ans)

# Optimized solution
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

n, k = list(map(int, readline().split()))
r, s, p = list(map(int, readline().split()))
t = read().rstrip().decode("utf-8")


points = {}
player = {}

player['r'] = 'p'
player['s'] = 'r'
player['p'] = 's'
points['p'] = p
points['r'] = r
points['s'] = s

ans = 0

for i in range(k):
    t_ = t[i::k] + '.'
    hands = ['.'] * len(t_)
    for i in range(len(t_) - 1):
        c = t_[i]
        if i < 1:
            ans += points[player[c]]
            hands[i] = player[c]
        elif player[c] != hands[i-1]:
            ans += points[player[c]]
            hands[i] = player[c]
        else:
            hands[i] = set(player.values()) and not player[c] and player[t_[i+1]]

print(ans)
# Original solution
# 2019-11-15 00:35:39(JST)
import sys
import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np 

def main():
    s = sys.stdin.readline().rstrip()
    for v in list(collections.Counter(s).values()):
        if v == 2:
            continue
        else:
            ans = 'No'
            break
    else:
        ans = 'Yes'

    print(ans)

if __name__ == "__main__":
    main()


# Optimized solution
import sys

s = sys.stdin.readline().rstrip()

def main():
    for char in set(s):
        if s.count(char) != 2:
            return 'No'
    return 'Yes'

if __name__ == '__main__':
    ans = main()
    print(ans)
# Original solution
def main():
  import sys
  read = sys.stdin.buffer.read
  r = 998244353
  U, S, *A = list(map(int, read().split()))
  import copy
  ans = 0
  f = [0]*3010
  for a in A:
      c = copy.deepcopy(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)
if __name__ == '__main__':
    main()

# Optimized solution
def main():
  import sys
  read = sys.stdin.buffer.read
  r = 998244353
  U, S, *A = list(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)
if __name__ == '__main__':
    main()
# Original solution
from copy import deepcopy

N, S = list(map(int, input().split()))
A = [0] + list(map(int, input().split()))
mod = 998244353

dp = [0] * (S + 1)
dp2 = [0] * (S + 1)

"""
dp[i][j] = (i個までの数を使ってj点とる組み合わせ)
としたはいいが、f(L, R)をf(1,L)とf(1, R)に分解できずに爆死したのが敗因。

各(L, R)に対してdpするとTLEになるから手詰まりになると思ったわけだけど、
上のdpテーブルを各iに対して使い回しつつ、新たなdpテーブル[1, 0, 0, ...]を
作成して「元のdpテーブルに加算しておけば」dpテーブル一個で1番目スタート、2番目スタート、
..., L番目スタートのdpテーブル全てを考えられる！
（解説放送前半を参考）
"""

# i == 0の時
dp[0] = 1
ans = 0

# i >= 1の時
for i in range(1, N + 1):
    for j in range(S + 1):
        if j - A[i] < 0:
            dp2[j] = dp[j]
        else:
            dp2[j] = dp[j] + dp[j - A[i]]
    ans += dp2[S]
    ans %= mod

    dp = deepcopy(dp2)
    dp[0] += 1
    dp2 = [0] * (S + 1)

print(ans)


# Optimized solution
N, S = list(map(int, input().split()))
A = [0] + list(map(int, input().split()))
mod = 998244353

dp = [0] * (S + 1)
dp2 = [0] * (S + 1)

"""
dp[i][j] = (i個までの数を使ってj点とる組み合わせ)
としたはいいが、f(L, R)をf(1,L)とf(1, R)に分解できずに爆死したのが敗因。

各(L, R)に対してdpするとTLEになるから手詰まりになると思ったわけだけど、
上のdpテーブルを各iに対して使い回しつつ、新たなdpテーブル[1, 0, 0, ...]を
作成して「元のdpテーブルに加算しておけば」dpテーブル一個で1番目スタート、2番目スタート、
..., L番目スタートのdpテーブル全てを考えられる！
（解説放送前半を参考）
"""

# i == 0の時
dp[0] = 1
ans = 0

# i >= 1の時
for i in range(1, N + 1):
    for j in range(S + 1):
        if j - A[i] < 0:
            dp2[j] = dp[j]
        else:
            dp2[j] = dp[j] + dp[j - A[i]]
    ans += dp2[S]
    ans %= mod

    dp = dp2 # deepcopyしなくてもこれで十分なはずだし、ポインタ渡しなので高速？
    dp[0] += 1
    dp2 = [0] * (S + 1)

print(ans)
# Original solution
N, S = list(map(int, input().split()))
A = list(map(int, input().split()))
d = sum(A)
mod = 998244353

"""
多項式係数を使った数え上げでリベンジしてみる。
maspyさんのを参考に実装する。

やってみてわかったけど、実装自体はdpでやったのとほぼ同じ。
多項式係数を使う方法は実質flexibleなdpということ？
"""

f = [0] * (1 + d) # f[i] = (coefficient of degree i)
ans = 0

for i in range(N):
    g = [0] * (1 + d) # g = (1 + f) * (1 + x^{A[i]})
    f[0] += 1
    for j in range(1 + d):
        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)


# Optimized solution
N, S = list(map(int, input().split()))
A = list(map(int, input().split()))
#d = sum(A)
mod = 998244353

"""
多項式係数を使った数え上げでリベンジしてみる。
maspyさんのを参考に実装する。

（注意）多項式係数全てを書き下すと、d = sum(A)次式になるが、
これは Ai*N = 3000*3000 次になりTLEする。。。
S次の項までで打ち切る事を忘れない事。

やってみてわかったけど、実装自体はdpでやったのとほぼ同じ。
多項式係数を使う方法は実質flexibleなdpということ？
"""

f = [0] * (1 + S) # f[i] = (coefficient of degree i)
ans = 0

for i in range(N):
    g = [0] * (1 + S) # g = (1 + f) * (1 + x^{A[i]})
    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)
# Original solution
from collections import defaultdict
import sys
input = sys.stdin.readline

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

# Optimized solution
import sys
input = sys.stdin.readline

mod = 998244353
N, S = list(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)
# Original solution
mod = 998244353
N,S = list(map(int,input().split()))
A = list(map(int,input().split()))

dp = [[[0]*2 for s in range(3001)] for i in range(N)]

for n in range(N):
    for s in range(3000,-1,-1):
        dp[n][s][1] = dp[n-1][s][1]
        dp[n][s][0] = dp[n-1][s][0]
        if s>A[n]:
            dp[n][s][1] += dp[n-1][s-A[n]][0]*(N-n)
            dp[n][s][0] += dp[n-1][s-A[n]][0]
        elif s==A[n]:
            dp[n][s][1] += (n+1)*(N-n)
            dp[n][s][0] += n+1
        dp[n][s][1] %= mod
        dp[n][s][0] %= mod

print((dp[N-1][S][1]))

# Optimized solution
mod = 998244353
N,S = list(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]))
# Original solution
import sys

# import bisect
# from collections import Counter, deque, defaultdict
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter

# import math

# from numba import jit

# from scipy import
# import numpy as np
# import networkx as nx

# import matplotlib.pyplot as plt

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, s = list(map(int, readline().split()))
    a = list(map(int, readline().split()))

    dp = [[0] * 6005 for _ in range(2)]
    dp[0][0] = 1
    dp[1][0] = 2
    dp[1][a[0]] = 1

    for ai in range(1, n):
        dp_temp = [0] * 6005
        w = a[ai]
        dp_temp[0] = 1
        for si in range(s + 1):
            dp_temp[si] += dp[ai][si]
            dp_temp[si + w] += dp[ai][si]
        dp.append(dp_temp)

    ans = 0
    for ai in range(n + 1):
        ans += dp[ai][s]

    print((ans % 998244353))


if __name__ == '__main__':
    main()


# Optimized solution
import sys

readline = sys.stdin.readline
MOD = 998244353
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, s = list(map(int, readline().split()))
    a = list(map(int, readline().split()))
    dp = [[0] * (s + 1) for _ in range(n + 1)]
    dp[0][0] = 1

    for i in range(n):
        cur = a[i]
        dp[i + 1][0] += 1
        for j in range(s + 1):
            dp[i + 1][j] += dp[i][j]
            dp[i + 1][j] %= MOD
            nx = cur + j
            if nx <= s:
                dp[i + 1][nx] += dp[i][j]
                dp[i + 1][nx] %= MOD
    ans = 0

    for i in range(1, n + 1):
        ans += dp[i][s]
        ans %= MOD

    print(ans)


if __name__ == '__main__':
    main()
# Original solution
import sys
input = sys.stdin.readline
n,s = list(map(int,input().split()))
a = list(map(int,input().split()))

mod = 998244353

res = 0

#dp[i][j]:a[i]まででf(L,?) = jとなるLの合計数
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]]
    dp[i][a[i]] += i+1
print(res)



# Optimized solution
import sys
input = sys.stdin.readline

def main():
    n,s = list(map(int,input().split()))
    a = tuple(map(int,input().split()))

    mod = 998244353

    res = 0

    #dp[i][j]:a[i]まででf(L,?) = jとなるLの合計数
    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)

if __name__ == "__main__":
    main()
# Original solution
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


class Mod:
    def __init__(self, m):
        self.m = m

    def add(self, a, b):
        return (a + b) % self.m

    def sub(self, a, b):
        return (a - b) % self.m

    def mul(self, a, b):
        return ((a % self.m) * (b % self.m)) % self.m

    def div(self, a, b):
        return self.mul(a, pow(b, self.m-2, self.m))

    def pow(self, a, b):
        return pow(a, b, self.m)


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


if __name__ == '__main__':
    main()


# Optimized solution
# -*- coding: utf-8 -*-
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)))


if __name__ == '__main__':
    main()
# Original solution
import sys
sys.setrecursionlimit(10**6) #再帰関数の上限
import math
from copy import copy, deepcopy
from operator import itemgetter

from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque 
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
#dequeを使うときはpython3を使う、pypyはダメ
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone

def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds

#mod = 10**9+7
#w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

#N = int(input())
N, S = map(int, input().split())
#L = [int(input()) for i in range(N)]
A = list(map(int, input().split()))
#S = [list(map(int, input().split())) for i in range(N)]
mod=998244353

ans=0
dp=[0]*(S+1)
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[-1]
    ans%=mod
    #print(dp)

print(ans)


# Optimized solution
import sys

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

#mod = 10**9+7
#w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

#N = int(input())
N, S = list(map(int, input().split()))
#L = [int(input()) for i in range(N)]
A = tuple(map(int, input().split()))
#S = [list(map(int, input().split())) for i in range(N)]
mod=998244353

ans=0
dp=[0]*(S+1)
for a in A:
    dp[0]+=1
    for i in reversed(list(range(a,S+1))):
        dp[i]+=dp[i-a]
        dp[i]%=mod
    ans+=dp[-1]
    ans%=mod
    #print(dp)

print(ans)
# Original solution
import sys

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

#mod = 10**9+7
#w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

#N = int(input())
N, S = list(map(int, input().split()))
#L = [int(input()) for i in range(N)]
A = tuple(map(int, input().split()))
#S = [list(map(int, input().split())) for i in range(N)]
mod=998244353

ans=0
dp=[0]*(S+1)
for a in A:
    dp[0]+=1
    for i in reversed(list(range(a,S+1))):
        dp[i]+=dp[i-a]
        dp[i]%=mod
    ans+=dp[-1]
    ans%=mod
    #print(dp)

print(ans)


# Optimized solution
import sys

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

#mod = 10**9+7
#w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

#N = int(input())
N, S = list(map(int, input().split()))
#L = [int(input()) for i in range(N)]
A = tuple(map(int, input().split()))
#S = [list(map(int, input().split())) for i in range(N)]
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(dp)

print(ans)
# Original solution
n, s = list(map(int, input().split()))
a = list(map(int, input().split()))

mod = 998244353

dp = [[0] * n for _ in range(3000 + 1)]
dp2 = [[0] * n for _ in range(3000 + 1)]

# init
dp[a[0]][0] = 1
dp2[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
        elif i - a[j] > 0:
            dp[i][j] = dp[i][j-1] + dp[i - a[j]][j - 1]
        else:
            dp[i][j] = dp[i][j-1]

        dp2[i][j] = dp2[i][j-1] + dp[i][j]


ans = 0
for j in range(n):
    ans += dp[s][j]

print((ans % mod))


# Optimized solution
n, s = list(map(int, input().split()))
a = list(map(int, input().split()))

mod = 998244353

dp = [[0] * n for _ in range(3000 + 1)]

# init
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
        elif i - a[j] > 0:
            dp[i][j] = dp[i][j-1] + dp[i - a[j]][j - 1]
        else:
            dp[i][j] = dp[i][j-1]

ans = 0
for j in range(n):
    ans += dp[s][j]

print((ans % mod))
# Original solution
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[i][j][k] i番目まで見て和がjとなる総数
# k=0がL,Rが決まっていない、k=1がLだけ決定、k=2がLとRが決定
dp = [[[0] * 3 for _ in range(S+1)] for _ in range(N+1)]
dp[0][0][0] = 1
for i in range(N):
    a = A[i]
    for j in range(S+1):
        zero = dp[i][j][0]
        one = dp[i][j][1]
        two = dp[i][j][2]
        dp[i+1][j][0] += zero
        dp[i+1][j][1] += zero + one
        dp[i+1][j][2] += zero + one + two
        if a + j <= S:
            dp[i+1][j+a][1] = zero + one
            dp[i+1][j+a][2] = zero + one

answer = dp[N][S][2] % MOD
print(answer)
# 11


# Optimized solution
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 # Lの数は１個ずつ加わる
    prev = dp.copy()
    for i in range(S-a+1):
        dp[i+a] += prev[i]
    answer += dp[-1] # その位置Rとした時

print((answer % MOD))
# 26
# Original solution
import sys
input=sys.stdin.readline


def solve():
    N, S = list(map(int, input().split()))
    *A, = list(map(int, input().split()))
    MOD = 998244353

    dp = [[[0]*3 for _ in range(6501)] for _ in range(N+1)]

    dp[0][0][0] = 1
    for i in range(N):
        for j in range(S+1):
            dp[i+1][j][0] += dp[i][j][0]
            dp[i+1][j+A[i]][1] += dp[i][j][0] * (i+1)
            dp[i+1][j+A[i]][2] += dp[i][j][0] * (i+1) * (N-i)

            dp[i+1][j][1] += dp[i][j][1]
            dp[i+1][j+A[i]][1] += dp[i][j][1]
            dp[i+1][j+A[i]][2] += dp[i][j][1] * (N-i)

            dp[i+1][j][2] += dp[i][j][2]

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

    print((dp[N][S][2]))


if __name__ == "__main__":
    solve()


# Optimized solution
import sys
input=sys.stdin.readline


def solve():
    N, S = list(map(int, input().split()))
    *A, = list(map(int, input().split()))
    MOD = 998244353

    dp = [[[0]*3 for _ in range(6501)] for _ in range(N+1)]

    dp[0][0][0] = 1
    for i in range(N):
        for j in range(S+1):
            dp[i+1][j][0] += dp[i][j][0]
            dp[i+1][j+A[i]][1] += dp[i][j][0] * (i+1)
            dp[i+1][j+A[i]][2] += dp[i][j][0] * (i+1) * (N-i)

            dp[i+1][j][1] += dp[i][j][1]
            dp[i+1][j+A[i]][1] += dp[i][j][1]
            dp[i+1][j+A[i]][2] += dp[i][j][1] * (N-i)

            dp[i+1][j][2] += dp[i][j][2]

    print((dp[N][S][2]%MOD))


if __name__ == "__main__":
    solve()
# Original solution
from sys import stdin
mod = 998244353
def main():
    N,S = list(map(int,stdin.readline().split()))
    a = list(map(int,stdin.readline().split()))
    dp = [[[0,0,0]for _ in range(S+1)]for _ in range(N+1)]
    dp[0][0][0] = 1
    for i in range(N):
        for j in range(S+1):
            dp[i+1][j][0] += dp[i][j][0] ;dp[i+1][j][0] %= mod
            dp[i+1][j][1] += dp[i][j][0]+dp[i][j][1];dp[i+1][j][1] %= mod
            dp[i+1][j][2] += dp[i][j][0]+dp[i][j][1]+dp[i][j][2];dp[i+1][j][2]%= mod
            if j+a[i] <= S:
                dp[i+1][j+a[i]][1] += dp[i][j][0]+dp[i][j][1];dp[i+1][j+a[i]][1] %= mod
                dp[i+1][j+a[i]][2] += dp[i][j][0]+dp[i][j][1];dp[i+1][j+a[i]][2] %= mod
    print((int(dp[N][S][2])))
if __name__ == "__main__":
    main()

# Optimized solution
from sys import stdin
mod = 998244353
def main():
    N,S = list(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(list(range(A,S+1))):
            dp[i] += dp[i-A]    
            dp[i] %= mod
        ans += dp[S]
        ans %= mod
    print(ans)
if __name__ == "__main__":
    main()
# Original solution
import sys
input = sys.stdin.buffer.readline


def convolve(a, b):
    """配列a, bの畳み込みをNTT(number-theoretical transform)によって計算する
    res[k] = (sum{i=0...n}a[i]*b[k-i]) % MOD
    """
    MOD = 998244353
    ROOT = 5

    def ntt(a, inverse=False):
        # バタフライ演算用の配置入れ替え
        for i in range(n):
            j = 0
            for k in range(log_sz):
                j |= (i >> k & 1) << (log_sz - 1 - k)
            if i < j:
                a[i], a[j] = a[j], a[i]

        h = pow(ROOT, (MOD - 1) * pow(n, MOD - 2, MOD) % MOD, MOD)
        if inverse:
            h = pow(h, MOD - 2, MOD)

        # バタフライ演算
        m = 1
        while m < n:
            zeta_pow = 1
            zeta = pow(h, n // (2 * m), MOD)
            for j in range(m):
                for k in range(0, n, 2 * m):
                    s = a[j + k]
                    t = a[j + k + m] * zeta_pow
                    a[j + k] = (s + t) % MOD
                    a[j + k + m] = (s - t) % MOD
                zeta_pow *= zeta
                zeta_pow %= MOD
            m <<= 1

        # 逆変換時には配列のサイズの逆元をかける
        if inverse:
            n_inv = pow(n, MOD - 2, MOD)
            for i in range(n):
                a[i] *= n_inv
                a[i] %= MOD
        return a

    def intt(a):
        return ntt(a, inverse=True)

    n = 1 << (len(a) + len(b) - 1).bit_length()
    log_sz = n.bit_length() - 1
    a += [0] * (n - len(a))
    b += [0] * (n - len(b))

    # in-placeで計算を進めることに注意
    ntt(a), ntt(b)
    for i, val in enumerate(b):
        a[i] *= val
        a[i] %= MOD
    intt(a)

    return a
  

n, s = list(map(int, input().split()))
a = list(map(int, input().split()))
MOD = 998244353

ptn = [1]
ans = 0
for i in range(n):
    add = [0] * (a[i] + 1)
    add[0] = 1
    add[-1] = 1
    ptn = convolve(ptn, add)[:s + 1]
    if len(ptn)  > s:
        ans += ptn[s]
        ans %= MOD
    ptn[0] += 1

print(ans)

# Optimized solution
n, s = list(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)