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

#include <stdio.h>

#include <cmath>

#include <cstring>

#include <string>

#include <set>

#include <map>

#include <algorithm>

#include <queue>

#include <vector>

#define f first

#define s second

#define mp make_pair

#define pb push_back

#define ll long long



using namespace std;



const int inf = 1e9 + 5;

const ll INF = 1e18 + 5;

const int maxn = 2e5 + 5;



ll n, a[maxn], w[maxn], s;

ll dp[maxn];



int main(){

    cin.tie(0);

    cout.tie(0);

    ios_base::sync_with_stdio(NULL);

	cin >> n >> s;

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

	dp[0] = 0;

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

		int w, cost;

		cin >> w >> cost;

		for (int j = s - w; j >= 0; j--) {

			if (dp[j] != -1)

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

		}

	}

	ll ans = -1;

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

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

	cout << ans;

	return 0;

}

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

#include<iostream>

#include<iomanip>

#include<map>

#include<cmath>

#include<algorithm>

#include<string>

#include<vector>

#include<queue>

#include<set>

#include<deque>

#include<stack>

#include<bitset>

#include<fstream>

#include<map>

#include<unordered_map>

using namespace std;

typedef int me;

typedef long long ll;

typedef unsigned long long ull;

#define andrew  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)

#define endl '\n'

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

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

#define PI 3.1415926535

#define sin(i) (long double)sin(i*PI/180.0);

#define OO 1e18;

ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }

ull lcm(ll x, ll y) { return x / gcd(x, y) * y; }

void the_end() {

#ifndef ONLINE_JUDGE;

    system("pause");

#endif

}

int dy8[] = { 0,0,1,-1,1,-1,-1,1 };

int dx8[] = { 1,-1,0,0,1,-1,1,-1 };

int id8[] = { 0, 1,2,3,4, 5,6, 7 };

// you can be specialist 

// soon will be (Cyain)

ll n, m;

vector<pair<ll,ll>>v;

ll mm[101][100001];

ll solve(int i,ll w)

{

    if (i == n)

        return 0;

    if (mm[i][w] != 0)

        return mm[i][w];

    mm[i][w] = solve(i + 1, w);

    if (w - v[i].first >= 0) {

        mm[i][w] = max(mm[i][w], solve(i + 1, w - v[i].first) + v[i].second);

    }

    return mm[i][w];

}

int main()

{

    andrew;

    cin >> n >> m;

    v.resize(n);

    for (int i = 0; i < n; i++)cin >> v[i].first >> v[i].second;

    cout << solve(0, m) << endl;

    the_end();

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

using namespace std;

const int maxn = 1e5 + 5;

typedef long long ll;

int main(){

	ll dp[maxn];

	ll n,W;

	ll w[105],v[105];

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

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

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

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

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

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

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

		}

	}

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

	return 0;

}

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

#include<iostream>

#include<iomanip>

#include<map>

#include<cmath>

#include<algorithm>

#include<string>

#include<vector>

#include<queue>

#include<set>

#include<deque>

#include<stack>

#include<bitset>

#include<fstream>

#include<map>

#include<unordered_map>

using namespace std;

typedef int me;

typedef long long ll;

typedef unsigned long long ull;

#define andrew  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)

#define endl '\n'

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

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

#define PI 3.1415926535

#define sin(i) (long double)sin(i*PI/180.0);

#define OO 1e18;

ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }

ull lcm(ll x, ll y) { return x / gcd(x, y) * y; }

void the_end() {

#ifndef ONLINE_JUDGE;

    system("pause");

#endif

}

int dy8[] = { 0,0,1,-1,1,-1,-1,1 };

int dx8[] = { 1,-1,0,0,1,-1,1,-1 };

int id8[] = { 0, 1,2,3,4, 5,6, 7 };

// you can be specialist 

// soon will be (Cyain)

ll n, m;

vector<pair<ll,ll>>v;

ll mm[101][100001];

ll solve(int i,ll w)

{

    if (i == n)

        return 0;

    if (mm[i][w] != 0)

        return mm[i][w];

    mm[i][w] = solve(i + 1, w);

    if (w - v[i].first >= 0) {

        mm[i][w] = max(mm[i][w], solve(i + 1, w - v[i].first) + v[i].second);

    }

    return mm[i][w];

}

int main()

{

    andrew;

    cin >> n >> m;

    v.resize(n);

    for (int i = 0; i < n; i++)cin >> v[i].first >> v[i].second;

    cout << solve(0, m) << endl;

    the_end();

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

#include <stdio.h>

#include <cmath>

#include <cstring>

#include <string>

#include <set>

#include <map>

#include <algorithm>

#include <queue>

#include <vector>

#define f first

#define s second

#define mp make_pair

#define pb push_back

#define ll long long



using namespace std;



const int inf = 1e9 + 5;

const ll INF = 1e18 + 5;

const int maxn = 2e5 + 5;



ll n, a[maxn], w[maxn], s;

ll dp[maxn];



int main(){

    cin.tie(0);

    cout.tie(0);

    ios_base::sync_with_stdio(NULL);

	cin >> n >> s;

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

	dp[0] = 0;

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

		int w, cost;

		cin >> w >> cost;

		for (int j = s - w; j >= 0; j--) {

			if (dp[j] != -1)

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

		}

	}

	ll ans = -1;

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

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

	cout << ans;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 2.6178659627344443x):
#include <iostream>



using namespace std;

typedef long long ll;

// A utility function that returns maximum of two integers

ll max(ll a, ll b)

{

    return (a > b) ? a : b;

}



// Returns the maximum value that can be put in a knapsack of capacity W

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()

{

    //cout << "Enter the number of items in a Knapsack:";

    int n, W;

    cin >> n;

    //cout << "Enter the capacity of knapsack";

    cin >> W;

    ll val[n], wt[n];

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

    {

        //cout << "Enter value and weight for item " << i << ":";

         cin >> wt[i];

        cin >> val[i];



    }



    //    int val[] = { 60, 100, 120 };

    //    int wt[] = { 10, 20, 30 };

    //    int W = 50;



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



    return 0;

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

using namespace std;

const int maxn = 1e5 + 5;

typedef long long ll;

int main(){

	ll dp[maxn];

	ll n,W;

	ll w[105],v[105];

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

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

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

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

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

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

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

		}

	}

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

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.8004545205996145x):
#include <iostream>



using namespace std;

typedef long long ll;

// A utility function that returns maximum of two integers

ll max(ll a, ll b)

{

    return (a > b) ? a : b;

}



// Returns the maximum value that can be put in a knapsack of capacity W

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()

{

    //cout << "Enter the number of items in a Knapsack:";

    int n, W;

    cin >> n;

    //cout << "Enter the capacity of knapsack";

    cin >> W;

    ll val[n], wt[n];

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

    {

        //cout << "Enter value and weight for item " << i << ":";

         cin >> wt[i];

        cin >> val[i];



    }



    //    int val[] = { 60, 100, 120 };

    //    int wt[] = { 10, 20, 30 };

    //    int W = 50;



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



    return 0;

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



#define SORT(v) sort(v.begin(),v.end())

#define si(n) scanf("%d",&n)

#define sii(n,m) scanf("%d %d",&n,&m)

#define sl(n) scanf("%lld",&n)

#define sll(n,m) scanf("%lld %lld",&n,&m)

#define ss(cad) scanf("%s",cad)

#define fst first

#define scn second

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

#define M 1000000007

#define N_MAX 100010



using namespace std;



typedef long long ll;

typedef vector<int> vi;

typedef vector<bool> vb;

typedef vector<ll> vl;

typedef pair<int,int> pi;

typedef pair<ll, ll> pll;

typedef vector<pi> vp;



ll dp[110][100100];

ll pesos[110];

ll costo[110];



int main(){

	int n, w;

	sii(n, w);



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

		sl(pesos[i]);

		sl(costo[i]);

	}



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

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

			ll ans = 0;

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

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

				ans = max(ans, costo[i] + dp[i-1][j-pesos[i]]);

			dp[i][j] = ans;

		}

	}

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

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.388351751851616x):
#include <iostream>



using namespace std;

typedef long long ll;

// A utility function that returns maximum of two integers

ll max(ll a, ll b)

{

    return (a > b) ? a : b;

}



// Returns the maximum value that can be put in a knapsack of capacity W

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()

{

    //cout << "Enter the number of items in a Knapsack:";

    int n, W;

    cin >> n;

    //cout << "Enter the capacity of knapsack";

    cin >> W;

    ll val[n], wt[n];

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

    {

        //cout << "Enter value and weight for item " << i << ":";

         cin >> wt[i];

        cin >> val[i];



    }



    //    int val[] = { 60, 100, 120 };

    //    int wt[] = { 10, 20, 30 };

    //    int W = 50;



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



    return 0;

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

#include <stdio.h>

#include <cmath>

#include <cstring>

#include <string>

#include <set>

#include <map>

#include <algorithm>

#include <queue>

#include <vector>

#define f first

#define s second

#define mp make_pair

#define pb push_back

#define ll long long



using namespace std;



const int inf = 1e9 + 5;

const ll INF = 1e18 + 5;

const int maxn = 2e5 + 5;



ll n, a[maxn], w[maxn], s;

ll dp[maxn];



int main(){

    cin.tie(0);

    cout.tie(0);

    ios_base::sync_with_stdio(NULL);

	cin >> n >> s;

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

	dp[0] = 0;

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

		int w, cost;

		cin >> w >> cost;

		for (int j = s - w; j >= 0; j--) {

			if (dp[j] != -1)

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

		}

	}

	ll ans = -1;

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

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

	cout << ans;

	return 0;

}

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

#define endl '\n'

#define ll long long

using namespace std;



const int MXN = 110;

const int MXK = 100005;

int n, k;

int v[MXN], w[MXN];

ll dp[MXN][MXK];



int main() {

    ios_base::sync_with_stdio(false); cin.tie(NULL);

    cin >> n >> k;

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

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

    }

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

        for(int j = k; j >= 0; j--) {

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

            if(j + w[i] <= k) {

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

            }

        }

    }

    cout << dp[0][0] << endl;

    return 0;

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

using namespace std;

const int maxn = 1e5 + 5;

typedef long long ll;

int main(){

	ll dp[maxn];

	ll n,W;

	ll w[105],v[105];

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

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

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

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

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

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

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

		}

	}

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

	return 0;

}

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

#define endl '\n'

#define ll long long

using namespace std;



const int MXN = 110;

const int MXK = 100005;

int n, k;

int v[MXN], w[MXN];

ll dp[MXN][MXK];



int main() {

    ios_base::sync_with_stdio(false); cin.tie(NULL);

    cin >> n >> k;

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

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

    }

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

        for(int j = k; j >= 0; j--) {

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

            if(j + w[i] <= k) {

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

            }

        }

    }

    cout << dp[0][0] << endl;

    return 0;

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



#define SORT(v) sort(v.begin(),v.end())

#define si(n) scanf("%d",&n)

#define sii(n,m) scanf("%d %d",&n,&m)

#define sl(n) scanf("%lld",&n)

#define sll(n,m) scanf("%lld %lld",&n,&m)

#define ss(cad) scanf("%s",cad)

#define fst first

#define scn second

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

#define M 1000000007

#define N_MAX 100010



using namespace std;



typedef long long ll;

typedef vector<int> vi;

typedef vector<bool> vb;

typedef vector<ll> vl;

typedef pair<int,int> pi;

typedef pair<ll, ll> pll;

typedef vector<pi> vp;



ll dp[110][100100];

ll pesos[110];

ll costo[110];



int main(){

	int n, w;

	sii(n, w);



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

		sl(pesos[i]);

		sl(costo[i]);

	}



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

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

			ll ans = 0;

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

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

				ans = max(ans, costo[i] + dp[i-1][j-pesos[i]]);

			dp[i][j] = ans;

		}

	}

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

    return 0;

}

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

#define endl '\n'

#define ll long long

using namespace std;



const int MXN = 110;

const int MXK = 100005;

int n, k;

int v[MXN], w[MXN];

ll dp[MXN][MXK];



int main() {

    ios_base::sync_with_stdio(false); cin.tie(NULL);

    cin >> n >> k;

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

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

    }

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

        for(int j = k; j >= 0; j--) {

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

            if(j + w[i] <= k) {

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

            }

        }

    }

    cout << dp[0][0] << endl;

    return 0;

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

#include <stdio.h>

#include <cmath>

#include <cstring>

#include <string>

#include <set>

#include <map>

#include <algorithm>

#include <queue>

#include <vector>

#define f first

#define s second

#define mp make_pair

#define pb push_back

#define ll long long



using namespace std;



const int inf = 1e9 + 5;

const ll INF = 1e18 + 5;

const int maxn = 2e5 + 5;



ll n, a[maxn], w[maxn], s;

ll dp[maxn];



int main(){

    cin.tie(0);

    cout.tie(0);

    ios_base::sync_with_stdio(NULL);

	cin >> n >> s;

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

	dp[0] = 0;

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

		int w, cost;

		cin >> w >> cost;

		for (int j = s - w; j >= 0; j--) {

			if (dp[j] != -1)

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

		}

	}

	ll ans = -1;

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

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

	cout << ans;

	return 0;

}

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



using namespace std;



long long memo[101][100001];



long long knapsack_tab(const int items[][2], const int &N, const int &C){

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

        memo[n][0] = 0;

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

        memo[0][c] = 0;

    

    

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

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

            if(c - items[n - 1][0] < 0) memo[n][c] = memo[n - 1][c];

            else{

                memo[n][c] = max(items[n - 1][1] + memo[n - 1][c - items[n - 1][0]], memo[n - 1][c]);

            }

        }

    }



    return memo[N][C];

}



int main(){

    int N, C;

    while(scanf("%d %d", &N, &C) != EOF){

        int items[N][2];

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

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

                memo[n][c] = -1;

            }

        }

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

            scanf("%d %d", &items[i][0], &items[i][1]);

        }

        printf("%lli\n", knapsack_tab(items, N, C));

    }

    return 0;

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

using namespace std;

const int maxn = 1e5 + 5;

typedef long long ll;

int main(){

	ll dp[maxn];

	ll n,W;

	ll w[105],v[105];

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

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

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

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

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

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

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

		}

	}

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

	return 0;

}

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



using namespace std;



long long memo[101][100001];



long long knapsack_tab(const int items[][2], const int &N, const int &C){

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

        memo[n][0] = 0;

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

        memo[0][c] = 0;

    

    

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

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

            if(c - items[n - 1][0] < 0) memo[n][c] = memo[n - 1][c];

            else{

                memo[n][c] = max(items[n - 1][1] + memo[n - 1][c - items[n - 1][0]], memo[n - 1][c]);

            }

        }

    }



    return memo[N][C];

}



int main(){

    int N, C;

    while(scanf("%d %d", &N, &C) != EOF){

        int items[N][2];

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

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

                memo[n][c] = -1;

            }

        }

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

            scanf("%d %d", &items[i][0], &items[i][1]);

        }

        printf("%lli\n", knapsack_tab(items, N, C));

    }

    return 0;

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



#define SORT(v) sort(v.begin(),v.end())

#define si(n) scanf("%d",&n)

#define sii(n,m) scanf("%d %d",&n,&m)

#define sl(n) scanf("%lld",&n)

#define sll(n,m) scanf("%lld %lld",&n,&m)

#define ss(cad) scanf("%s",cad)

#define fst first

#define scn second

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

#define M 1000000007

#define N_MAX 100010



using namespace std;



typedef long long ll;

typedef vector<int> vi;

typedef vector<bool> vb;

typedef vector<ll> vl;

typedef pair<int,int> pi;

typedef pair<ll, ll> pll;

typedef vector<pi> vp;



ll dp[110][100100];

ll pesos[110];

ll costo[110];



int main(){

	int n, w;

	sii(n, w);



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

		sl(pesos[i]);

		sl(costo[i]);

	}



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

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

			ll ans = 0;

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

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

				ans = max(ans, costo[i] + dp[i-1][j-pesos[i]]);

			dp[i][j] = ans;

		}

	}

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

    return 0;

}

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



using namespace std;



long long memo[101][100001];



long long knapsack_tab(const int items[][2], const int &N, const int &C){

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

        memo[n][0] = 0;

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

        memo[0][c] = 0;

    

    

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

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

            if(c - items[n - 1][0] < 0) memo[n][c] = memo[n - 1][c];

            else{

                memo[n][c] = max(items[n - 1][1] + memo[n - 1][c - items[n - 1][0]], memo[n - 1][c]);

            }

        }

    }



    return memo[N][C];

}



int main(){

    int N, C;

    while(scanf("%d %d", &N, &C) != EOF){

        int items[N][2];

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

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

                memo[n][c] = -1;

            }

        }

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

            scanf("%d %d", &items[i][0], &items[i][1]);

        }

        printf("%lli\n", knapsack_tab(items, N, C));

    }

    return 0;

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

#include <stdio.h>

#include <cmath>

#include <cstring>

#include <string>

#include <set>

#include <map>

#include <algorithm>

#include <queue>

#include <vector>

#define f first

#define s second

#define mp make_pair

#define pb push_back

#define ll long long



using namespace std;



const int inf = 1e9 + 5;

const ll INF = 1e18 + 5;

const int maxn = 2e5 + 5;



ll n, a[maxn], w[maxn], s;

ll dp[maxn];



int main(){

    cin.tie(0);

    cout.tie(0);

    ios_base::sync_with_stdio(NULL);

	cin >> n >> s;

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

	dp[0] = 0;

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

		int w, cost;

		cin >> w >> cost;

		for (int j = s - w; j >= 0; j--) {

			if (dp[j] != -1)

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

		}

	}

	ll ans = -1;

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

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

	cout << ans;

	return 0;

}

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

#define INF 0x3f3f3f3f

#define LL long long

using namespace std;

const int maxn = 1e5+10;

int a[maxn];

LL b[maxn];

LL dp[maxn];

int main()

{

    int n,w;

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

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

    {

        scanf("%d%lld",a+i,b+i);

    }

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

    {

        for(int j=w;j>=0;j--)

        {

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

            {

                dp[j]=max(dp[j],dp[j-a[i]]+b[i]);

            }

        }

    }

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

    return 0;

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

using namespace std;

const int maxn = 1e5 + 5;

typedef long long ll;

int main(){

	ll dp[maxn];

	ll n,W;

	ll w[105],v[105];

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

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

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

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

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

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

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

		}

	}

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

	return 0;

}

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

#define INF 0x3f3f3f3f

#define LL long long

using namespace std;

const int maxn = 1e5+10;

int a[maxn];

LL b[maxn];

LL dp[maxn];

int main()

{

    int n,w;

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

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

    {

        scanf("%d%lld",a+i,b+i);

    }

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

    {

        for(int j=w;j>=0;j--)

        {

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

            {

                dp[j]=max(dp[j],dp[j-a[i]]+b[i]);

            }

        }

    }

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

    return 0;

}