stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 4.858388019295464x):
/*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;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 4.819798419470636x):
/*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;

}
// Slower C++ solution:
#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";

}


// Faster C++ solution for the same problem (measured speedup: 4.874511807523107x):
/*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;

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 4.7408051277627745x):
/*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;

}
// Slower C++ solution:
#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);

}

// Faster C++ solution for the same problem (measured speedup: 2.955130551321403x):
#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;           

        }

        

    }

    



}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 5.198717489971957x):
#include <stdio.h>

int A[3001],d[3001],M=998244353,i,K,N,S,j,P;

int main(){scanf("%d%d",&N,&S);while(i++<N)scanf("%d",&A[i]);while(--i){j=S+1;P=A[i];while(j--){d[j]+=(j>=A[i]?d[j-P]:0)+(j==P);d[j]%=M;}K=(K+d[S])%M;d[0]++;}printf("%d\n",K);}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 5.22189990538725x):
#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);}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 2.2380291523869684x):
#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;

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 2.217734901696565x):
#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))

#include <functional>

#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;

    vector<int> a(n);

    rep(i,n) cin >> a[i];

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

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

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

    rep(i,n){

        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[i]>=0){

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

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

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

            }

        }

    }

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

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 1.2004450858079154x):
#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;

}