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



using namespace std;



int main()

{

    int n, c;

    cin >> n >> c;

    int w[n];

    int v[n];

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

    {

        cin >> w[i] >> v[i];

    }

    long long mem[2][c + 1];

    for(int i = 0;i < (c + 1);i++)

        mem[0][i] = 0;

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

    {

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

        {

            if(i % 2 == 0)

            {

                if(w[i] <= j)

                {

                    long long val1 = mem[0][j];

                    long long val2 = v[i] + mem[0][j - w[i]];

                    mem[1][j] = max(val1, val2);

                }

                else

                {

                    mem[1][j] = mem[0][j];

                }

            }

            else

            {

                if(w[i] <= j)

                    mem[0][j] = max(mem[1][j] , v[i] + mem[1][j - w[i]]);

                else

                    mem[0][j] = mem[1][j];

            }

        }

    }

    if(n % 2 == 0)

        cout << mem[0][c] << endl;

    else

        cout << mem[1][c] << 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.3071706034811639x):
#include <bits/stdc++.h>



using namespace std;



int main()

{

    int n, c;

    cin >> n >> c;

    int w[n];

    int v[n];

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

    {

        cin >> w[i] >> v[i];

    }

    long long mem[2][c + 1];

    for(int i = 0;i < (c + 1);i++)

        mem[0][i] = 0;

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

    {

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

        {

            if(i % 2 == 0)

            {

                if(w[i] <= j)

                {

                    long long val1 = mem[0][j];

                    long long val2 = v[i] + mem[0][j - w[i]];

                    mem[1][j] = max(val1, val2);

                }

                else

                {

                    mem[1][j] = mem[0][j];

                }

            }

            else

            {

                if(w[i] <= j)

                    mem[0][j] = max(mem[1][j] , v[i] + mem[1][j - w[i]]);

                else

                    mem[0][j] = mem[1][j];

            }

        }

    }

    if(n % 2 == 0)

        cout << mem[0][c] << endl;

    else

        cout << mem[1][c] << endl;

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



using namespace std;



int main()

{

    int n, c;

    cin >> n >> c;

    int w[n];

    int v[n];

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

    {

        cin >> w[i] >> v[i];

    }

    long long mem[2][c + 1];

    for(int i = 0;i < (c + 1);i++)

        mem[0][i] = 0;

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

    {

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

        {

            if(i % 2 == 0)

            {

                if(w[i] <= j)

                {

                    long long val1 = mem[0][j];

                    long long val2 = v[i] + mem[0][j - w[i]];

                    mem[1][j] = max(val1, val2);

                }

                else

                {

                    mem[1][j] = mem[0][j];

                }

            }

            else

            {

                if(w[i] <= j)

                    mem[0][j] = max(mem[1][j] , v[i] + mem[1][j - w[i]]);

                else

                    mem[0][j] = mem[1][j];

            }

        }

    }

    if(n % 2 == 0)

        cout << mem[0][c] << endl;

    else

        cout << mem[1][c] << endl;

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



using namespace std;



int main()

{

    int n, c;

    cin >> n >> c;

    int w[n];

    int v[n];

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

    {

        cin >> w[i] >> v[i];

    }

    long long mem[2][c + 1];

    for(int i = 0;i < (c + 1);i++)

        mem[0][i] = 0;

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

    {

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

        {

            if(i % 2 == 0)

            {

                if(w[i] <= j)

                {

                    long long val1 = mem[0][j];

                    long long val2 = v[i] + mem[0][j - w[i]];

                    mem[1][j] = max(val1, val2);

                }

                else

                {

                    mem[1][j] = mem[0][j];

                }

            }

            else

            {

                if(w[i] <= j)

                    mem[0][j] = max(mem[1][j] , v[i] + mem[1][j - w[i]]);

                else

                    mem[0][j] = mem[1][j];

            }

        }

    }

    if(n % 2 == 0)

        cout << mem[0][c] << endl;

    else

        cout << mem[1][c] << endl;

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



using namespace std;



int main()

{

    int n, c;

    cin >> n >> c;

    int w[n];

    int v[n];

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

    {

        cin >> w[i] >> v[i];

    }

    long long mem[2][c + 1];

    for(int i = 0;i < (c + 1);i++)

        mem[0][i] = 0;

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

    {

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

        {

            if(i % 2 == 0)

            {

                if(w[i] <= j)

                {

                    long long val1 = mem[0][j];

                    long long val2 = v[i] + mem[0][j - w[i]];

                    mem[1][j] = max(val1, val2);

                }

                else

                {

                    mem[1][j] = mem[0][j];

                }

            }

            else

            {

                if(w[i] <= j)

                    mem[0][j] = max(mem[1][j] , v[i] + mem[1][j - w[i]]);

                else

                    mem[0][j] = mem[1][j];

            }

        }

    }

    if(n % 2 == 0)

        cout << mem[0][c] << endl;

    else

        cout << mem[1][c] << 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.775203004432498x):
#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;

typedef long double ld;

ll dp[105][100005];

int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    ll w, n;

    cin >> n >> w;

    ll W[n+1] , v[n+1];

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

    {

        cin >> W[i] >> v[i];

    }

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

    {

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

        {

            if(W[i] <= j)dp[i][j] = max((v[i] + dp[i-1][j- W[i]]), dp[i-1][j]);

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

        }

    }

    cout << dp[n][w] << '\n';

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

using namespace std;

typedef long long int ll;

typedef long double ld;

ll dp[105][100005];

int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    ll w, n;

    cin >> n >> w;

    ll W[n+1] , v[n+1];

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

    {

        cin >> W[i] >> v[i];

    }

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

    {

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

        {

            if(W[i] <= j)dp[i][j] = max((v[i] + dp[i-1][j- W[i]]), dp[i-1][j]);

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

        }

    }

    cout << dp[n][w] << '\n';

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

using namespace std;

typedef long long int ll;

typedef long double ld;

ll dp[105][100005];

int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    ll w, n;

    cin >> n >> w;

    ll W[n+1] , v[n+1];

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

    {

        cin >> W[i] >> v[i];

    }

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

    {

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

        {

            if(W[i] <= j)dp[i][j] = max((v[i] + dp[i-1][j- W[i]]), dp[i-1][j]);

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

        }

    }

    cout << dp[n][w] << '\n';

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

using namespace std;

typedef long long int ll;

typedef long double ld;

ll dp[105][100005];

int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    ll w, n;

    cin >> n >> w;

    ll W[n+1] , v[n+1];

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

    {

        cin >> W[i] >> v[i];

    }

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

    {

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

        {

            if(W[i] <= j)dp[i][j] = max((v[i] + dp[i-1][j- W[i]]), dp[i-1][j]);

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

        }

    }

    cout << dp[n][w] << '\n';

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

using namespace std;

typedef long long int ll;

typedef long double ld;

ll dp[105][100005];

int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    ll w, n;

    cin >> n >> w;

    ll W[n+1] , v[n+1];

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

    {

        cin >> W[i] >> v[i];

    }

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

    {

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

        {

            if(W[i] <= j)dp[i][j] = max((v[i] + dp[i-1][j- W[i]]), dp[i-1][j]);

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

        }

    }

    cout << dp[n][w] << '\n';

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

using namespace std;

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



const int MAXN = 100 + 5;

const int MAXW = 1e5 + 5;



int N, W, we[MAXN], vl[MAXN];

long long dp[MAXW];



int main() {

    IOS

    

    cin >> N >> W;

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

        cin >> we[i] >> vl[i];

    }



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

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

            dp[j] = max(dp[j], dp[j - we[i]] + vl[i]);

        }

    }



    cout << dp[W] << '\n';

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

using namespace std;

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



const int MAXN = 100 + 5;

const int MAXW = 1e5 + 5;



int N, W, we[MAXN], vl[MAXN];

long long dp[MAXW];



int main() {

    IOS

    

    cin >> N >> W;

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

        cin >> we[i] >> vl[i];

    }



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

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

            dp[j] = max(dp[j], dp[j - we[i]] + vl[i]);

        }

    }



    cout << dp[W] << '\n';

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

using namespace std;

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



const int MAXN = 100 + 5;

const int MAXW = 1e5 + 5;



int N, W, we[MAXN], vl[MAXN];

long long dp[MAXW];



int main() {

    IOS

    

    cin >> N >> W;

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

        cin >> we[i] >> vl[i];

    }



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

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

            dp[j] = max(dp[j], dp[j - we[i]] + vl[i]);

        }

    }



    cout << dp[W] << '\n';

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

using namespace std;

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



const int MAXN = 100 + 5;

const int MAXW = 1e5 + 5;



int N, W, we[MAXN], vl[MAXN];

long long dp[MAXW];



int main() {

    IOS

    

    cin >> N >> W;

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

        cin >> we[i] >> vl[i];

    }



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

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

            dp[j] = max(dp[j], dp[j - we[i]] + vl[i]);

        }

    }



    cout << dp[W] << '\n';

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

using namespace std;

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



const int MAXN = 100 + 5;

const int MAXW = 1e5 + 5;



int N, W, we[MAXN], vl[MAXN];

long long dp[MAXW];



int main() {

    IOS

    

    cin >> N >> W;

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

        cin >> we[i] >> vl[i];

    }



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

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

            dp[j] = max(dp[j], dp[j - we[i]] + vl[i]);

        }

    }



    cout << dp[W] << '\n';

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

using namespace std;



typedef long long ll;

typedef vector<int> vi;



#define PB push_back

#define MP make_pair

#define endl '\n'

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

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

ll n,w[105],v[105], dp[100][100005],limit;



ll f(int pos,int weight)

{

    if(pos== n)   return 0;

    if(dp[pos][weight]> 0)

        return dp[pos][weight];

    ll x=0,y=0;

    if(weight>=w[pos])

        x=v[pos]+f(pos+1,weight-w[pos]);

    y=f(pos+1,weight);

    return dp[pos][weight]=max(x,y);





}



int main()

{

    optimize();

    cin>>n>>limit;

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

        cin>>w[i]>>v[i];

    ll x=f(0,limit);

    cout<<x;

    return 0;

}