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

#include<cstring>

#include<iostream>

#include<algorithm>

using namespace std;

typedef long long ll;

const int maxn=100025;

const int inf=0x3f3f3f3f;

int n,m;

int w[maxn];

ll v[maxn];

ll val[maxn];

ll dp[maxn];

int main()

{

    int n,V;

	ll ans=0;

	cin>>n>>V;

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

    cin>>v[i]>>val[i];

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

    dp[0]=0;

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

        for(int j=100000;j>=val[i];j--)

            dp[j]=min(dp[j],dp[j-val[i]]+v[i]);

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

	if(dp[i]<=V) 

	ans=max(ans,1ll*i);

	cout<<ans<<endl;

}


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

using namespace std;



typedef long long ll;

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

ll dp[102][100009],wt[102],v[102];



ll knapsack(ll n,ll s,ll w)

{

    ll a,b;

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

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

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

            else if(j==0) dp[i][j]=0;

            else if(v[i]>j){

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

            }

            else

            {

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

                b= dp[i-1][j-v[i]]==-1? -1:wt[i]+dp[i-1][j-v[i]];

                if(a==-1 && b==-1)

                {

                    dp[i][j]=-1;

                }

                else if(a==-1)

                {

                    dp[i][j]=b;

                }

                else if(b==-1){

                    dp[i][j]=a;

                }

                else{

                    dp[i][j]=min(a,b);

                }

            }

        }

        dp[0][0]=0;

    }

    

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

        if(dp[n][j]<=w && dp[n][j]!=-1) return j;

    }

}

int main()

{

   ll n,w,i,s=0;

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

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

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

        s+=v[i];

   }

 

   ll ans=knapsack(n,s,w);

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

   return 0;

}

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

using namespace std;

const int   N=1e2+10,M=1e5+10;

long long f[N][M],w[N],v[N];

int main()

{

	long long n,m;

	cin>>n>>m;

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

	{

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

	}

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

		for(int j=0;j<=M;j++)f[i][j]=1e9+1;

	f[0][0]=0;

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

	{

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

		{

			f[i][j]=min(w[i],f[i-1][j]);

			if(j>v[i])f[i][j]=min(f[i-1][j],f[i-1][j-v[i]]+w[i]);



		}

	}

	long long ans=0;

	for(long long  j=1;j<=M;j++)

		if(f[n][j]<=m)ans=max(ans,j);

	cout<<ans<<endl;

   return 0;

}


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

using namespace std;



typedef long long ll;

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

ll dp[102][100009],wt[102],v[102];



ll knapsack(ll n,ll s,ll w)

{

    ll a,b;

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

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

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

            else if(j==0) dp[i][j]=0;

            else if(v[i]>j){

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

            }

            else

            {

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

                b= dp[i-1][j-v[i]]==-1? -1:wt[i]+dp[i-1][j-v[i]];

                if(a==-1 && b==-1)

                {

                    dp[i][j]=-1;

                }

                else if(a==-1)

                {

                    dp[i][j]=b;

                }

                else if(b==-1){

                    dp[i][j]=a;

                }

                else{

                    dp[i][j]=min(a,b);

                }

            }

        }

        dp[0][0]=0;

    }

    

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

        if(dp[n][j]<=w && dp[n][j]!=-1) return j;

    }

}

int main()

{

   ll n,w,i,s=0;

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

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

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

        s+=v[i];

   }

 

   ll ans=knapsack(n,s,w);

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

   return 0;

}

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

using namespace std;

int f[105][100005];

int N,W;

int w[105],v[105];

int main()

{

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

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

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

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

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

	       f[i][j]=1e9+1;

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

	{

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

	    {

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

		    if(j >=v[i]) f[i][j]=min(f[i][j],f[i-1][j-v[i]] + w[i]);

 	    }

	}

	int ans=0;

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

	   if(f[N][i] <= W) ans=i;//cout<<f[N][i]<<endl;

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

	return 0;

}

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

using namespace std;



typedef long long ll;

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

ll dp[102][100009],wt[102],v[102];



ll knapsack(ll n,ll s,ll w)

{

    ll a,b;

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

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

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

            else if(j==0) dp[i][j]=0;

            else if(v[i]>j){

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

            }

            else

            {

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

                b= dp[i-1][j-v[i]]==-1? -1:wt[i]+dp[i-1][j-v[i]];

                if(a==-1 && b==-1)

                {

                    dp[i][j]=-1;

                }

                else if(a==-1)

                {

                    dp[i][j]=b;

                }

                else if(b==-1){

                    dp[i][j]=a;

                }

                else{

                    dp[i][j]=min(a,b);

                }

            }

        }

        dp[0][0]=0;

    }

    

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

        if(dp[n][j]<=w && dp[n][j]!=-1) return j;

    }

}

int main()

{

   ll n,w,i,s=0;

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

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

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

        s+=v[i];

   }

 

   ll ans=knapsack(n,s,w);

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

   return 0;

}

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

#define f first

#define s second

#define pb push_back

#define ENDL '\n'

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

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

#define deb(a) cout << #a << ": " << a << ENDL

#define fore(i, a, b) for(int i(a), ThkMk(b); i < ThkMk; ++i)

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



using namespace std;



typedef long long lli;

typedef long double ld;

typedef pair<lli, lli> ii;

typedef vector<lli> vi;



int main()

{   _

    lli n, w, u, v; cin >> n >> w;

    lli MXV = 1e5 + 5;

    lli INF = 1e18;

    vector<lli> dp(MXV, INF);

    dp[0] = 0;

    fore(t, 0, n) {

        cin >> u >> v;

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

            if(dp[i] != INF) dp[i + v] = min(dp[i + v], dp[i] + u);

        }

    }

    lli ans = 0;

    fore(i, 1, MXV) if(dp[i] <= w) ans = i;

    cout << ans << ENDL;

    return 0;

}


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

using namespace std;



typedef long long ll;

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

ll dp[102][100009],wt[102],v[102];



ll knapsack(ll n,ll s,ll w)

{

    ll a,b;

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

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

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

            else if(j==0) dp[i][j]=0;

            else if(v[i]>j){

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

            }

            else

            {

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

                b= dp[i-1][j-v[i]]==-1? -1:wt[i]+dp[i-1][j-v[i]];

                if(a==-1 && b==-1)

                {

                    dp[i][j]=-1;

                }

                else if(a==-1)

                {

                    dp[i][j]=b;

                }

                else if(b==-1){

                    dp[i][j]=a;

                }

                else{

                    dp[i][j]=min(a,b);

                }

            }

        }

        dp[0][0]=0;

    }

    

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

        if(dp[n][j]<=w && dp[n][j]!=-1) return j;

    }

}

int main()

{

   ll n,w,i,s=0;

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

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

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

        s+=v[i];

   }

 

   ll ans=knapsack(n,s,w);

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

   return 0;

}

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

#include <set>

#include <cmath>

#include <queue>

#include <stack>

#include <vector>

#include <cstdio>

#include <string>

#include <cstdlib>

#include <cstring>

#include <iostream>

#include <algorithm>

//全华班

using namespace std;



#define fi first

#define se second

#define mp make_pair

#define LL long long

#define pll pair<LL, LL>

#define pii pair<int, int>



const LL mod = 1e9 + 7;

const int maxn = 1e5 + 5;

const LL inf = 0x3f3f3f3f;

const double eps = 1e-8;

const double pi = acos(-1.0);



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



int main() {

	int n, W; cin >> n >> W;

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

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

	}

	memset(dp, 0x3f, sizeof dp);

	dp[0] = 0;

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

		for(int j = maxn - 1; j >= v[i]; --j) {

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

		}

	}

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

		if(dp[i] > W) continue;

		cout << i << endl; break;

	}

	return 0;

}

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

using namespace std;



typedef long long ll;

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

ll dp[102][100009],wt[102],v[102];



ll knapsack(ll n,ll s,ll w)

{

    ll a,b;

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

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

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

            else if(j==0) dp[i][j]=0;

            else if(v[i]>j){

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

            }

            else

            {

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

                b= dp[i-1][j-v[i]]==-1? -1:wt[i]+dp[i-1][j-v[i]];

                if(a==-1 && b==-1)

                {

                    dp[i][j]=-1;

                }

                else if(a==-1)

                {

                    dp[i][j]=b;

                }

                else if(b==-1){

                    dp[i][j]=a;

                }

                else{

                    dp[i][j]=min(a,b);

                }

            }

        }

        dp[0][0]=0;

    }

    

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

        if(dp[n][j]<=w && dp[n][j]!=-1) return j;

    }

}

int main()

{

   ll n,w,i,s=0;

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

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

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

        s+=v[i];

   }

 

   ll ans=knapsack(n,s,w);

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

   return 0;

}

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

using namespace std;

const int N = 105;

const int V = 1e5 + 100;

int n, we, w[N], v[N];

long long dp[V];



int main() {

	ios_base::sync_with_stdio(0);

	cin.tie(0);



	cin >> n >> we;



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

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

	}



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

		dp[j] = LLONG_MAX;

	}



	dp[0] = 0;

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

		for (int j = V - 1; j >= 0; j--) {

			if (dp[j] == LLONG_MAX) continue;

			dp[j + v[i]] = min(dp[j + v[i]], dp[j] + (long long) w[i]);

		}

	}



	int ans = 0 ;

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

		if (dp[i] > we) continue;

		ans = i;

		break;

	}



	cout << ans << '\n';



	return 0;

}


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

using namespace std;

const int N = 105;

const int V = 1e5 + 100;

const int W_MAX = 1e9 + 5;

int n, we, w[N], v[N];

int dp[V];



int main() {

	ios_base::sync_with_stdio(0);

	cin.tie(0);



	cin >> n >> we;



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

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

	}



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

		dp[j] = W_MAX;

	}



	dp[0] = 0;

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

		for (int j = V - 1; j >= 0; j--) {

			if (dp[j] == W_MAX) continue;

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

		}

	}



	int ans = 0 ;

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

		if (dp[i] > we) continue;

		ans = i;

		break;

	}



	cout << ans << '\n';



	return 0;

}


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

#include<algorithm>

#define INF 100000000000

using namespace std;

typedef long long ll;

int n,W;

ll w[100],v[100];

ll dp[101][100001];

int main(){

  cin >> n >> W;

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

  for(int i=1;i<=100000;i++) dp[0][i]=INF;

  dp[0][0]=0;

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

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

      if(j<v[i]) dp[i+1][j]=dp[i][j];

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

    }

  }

  int res=0;

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

    if(dp[n][i]<=W) res=i;

  }

  cout << res << "\n";



  

  return 0;

}


// Optimized solution to the same problem (faster):
#include<iostream>

#include<algorithm>

#include<climits>

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

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

#define scan(arg) cin>>arg

#define prin(arg) cout<<arg<<"\n"

#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"

using namespace std;

typedef long long ll;

const ll INF=1e+15;

int n;

ll W;

ll w[110],v[110];

ll dp[110][100010];

int main(){

  scan(n);scan(W);

  int sumv=0;

  rep(i,n){

    scan(w[i]);scan(v[i]);

    sumv+=v[i];

  }

  rep(j,sumv+1){

    dp[0][j]=INF;

  }

  rep1(i,n){

    rep(j,sumv+1){

      if(j<=v[i-1]){

	dp[i][j]=min(w[i-1],dp[i-1][j]);

      }

      else{

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

      }

    }

  }

  bool f=true;

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

    if(dp[n][j]<=W){

      prin(j);

      f=false;

      break;

    }

  }

  if(f)prin(0);

  /* rep(i,n+1){

    rep(j,sumv+1){

      cout<<dp[i][j]<<" ";

    }

    prin('.');

    }*/



  



  

  return 0;

}


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

using namespace std;

#define endl '\n'

typedef long long ll;

const ll oo = 0x3f3f3f3f3f3f3f3f;



int main()

{

  ios_base::sync_with_stdio(0);

  cin.tie(0);

  

  ll n, w;

  cin >> n >> w;

  

  ll N = n * 5000 + 100;

  vector<ll> dp(N, oo);

  dp[0] = 0;

  

  for(ll i = 0, a, b; i < n; ++i)

  {

  	cin >> a >> b;

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

      if(dp[j] != oo && j + b < N)

        dp[j + b] = min(dp[j + b], dp[j] + a);

  }

  

  for(ll i = N - 1; i >= 0; --i)

  {

  	if(dp[i] <= w)

    {

      cout << i << endl;

      return 0;

    }

  }

  

}


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

using namespace std;

#define endl '\n'

typedef long long ll;

const ll oo = 0x3f3f3f3f3f3f3f3f;



int main()

{

  ios_base::sync_with_stdio(0);

  cin.tie(0);

  

  ll n, w;

  cin >> n >> w;

  

  ll N = n * 1000 + 100;

  vector<ll> dp(N, oo);

  dp[0] = 0;

  

  for(ll i = 0, a, b; i < n; ++i)

  {

  	cin >> a >> b;

    for(int j = N - 1; j >= 0; --j)

      if(dp[j] != oo)

        dp[j + b] = min(dp[j + b], dp[j] + a);

  }

  

  for(ll i = N - 1; i >= 0; --i)

  {

  	if(dp[i] <= w)

    {

      cout << i << endl;

      return 0;

    }

  }

  

}


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

using namespace std;



template<class T> inline bool chmin(T& a, const T b) {

	if (a > b) {

		a = b;

		return true;

	}

	return false;

}



const long INF = 1L << 60;



int weight[110];

int value[110];

long dp[2][110000];



int main(){

	int n, w;

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

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

		scanf("%d%d", &weight[i], &value[i]);

	}

	for(int i = 1; i < 110000; i++) dp[0][i] = INF;

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

		int t = i % 2;

		for(int j = 0; j < 110000; j++) dp[t][j] = INF;

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

			chmin(dp[t][j], dp[!t][j]);

			if(j - value[i-1] >= 0)

				chmin(dp[t][j], dp[!t][j-value[i-1]] + weight[i-1]);

		}

	}

	long ret = 0;

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

		if(dp[n%2][i] <= w) ret = i;

	printf("%ld", ret);

}


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

using namespace std;



template<class T> inline bool chmin(T& a, const T b) {

	if (a > b) {

		a = b;

		return true;

	}

	return false;

}



const long INF = 1L << 60;



int weight[110];

int value[110];

long dp[110000];



int main(){

	int n, w, sum = 0;

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

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

		scanf("%d%d", &weight[i], &value[i]);

		sum += value[i];

	}

	for(int i = 0; i <= sum; i++) dp[i] = INF;

	dp[0] = 0;

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

		for(int j = sum-value[i]; j >= 0; j--)

			chmin(dp[j+value[i]], dp[j] + weight[i]);

	long ret = 0;

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

		if(dp[i] <= w) ret = max(ret, (long)i);

	printf("%ld", ret);

}


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

#define endl '\n'

#define ll long long int

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

#define pb                    push_back

#define F                     first

#define S                     second

#define mp                    make_pair

#define clr(x)                x.clear()

#define MOD                   1000000007

#define itoc(c)               ((char)(((int)'0')+c))

#define vl                    vector<ll>

#define SZ(x)                 (x).size()

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

#define mid(s,e)              (s+(e-s)/2)

#define sv()                  ll t,n; scanf("%lld",&t);n=t; while(t--)

#define tcase()               ll t,n; cin>>t;n=t; while(t--)

#define iscn(num)             scanf("%d",&num);

#define scn(num)              scanf("%lld",&num);

#define scn2(num,num2)        scanf("%lld%lld",&num,&num2);

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

using namespace std;

const ll INF = 2e18 + 99;

typedef pair<ll,ll> Pair;

typedef vector<ll> vec;;

void FAST_IO();

void ara_read(vec &v,ll n);

////////////////////////



int main()

{

	ll n, knapsack ;

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

	/* now in this problem knapsack size is huge,

	 * so we can't use it as dp dimension. but here now value 

	 * is kinda small , we can this as dp dimension..

	 * we will use raw swapping to solve this dp problem */

	ll nax = n* 1000 + 10;

	vector< vector<ll > > dp(2,vector<ll> (nax,INF));

	bool prev=0, next =1;

	dp[0][0]=0 ;

	ll w, v ;

	

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

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

		for(int value =0 ; value < nax ; ++value){

			if(value<v){

				dp[next][value]= dp[prev][value];

			}else{

				dp[next][value]= min(dp[prev][value],dp[prev][value-v]+ w);

				

			}

		}

		swap(prev, next);

	}

	cerr << knapsack << endl;

	ll ans =0 ;

	for (int x = 0 ; x < nax ; ++x){

		if(dp[prev][x] <= knapsack){

			ans = x ;

			

		}

	}

	

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

    return 0;

}



void FAST_IO()

{

    // ios_base::sync_with_stdio(0);

    //cin.tie(NULL);

    //cout.tie(NULL);

    //cout.setf(ios::fixed);

    //cout.precision(2);



}

void ara_read(vec &v,ll n){

	ll temp;

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

		scanf("%lld",&temp);

		v.emplace_back(temp);

	}

	

}


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

#define ll long long int

using namespace std;



void min_self(ll &a , ll b){

	a=min(a,b);

}

const ll INF = 2e18 + 90 ;

int main(){

	

	ll  items, knapsack ;

	scanf("%lld%lld",&items,&knapsack);

	const ll nax = items * 1000 + 90 ;

	vector<ll> dp(nax+1,INF);

	dp[0] = 0;

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

		ll weight,value;

		scanf("%lld%lld",&weight,&value);

		for(ll j = nax-1; j>=value ; --j){

			min_self(dp[j], dp[j-value]+weight);

		}

	}

	

	ll ans = INF;

	for(ll i=nax-1 ; i>=0 ; i--){

		if(dp[i]<=knapsack){

			ans=i;

			break ;

		}

	}

	

	

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

	return 0;

}


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

using namespace std;

using ll=long long;

using llu=unsigned long long;

#define mod 1000000007

#define mode 998244353

#define PI 3.14159265358979323846

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

#define mms(x,y) memset(x,y,sizeof(x))

#define pqm priority_queue<ll,vector<ll>,greater<ll>>

#define pb push_back

#define um unordered_map

#define pr pair

#define mm multimap

#define ms multiset

#define mp make_pair

#define vr vector

#define pq priority_queue

#define lb lower_bound

#define ub upper_bound

#define inf INT_MAX

#define ninf INT_MIN

#define ff first

#define ss second

#define gcd __gcd

int main()

{

    fast;

    ll t,n,m,i,j,k;

    cin>>n>>k;

    ll w[n],val[n];

    for(i=0;i<n;i++)cin>>w[i]>>val[i];

    ll dp[n+1][100001];

    for(i=0;i<=n;i++)dp[i][0]=0;

    for(i=1;i<=100000;i++)dp[0][i]=inf;

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

    {

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

        {

            if(j>=val[i-1])

            {

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

            }

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

        }

    }

    for(i=100000;i>=0;i--)

    {

        if(dp[n][i]<=k)

        {

            cout<<i;

            break;

        }

    }

}


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

using namespace std;

using ll=long long;

using llu=unsigned long long;

#define mod 1000000007

#define mode 998244353

#define PI 3.14159265358979323846

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

#define mms(x,y) memset(x,y,sizeof(x))

#define pqm priority_queue<ll,vector<ll>,greater<ll>>

#define pb push_back

#define um unordered_map

#define pr pair

#define mm multimap

#define ms multiset

#define mp make_pair

#define vr vector

#define pq priority_queue

#define lb lower_bound

#define ub upper_bound

#define inf INT_MAX

#define ninf INT_MIN

#define ff first

#define ss second

#define gcd __gcd

int main()

{

    fast;

    ll t,n,m,i,j,k;

    cin>>n>>k;

    ll w[n],val[n];

    for(i=0;i<n;i++)cin>>w[i]>>val[i];

    ll dp[100001];

    dp[0]=0;

    for(i=1;i<=100000;i++)dp[i]=inf;

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

    {

        for(j=100000;j>=val[i-1];j--)

        {

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

        }

    }

    for(i=100000;i>=0;i--)

    {

        if(dp[i]<=k)

        {

            cout<<i;

            break;

        }

    }

}


// Fastest known solution for this problem: