stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

    long long N,W,k,val[109],we[109],i,j;

        long long Kn[105][100007];

    void knap()

    {

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

            Kn[0][i]=0;

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

            Kn[i][0]=0;

//            cout<<"HA";

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

            for(j=1;j<=W;j++)

{

                if(we[i]>j) {

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

//                        cout<<i<<" "<<we[i]<<" "<<j<<" "<<Kn[i][j]<<endl;

                }

                else

                    {

                        Kn[i][j]=max(Kn[i-1][j],val[i]+Kn[i-1][j-we[i]]);

//                        cout<<we[i]<<" "<<j<<" "<<Kn[i][j]<<endl;

                    }

}

        cout<<Kn[N][W]<<endl;

    }

int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cin>>N>>W;

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

        cin>>we[i]>>val[i];

        knap();

//        cout<<"?";

        return 0;

}


// Optimized solution to the same problem (faster):
#include <stdio.h>

#include <stdlib.h>

long long max(long long a,long long b)

{

	if(a>b)	return a;

	return b; 

}

int main()

{

	int i,n,j,W;

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

	long long *dp=(long long*)malloc(sizeof(long long)*W);

	dp[0]=0;

	for(i=1;i<=W;i++) dp[i]=-1;

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

	{

		int w1,v1;

		scanf("%d %d",&w1,&v1);

		for(j=W;j>=0;j--)

		{

			if(dp[j]==-1)	continue;

			if(j+w1<=W) dp[j+w1] = max(dp[j+w1],dp[j]+v1);

		}	

	}

	long long ans=-1;

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

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

	printf("%lld",ans);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<cstring>

#include<cstdio>

#include<algorithm>

using namespace std;

#define MAXN 100000 + 100

#define ll long long int

ll N[MAXN];

ll w[200];

ll v[200];

ll n;

ll max_V;

int main()

{

    cin>>n>>max_V;

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

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

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

        for(int j = max_V;j >= v[i];--j)

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

    cout<<N[max_V]<<endl;



    return 0;

}





//12

// Optimized solution to the same problem (faster):
#include <stdio.h>

#include <stdlib.h>

long long max(long long a,long long b)

{

	if(a>b)	return a;

	return b; 

}

int main()

{

	int i,n,j,W;

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

	long long *dp=(long long*)malloc(sizeof(long long)*W);

	dp[0]=0;

	for(i=1;i<=W;i++) dp[i]=-1;

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

	{

		int w1,v1;

		scanf("%d %d",&w1,&v1);

		for(j=W;j>=0;j--)

		{

			if(dp[j]==-1)	continue;

			if(j+w1<=W) dp[j+w1] = max(dp[j+w1],dp[j]+v1);

		}	

	}

	long long ans=-1;

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

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

	printf("%lld",ans);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;



int main(){



    int s, n, ans = 0;



    cin >> s >> n;

    long long w[s + 5], v[s + 5];

    for(int i = 1; i <= s; i++) cin >> w[i] >> v[i];

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

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

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

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

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

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

        }

    }

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



    return 0;

}


// Optimized solution to the same problem (faster):
#include <stdio.h>

#include <stdlib.h>

long long max(long long a,long long b)

{

	if(a>b)	return a;

	return b; 

}

int main()

{

	int i,n,j,W;

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

	long long *dp=(long long*)malloc(sizeof(long long)*W);

	dp[0]=0;

	for(i=1;i<=W;i++) dp[i]=-1;

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

	{

		int w1,v1;

		scanf("%d %d",&w1,&v1);

		for(j=W;j>=0;j--)

		{

			if(dp[j]==-1)	continue;

			if(j+w1<=W) dp[j+w1] = max(dp[j+w1],dp[j]+v1);

		}	

	}

	long long ans=-1;

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

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

	printf("%lld",ans);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>



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

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

#define dbg(x) cerr << #x << ": " << x << endl



using namespace std;

typedef long long ll;



const int maxn = 102;



ll w[maxn];

ll v[maxn];

ll dp[maxn][100005];



int main(){

	ll n, W;

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

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

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

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

		for (ll j = 1; j <= W; j++){

			if (j < w[i])

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

			else

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

		}

	}

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

	return 0;

}

// Optimized solution to the same problem (faster):
#include <stdio.h>

#include <stdlib.h>

long long max(long long a,long long b)

{

	if(a>b)	return a;

	return b; 

}

int main()

{

	int i,n,j,W;

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

	long long *dp=(long long*)malloc(sizeof(long long)*W);

	dp[0]=0;

	for(i=1;i<=W;i++) dp[i]=-1;

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

	{

		int w1,v1;

		scanf("%d %d",&w1,&v1);

		for(j=W;j>=0;j--)

		{

			if(dp[j]==-1)	continue;

			if(j+w1<=W) dp[j+w1] = max(dp[j+w1],dp[j]+v1);

		}	

	}

	long long ans=-1;

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

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

	printf("%lld",ans);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <cstring>

#include <iostream>

#include <string>

#include <vector>

#include <algorithm>

#include <sstream>

#include <queue>

#include <deque>

#include <bitset>

#include <iterator>

#include <list>

#include <stack>

#include <map>

#include <set>

#include <functional>

#include <numeric>

#include <utility>



#include <cmath>

#include <iomanip>



using namespace std;



int main()

{

  ios::sync_with_stdio(false);

  cin.tie(0);

  int n;

  cin >> n;

  int w;

  cin >> w;

  int weights[n];

  long long int values[n];

  long long int cur;

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

    cin >> cur;

    weights[i] = cur;

    cin >> cur;

    values[i] = cur;

  }

  long long int dp[n+1][w+1];

  // dp[n][w] represents the maximum value that can be achieved with at most w weight and only using items with number up to n.

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

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

      dp[i][j] = 0;

    }

  }

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

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

      dp[minInd+1][allowed] = max(dp[minInd+1][allowed], dp[minInd][allowed]);

      if (allowed+weights[minInd] <= w) {

	dp[minInd+1][allowed+weights[minInd]] = max(dp[minInd+1][allowed+weights[minInd]], dp[minInd][allowed]+values[minInd]);

      }

    }

  }

  long long int best = dp[n][0];

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

    best = max(best, dp[n][i]);

  }

  cout << best << "\n";

  return 0;

}

// Optimized solution to the same problem (faster):
#include <stdio.h>

#include <stdlib.h>

long long max(long long a,long long b)

{

	if(a>b)	return a;

	return b; 

}

int main()

{

	int i,n,j,W;

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

	long long *dp=(long long*)malloc(sizeof(long long)*W);

	dp[0]=0;

	for(i=1;i<=W;i++) dp[i]=-1;

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

	{

		int w1,v1;

		scanf("%d %d",&w1,&v1);

		for(j=W;j>=0;j--)

		{

			if(dp[j]==-1)	continue;

			if(j+w1<=W) dp[j+w1] = max(dp[j+w1],dp[j]+v1);

		}	

	}

	long long ans=-1;

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

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

	printf("%lld",ans);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<cstdio>

#include<iostream>

#include<algorithm>

#include<queue>

#define inf 0x3f3f3f3f

using namespace std;

typedef long long LL;

const int maxn = 1e5+5;



LL w[maxn],v[maxn],dp[maxn];



int main(){

	int n,m;

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

	for(int i = 1; i <= n; i++) scanf("%lld %lld", &w[i],&v[i]);

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

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

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

		}

	}

	printf("%lld",dp[m]);

}

// Optimized solution to the same problem (faster):
#include <stdio.h>

#include <stdlib.h>

long long max(long long a,long long b)

{

	if(a>b)	return a;

	return b; 

}

int main()

{

	int i,n,j,W;

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

	long long *dp=(long long*)malloc(sizeof(long long)*W);

	dp[0]=0;

	for(i=1;i<=W;i++) dp[i]=-1;

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

	{

		int w1,v1;

		scanf("%d %d",&w1,&v1);

		for(j=W;j>=0;j--)

		{

			if(dp[j]==-1)	continue;

			if(j+w1<=W) dp[j+w1] = max(dp[j+w1],dp[j]+v1);

		}	

	}

	long long ans=-1;

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

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

	printf("%lld",ans);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<cstdio>

#include<iostream>

#include<cstring>

#include<algorithm>

using namespace std;



const int MAXN = 1e5 + 100;

const int inf = 0x3f3f3f3f;

int n, k;

long long dp[105][MAXN];//dp[i][j]：前i个物品，容量为j时的最大价值

int w[MAXN];

long long v[MAXN];



int main(){

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

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

		int a, b;

		scanf("%d %d", &a, &b);

		w[i] = a, v[i] = b;

	}

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

		for(int j = 1; j <= k; j++){

			if(j < w[i]) dp[i][j] = dp[i-1][j];

			else dp[i][j] = dp[i-1][j] > dp[i-1][j-w[i]]+v[i] ? dp[i-1][j] : dp[i-1][j-w[i]]+v[i];

		}

	}

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

	return 0;

}

// Optimized solution to the same problem (faster):
#include <stdio.h>

#include <stdlib.h>

long long max(long long a,long long b)

{

	if(a>b)	return a;

	return b; 

}

int main()

{

	int i,n,j,W;

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

	long long *dp=(long long*)malloc(sizeof(long long)*W);

	dp[0]=0;

	for(i=1;i<=W;i++) dp[i]=-1;

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

	{

		int w1,v1;

		scanf("%d %d",&w1,&v1);

		for(j=W;j>=0;j--)

		{

			if(dp[j]==-1)	continue;

			if(j+w1<=W) dp[j+w1] = max(dp[j+w1],dp[j]+v1);

		}	

	}

	long long ans=-1;

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

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

	printf("%lld",ans);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <algorithm>



using namespace std;



int main () {

	int n, w;

	cin >> n >> w;

	int peso[n];

	long int valor[n];

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

		cin >> peso[i] >> valor[i];



	long int solucoes[n+1][w+1];

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

		solucoes[0][i] = 0;

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

		int curPeso = peso[i-1];

		long int curValor = valor[i-1];



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

			if (j - curPeso >= 0)

				solucoes[i][j] = max(solucoes[i - 1][j],(curValor + solucoes[i - 1][j - curPeso]));

			else

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

		}

	}



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

}

// Optimized solution to the same problem (faster):
#include <stdio.h>

#include <stdlib.h>

long long max(long long a,long long b)

{

	if(a>b)	return a;

	return b; 

}

int main()

{

	int i,n,j,W;

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

	long long *dp=(long long*)malloc(sizeof(long long)*W);

	dp[0]=0;

	for(i=1;i<=W;i++) dp[i]=-1;

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

	{

		int w1,v1;

		scanf("%d %d",&w1,&v1);

		for(j=W;j>=0;j--)

		{

			if(dp[j]==-1)	continue;

			if(j+w1<=W) dp[j+w1] = max(dp[j+w1],dp[j]+v1);

		}	

	}

	long long ans=-1;

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

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

	printf("%lld",ans);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <algorithm>

#include <bits/stdc++.h>



using namespace std;



int main(){

    int N, W;

    cin >> N >> W;

    long int items[N+1][2];

    items[0][0] = 0;

    items[0][1] = 0;

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

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

    }

    long int mat[W+1][N+1];

    mat[0][0] = 0;

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

        for(int capacidade = 0; capacidade <= W; capacidade++){

            if(num_item == 0 || capacidade == 0){

                mat[capacidade][num_item] = 0;

            }

            else {

                long int custo_anterior = mat[capacidade][max(num_item-1, 0)];

                long int peso_item_atual = items[num_item][0];

                long int valor_item_atual = items[num_item][1];

                long int capacidade_restante = capacidade - peso_item_atual;

                long int custo_com_item_atual = valor_item_atual + mat[capacidade_restante][num_item-1];

                if(capacidade_restante < 0){

                    mat[capacidade][num_item] = custo_anterior;

                }

                else {

                    mat[capacidade][num_item] = max(custo_anterior, custo_com_item_atual);

                }

            }

        }

    }

    cout << mat[W][N];

    return 0;

}

// Optimized solution to the same problem (faster):
#include <stdio.h>

#include <stdlib.h>

long long max(long long a,long long b)

{

	if(a>b)	return a;

	return b; 

}

int main()

{

	int i,n,j,W;

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

	long long *dp=(long long*)malloc(sizeof(long long)*W);

	dp[0]=0;

	for(i=1;i<=W;i++) dp[i]=-1;

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

	{

		int w1,v1;

		scanf("%d %d",&w1,&v1);

		for(j=W;j>=0;j--)

		{

			if(dp[j]==-1)	continue;

			if(j+w1<=W) dp[j+w1] = max(dp[j+w1],dp[j]+v1);

		}	

	}

	long long ans=-1;

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

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

	printf("%lld",ans);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

using namespace std;



unsigned long long achaValorMaximo(unsigned long long valorDosItens[], int pesoDosItens[], int capacidade, int qtdItens)

{

    unsigned long long tabelaDeMaximos[qtdItens + 1][capacidade + 1];



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

    {

        tabelaDeMaximos[0][i] = 0;

    }

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

    {

        tabelaDeMaximos[i][0] = 0;

    }



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

    {

        for (int iCapacidade = 1; iCapacidade <= capacidade; iCapacidade++)

        {

            if (pesoDosItens[i - 1] <= iCapacidade)

            {

                if ((valorDosItens[i - 1] + tabelaDeMaximos[i - 1][iCapacidade - pesoDosItens[i - 1]]) > tabelaDeMaximos[i - 1][iCapacidade])

                {

                    tabelaDeMaximos[i][iCapacidade] = valorDosItens[i - 1] + tabelaDeMaximos[i - 1][iCapacidade - pesoDosItens[i - 1]];

                }

                else

                {

                    tabelaDeMaximos[i][iCapacidade] = tabelaDeMaximos[i - 1][iCapacidade];

                }

            }

            else

            {

                tabelaDeMaximos[i][iCapacidade] = tabelaDeMaximos[i - 1][iCapacidade];

            }

        }

    }

    return tabelaDeMaximos[qtdItens][capacidade];

}



int main()

{



    int qtdItens, capacidade;

    cin >> qtdItens >> capacidade;

    int pesoDosItens[qtdItens];

    unsigned long long valorDosItens[qtdItens];

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

    {

        cin >> pesoDosItens[i] >> valorDosItens[i];

    }



    unsigned long long valorMaximo = achaValorMaximo(valorDosItens, pesoDosItens, capacidade, qtdItens);

    cout << valorMaximo << endl;

}


// Optimized solution to the same problem (faster):
#include <stdio.h>

#include <stdlib.h>

long long max(long long a,long long b)

{

	if(a>b)	return a;

	return b; 

}

int main()

{

	int i,n,j,W;

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

	long long *dp=(long long*)malloc(sizeof(long long)*W);

	dp[0]=0;

	for(i=1;i<=W;i++) dp[i]=-1;

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

	{

		int w1,v1;

		scanf("%d %d",&w1,&v1);

		for(j=W;j>=0;j--)

		{

			if(dp[j]==-1)	continue;

			if(j+w1<=W) dp[j+w1] = max(dp[j+w1],dp[j]+v1);

		}	

	}

	long long ans=-1;

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

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

	printf("%lld",ans);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#define ll long long

using namespace std;



ll arr[107], weight[107];

ll dp[107][100007];

bool vis[107][100007];

ll W;

int n;



ll rec( int i, ll w )

{

    if(i>=n)

        return 0;

    if(vis[i][w])

        return dp[i][w];



    ll q1= rec( i+1, w );

    ll q2= 0;



    if( weight[i]+w<= W )

        q2= arr[i]+rec( i+1, w+weight[i] );



    vis[i][w]= 1;



    return dp[i][w]= max(q1,q2);

}



int main()

{

    cin>>n>>W;



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

        cin>>weight[i]>>arr[i];



    cout<< rec( 0, 0 ) <<endl;

}


// Optimized solution to the same problem (faster):
#include <stdio.h>

#include <stdlib.h>

long long max(long long a,long long b)

{

	if(a>b)	return a;

	return b; 

}

int main()

{

	int i,n,j,W;

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

	long long *dp=(long long*)malloc(sizeof(long long)*W);

	dp[0]=0;

	for(i=1;i<=W;i++) dp[i]=-1;

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

	{

		int w1,v1;

		scanf("%d %d",&w1,&v1);

		for(j=W;j>=0;j--)

		{

			if(dp[j]==-1)	continue;

			if(j+w1<=W) dp[j+w1] = max(dp[j+w1],dp[j]+v1);

		}	

	}

	long long ans=-1;

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

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

	printf("%lld",ans);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <bits/stdc++.h>

#include <math.h>

#include <string>

#include <stdio.h>



int R; // n. requisitos

int TMP; // tempo total

long long int solMelhor;



int T[101]; //tempo para execução do requisito

long long int V[101]; //valor adquirido





long long int memo[101][100001];



long long int max(long a, long b){

  if(a>b)

    return a;

  else

    return b;

}



void inicializar(){



  std::cin >> R >> TMP;



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

    std::cin >> T[i] >> V[i];

  }

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

    for(long long int j=0; j<TMP+1;j++)

      memo[i][j]=0;

}



void imprimeResultados(){

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

    for(long long int j = 0;j<=TMP;j++){

      std::cout<<memo[i][j]<<"|";

    }

    std::cout<<std::endl;

  }

  std::cout << solMelhor;    

}



long long int v1,v2;

long long int nrp(){

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

    for(long long int j = 1;j<=TMP;j++){

      //v1 = memo[i][j-1];

      if(T[i]>j)

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

      else{

        v1=memo[i-1][j-T[i]]+V[i];

        v2=memo[i-1][j];

        memo[i][j] = max(v1,v2);

      }

    }

  }

  return memo[R][TMP];

}



int main() {

  inicializar();

  

  solMelhor = nrp();



 std::cout << solMelhor;  

}

// Optimized solution to the same problem (faster):
#include <stdio.h>

#include <stdlib.h>

long long max(long long a,long long b)

{

	if(a>b)	return a;

	return b; 

}

int main()

{

	int i,n,j,W;

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

	long long *dp=(long long*)malloc(sizeof(long long)*W);

	dp[0]=0;

	for(i=1;i<=W;i++) dp[i]=-1;

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

	{

		int w1,v1;

		scanf("%d %d",&w1,&v1);

		for(j=W;j>=0;j--)

		{

			if(dp[j]==-1)	continue;

			if(j+w1<=W) dp[j+w1] = max(dp[j+w1],dp[j]+v1);

		}	

	}

	long long ans=-1;

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

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

	printf("%lld",ans);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

/**

*   author: j o s e m a g o

*   date:

**/

using namespace std;

#pragma GCC optimize ("Ofast")

#define f first

#define s second

#define mp make_pair

#define lb lower_bound

#define ub upper_bound

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

#define mset(a,v) memset(a,v,sizeof(a))

#define pb push_back

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

#define rsz resize

#define ln "\n"



typedef double db;

typedef unsigned long long ull;

typedef long long ll;

typedef long double ld;

const ld PI = 2*acos(0.0);

const int MOD = 1000000007;









ll table[100009];





int main(){



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

  //freopen("input.out","w",stdout);



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





    int n,m;

    cin >> n >> m;

    vector<pair<int,ll> >v(n);





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

        cin >> v[i].f >> v[i].s;

    }



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

        for(int cap = m;cap >= v[i].f;cap--){

            table[cap] = max(table[cap],table[cap-v[i].f]+v[i].s);

        }

    }



    cout<<table[m];







    return 0;

}

/*

5 5

1 1000000000

1 1000000000

1 1000000000

1 1000000000

1 1000000000







*/

// Optimized solution to the same problem (faster):
#include <stdio.h>

#include <stdlib.h>

long long max(long long a,long long b)

{

	if(a>b)	return a;

	return b; 

}

int main()

{

	int i,n,j,W;

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

	long long *dp=(long long*)malloc(sizeof(long long)*W);

	dp[0]=0;

	for(i=1;i<=W;i++) dp[i]=-1;

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

	{

		int w1,v1;

		scanf("%d %d",&w1,&v1);

		for(j=W;j>=0;j--)

		{

			if(dp[j]==-1)	continue;

			if(j+w1<=W) dp[j+w1] = max(dp[j+w1],dp[j]+v1);

		}	

	}

	long long ans=-1;

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

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

	printf("%lld",ans);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<cmath>

#include<algorithm>

using namespace std;



long long K[101][100001];

int values[101];

int weights[101];



long long knapSack(int W, int wt[], int val[], int n)

{

	int i, w;





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

{

	int n, w;

	cin >> n >> w;

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

	{

		cin >> weights[i] >> values[i];

	}



	cout << knapSack(w, weights, values, n) << endl;

	system("pause");

}


// Optimized solution to the same problem (faster):
#include <stdio.h>

#include <stdlib.h>

long long max(long long a,long long b)

{

	if(a>b)	return a;

	return b; 

}

int main()

{

	int i,n,j,W;

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

	long long *dp=(long long*)malloc(sizeof(long long)*W);

	dp[0]=0;

	for(i=1;i<=W;i++) dp[i]=-1;

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

	{

		int w1,v1;

		scanf("%d %d",&w1,&v1);

		for(j=W;j>=0;j--)

		{

			if(dp[j]==-1)	continue;

			if(j+w1<=W) dp[j+w1] = max(dp[j+w1],dp[j]+v1);

		}	

	}

	long long ans=-1;

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

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

	printf("%lld",ans);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#define eps 1e-3

#define pi acos(-1.0)

#define inf 0x3f3f3f3f

#define debug1 cout<<"&&";

#define debug2 cout<<"**";

#define pb push_back

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

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

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

typedef double db;

typedef long long ll;

typedef unsigned long long ull;

using namespace std;

const int mod = 1e9;

const int N = 1e5+10;

/*=======================================================================*/



ll n, W, w[N], v[N], f[N];

int main() {

  cin >> n >> W;

  for (int i = 1; i <= n; i++) cin >> w[i] >> v[i];



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

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

      //   debug1

      //   cout << i << endl;

      //   cout << f[l - w[i]] + v[i] << " " << f[l] << endl;

        if (f[l - w[i]] + v[i] > f[l]) {

            f[l] = f[l - w[i]] + v[i];

            // debug1

            // cout << i << " " << l << endl;

         }

     }

   //   cout << i << " " << n << endl;

  }

    

      

  cout << f[W] << endl;

  return 0;

}

// Optimized solution to the same problem (faster):
#include <stdio.h>

#include <stdlib.h>

long long max(long long a,long long b)

{

	if(a>b)	return a;

	return b; 

}

int main()

{

	int i,n,j,W;

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

	long long *dp=(long long*)malloc(sizeof(long long)*W);

	dp[0]=0;

	for(i=1;i<=W;i++) dp[i]=-1;

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

	{

		int w1,v1;

		scanf("%d %d",&w1,&v1);

		for(j=W;j>=0;j--)

		{

			if(dp[j]==-1)	continue;

			if(j+w1<=W) dp[j+w1] = max(dp[j+w1],dp[j]+v1);

		}	

	}

	long long ans=-1;

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

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

	printf("%lld",ans);

}

// Fastest known solution for this problem: