stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll max_n=1e5+100;

const ll inf=0x3f3f3f3f;

ll t,n,m,p[max_n],v[max_n],q[max_n],dp[max_n];

int main(){

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

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

    while(cin>>n>>m){

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

            cin>>p[i]>>q[i];

        }

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

        ll ans=0;

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

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

                dp[j]=max(dp[j],dp[j-p[i]]+q[i]);

                ans=max(ans,dp[j]);

            }

        }cout<<ans<<endl;

    }

    return 0;

}


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

#define ll long long int

#define vll vector<pair<ll, ll> >

#define vl vector<ll>

#define vi vector<int>

#define vii vector<pair<int, int> >

const ll mod = 1e9 + 7;

const ll inf = LLONG_MAX;

using namespace std;



ll power_mod(ll x, ll y, ll p)

{

	ll ans = 1;

	x = x%p;

	if(x==0)

	return p;



	while(y>0)

	{

		if(y&1)

		{

			ans = (ans*x)%p;

		}

		y = y>>1;

		x = (x*x)%p;

	}

	return ans;

} 

ll knapSack(ll W, ll wt[], ll val[], ll n) 

{ 

    ll i, w; 

    ll K[n + 1][W + 1]; 

  

    // Build table K[][] in bottom up manner 

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

        for (w = 0; w <= W; w++) { 

            if (i == 0 || w == 0) 

                K[i][w] = 0; 

            else if (wt[i - 1] <= w) 

                K[i][w] = max( 

                    val[i - 1] + K[i - 1][w - wt[i - 1]], 

                    K[i - 1][w]); 

            else

                K[i][w] = K[i - 1][w]; 

        } 

    } 

  

    return K[n][W]; 

} 



int main()

{

	ios_base::sync_with_stdio(false);

	cin.tie(0);

	int t;

	ll n,w,i,j,k;

	cin>>n>>w;

	ll val[n], wt[n];

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

	{

	    cin>>wt[i]>>val[i];

	}

	cout<<knapSack(w, wt, val, n);

	return 0;

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

using namespace std;



typedef long long ll;



const int maxn = 105, maxw = 1e5 + 5;



int main(int argc, const char * argv[])

{

    ll n, W, w[maxn], v[maxn], dp[maxw] = {0};

    cin >> n >> W;

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

        scanf("%lld %lld", &w[i], &v[i]);



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

        for (int j = W; j >= w[i]; j--)

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

    

    cout << dp[W] << endl;

    return 0;

}

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

#define ll long long int

#define vll vector<pair<ll, ll> >

#define vl vector<ll>

#define vi vector<int>

#define vii vector<pair<int, int> >

const ll mod = 1e9 + 7;

const ll inf = LLONG_MAX;

using namespace std;



ll power_mod(ll x, ll y, ll p)

{

	ll ans = 1;

	x = x%p;

	if(x==0)

	return p;



	while(y>0)

	{

		if(y&1)

		{

			ans = (ans*x)%p;

		}

		y = y>>1;

		x = (x*x)%p;

	}

	return ans;

} 

ll knapSack(ll W, ll wt[], ll val[], ll n) 

{ 

    ll i, w; 

    ll K[n + 1][W + 1]; 

  

    // Build table K[][] in bottom up manner 

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

        for (w = 0; w <= W; w++) { 

            if (i == 0 || w == 0) 

                K[i][w] = 0; 

            else if (wt[i - 1] <= w) 

                K[i][w] = max( 

                    val[i - 1] + K[i - 1][w - wt[i - 1]], 

                    K[i - 1][w]); 

            else

                K[i][w] = K[i - 1][w]; 

        } 

    } 

  

    return K[n][W]; 

} 



int main()

{

	ios_base::sync_with_stdio(false);

	cin.tie(0);

	int t;

	ll n,w,i,j,k;

	cin>>n>>w;

	ll val[n], wt[n];

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

	{

	    cin>>wt[i]>>val[i];

	}

	cout<<knapSack(w, wt, val, n);

	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.8204557200942706x):
#include <bits/stdc++.h>

#define eps 1e-3

#define pi acos(-1.0)

#define inf 0x3f

#define INF 0x3f3f3f3f

#define pb push_back

#define debug1 cout<<"&&";

#define debug2 cout<<"**";

#define ms(a, x) memset(a, x, sizeof(a))

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

#define for1(i, n) for(int i = 1; i <= n; ++i)

using namespace std;

typedef double db;

typedef long long ll;

typedef unsigned long long ull;

typedef pair<int, int> pii;

typedef pair<long long, int> pli;

typedef pair<long long, long long> pll;

const int mod = 1e9 + 7;

const int N = 1e5+10;

const int M = 1e6+10;

inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

inline ll Pow(ll a, ll b) { ll ans = 1; for( ; b; b >>= 1) { if(b&1) ans = ans * a % mod; a = a * a % mod;} return ans;}

inline ll Mul ( ll a, ll b)  { ll lf = a * ( b >> 25ll ) % mod * ( 1LL << 25 ) % mod; ll rg = a * ( b & ( ( 1ll << 25 ) - 1 ) ) % mod; return ( lf + rg ) % mod;}

//==================================================================================================================================================================//



ll n, W, dp[N];



int main() {

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

   for1(i, n) {

      ll w, v;

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

      for(ll j = W; j >= w; --j) {

         dp[j] = max(dp[j], dp[j-w] + v);

      }

   }

   printf("%lld\n", dp[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.325029074101263x):
#include <bits/stdc++.h>

#define eps 1e-3

#define pi acos(-1.0)

#define inf 0x3f

#define INF 0x3f3f3f3f

#define pb push_back

#define debug1 cout<<"&&";

#define debug2 cout<<"**";

#define ms(a, x) memset(a, x, sizeof(a))

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

#define for1(i, n) for(int i = 1; i <= n; ++i)

using namespace std;

typedef double db;

typedef long long ll;

typedef unsigned long long ull;

typedef pair<int, int> pii;

typedef pair<long long, int> pli;

typedef pair<long long, long long> pll;

const int mod = 1e9 + 7;

const int N = 1e5+10;

const int M = 1e6+10;

inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

inline ll Pow(ll a, ll b) { ll ans = 1; for( ; b; b >>= 1) { if(b&1) ans = ans * a % mod; a = a * a % mod;} return ans;}

inline ll Mul ( ll a, ll b)  { ll lf = a * ( b >> 25ll ) % mod * ( 1LL << 25 ) % mod; ll rg = a * ( b & ( ( 1ll << 25 ) - 1 ) ) % mod; return ( lf + rg ) % mod;}

//==================================================================================================================================================================//



ll n, W, dp[N];



int main() {

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

   for1(i, n) {

      ll w, v;

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

      for(ll j = W; j >= w; --j) {

         dp[j] = max(dp[j], dp[j-w] + v);

      }

   }

   printf("%lld\n", dp[W]);

   return 0;

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



using namespace std;

typedef long long ll;

typedef unsigned long long ull;



const int mod  = 100003;

const int maxn = 1e5+10;



struct yao

{

	ll val,tim;

};

ll dp[maxn];

yao p[110];

int main()

{

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

	int t,m;

	cin>>m>>t;

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

		cin>>p[i].tim>>p[i].val;

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

	{

		for (int j=t;j>=1;j--)

		{

			if (j>=p[i].tim)

				dp[j]=max(dp[j],dp[j-p[i].tim]+p[i].val);

		}

	}

	cout<<dp[t];

    return 0;

}


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

#define eps 1e-3

#define pi acos(-1.0)

#define inf 0x3f

#define INF 0x3f3f3f3f

#define pb push_back

#define debug1 cout<<"&&";

#define debug2 cout<<"**";

#define ms(a, x) memset(a, x, sizeof(a))

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

#define for1(i, n) for(int i = 1; i <= n; ++i)

using namespace std;

typedef double db;

typedef long long ll;

typedef unsigned long long ull;

typedef pair<int, int> pii;

typedef pair<long long, int> pli;

typedef pair<long long, long long> pll;

const int mod = 1e9 + 7;

const int N = 1e5+10;

const int M = 1e6+10;

inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

inline ll Pow(ll a, ll b) { ll ans = 1; for( ; b; b >>= 1) { if(b&1) ans = ans * a % mod; a = a * a % mod;} return ans;}

inline ll Mul ( ll a, ll b)  { ll lf = a * ( b >> 25ll ) % mod * ( 1LL << 25 ) % mod; ll rg = a * ( b & ( ( 1ll << 25 ) - 1 ) ) % mod; return ( lf + rg ) % mod;}

//==================================================================================================================================================================//



ll n, W, dp[N];



int main() {

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

   for1(i, n) {

      ll w, v;

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

      for(ll j = W; j >= w; --j) {

         dp[j] = max(dp[j], dp[j-w] + v);

      }

   }

   printf("%lld\n", dp[W]);

   return 0;

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

using namespace std;

typedef long long ll;

const ll max_n=1e5+100;

const ll inf=0x3f3f3f3f;

ll t,n,m,p[max_n],v[max_n],q[max_n],dp[max_n];

int main(){

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

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

    while(cin>>n>>m){

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

            cin>>p[i]>>q[i];

        }

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

        ll ans=0;

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

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

                dp[j]=max(dp[j],dp[j-p[i]]+q[i]);

                ans=max(ans,dp[j]);

            }

        }cout<<ans<<endl;

    }

    return 0;

}


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

#define eps 1e-3

#define pi acos(-1.0)

#define inf 0x3f

#define INF 0x3f3f3f3f

#define pb push_back

#define debug1 cout<<"&&";

#define debug2 cout<<"**";

#define ms(a, x) memset(a, x, sizeof(a))

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

#define for1(i, n) for(int i = 1; i <= n; ++i)

using namespace std;

typedef double db;

typedef long long ll;

typedef unsigned long long ull;

typedef pair<int, int> pii;

typedef pair<long long, int> pli;

typedef pair<long long, long long> pll;

const int mod = 1e9 + 7;

const int N = 1e5+10;

const int M = 1e6+10;

inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

inline ll Pow(ll a, ll b) { ll ans = 1; for( ; b; b >>= 1) { if(b&1) ans = ans * a % mod; a = a * a % mod;} return ans;}

inline ll Mul ( ll a, ll b)  { ll lf = a * ( b >> 25ll ) % mod * ( 1LL << 25 ) % mod; ll rg = a * ( b & ( ( 1ll << 25 ) - 1 ) ) % mod; return ( lf + rg ) % mod;}

//==================================================================================================================================================================//



ll n, W, dp[N];



int main() {

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

   for1(i, n) {

      ll w, v;

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

      for(ll j = W; j >= w; --j) {

         dp[j] = max(dp[j], dp[j-w] + v);

      }

   }

   printf("%lld\n", dp[W]);

   return 0;

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

using namespace std;



typedef long long ll;



const int maxn = 105, maxw = 1e5 + 5;



int main(int argc, const char * argv[])

{

    ll n, W, w[maxn], v[maxn], dp[maxw] = {0};

    cin >> n >> W;

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

        scanf("%lld %lld", &w[i], &v[i]);



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

        for (int j = W; j >= w[i]; j--)

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

    

    cout << dp[W] << endl;

    return 0;

}

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

#define eps 1e-3

#define pi acos(-1.0)

#define inf 0x3f

#define INF 0x3f3f3f3f

#define pb push_back

#define debug1 cout<<"&&";

#define debug2 cout<<"**";

#define ms(a, x) memset(a, x, sizeof(a))

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

#define for1(i, n) for(int i = 1; i <= n; ++i)

using namespace std;

typedef double db;

typedef long long ll;

typedef unsigned long long ull;

typedef pair<int, int> pii;

typedef pair<long long, int> pli;

typedef pair<long long, long long> pll;

const int mod = 1e9 + 7;

const int N = 1e5+10;

const int M = 1e6+10;

inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

inline ll Pow(ll a, ll b) { ll ans = 1; for( ; b; b >>= 1) { if(b&1) ans = ans * a % mod; a = a * a % mod;} return ans;}

inline ll Mul ( ll a, ll b)  { ll lf = a * ( b >> 25ll ) % mod * ( 1LL << 25 ) % mod; ll rg = a * ( b & ( ( 1ll << 25 ) - 1 ) ) % mod; return ( lf + rg ) % mod;}

//==================================================================================================================================================================//



ll n, W, dp[N];



int main() {

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

   for1(i, n) {

      ll w, v;

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

      for(ll j = W; j >= w; --j) {

         dp[j] = max(dp[j], dp[j-w] + v);

      }

   }

   printf("%lld\n", dp[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.7744609216447542x):
#include <bits/stdc++.h>

 

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

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

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

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

#define ones(x) (ll) __builtin_popcount(x)

#define fs first

#define sc second

#define pb push_back

#define po pop_back

#define mp make_pair  

#define sz(a) (ll) a.size()

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

#define sor(a) sort( a.begin(), a.end() )

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

#define ller ios::sync_with_stdio(false);cin.tsie(nullptr);cout.tie(nullptr)

#define watch(x) cout << (#x) << " is #" << (x) <<"#" <<endl

#define PI 3.1415926535

using namespace std;

typedef long long ll;

typedef long double ld; 

typedef pair<ll,ll> ii ;

typedef vector<ll>  vi ;

typedef vector<ii> vii ;

const ll mod = 1e9+7;

const ll MAX = 1e5+5;

const ll inf = 1e18+7;

ll w[MAX],valor[MAX],dp[MAX];

int main() {

  fastio;

  ll n,cap;

  cin>>n>>cap;

  f(i,0,n) cin>>w[i]>>valor[i];

  f(i,0,n){

    af(j,cap,1){

      if(j>=w[i]) dp[j] = max(dp[j],dp[j-w[i]]+valor[i]);

    }

  }

  cout<<dp[cap]<<"\n";

  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.2915514978381717x):
#include <bits/stdc++.h>

 

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

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

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

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

#define ones(x) (ll) __builtin_popcount(x)

#define fs first

#define sc second

#define pb push_back

#define po pop_back

#define mp make_pair  

#define sz(a) (ll) a.size()

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

#define sor(a) sort( a.begin(), a.end() )

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

#define ller ios::sync_with_stdio(false);cin.tsie(nullptr);cout.tie(nullptr)

#define watch(x) cout << (#x) << " is #" << (x) <<"#" <<endl

#define PI 3.1415926535

using namespace std;

typedef long long ll;

typedef long double ld; 

typedef pair<ll,ll> ii ;

typedef vector<ll>  vi ;

typedef vector<ii> vii ;

const ll mod = 1e9+7;

const ll MAX = 1e5+5;

const ll inf = 1e18+7;

ll w[MAX],valor[MAX],dp[MAX];

int main() {

  fastio;

  ll n,cap;

  cin>>n>>cap;

  f(i,0,n) cin>>w[i]>>valor[i];

  f(i,0,n){

    af(j,cap,1){

      if(j>=w[i]) dp[j] = max(dp[j],dp[j-w[i]]+valor[i]);

    }

  }

  cout<<dp[cap]<<"\n";

  return 0; 

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



using namespace std;

typedef long long ll;

typedef unsigned long long ull;



const int mod  = 100003;

const int maxn = 1e5+10;



struct yao

{

	ll val,tim;

};

ll dp[maxn];

yao p[110];

int main()

{

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

	int t,m;

	cin>>m>>t;

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

		cin>>p[i].tim>>p[i].val;

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

	{

		for (int j=t;j>=1;j--)

		{

			if (j>=p[i].tim)

				dp[j]=max(dp[j],dp[j-p[i].tim]+p[i].val);

		}

	}

	cout<<dp[t];

    return 0;

}


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

 

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

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

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

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

#define ones(x) (ll) __builtin_popcount(x)

#define fs first

#define sc second

#define pb push_back

#define po pop_back

#define mp make_pair  

#define sz(a) (ll) a.size()

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

#define sor(a) sort( a.begin(), a.end() )

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

#define ller ios::sync_with_stdio(false);cin.tsie(nullptr);cout.tie(nullptr)

#define watch(x) cout << (#x) << " is #" << (x) <<"#" <<endl

#define PI 3.1415926535

using namespace std;

typedef long long ll;

typedef long double ld; 

typedef pair<ll,ll> ii ;

typedef vector<ll>  vi ;

typedef vector<ii> vii ;

const ll mod = 1e9+7;

const ll MAX = 1e5+5;

const ll inf = 1e18+7;

ll w[MAX],valor[MAX],dp[MAX];

int main() {

  fastio;

  ll n,cap;

  cin>>n>>cap;

  f(i,0,n) cin>>w[i]>>valor[i];

  f(i,0,n){

    af(j,cap,1){

      if(j>=w[i]) dp[j] = max(dp[j],dp[j-w[i]]+valor[i]);

    }

  }

  cout<<dp[cap]<<"\n";

  return 0; 

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

using namespace std;

typedef long long ll;

const ll max_n=1e5+100;

const ll inf=0x3f3f3f3f;

ll t,n,m,p[max_n],v[max_n],q[max_n],dp[max_n];

int main(){

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

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

    while(cin>>n>>m){

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

            cin>>p[i]>>q[i];

        }

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

        ll ans=0;

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

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

                dp[j]=max(dp[j],dp[j-p[i]]+q[i]);

                ans=max(ans,dp[j]);

            }

        }cout<<ans<<endl;

    }

    return 0;

}


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

 

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

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

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

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

#define ones(x) (ll) __builtin_popcount(x)

#define fs first

#define sc second

#define pb push_back

#define po pop_back

#define mp make_pair  

#define sz(a) (ll) a.size()

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

#define sor(a) sort( a.begin(), a.end() )

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

#define ller ios::sync_with_stdio(false);cin.tsie(nullptr);cout.tie(nullptr)

#define watch(x) cout << (#x) << " is #" << (x) <<"#" <<endl

#define PI 3.1415926535

using namespace std;

typedef long long ll;

typedef long double ld; 

typedef pair<ll,ll> ii ;

typedef vector<ll>  vi ;

typedef vector<ii> vii ;

const ll mod = 1e9+7;

const ll MAX = 1e5+5;

const ll inf = 1e18+7;

ll w[MAX],valor[MAX],dp[MAX];

int main() {

  fastio;

  ll n,cap;

  cin>>n>>cap;

  f(i,0,n) cin>>w[i]>>valor[i];

  f(i,0,n){

    af(j,cap,1){

      if(j>=w[i]) dp[j] = max(dp[j],dp[j-w[i]]+valor[i]);

    }

  }

  cout<<dp[cap]<<"\n";

  return 0; 

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

using namespace std;



typedef long long ll;



const int maxn = 105, maxw = 1e5 + 5;



int main(int argc, const char * argv[])

{

    ll n, W, w[maxn], v[maxn], dp[maxw] = {0};

    cin >> n >> W;

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

        scanf("%lld %lld", &w[i], &v[i]);



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

        for (int j = W; j >= w[i]; j--)

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

    

    cout << dp[W] << endl;

    return 0;

}

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

 

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

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

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

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

#define ones(x) (ll) __builtin_popcount(x)

#define fs first

#define sc second

#define pb push_back

#define po pop_back

#define mp make_pair  

#define sz(a) (ll) a.size()

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

#define sor(a) sort( a.begin(), a.end() )

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

#define ller ios::sync_with_stdio(false);cin.tsie(nullptr);cout.tie(nullptr)

#define watch(x) cout << (#x) << " is #" << (x) <<"#" <<endl

#define PI 3.1415926535

using namespace std;

typedef long long ll;

typedef long double ld; 

typedef pair<ll,ll> ii ;

typedef vector<ll>  vi ;

typedef vector<ii> vii ;

const ll mod = 1e9+7;

const ll MAX = 1e5+5;

const ll inf = 1e18+7;

ll w[MAX],valor[MAX],dp[MAX];

int main() {

  fastio;

  ll n,cap;

  cin>>n>>cap;

  f(i,0,n) cin>>w[i]>>valor[i];

  f(i,0,n){

    af(j,cap,1){

      if(j>=w[i]) dp[j] = max(dp[j],dp[j-w[i]]+valor[i]);

    }

  }

  cout<<dp[cap]<<"\n";

  return 0; 

}