stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<cstring>

#include<cstdlib>

#include<algorithm>

#include<stack>

#include<queue>

#include<vector>

#include<set>

#include<string>

#include<cmath>

#include<map>

#include<bitset>

#include<utility>

//#include<unordered_map>

#ifdef LOCAL

#include"file.h"

#endif



using namespace std;



typedef long long LL;

typedef unsigned long long ULL;

const double eps = 1e-12;

const double Pi = 3.1415926535897932;

const int dir[4][2] = { -1,0,1,0,0,-1,0,1 };

//const int dir[8][2] = { -2,-1,-2,1,2,-1,2,1,-1,2,-1,-2,1,2,1,-2 };











const int maxn = 1e5 + 5;

LL f[maxn];





int main() {

#ifdef LOCAL

	fileopen();

#endif

	int n, C;

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

	memset(f, -1, sizeof(f));

	f[0] = 0;

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

		int w, v;

		scanf("%d%d", &w, &v);

		for (int i = C; i >= w; i--)if(f[i-w]!=-1) {

			f[i] = max(f[i], f[i - w] + v);

		}

	}

	LL ans = 0;

	for (int i = 0; i <= C; i++)ans = max(ans, f[i]);

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



#ifdef LOCAL

	fileclose();

#endif

	return 0;

}

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

using namespace std;

typedef long long ll;

#define fast ios_base::sync_with_stdio(false),cin.tie(NULL)

#define x first

#define y second



vector<vector<int>> dp, arr;

int main() {

    fast;

    int n, w;

    cin>>n>>w;

    vector<int> weight(n), value(n);

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

        cin>>weight[i]>>value[i];

    }

    ll dp[n+1][w+1];

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

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

            if(i == 0 || j == 0)

                dp[i][j] = 0;

            else{

                ll leave = dp[i-1][j], take = -1;

                if(weight[i-1] <= j)

                    take = dp[i - 1][j - weight[i-1]] + value[i-1];

                dp[i][j] = max(take, leave);

            }



        }

    }

    cout<<dp[n][w];

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;



ll dp[100005];



int main(){

    ll n,w;

    cin>>n>>w;

    ll wi,vi;

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

        cin>>wi>>vi;

        for(ll wc=w-wi;wc>=0;wc--){

            dp[wc+wi]=max(dp[wc+wi],dp[wc]+vi);

        }

    }

    ll ans=0;

    for(auto i:dp) ans=max(ans,i);

    cout<<ans;



    return 0;

}


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

using namespace std;

typedef long long ll;

#define fast ios_base::sync_with_stdio(false),cin.tie(NULL)

#define x first

#define y second



vector<vector<int>> dp, arr;

int main() {

    fast;

    int n, w;

    cin>>n>>w;

    vector<int> weight(n), value(n);

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

        cin>>weight[i]>>value[i];

    }

    ll dp[n+1][w+1];

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

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

            if(i == 0 || j == 0)

                dp[i][j] = 0;

            else{

                ll leave = dp[i-1][j], take = -1;

                if(weight[i-1] <= j)

                    take = dp[i - 1][j - weight[i-1]] + value[i-1];

                dp[i][j] = max(take, leave);

            }



        }

    }

    cout<<dp[n][w];

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<cstring>

#include<cstdlib>

#include<algorithm>

#include<stack>

#include<queue>

#include<vector>

#include<set>

#include<string>

#include<cmath>

#include<map>

#include<bitset>

#include<utility>

//#include<unordered_map>

#ifdef LOCAL

#include"file.h"

#endif



using namespace std;



typedef long long LL;

typedef unsigned long long ULL;

const double eps = 1e-12;

const double Pi = 3.1415926535897932;

const int dir[4][2] = { -1,0,1,0,0,-1,0,1 };

//const int dir[8][2] = { -2,-1,-2,1,2,-1,2,1,-1,2,-1,-2,1,2,1,-2 };











const int maxn = 1e5 + 5;

LL f[maxn];





int main() {

#ifdef LOCAL

	fileopen();

#endif

	int n, C;

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

	memset(f, -1, sizeof(f));

	f[0] = 0;

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

		int w, v;

		scanf("%d%d", &w, &v);

		for (int i = C; i >= w; i--)if(f[i-w]!=-1) {

			f[i] = max(f[i], f[i - w] + v);

		}

	}

	LL ans = 0;

	for (int i = 0; i <= C; i++)ans = max(ans, f[i]);

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



#ifdef LOCAL

	fileclose();

#endif

	return 0;

}

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

#define Joe ios::sync_with_stdio(0); cin.tie(NULL); ios_base::sync_with_stdio(0); cout.tie(NULL);

#define INF 1e9+7

const long long N =1e5+5;

using namespace std;

int main(){

	Joe

	int n,w;

	cin>>n>>w;

	long long weight[n+5],price[n+5];

	long long arr[n+5][w+5];

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

		cin>>weight[i];

		cin>>price[i];

	}

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

		for(int c=0;c<=w;c++){

			if(r==0||w==0)

				arr[r][c]=0;

			else if(weight[r]<=c)

				arr[r][c]=max(arr[r-1][c],price[r]+arr[r-1][c-weight[r]]);

			else

				arr[r][c]=arr[r-1][c];

		}

	}

	cout<<arr[n][w]<<endl;

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;



ll dp[100005];



int main(){

    ll n,w;

    cin>>n>>w;

    ll wi,vi;

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

        cin>>wi>>vi;

        for(ll wc=w-wi;wc>=0;wc--){

            dp[wc+wi]=max(dp[wc+wi],dp[wc]+vi);

        }

    }

    ll ans=0;

    for(auto i:dp) ans=max(ans,i);

    cout<<ans;



    return 0;

}


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

#define Joe ios::sync_with_stdio(0); cin.tie(NULL); ios_base::sync_with_stdio(0); cout.tie(NULL);

#define INF 1e9+7

const long long N =1e5+5;

using namespace std;

int main(){

	Joe

	int n,w;

	cin>>n>>w;

	long long weight[n+5],price[n+5];

	long long arr[n+5][w+5];

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

		cin>>weight[i];

		cin>>price[i];

	}

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

		for(int c=0;c<=w;c++){

			if(r==0||w==0)

				arr[r][c]=0;

			else if(weight[r]<=c)

				arr[r][c]=max(arr[r-1][c],price[r]+arr[r-1][c-weight[r]]);

			else

				arr[r][c]=arr[r-1][c];

		}

	}

	cout<<arr[n][w]<<endl;

	return 0;

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<cstring>

#include<cstdlib>

#include<algorithm>

#include<stack>

#include<queue>

#include<vector>

#include<set>

#include<string>

#include<cmath>

#include<map>

#include<bitset>

#include<utility>

//#include<unordered_map>

#ifdef LOCAL

#include"file.h"

#endif



using namespace std;



typedef long long LL;

typedef unsigned long long ULL;

const double eps = 1e-12;

const double Pi = 3.1415926535897932;

const int dir[4][2] = { -1,0,1,0,0,-1,0,1 };

//const int dir[8][2] = { -2,-1,-2,1,2,-1,2,1,-1,2,-1,-2,1,2,1,-2 };











const int maxn = 1e5 + 5;

LL f[maxn];





int main() {

#ifdef LOCAL

	fileopen();

#endif

	int n, C;

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

	memset(f, -1, sizeof(f));

	f[0] = 0;

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

		int w, v;

		scanf("%d%d", &w, &v);

		for (int i = C; i >= w; i--)if(f[i-w]!=-1) {

			f[i] = max(f[i], f[i - w] + v);

		}

	}

	LL ans = 0;

	for (int i = 0; i <= C; i++)ans = max(ans, f[i]);

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



#ifdef LOCAL

	fileclose();

#endif

	return 0;

}

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

using namespace std;

int main()

{

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

  int n,c;

  cin>>n>>c;

  int val[n+1],w[n+1];

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

    cin>>w[i]>>val[i];

    long long dp[n+5][c+5];

    for(int j=0;j<=c;j++)

        dp[0][j]=0;

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

  {

      for(int j=0;j<=c;j++)

      {

          if(j==0)

            dp[i][j]=0;

          else if(w[i]<=j)

          {

              dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+val[i]);

          }

          else

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

      }

  }

  cout<<dp[n][c];

   return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;



ll dp[100005];



int main(){

    ll n,w;

    cin>>n>>w;

    ll wi,vi;

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

        cin>>wi>>vi;

        for(ll wc=w-wi;wc>=0;wc--){

            dp[wc+wi]=max(dp[wc+wi],dp[wc]+vi);

        }

    }

    ll ans=0;

    for(auto i:dp) ans=max(ans,i);

    cout<<ans;



    return 0;

}


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

using namespace std;

int main()

{

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

  int n,c;

  cin>>n>>c;

  int val[n+1],w[n+1];

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

    cin>>w[i]>>val[i];

    long long dp[n+5][c+5];

    for(int j=0;j<=c;j++)

        dp[0][j]=0;

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

  {

      for(int j=0;j<=c;j++)

      {

          if(j==0)

            dp[i][j]=0;

          else if(w[i]<=j)

          {

              dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+val[i]);

          }

          else

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

      }

  }

  cout<<dp[n][c];

   return 0;

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<cstring>

#include<cstdlib>

#include<algorithm>

#include<stack>

#include<queue>

#include<vector>

#include<set>

#include<string>

#include<cmath>

#include<map>

#include<bitset>

#include<utility>

//#include<unordered_map>

#ifdef LOCAL

#include"file.h"

#endif



using namespace std;



typedef long long LL;

typedef unsigned long long ULL;

const double eps = 1e-12;

const double Pi = 3.1415926535897932;

const int dir[4][2] = { -1,0,1,0,0,-1,0,1 };

//const int dir[8][2] = { -2,-1,-2,1,2,-1,2,1,-1,2,-1,-2,1,2,1,-2 };











const int maxn = 1e5 + 5;

LL f[maxn];





int main() {

#ifdef LOCAL

	fileopen();

#endif

	int n, C;

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

	memset(f, -1, sizeof(f));

	f[0] = 0;

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

		int w, v;

		scanf("%d%d", &w, &v);

		for (int i = C; i >= w; i--)if(f[i-w]!=-1) {

			f[i] = max(f[i], f[i - w] + v);

		}

	}

	LL ans = 0;

	for (int i = 0; i <= C; i++)ans = max(ans, f[i]);

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



#ifdef LOCAL

	fileclose();

#endif

	return 0;

}

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

using namespace std;

#define ll long long

#define pb push_back

#define F first

#define S second

const int mod = 1e9+7, A = 1e2+5;

int n, w, weight[A], val[A];

ll dp[A][100005];

ll build()

{

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

	{

		for (int j = 1; j <= w; j++)

		{

			ll ret = dp[i-1][j];

			

			if (j - weight[i] >= 0)

				ret = max(ret, dp[i-1][j - weight[i]] + val[i]);

			

			dp[i][j] = ret;

		}

	}

	return dp[n][w];

}



int main()

{

	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);

	cin >> n >> w;

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

		cin >> weight[i] >> val[i];

	cout << build();

	return 0;

}

	/*



	states : indx , weight



	base case : dp[0][ay 7aga] = 0, dp[ay 7aga][0] = 0



	transitions : dp[i][j] = dp[i-1][j]  |  dp[i-1][j-w] + val



	0   0



	3   30

		

	4   50

	

	5   60

	

	

	 */
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;



ll dp[100005];



int main(){

    ll n,w;

    cin>>n>>w;

    ll wi,vi;

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

        cin>>wi>>vi;

        for(ll wc=w-wi;wc>=0;wc--){

            dp[wc+wi]=max(dp[wc+wi],dp[wc]+vi);

        }

    }

    ll ans=0;

    for(auto i:dp) ans=max(ans,i);

    cout<<ans;



    return 0;

}


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

using namespace std;

#define ll long long

#define pb push_back

#define F first

#define S second

const int mod = 1e9+7, A = 1e2+5;

int n, w, weight[A], val[A];

ll dp[A][100005];

ll build()

{

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

	{

		for (int j = 1; j <= w; j++)

		{

			ll ret = dp[i-1][j];

			

			if (j - weight[i] >= 0)

				ret = max(ret, dp[i-1][j - weight[i]] + val[i]);

			

			dp[i][j] = ret;

		}

	}

	return dp[n][w];

}



int main()

{

	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);

	cin >> n >> w;

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

		cin >> weight[i] >> val[i];

	cout << build();

	return 0;

}

	/*



	states : indx , weight



	base case : dp[0][ay 7aga] = 0, dp[ay 7aga][0] = 0



	transitions : dp[i][j] = dp[i-1][j]  |  dp[i-1][j-w] + val



	0   0



	3   30

		

	4   50

	

	5   60

	

	

	 */
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<cstring>

#include<cstdlib>

#include<algorithm>

#include<stack>

#include<queue>

#include<vector>

#include<set>

#include<string>

#include<cmath>

#include<map>

#include<bitset>

#include<utility>

//#include<unordered_map>

#ifdef LOCAL

#include"file.h"

#endif



using namespace std;



typedef long long LL;

typedef unsigned long long ULL;

const double eps = 1e-12;

const double Pi = 3.1415926535897932;

const int dir[4][2] = { -1,0,1,0,0,-1,0,1 };

//const int dir[8][2] = { -2,-1,-2,1,2,-1,2,1,-1,2,-1,-2,1,2,1,-2 };











const int maxn = 1e5 + 5;

LL f[maxn];





int main() {

#ifdef LOCAL

	fileopen();

#endif

	int n, C;

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

	memset(f, -1, sizeof(f));

	f[0] = 0;

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

		int w, v;

		scanf("%d%d", &w, &v);

		for (int i = C; i >= w; i--)if(f[i-w]!=-1) {

			f[i] = max(f[i], f[i - w] + v);

		}

	}

	LL ans = 0;

	for (int i = 0; i <= C; i++)ans = max(ans, f[i]);

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



#ifdef LOCAL

	fileclose();

#endif

	return 0;

}

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



#define ll long long

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

#define pb push_back

const long double pi=3.141592654;

#define OSOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;



const ll inf = 1e9 +5, mod = 1e9+7,N = 1e5+5;



    int val[N],weights[N];

    ll dp[102][N];

int main()

{

    OSOS

	ll n,w;

    cin>>n>>w;



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

    	cin>>weights[i]>>val[i];



    for(int rem = 1; rem <= w; rem++)

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

    	{

    		ll op1,op2;

    		op1 = dp[item-1][rem];

    		op2 = 0;

    		if(rem >= weights[item])

    		{

    			op2 = val[item] + dp[item-1][rem - weights[item]];

    		}

    		dp[item][rem] = max(op1,op2);

    	}



    cout<<dp[n][w];



    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;



ll dp[100005];



int main(){

    ll n,w;

    cin>>n>>w;

    ll wi,vi;

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

        cin>>wi>>vi;

        for(ll wc=w-wi;wc>=0;wc--){

            dp[wc+wi]=max(dp[wc+wi],dp[wc]+vi);

        }

    }

    ll ans=0;

    for(auto i:dp) ans=max(ans,i);

    cout<<ans;



    return 0;

}


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



#define ll long long

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

#define pb push_back

const long double pi=3.141592654;

#define OSOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;



const ll inf = 1e9 +5, mod = 1e9+7,N = 1e5+5;



    int val[N],weights[N];

    ll dp[102][N];

int main()

{

    OSOS

	ll n,w;

    cin>>n>>w;



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

    	cin>>weights[i]>>val[i];



    for(int rem = 1; rem <= w; rem++)

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

    	{

    		ll op1,op2;

    		op1 = dp[item-1][rem];

    		op2 = 0;

    		if(rem >= weights[item])

    		{

    			op2 = val[item] + dp[item-1][rem - weights[item]];

    		}

    		dp[item][rem] = max(op1,op2);

    	}



    cout<<dp[n][w];



    return 0;

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<cstring>

#include<cstdlib>

#include<algorithm>

#include<stack>

#include<queue>

#include<vector>

#include<set>

#include<string>

#include<cmath>

#include<map>

#include<bitset>

#include<utility>

//#include<unordered_map>

#ifdef LOCAL

#include"file.h"

#endif



using namespace std;



typedef long long LL;

typedef unsigned long long ULL;

const double eps = 1e-12;

const double Pi = 3.1415926535897932;

const int dir[4][2] = { -1,0,1,0,0,-1,0,1 };

//const int dir[8][2] = { -2,-1,-2,1,2,-1,2,1,-1,2,-1,-2,1,2,1,-2 };











const int maxn = 1e5 + 5;

LL f[maxn];





int main() {

#ifdef LOCAL

	fileopen();

#endif

	int n, C;

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

	memset(f, -1, sizeof(f));

	f[0] = 0;

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

		int w, v;

		scanf("%d%d", &w, &v);

		for (int i = C; i >= w; i--)if(f[i-w]!=-1) {

			f[i] = max(f[i], f[i - w] + v);

		}

	}

	LL ans = 0;

	for (int i = 0; i <= C; i++)ans = max(ans, f[i]);

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



#ifdef LOCAL

	fileclose();

#endif

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.7654553739733705x):
#define _CRT_SECURE_NO_WARNINGS

#include<bits/stdc++.h>

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

#define per(i,a,n) for (int i=n-1;i>=a;i--)

#define all(s) s.begin(),s.end()

#define sz(s) (int)s.size()

#define clr(v, d) memset(v, d, sizeof(v))

#define fi first

#define se second

#define pp push_back

#define pb pop_back

#define pi 3.141592654

#define MOD 1000000007 

#define cons1 1e12

#define cons2 1e6

using namespace std;

typedef long long ll;

typedef vector<int> vi;

typedef pair<int, ll> pa;

typedef unsigned long long int ull;

typedef double long dl;

const int N = 1e5+9,oo=-1e9;

ll dp[109][N], n, v[109][109];

ll sol(int i, int k){

	if (n-i&&!dp[i][k]) {

		if (k >= v[i][0])   

			dp[i][k] = v[i][1] + sol(i + 1, k - v[i][0]);

		dp[i][k] = max(dp[i][k], sol(i + 1, k));

	}



	return dp[i][k];

}

void solve() {

	int w;

	cin >> n >> w;

	rep(i, 0, n)

		cin >> v[i][0] >> v[i][1];

	cout << sol(0, w) << endl;

}

int main() {

	ios::sync_with_stdio(0);

	cin.tie(NULL);

	cout.tie(NULL);

	int t = 1;

	//cin >> t;

	while (t--)

		solve();



#ifndef ONLINE_JUDGE

	- system("pause");

#endif



}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;



ll dp[100005];



int main(){

    ll n,w;

    cin>>n>>w;

    ll wi,vi;

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

        cin>>wi>>vi;

        for(ll wc=w-wi;wc>=0;wc--){

            dp[wc+wi]=max(dp[wc+wi],dp[wc]+vi);

        }

    }

    ll ans=0;

    for(auto i:dp) ans=max(ans,i);

    cout<<ans;



    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.2849967586258548x):
#define _CRT_SECURE_NO_WARNINGS

#include<bits/stdc++.h>

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

#define per(i,a,n) for (int i=n-1;i>=a;i--)

#define all(s) s.begin(),s.end()

#define sz(s) (int)s.size()

#define clr(v, d) memset(v, d, sizeof(v))

#define fi first

#define se second

#define pp push_back

#define pb pop_back

#define pi 3.141592654

#define MOD 1000000007 

#define cons1 1e12

#define cons2 1e6

using namespace std;

typedef long long ll;

typedef vector<int> vi;

typedef pair<int, ll> pa;

typedef unsigned long long int ull;

typedef double long dl;

const int N = 1e5+9,oo=-1e9;

ll dp[109][N], n, v[109][109];

ll sol(int i, int k){

	if (n-i&&!dp[i][k]) {

		if (k >= v[i][0])   

			dp[i][k] = v[i][1] + sol(i + 1, k - v[i][0]);

		dp[i][k] = max(dp[i][k], sol(i + 1, k));

	}



	return dp[i][k];

}

void solve() {

	int w;

	cin >> n >> w;

	rep(i, 0, n)

		cin >> v[i][0] >> v[i][1];

	cout << sol(0, w) << endl;

}

int main() {

	ios::sync_with_stdio(0);

	cin.tie(NULL);

	cout.tie(NULL);

	int t = 1;

	//cin >> t;

	while (t--)

		solve();



#ifndef ONLINE_JUDGE

	- system("pause");

#endif



}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<cstring>

#include<cstdlib>

#include<algorithm>

#include<stack>

#include<queue>

#include<vector>

#include<set>

#include<string>

#include<cmath>

#include<map>

#include<bitset>

#include<utility>

//#include<unordered_map>

#ifdef LOCAL

#include"file.h"

#endif



using namespace std;



typedef long long LL;

typedef unsigned long long ULL;

const double eps = 1e-12;

const double Pi = 3.1415926535897932;

const int dir[4][2] = { -1,0,1,0,0,-1,0,1 };

//const int dir[8][2] = { -2,-1,-2,1,2,-1,2,1,-1,2,-1,-2,1,2,1,-2 };











const int maxn = 1e5 + 5;

LL f[maxn];





int main() {

#ifdef LOCAL

	fileopen();

#endif

	int n, C;

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

	memset(f, -1, sizeof(f));

	f[0] = 0;

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

		int w, v;

		scanf("%d%d", &w, &v);

		for (int i = C; i >= w; i--)if(f[i-w]!=-1) {

			f[i] = max(f[i], f[i - w] + v);

		}

	}

	LL ans = 0;

	for (int i = 0; i <= C; i++)ans = max(ans, f[i]);

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



#ifdef LOCAL

	fileclose();

#endif

	return 0;

}

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

#define ull unsigned long long

#define ll long long

#define pb push_back

#define endl '\n'

#define line cout<<"----------------------"<<endl

#define mp make_pair

#define mod 1000000007

#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)

#define filein freopen("input.txt","r",stdin)

#define fileout freopen("output.txt","w",stdout)

using namespace std;

const ll  mx=300009;

vector<pair<ll ,ll > > v;

ll  dp[100001][109];

int main()

{

    ll  n,w;

    cin>>n>>w;

    for(ll  i=0;i<n;i++)

    {

        ll  a,b;

        cin>>a>>b;

        v.pb(mp(a,b));

    }

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

    {



        for(int j=0;j<n;j++)

        {

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

            if(v[j].first>i) continue;

            dp[i][j]=max(dp[i][j],dp[i-v[j].first][j-1]+v[j].second);

        }

    }

    cout<<dp[w][n-1]<<endl;

}

/*

3 5

3 3

4 2

2 4

*/
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;



ll dp[100005];



int main(){

    ll n,w;

    cin>>n>>w;

    ll wi,vi;

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

        cin>>wi>>vi;

        for(ll wc=w-wi;wc>=0;wc--){

            dp[wc+wi]=max(dp[wc+wi],dp[wc]+vi);

        }

    }

    ll ans=0;

    for(auto i:dp) ans=max(ans,i);

    cout<<ans;



    return 0;

}


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

#define ull unsigned long long

#define ll long long

#define pb push_back

#define endl '\n'

#define line cout<<"----------------------"<<endl

#define mp make_pair

#define mod 1000000007

#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)

#define filein freopen("input.txt","r",stdin)

#define fileout freopen("output.txt","w",stdout)

using namespace std;

const ll  mx=300009;

vector<pair<ll ,ll > > v;

ll  dp[100001][109];

int main()

{

    ll  n,w;

    cin>>n>>w;

    for(ll  i=0;i<n;i++)

    {

        ll  a,b;

        cin>>a>>b;

        v.pb(mp(a,b));

    }

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

    {



        for(int j=0;j<n;j++)

        {

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

            if(v[j].first>i) continue;

            dp[i][j]=max(dp[i][j],dp[i-v[j].first][j-1]+v[j].second);

        }

    }

    cout<<dp[w][n-1]<<endl;

}

/*

3 5

3 3

4 2

2 4

*/