CodeEff/ECCO huggingface dataset:
# Original solution
n,k = list(map(int, input().split(' ')))
r,s,p = list(map(int, input().split(' ')))
seq = input()


dp = [[0,0,0] for _ in range(len(seq))]
"""
	0 rock
	1 paper
	2 scisor
"""

for i in range(len(dp)):
	if i - k < 0:
		dp[i][0] = r if seq[i]  == 's' else 0
		dp[i][1] = s if seq[i]  == 'p' else 0
		dp[i][2] = p if seq[i]  == 'r' else 0
	elif i - k >=0:
		dp[i][0] = max(dp[i- k][1], dp[i-k][2]) + 	(r if seq[i]  == 's' else 0)
		dp[i][1] = max(dp[i- k][0], dp[i-k][2]) + 	(s if seq[i]  == 'p' else 0)
		dp[i][2] = max(dp[i- k][0], dp[i-k][1]) + 	(p if seq[i]  == 'r' else 0)

cumul = 0
seen = set([])
for j in range(len(dp)-1, -1, -1):
	#print j % k
	if (j % k) not in seen:
		seen.add(j % k)
		cumul += max(dp[j])

print(cumul)


# Optimized solution
n,k = list(map(int, input().split(' ')))
r,s,p = list(map(int, input().split(' ')))
seq = input()


dp = [[0,0,0] for _ in range(len(seq))]
"""
	0 rock
	1 paper
	2 scisor
"""

for i in range(len(dp)):
	if i - k < 0:
		dp[i][0] = r if seq[i]  == 's' else 0
		dp[i][1] = s if seq[i]  == 'p' else 0
		dp[i][2] = p if seq[i]  == 'r' else 0
	elif i - k >=0:
		dp[i][0] = max(dp[i- k][1], dp[i-k][2]) + 	(r if seq[i]  == 's' else 0)
		dp[i][1] = max(dp[i- k][0], dp[i-k][2]) + 	(s if seq[i]  == 'p' else 0)
		dp[i][2] = max(dp[i- k][0], dp[i-k][1]) + 	(p if seq[i]  == 'r' else 0)

cumul = 0
seen = set([])
for j in range(len(dp)-1, -1, -1):
	#print j % k
	if (j % k) not in seen:
		seen.add(j % k)
		cumul += max(dp[j])
	else:
		break

print(cumul)
# Original solution
N,K=list(map(int,input().split()))
R,S,P=list(map(int,input().split()))
T=input().replace("s","R").replace("p","S").replace("r","P")

ans=0

def win(type):
  if type=="R":
    return R
  elif type=="S":
    return S
  elif type=="P":
    return P
  return 0

yaku=set(["R","S","P"])
def rest(a,b):
  re=yaku-set([a,b])
  for c in re:
    return c

def restRand(a):
  re=yaku-set([a])
  for c in re:
    return c

me=[""]*len(T)
for i in range(len(T)):
  if i-K<0:
    ans+=win(T[i])
    me[i]=T[i]
  else:
    if me[i-K]==T[i]:
      # 勝つ手は出せない
      # 残り二つのうち、K回あとに勝負がある場合、K回あとに勝てる手以外を出す
      if i+K<len(T):
        me[i]=rest(T[i],T[i+K])
      else:
        me[i]=restRand(T[i])
    else:
      # 勝つ手を出せる
      ans+=win(T[i])
      me[i]=T[i]

print(ans)


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

N,K = list(map(int,readline().split()))
R,S,P = list(map(int,readline().split()))
T = list(readline().rstrip())

P = {"r":P,"s":R,"p":S}
ans = 0
for i in range(len(T)):
  if i < K:
    ans += P[T[i]]
    continue
  if T[i] == T[i - K]:
    T[i] = "x"
  else:
    ans += P[T[i]]
print(ans)
# Original solution
MOVES = 'rsp'

def points(me, rival):
    if me == 'r' and rival == 's':
        return r
    if me == 's' and rival == 'p':
        return s
    if me == 'p' and rival == 'r':
        return p
    return 0

def pos(hand):
    return MOVES.index(hand)

n, k = list(map(int, input().split()))
r, s, p = list(map(int, input().split()))
t = input().rstrip()
ret = 0
me = []
for i, rival in enumerate(t):
    if rival == 'r':
        if i - k >= 0 and me[i - k] == 'p':
            if i + k < n:
                if t[i + k] == 'p':
                    me.append('r')
                elif t[i + k] == 's':
                    me.append('s')
                elif t[i + k] == 'r':
                    me.append('s')
        else:
            me.append('p')
            ret += p
    elif rival == 's':
        if i - k >= 0 and me[i - k] == 'r':
            if i + k < n:
                if t[i + k] == 'r':
                    me.append('s')
                elif t[i + k] == 'p':
                    me.append('p')
                elif t[i + k] == 's':
                    me.append('s')
        else:
            me.append('r')
            ret += r
    elif rival == 'p':
        if i - k >= 0 and me[i - k] == 's':
            if i + k < n:
                if t[i + k] == 'r':
                    me.append('r')
                elif t[i + k] == 's':
                    me.append('p')
                elif t[i + k] == 'p':
                    me.append('r')
        else:
            me.append('s')
            ret += s
print(ret)


# Optimized solution
n, k = list(map(int, input().split()))
r, s, p = list(map(int, input().split()))
t = input().rstrip()
ret = 0
me = []
for i, rival in enumerate(t):
    if rival == 'r':
        if i - k >= 0 and me[i - k] == 'p':
            if i + k < n:
                if t[i + k] == 'p':
                    me.append('r')
                elif t[i + k] == 's':
                    me.append('s')
                elif t[i + k] == 'r':
                    me.append('s')
        else:
            me.append('p')
            ret += p
    elif rival == 's':
        if i - k >= 0 and me[i - k] == 'r':
            if i + k < n:
                if t[i + k] == 'r':
                    me.append('s')
                elif t[i + k] == 'p':
                    me.append('p')
                elif t[i + k] == 's':
                    me.append('s')
        else:
            me.append('r')
            ret += r
    elif rival == 'p':
        if i - k >= 0 and me[i - k] == 's':
            if i + k < n:
                if t[i + k] == 'r':
                    me.append('r')
                elif t[i + k] == 's':
                    me.append('p')
                elif t[i + k] == 'p':
                    me.append('r')
        else:
            me.append('s')
            ret += s
print(ret)
# Original solution
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, K = list(map(int, readline().split()))
    R, S, P = list(map(int, readline().split()))
    T = readline().strip()

    T = [int(c) for c in T.translate(str.maketrans('rsp', '012'))]
    H = [R, S, P]

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

    for i in range(N):
        com = T[i]
        for h in range(3):
            if i > K - 1:
                dp[i + 1][h] = max(dp[i + 1 - K][(h + 1) % 3], dp[i + 1 - K][(h + 2) % 3])
            if (h + 1) % 3 == com:
                dp[i + 1][h] += H[h]

    print((sum(max(p) for p in dp[-K:])))

    return


if __name__ == '__main__':
    main()


# Optimized solution
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, K = list(map(int, readline().split()))
    R, S, P = list(map(int, readline().split()))
    T = readline().strip()

    T = [int(c) for c in T.translate(str.maketrans('rsp', '012'))]

    point = [R, S, P]
    hand = [0] * N

    ans = 0
    for i, com in enumerate(T):
        win = (com - 1) % 3
        if i >= K and win == hand[i - K]:
            hand[i] = -1
        else:
            hand[i] = win
            ans += point[win]

    print(ans)
    return


if __name__ == '__main__':
    main()
# Original solution
def main():
  N,S = list(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(q)
  print((ans%MOD))
  
main()

# Optimized solution
def main():
  N,S = list(map(int,input().split()))
  A = list(map(int,input().split()))
  MOD = 998244353

  # サンプル3 4 2,2,4の場合、P1=1+x^2,P2=1+x^2,P3=1+x^4とすると、解は
  # P1P2P3+P1P2+P2P3+P1P3+P1+P2+P3におけるx^4の係数となる。
  # Q1=P1,Q2=P2+P1P2,Q3=P3+P2P3+P1P2P3とすると、
  # P1P2P3+P1P2+P2P3+P1P3+P1+P2+P3=Q1+Q2+Q3
  # Q1=P1(1+0)
  # Q2=P2(1+Q1)
  # Q3=P3(1+Q2)
  # 今のQに1を足してからPを掛けて、次のQを求める。
  # 解は、それぞれのQのx^4の係数を足していけばよい。
  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(q)
  print((ans%MOD))
  
main()
# Original solution
n,s=list(map(int,input().split()))
a=list(map(int,input().split()))
mod=998244353
dp=[[[0]*3 for i in range(s+1)] for j in range(n+1)]
dp[0][0][0]=1
for i in range(n):
  for j in range(s+1):
    if j>=a[i]:
      x=dp[i][j-a[i]][0]+dp[i][j-a[i]][1]+dp[i][j][0]+dp[i][j][1]
      dp[i+1][j][1]=x%mod
      dp[i+1][j][2]=(x+dp[i][j][2])%mod
    else:
      dp[i+1][j][0]=dp[i][j][0]%mod
      dp[i+1][j][1]=(dp[i][j][0]+dp[i][j][1])%mod
      dp[i+1][j][2]=(dp[i][j][0]+dp[i][j][1]+dp[i][j][2])%mod
print((dp[n][s][2]))

# Optimized solution
n,s=list(map(int,input().split()))
a=list(map(int,input().split()))
mod=998244353
dp0=[[0 for i in range(s+1)] for j in range(n+1)]
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)]
dp0[0][0]=1
for i in range(n):
  for j in range(s+1):
    if j>=a[i]:
      dp1[i+1][j]=(dp0[i][j-a[i]]+dp1[i][j-a[i]]+dp0[i][j]+dp1[i][j])%mod
      dp2[i+1][j]=(dp0[i][j-a[i]]+dp1[i][j-a[i]]+dp0[i][j]+dp1[i][j]+dp2[i][j])%mod
    else:
      dp0[i+1][j]=dp0[i][j]%mod
      dp1[i+1][j]=(dp0[i][j]+dp1[i][j])%mod
      dp2[i+1][j]=(dp0[i][j]+dp1[i][j]+dp2[i][j])%mod
print((dp2[n][s]))
# Original solution
n,s=list(map(int,input().split()))
a=list(map(int,input().split()))
mod=998244353
dp0=[[0 for i in range(s+1)] for j in range(n+1)]
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)]
dp0[0][0]=1
for i in range(n):
  for j in range(s+1):
    if j>=a[i]:
      dp1[i+1][j]=(dp0[i][j-a[i]]+dp1[i][j-a[i]]+dp0[i][j]+dp1[i][j])%mod
      dp2[i+1][j]=(dp0[i][j-a[i]]+dp1[i][j-a[i]]+dp0[i][j]+dp1[i][j]+dp2[i][j])%mod
    else:
      dp0[i+1][j]=dp0[i][j]%mod
      dp1[i+1][j]=(dp0[i][j]+dp1[i][j])%mod
      dp2[i+1][j]=(dp0[i][j]+dp1[i][j]+dp2[i][j])%mod
print((dp2[n][s]))

# Optimized solution
n,s=list(map(int,input().split()))
a=list(map(int,input().split()))
mod=998244353
dp0=[[0]*(s+1) for i in range(n+1)]
dp1=[[0]*(s+1) for i in range(n+1)]
dp2=[[0]*(s+1) for i in range(n+1)]
dp0[0][0]=1
for i in range(n):
  for j in range(s+1):
    if j>=a[i]:
      dp1[i+1][j]=(dp0[i][j-a[i]]+dp1[i][j-a[i]]+dp0[i][j]+dp1[i][j])%mod
      dp2[i+1][j]=(dp0[i][j-a[i]]+dp1[i][j-a[i]]+dp0[i][j]+dp1[i][j]+dp2[i][j])%mod
    else:
      dp0[i+1][j]=dp0[i][j]%mod
      dp1[i+1][j]=(dp0[i][j]+dp1[i][j])%mod
      dp2[i+1][j]=(dp0[i][j]+dp1[i][j]+dp2[i][j])%mod
print((dp2[n][s]))
# Original solution
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]
        dp[j] %= mod
    ans += dp[s]
    ans %= mod
print(ans)

# Optimized solution
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)
# Original solution
import sys
from functools import lru_cache
 
#read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**6)
def read():
  return int(readline())
def reads():
  return list(map(int, readline().split()))
def mp(arg):
  return list(map(int,arg.split()))
n,s=reads()
a=list(reads())
mod= 998244353
@lru_cache(None)
def F(k):#ｆ１＋ｆ２＋．。。ｆｋ
  if k==1:
    res=[0]*(s+1)
    res[0]=1
    if a[0]<s+1:
      res[a[0]]=1
    return res
  res=F(k-1)
  k-=1
  for i in range(s,-1,-1):
    if i-a[k]>=0:
      res[i]+=res[i-a[k]]
      res[i]%=mod
  if a[k]<s+1:
      res[a[k]]+=1
  res[0]+=1
  return res
ans=0
for i in range(1,n+1):
  ls=F(i)
  ans+=ls[-1]
ans%=mod
print(ans)

# Optimized solution
import sys
from functools import lru_cache
 
#read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**6)
def read():
  return int(readline())
def reads():
  return list(map(int, readline().split()))
def mp(arg):
  return list(map(int,arg.split()))
n,s=reads()
a=list(reads())
mod= 998244353
f=[[] for i in range(n+1)]
for k in range(1,n+1):
  if k==1:
    res=[0]*(s+1)
    res[0]=1
    if a[0]<s+1:
      res[a[0]]=1
    f[1]=res
    continue
  res=f[k-1][:]
  k-=1
  for i in range(s,-1,-1):
    if i-a[k]>=0:
      res[i]+=res[i-a[k]]
      res[i]%=mod
  if a[k]<s+1:
      res[a[k]]+=1
  res[0]+=1
  f[k+1]=res
ans=0
#print(f)
for i in range(1,n+1):
  ans+=f[i][-1]
ans%=mod
print(ans)
# Original solution
N, S = list(map(int, input().split()))
data = list(map(int, input().split()))

MOD = 998244353
# dp = [[0]*(3000+1) for _ in range(N)]
# ans = 0

# for i, num in enumerate(data):
#     dp[i][num] = 1
#     for j in range(i):
#         for k in range(S-num, 0, -1):
#             if dp[j][k] >= 1:
#                 dp[j][k+num] += dp[j][k]
#             if k == num:
#                 dp[j][num] += 1
#     for j in range(i+1):
#         ans += dp[j][S]
#     ans %= MOD

# print(ans)

ans = 0
dp = [[] for _ in range(3001)]
dp[0] = [0]
for i, num in enumerate(data):
    for j in range(S-num, -1, -1):
        for item in dp[j]:
            dp[j+num] += [item+(1<<i)]

for item in dp[S]:
    for i in range(N+1):
        if item < (1<<i):
            a = N - i + 1
            break
    for i in range(N):
        if item & (1<<i) != 0:
            b = i + 1
            break
    ans = (a*b+ans)%MOD

print(ans)


# Optimized solution
P = 998244353

N, S = list(map(int, input().split()))
A = list(map(int, input().split()))

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

dp[0][0][0] = 1
dp[0][0][1] = 1
if A[0] <= S:
    dp[0][A[0]][1] = 1

for i in range(1, N):
    dp[i][0][0] = 1
    dp[i][0][1] = dp[i-1][0][1] + 1
    dp[i][S][2] = dp[i-1][S][2] + dp[i-1][S][1]
    if A[i] == S:
        dp[i][S][2] += 1 + dp[i-1][0][1]
        dp[i][S][1] += dp[i-1][0][1] + 1
    elif A[i] < S:
        dp[i][A[i]][1] += 1 + dp[i-1][0][1]
    for j in range(1, S+1):
        dp[i][j][1] += dp[i-1][j][1]
        if j + A[i] < S:
            dp[i][j+A[i]][1] += dp[i-1][j][1]
        elif j + A[i] == S:
            dp[i][S][2] += dp[i-1][j][1]
            dp[i][S][1] += dp[i-1][j][1]
        dp[i][j][0] %= P
        dp[i][j][1] %= P
        dp[i][j][2] %= P

print((dp[N-1][S][2]))
# Original solution
import sys
input = sys.stdin.readline
N, S = list(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):
  dp[i][0] = i + 1
  for j in range(S + 1):
    if j + a[i] < S:
      dp[i + 1][j + a[i]] += dp[i][j]
      dp[i + 1][j + a[i]] %= mod
    elif j + a[i] == S:
      dp[i + 1][j + a[i]] += dp[i][j] * (N - i)
      dp[i + 1][j + a[i]] %= mod
    dp[i + 1][j] += dp[i][j]
    dp[i + 1][j] %= mod
print((dp[-1][-1]))


# Optimized solution
import sys
input = sys.stdin.readline
N, S = list(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)
print((dp[-1]))
# Original solution
from collections import defaultdict

MOD = 998244353


def main():
    N, S = list(map(int, input().split()))
    A = list(map(int, input().split()))
    dp = [defaultdict(int) for _ in range(S)]
    ans = 0
    for right in range(N):
        num = A[right]
        if num > S:
            continue
        elif num == S:
            ans = (ans + (right+1) * (N-right)) % MOD
            continue
        for left in dp[S-num]:
            cnt = dp[S-num][left]
            ans = (ans + (left+1) * (N-right) * cnt) % MOD
        for i in range(S-num-1, -1, -1):
            for left in dp[i]:
                dp[i+num][left] += dp[i][left]
        dp[num][right] = 1
    print(ans)


if __name__ == "__main__":
    main()


# Optimized solution
from collections import defaultdict

MOD = 998244353


def main():
    N, S = list(map(int, input().split()))
    A = list(map(int, input().split()))
#    dp = [defaultdict(int) for _ in range(S)]
    dp = [0] * S
    ans = 0
    for right in range(N):
        num = A[right]
        if num > S:
            continue
        elif num == S:
            ans = (ans + (right+1) * (N-right)) % MOD
            continue
        # for left in dp[S-num]:
        #     cnt = dp[S-num][left]
        #     ans = (ans + (left+1) * (N-right) * cnt) % MOD
        # for i in range(S-num-1, -1, -1):
        #     for left in dp[i]:
        #         dp[i+num][left] += dp[i][left]
        # dp[num][right] = 1
        ans = (ans + dp[S-num] * (N-right)) % MOD
        for i in range(S-num-1, -1, -1):
            dp[i+num] += dp[i]
        dp[num] += right + 1
    print(ans)


if __name__ == "__main__":
    main()
# Original solution
n,s=list(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]=1
ans=0

# i indicade low , c indicade column
for i,w in enumerate(a):
    for c in range(s+1):
        dp[i][c]+=dp[i-1][c]
    for c in range(s-w+1):
        dp[i][c+w]+=dp[i-1][c]
    ans+=dp[i][-1]
    ans%=998244353

print(ans)


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

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

for i,w in enumerate(a):
    for j in range(s-w,-1,-1):
        dp[j+w]+=dp[j]
        dp[j+w]%=998244353
    ans+=dp[-1]
    ans%=998244353
    dp[0]+=1

print(ans)
# Original solution
mod=998244353
n,s=list(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]))


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

    N, S = list(map(int, input().split()))
    As = list(map(int, input().split()))

    dp0, dp1, dp2 = [0]*(S+1), [0]*(S+1), [0]*(S+1)
    dp0[0] = 1
    for A in As:
        for sm in reversed(list(range(S+1))):
            dp2[sm] += dp1[sm] + dp0[sm]
            if sm-A >= 0:
                dp2[sm] += dp1[sm-A] + dp0[sm-A]
            dp2[sm] %= MOD
            dp1[sm] += dp0[sm]
            if sm-A >= 0:
                dp1[sm] += dp1[sm-A] + dp0[sm-A]
            dp1[sm] %= MOD

    print((dp2[S]))


solve()


# Optimized solution
def solve():
    MOD = 998244353

    N, S = list(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(list(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()
# Original solution
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()


# Optimized solution
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]
        ans += dp[s]
    print(ans%md)

main()
# 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 range(S,a-1,-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())
_, 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 map(int, input().split()):
    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
import sys
input = sys.stdin.readline

mod = 998244353

N,S = list(map(int,input().split()))
A = list(map(int,input().split()))

dp = [[[0]*3 for __ in range(S+1)] for _ in range(N+1)]
###dp[i][j][k]:Aのindex[i-1]まで見て和がjになっているもの
###kの意味は解説の通り


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((dp[N][S][2]))

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

mod = 998244353

N,S = list(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)]
###dp[i][j][k]:Aのindex[i-1]まで見て和がjになっているもの
###kの意味は解説の通り


dp0[0][0] = 1

for i in range(N):
    for j in range(S+1):
        dp0[i+1][j] += dp0[i][j]
        dp0[i+1][j] %= mod

        dp1[i+1][j] += dp0[i][j] + dp1[i][j]
        dp1[i+1][j] %= mod

        dp2[i+1][j] += dp0[i][j] + dp1[i][j] + dp2[i][j]
        dp2[i+1][j] %= mod

        if j+A[i] <= S:
            dp1[i+1][j+A[i]] += dp0[i][j] + dp1[i][j]
            dp1[i+1][j+A[i]] %= mod
        
            dp2[i+1][j+A[i]] += dp0[i][j] + dp1[i][j]
            dp2[i+1][j+A[i]] %= mod

print((dp2[N][S]))