stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;



using VS = vector<string>;    using LL = long long;

using VI = vector<int>;       using VVI = vector<VI>;

using PII = pair<int, int>;   using PLL = pair<LL, LL>;

using VL = vector<LL>;        using VVL = vector<VL>;



#define ALL(a)  begin((a)),end((a))

#define RALL(a) (a).rbegin(), (a).rend()

#define PB push_back

#define EB emplace_back

#define MP make_pair

#define SZ(a) int((a).size())

#define SORT(c) sort(ALL((c)))

#define RSORT(c) sort(RALL((c)))

#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)

#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)

#define debug(x) cerr << #x << ": " << x << endl

const int INF = 1e9;                          const LL LINF = 1e16;

const LL MOD = 1000000007;                    const double PI = acos(-1.0);

int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };





LL N;



LL ans = 0LL;





LL f(LL b, LL n) {

	if (n < b)return n;

	else return f(b, n / b) + n % b;

}

int main() {

	cin.tie(0);

	ios_base::sync_with_stdio(false);





	cin >> N;

	LL s; cin >> s;



	ans = LINF;

	if (N == s)ans = N + 1;



	for (LL i = 2; i*i <= N; i++) {

		LL val = f(i, N);

		if (val == s)

			ans = min(ans, i);

	}



	for (LL i = 1; i*i < N; i++) {

		LL b = (N - s) / i + 1;

		if (b > 1) {

			if (f(b, N) == s) {

				ans = min(ans, b);

			}

		}

	}



	if (ans == LINF)ans = -1;

	cout << ans << "\n";



	return 0;

}


// Optimized solution to the same problem (faster):
/*Lucky_Glass*/

#include<cstdio>

#include<cstring>

#include<cmath>

#include<algorithm>

using namespace std;

typedef long long ll;

const ll INF=9223372036854775807ll;

ll n,s,ans=INF;

ll GetS(ll x)

{

	ll f=n,ret=0;

	while(f)

		ret+=f%x,f/=x;

	return ret;

}

int main()

{

	scanf("%lld%lld",&n,&s);

	if(n==s) {printf("%lld\n",n+1ll);return 0;}

	ll T=n-s;

	for(ll i=1;i<=sqrt(T);i++)

		if(T%i==0)

		{

			ll x=i+1ll,y=T/i+1ll;

			if(GetS(x)==s) ans=min(ans,x);

			if(GetS(y)==s) ans=min(ans,y);

		}

	for(ll i=2;i<=sqrt(n);i++)

		if(GetS(i)==s)

		{

			ans=min(ans,i);

			break;

		}

	printf("%lld\n",ans==INF? -1ll:ans);

	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;



typedef long long ll;



ll f(ll b, ll n) {

	if (n < b) return n;

	return f(b, n / b) + n % b;

}



int main() {

	ios_base::sync_with_stdio(false);

	ll n, s; cin >> n >> s;

	if (n < s) return cout << -1 << '\n',0;

	if (n == s) return cout << n + 1 << '\n',0;

	ll res = n + 1; 

	for (ll i = 1; i * i <= n - s; ++i) {

		if ((n - s) % i == 0) {

			if (f(i + 1, n) == s) res = min(res, i + 1);

			if (f((n - s) / i + 1, n) == s) res = min(res, (n - s) / i + 1);

		}

	}

	if (res == n + 1) res = -1;

	cout << res;

}

// Optimized solution to the same problem (faster):
/*Lucky_Glass*/

#include<cstdio>

#include<cstring>

#include<cmath>

#include<algorithm>

using namespace std;

typedef long long ll;

const ll INF=9223372036854775807ll;

ll n,s,ans=INF;

ll GetS(ll x)

{

	ll f=n,ret=0;

	while(f)

		ret+=f%x,f/=x;

	return ret;

}

int main()

{

	scanf("%lld%lld",&n,&s);

	if(n==s) {printf("%lld\n",n+1ll);return 0;}

	ll T=n-s;

	for(ll i=1;i<=sqrt(T);i++)

		if(T%i==0)

		{

			ll x=i+1ll,y=T/i+1ll;

			if(GetS(x)==s) ans=min(ans,x);

			if(GetS(y)==s) ans=min(ans,y);

		}

	for(ll i=2;i<=sqrt(n);i++)

		if(GetS(i)==s)

		{

			ans=min(ans,i);

			break;

		}

	printf("%lld\n",ans==INF? -1ll:ans);

	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>



using namespace std;



#define int long long

long long m, s, ans = 1e12;



long long f(long long b, long long n){

    if(b == 1) return 0;

    if(n < b) return n;

    else return f(b, n / b) + n % b;

}



signed main(){

    cin.tie(0), ios::sync_with_stdio(0);

    cin >> m >> s;

    if(m == s){

        cout << m + 1;

        return 0;

    }

    for(int i = 2; i*i <= m; i++){

        if(f(i, m) == s)

            ans = min (ans,i);

    }

    for(int i = 2; i*i <= s; i++){

        if(f(i, m) == s)

            ans = min (ans,i);

    }

    if(m > s){

        for(int i = 1; i*i <= m - s; i++){

            int pointer = (m - s)/i + 1;

            if(f(i, m) == s)

                ans = min(ans,i);

            if(f(pointer, m) == s)

                ans = min(ans,pointer);

        }

    }

    if(ans != 1e12) {cout << ans; exit(0);}

    cout << "-1\n";

}


// Optimized solution to the same problem (faster):
/*Lucky_Glass*/

#include<cstdio>

#include<cstring>

#include<cmath>

#include<algorithm>

using namespace std;

typedef long long ll;

const ll INF=9223372036854775807ll;

ll n,s,ans=INF;

ll GetS(ll x)

{

	ll f=n,ret=0;

	while(f)

		ret+=f%x,f/=x;

	return ret;

}

int main()

{

	scanf("%lld%lld",&n,&s);

	if(n==s) {printf("%lld\n",n+1ll);return 0;}

	ll T=n-s;

	for(ll i=1;i<=sqrt(T);i++)

		if(T%i==0)

		{

			ll x=i+1ll,y=T/i+1ll;

			if(GetS(x)==s) ans=min(ans,x);

			if(GetS(y)==s) ans=min(ans,y);

		}

	for(ll i=2;i<=sqrt(n);i++)

		if(GetS(i)==s)

		{

			ans=min(ans,i);

			break;

		}

	printf("%lld\n",ans==INF? -1ll:ans);

	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>



#define int long long



using namespace std;



int solve (int b, int n) {

    if (b > n) return n;



    return solve(b, n / b) + n % b;

}



signed main(){

    int n, s;

    scanf("%lld %lld", &n, &s);



    if (n == s) printf("%lld", n + 1);

    else {

        int m = n - s;

        int cur = 0x3f3f3f3f3f3f3f3f;



        for (int i = 1; i <= sqrt(m); i++) {

            if (m % i == 0) {

                int res = solve(i + 1, n);

                int ans = solve(m / i + 1, n);



                if (res == s) cur = min(cur, i + 1);

                if (ans == s) cur = min(cur, m / i + 1);

            }

        }



        if (cur > 1e18) printf("%lld", -1LL);

        else printf("%lld", cur);

    }

    return 0;

}


// Optimized solution to the same problem (faster):
/*Lucky_Glass*/

#include<cstdio>

#include<cstring>

#include<cmath>

#include<algorithm>

using namespace std;

typedef long long ll;

const ll INF=9223372036854775807ll;

ll n,s,ans=INF;

ll GetS(ll x)

{

	ll f=n,ret=0;

	while(f)

		ret+=f%x,f/=x;

	return ret;

}

int main()

{

	scanf("%lld%lld",&n,&s);

	if(n==s) {printf("%lld\n",n+1ll);return 0;}

	ll T=n-s;

	for(ll i=1;i<=sqrt(T);i++)

		if(T%i==0)

		{

			ll x=i+1ll,y=T/i+1ll;

			if(GetS(x)==s) ans=min(ans,x);

			if(GetS(y)==s) ans=min(ans,y);

		}

	for(ll i=2;i<=sqrt(n);i++)

		if(GetS(i)==s)

		{

			ans=min(ans,i);

			break;

		}

	printf("%lld\n",ans==INF? -1ll:ans);

	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

LL f(LL b, LL n){

    if(b > n) return n;

    return f(b, n/b) + n%b;

}

int main(){

    LL n, s, ans = 1e18;

    scanf("%lld%lld", &n, &s);

    for(int b=2;b<=1000000;b++) if(f(b, n) == s) ans = min(ans, b*1ll);

    if(n == s) ans = min(ans, n+1);

    else if(n > s){

        LL ns = n-s;

        for(LL i=1;i*i<=ns;i++){

            if(ns%i == 0){

                if(f(i+1, n) == s) ans = min(ans, i+1);

                if(f(ns/i+1, n) == s) ans = min(ans, ns/i+1);

            }

        }

    }



    if(ans == 1e18) ans = -1;

    printf("%lld\n", ans);

}

// Optimized solution to the same problem (faster):
#include <iostream>

#include <cstdio>

#include <set>

#include <list>

#include <vector>

#include <stack>

#include <queue>

#include <map>

#include <string>

#include <sstream>

#include <algorithm>

#include <cstring>

#include <cstdlib>

#include <cctype>

#include <cmath>

#include <fstream>

#include <iomanip>

//#include <unordered_map>

using namespace std;

#define dbg(x) cerr << #x " = " << x << endl;

typedef pair<int, int> P;

typedef long long ll;

ll f(ll b, ll n)

{

    ll ans = 0;

    while(n)

    {

        ans += n % b;

        n /= b;

    }

    ans += n;

    return ans;

}

int main()

{

   // freopen("in.txt", "r", stdin);

    ios::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

    ll n, s;

    cin >> n >> s;

    ll b = -1;

    if(s > n)

    {

        cout << -1 << endl;

    }

    else if(s == n)

    {

        cout << n + 1 << endl;

    }

    else

    {

        for(ll i = 2; i <= sqrt(n) + 1; i++)

        {

            if(f(i, n) == s)

            {

                b = i;

                break;

            }

        }

        if(b != -1)

        {

            cout << b << endl;

            return 0;

        }

        if(b == -1)

        {

            for(ll i = 1; i <= sqrt(n - s) + 1; i++)

            {

                if((n - s) % i == 0)

                {

                    ll x1 = i;

                    ll x0 = s - x1;

                    ll tmpb = (n - s) / i + 1;

                    if(x1 < tmpb && x0 < tmpb && x0 >= 0 && tmpb >= 2)

                    {

                        if(b == -1) b = tmpb;

                        else

                        b = min(b, tmpb);

                    }

                    

                }

            }

            cout << b << endl;           

        }

        

    }

    



}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <iomanip>

#include <string>

#include <stack>

#include <vector>

#include <complex>

#include <math.h>

#include <stdio.h>

#include <algorithm>

#include <utility>

#include <functional>

#include <iterator>

#include <map>

#include <set>

#include <queue>

#include <list>

#include <regex>

#include <limits>

#include <time.h>

#include <cstdint>

using namespace std;

using pii  = pair<int,int>;

using ll=long long;

using ld=long double;

#define pb push_back

#define mp make_pair

#define sc second

#define fr first

#define stpr setprecision

#define cYES cout<<"YES"<<endl

#define cNO cout<<"NO"<<endl

#define cYes cout<<"Yes"<<endl

#define cNo cout<<"No"<<endl

#define rep(i,n) for(ll i=0;i<(n);++i)

#define Rep(i,a,b) for(ll i=(a);i<(b);++i)

#define rrep(i,n) for(ll i=n-1;i>=0;i--)

#define rRep(i,a,b) for(ll i=a;i>=b;i--)

#define crep(i) for(char i='a';i<='z';++i)

#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});

#define ALL(x) (x).begin(),(x).end()

#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;

#define endl '\n'

int ctoi(const char c){

  if('0' <= c && c <= '9') return (c-'0');

  return -1;

}

ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}

ll lcm(ll a,ll b){return a*b/gcd(a,b);}

constexpr ll MOD=1000000007;

constexpr ll INF=1000000011;

constexpr ll MOD2=998244353;

constexpr ll LINF = 1001002003004005006ll;

constexpr ld EPS=10e-8;

template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }

template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }

template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}

template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}

template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}

template<class T> ostream& operator<<(ostream& os, vector<T>& v){

  for(auto i=begin(v); i != end(v); ++i){

    if(i !=begin(v)) os << ' ';

    os << *i;

  }

  return os;

}



ll A[3007],dp[3007][3007];



int main(){

  ll N,S,ANS=0;

  cin >> N >> S;

  rep(i,N){

    cin >> A[i+1];

  }

  Rep(i,1,N+1){

    rep(j,S+1){

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

      if(j==0){

        dp[i][j]++;

      }

      if(j>=A[i]){

        dp[i][j]+=dp[i-1][j-A[i]];

        if(j==A[i]){

          dp[i][j]++;

        }

      }

      dp[i][j]%=MOD2;

    }

    ANS=(ANS+dp[i][S])%MOD2;

  }

  cout << ANS << endl;

}

// Optimized solution to the same problem (faster):
#include <stdio.h>

int k,n,s,j,a,m=998244353,d[3001];int main(){scanf("%d%d",&n,&s);while(n--){scanf("%d",&a);for(j=s+1;j-->a;)d[j]=(d[j]+d[j-a])%m;d[a]++;d[0]++;k=(k+d[s])%m;}printf("%d",k);}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <vector>

#include <algorithm>

#include <string>

#include <set>

#include <queue>

#include <stack>

#include <tuple>

#include <cmath>

#include <iomanip>

#include <map>

#include <stdio.h>

#include <cstring> //memset(dp,0,sizeof(dp))

#include <functional> //operator[]

#define ll long long

#define rep(i,n) for(int i=0;i<(n);i++)

#define rrep(i,n) for(int i=n-1;i>=0;i--)

#define fi first

#define se second

#define pb push_back

#define ALL(a) (a).begin(),(a).end()

using namespace std;

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}

template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

typedef pair<int,int> P;

typedef pair<ll,ll> Pll;



const ll MOD = 998244353;



signed main(){

    int n,s; cin >> n >> s;

    ll dp[n+1][3030][3];

    //dp[i][j][k]:=i番目sum=j k=0,1,2でo,l,lr;

    memset(dp,0,sizeof(dp));

    dp[0][0][0]=1;

    rep(i,n){

        int a; cin >> a;

        rep(j,3030){

            

            dp[i+1][j][0]+=dp[i][j][0];

            dp[i+1][j][1]+=dp[i][j][0]+dp[i][j][1];

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

            

            rep(k,3)dp[i+1][j][k]%=MOD;

            

            if(j+a<3030){

                dp[i+1][j+a][1]+=dp[i][j][0]+dp[i][j][1];

                dp[i+1][j+a][2]+=dp[i][j][0]+dp[i][j][1];

                rep(k,3){

                    dp[i+1][j+a][k]%=MOD;

                }

            }

            

        }

    }

    cout << dp[n][s][2] << endl;

}


// Optimized solution to the same problem (faster):
#include <iostream>

#include <vector>

#include <algorithm>

#include <string>

#include <set>

#include <queue>

#include <stack>

#include <tuple>

#include <cmath>

#include <iomanip>

#include <map>

#include <cstring> //memset(dp,0,sizeof(dp))

#define ll long long

#define rep(i,n) for(int i=0;i<(n);i++)

#define repp(i,n) for(int i=n-1;i>=0;i--)

#define fi first

#define se second

#define pb push_back

#define ppb pop_back()

#define ALL(a) (a).begin(),(a).end()

using namespace std;

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}

template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

typedef pair<int,int> P;

typedef pair<ll,ll> Pll;



const ll MOD = 998244353;

signed main(){

    int n,s; cin >> n >> s;

    ll dp[n+1][s+1][3];

    memset(dp,0,sizeof(dp));

    dp[0][0][0]=1;

    rep(i,n){

        int a; cin >> a;

        rep(j,s+1){

            dp[i+1][j][0]+=dp[i][j][0];

            dp[i+1][j][1]+=dp[i][j][0]+dp[i][j][1];

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

            rep(k,3)dp[i+1][j][k]%=MOD;

            if(j+a<=s){

                dp[i+1][j+a][1]+=dp[i][j][0]+dp[i][j][1];

                dp[i+1][j+a][2]+=dp[i][j][0]+dp[i][j][1];

                rep(k,3)dp[i+1][j+a][k]%=MOD;

            }

        }

    }

    cout << dp[n][s][2] << endl;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<string>

#include<iomanip>

#include<cmath>

#include<vector>

#include<algorithm>

#include<utility>



using namespace std;



#define int long long

#define endl "\n"



constexpr long long INF = (long long)1e18;

constexpr long long MOD = 998244353; 



struct fast_io {

	fast_io(){

		std::cin.tie(nullptr);

		std::ios::sync_with_stdio(false);

	};

} fio;



signed main(){

	cout<<fixed<<setprecision(10);

	

	constexpr int MAX = 3100;

	int N, S;

	int ans = 0;

	vector<int> A;

	vector<int> dp(MAX);

	vector<int> dp2(MAX);

	

	cin>>N>>S;

	

	A.resize(N);

	// dp.resize(MAX):

	

	for(int i = 0; i < N; i++){

		cin>>A[i];

	}

	

	dp2[0] = 1;

	

	for(int i = 0; i < N; i++){

		vector<int> next(MAX);

		

		// cout<<endl<<"i = "<<i<<endl;

		

		for(int k = 0; k < MAX; k++){

			next[k] += dp[k];

			next[k] %= MOD;

			if(k+A[i] < MAX){

				next[k+A[i]] += dp[k];

				next[k+A[i]] %= MOD;

			}

		}

		

		next[A[i]] += (i+1);

		next[A[i]] %= MOD;

		

		for(int j = 0; j < MAX; j++){

			dp[j] = next[j];

			

			// cout<<"j = "<<j<<" dp = "<<dp[j]<<" "<<dp2[j]<<endl;

			if(j == S){

				ans += dp[j];

				ans %= MOD;

			}

		}

		

	}

	

	cout<<ans<<endl;

	

	return 0;

}

// Optimized solution to the same problem (faster):
#include<iostream>

#include<string>

#include<iomanip>

#include<cmath>

#include<vector>

#include<algorithm>

#include<utility>



using namespace std;



#define int long long

#define endl "\n"



constexpr long long INF = (long long)1e18;

constexpr long long MOD = 998244353; 



struct fast_io {

	fast_io(){

		std::cin.tie(nullptr);

		std::ios::sync_with_stdio(false);

	};

} fio;



signed main(){

	cout<<fixed<<setprecision(10);

	

	constexpr int MAX = 3100;

	

	int N, S;

	int ans = 0;

	vector<int> A, dp(MAX);

	

	cin>>N>>S;

	

	A.resize(N);

	

	for(int i = 0; i < N; i++)

		cin>>A[i];

	

	for(int i = 0; i < N; i++){

		for(int k = MAX - A[i] - 1; k >= 0; k--)

			dp[k+A[i]] = (dp[k+A[i]]+dp[k])%MOD;

		dp[A[i]] = (dp[A[i]]+(i+1))%MOD;

		ans = (ans + dp[S])%MOD;

	}

	

	cout<<ans<<endl;

	

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <cstdio>

#include <cstring>



const int MaxN = 3000, MaxM = 3000;

const int Mod = 998244353;



int N, M, Ans;

int A[MaxN + 5];

int F[MaxM + 5], Buc[MaxM + 5];



inline int add(int x, int y) { return (x += y) >= Mod ? x - Mod : x; }

inline int sub(int x, int y) { return (x -= y) < 0 ? x + Mod : x; }

inline int mul(int x, int y) { return 1LL * x * y % Mod; }

inline void inc(int &x, int y = 1) { x = add(x, y); }



void init() {

  scanf("%d %d", &N, &M);

  for (int i = 1; i <= N; ++i) scanf("%d", &A[i]);

}



void fun(int l, int r) {

  if (l == r) {

    if (A[l] == M) inc(Ans);

    return;

  }

  int m = (l + r) >> 1;

  fun(l, m);

  fun(m + 1, r);

  memset(Buc, 0, sizeof Buc);

  memset(F, 0, sizeof F);

  F[0] = 1;

  for (int i = m; i >= l; --i) {

    for (int j = M; j >= A[i]; --j) inc(F[j], F[j - A[i]]);

    for (int j = 0; j <= M; ++j) inc(Buc[j], F[j]);

  }

  memset(F, 0, sizeof F);

  F[0] = 1;

  for (int i = m + 1; i <= r; ++i) {

    for (int j = M; j >= A[i]; --j) inc(F[j], F[j - A[i]]);

    for (int j = 0; j <= M; ++j) inc(Ans, mul(F[j], Buc[M - j]));

  }

}



void solve() {

  fun(1, N);

  printf("%d\n", Ans);

}



int main() {

  init();

  solve();

  return 0;

}

// Optimized solution to the same problem (faster):
#include <cstdio>



const int MaxN = 3000;

const int Mod = 998244353;



int N, M;

int A[MaxN + 5];

int F[MaxN + 5][3];



inline int add(int x, int y) { return (x += y) >= Mod ? x - Mod : x; }

inline void inc(int &x, int y = 1) { x = add(x, y); }



void init() {

  scanf("%d %d", &N, &M);

  for (int i = 1; i <= N; ++i) scanf("%d", &A[i]);

}



void solve() {

  F[0][0] = 1;

  for (int i = 1; i <= N; ++i) {

    for (int j = 0; j <= M; ++j) inc(F[j][1], F[j][0]);

    for (int j = M; j >= A[i]; --j) inc(F[j][1], F[j - A[i]][1]);

    for (int j = 0; j <= M; ++j) inc(F[j][2], F[j][1]);

  }

  printf("%d\n", F[M][2]);

}



int main() {

  init();

  solve();

  return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;



#define ll long long

#define ar array



const int mxN=3e3, M=998244353;

int n, s, a[mxN];

ll dp[mxN+1][mxN+1], ans;



int main() {

	ios::sync_with_stdio(0);

	cin.tie(0);



	cin >> n >> s;

	for(int i=0; i<n; ++i) {

		cin >> a[i];

		memcpy(dp[i+1], dp[i], sizeof(dp[0]));

		//start a new sequence

		dp[i+1][a[i]]=(dp[i+1][a[i]]+i+1)%M;

		for(int j=0; j+a[i]<=s; ++j)

			dp[i+1][j+a[i]]=(dp[i+1][j+a[i]]+dp[i][j])%M;

		ans=(dp[i+1][s]+ans)%M;

	}

	cout << ans;

}


// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;



const int M = 998244353;



int main(){

    int n,s;

    cin>>n>>s;



    vector<int> arr(n);

    for(int i = 0; i < n; i++) cin>>arr[i];



    vector<int> dp(s+1);



    int res = 0;

    for(int i = 0; i < n; i++){

        for(int j = s - arr[i]; j>=0; j--){

            dp[j+arr[i]]+=dp[j];

            dp[j+arr[i]]%=M;

        }

        if(arr[i]<=s){

            dp[arr[i]]+=i+1;

        }

    

        res += dp[s]%M;

        res%=M;

    }

    cout<<res;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<fstream>

#include <cmath>

#include <algorithm>

#include <stack>

#include <vector>

#include <random>

#include <set>

using namespace std;

typedef long long ll;





int main(){

	ll n,s,m=998244353,ans=0;

	cin >> n >> s;

	vector<ll> a(n),dp(3001,0),t,cls(3001,0);

	for(auto &&x:a)cin >> x;

	for(auto &&x:a){

		t = cls;

		for(int i=0;i<3001;i++){

			( t[i] += dp[i] ) %= m;

			if(i+x<=3000)( t[i+x] += dp[i] ) %= m;

		}

		t[0]++;

		t[x]++;

		dp = t;

		( ans += dp[s] ) %= m;

	}

	cout << ans << endl;

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)





/*

https://maspypy.com/atcoder-%E5%8F%82%E5%8A%A0%E6%84%9F%E6%83%B3-2019-03-22abc-159





ans = sum_(i<=j){ f(i,j) }

  

    = f(1,1) +f(1,2) +f(1,3) +...

             +f(2,2) +f(2,3) +...

                     +f(3,3) +...



形式的べき級数で考えると





f(i,j-1) {i<j} について *(x^A[j] + 1) をやることで f(i,j) の分を足す

(x^A[j] + 1)を足すことで f(j,j) を足す



*/





int main(){

  ll ans = 0;

  ll mod = 998244353;

  ll N,S;

  cin >> N >> S;

  vector<ll> coefficient(3003,0);

  FOR(i,0,N){

    ll a;

    cin >> a;

    vector<ll> t = coefficient;

    FOR(j,a,S+1){

      (t[j] += coefficient[j-a]) %= mod;

    }

    t[a]++;

    t[0]++;

    coefficient = t;

    (ans += coefficient[S]) %= mod;

  }

  cout << ans << endl;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

const int mxn =  5e5+5;

const int inf = 0x3f3f3f3f;

typedef long long ll;

const ll mod =998244353; 

int n,m;

ll dp[mxn],v[mxn];

//dp[i] : 装满i容量的物品 的方案数 



int main()

{



	ll ans = 0;

	memset(dp,0,sizeof(dp));

	scanf("%d%d",&n,&m);

	for(int i = 1;i<=n;i++)scanf("%lld",&v[i]);

	

	for(int i  = 1;i<=n;i++)

	{

		dp[0] ++;

		for(int j = m;j>=v[i];j--)

		{

			dp[j] = ( dp[j]+dp[j-v[i]])%mod;

		}

		ans = (ans + dp[m])%mod;

	}

	printf("%lld",ans);

	

	

	return 0;

}

// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

const int maxn = 3005;

const int mod = 998244353;

#define pb push_back

#define pii pair<int,int>

#define fi first

#define se second

int t;

int n,m; 

int c[maxn];

int f[maxn];

int add(int a,int b){ a+=b; return a>=mod?a-mod:a;}  



int main()

{

	scanf("%d%d",&n,&m);

	for(int i=1;i<=n;++i) scanf("%d",c+i);

	int ans = 0;

	for(int i=n;i>=1;--i)

	{

		++f[0];

		for(int j=m;j>=c[i];--j)

		{

			f[j] = add(f[j],f[j-c[i]]);

		}

		ans = add(ans,f[m]);

	}

	printf("%d\n",ans);

}

// Fastest known solution for this problem: