output_description: Print the maximum possible total value of the selected items.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N W
      w_1 v_1
      w_2 v_2
      :
      w_N v_N
attempt: #include <bits/stdc++.h>
    
  using namespace std;
    
  #define rep(i,n) REP(i,0,n)
  #define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
  #define pb push_back
  #define all(r) r.begin(),r.end()
  #define rall(r) r.rbegin(),r.rend()
  #define fi first
  #define se second
    
  typedef long long ll;
  typedef vector<int> vi;
  typedef vector<ll> vl;
  typedef pair<int, int> pii;
  typedef pair<ll, ll> pll;
   
  const int INF = 1e9;
  const ll MOD = 1e9 + 7;
  double EPS = 1e-8;
  
  int main(){
  	ll ans = 0LL;
  	int N, W;
  	cin >> N >> W;
  	vl w(N), v(N);
  	rep(i, N) cin >> w[i] >> v[i];
  	deque<ll> V[4];
  	rep(i, N) V[w[i]-w[0]].push_back(v[i]);
  	rep(i, 4) sort(rall(V[i]));
  	rep(i, 4) REP(j, 1, V[i].size()) V[i][j] += V[i][j-1];
  	rep(i, 4) V[i].push_front(0LL);
  	rep(i, V[0].size()) rep(j, V[1].size()) rep(k, V[2].size()) rep(l, V[3].size()) {
  		ll now_W = 0LL;
  		now_W += (ll)w[0]*(i);
  		now_W += (ll)(w[0]+1)*(j);
  		now_W += (ll)(w[0]+2)*(k);
  		now_W += (ll)(w[0]+3)*(l);
  		//cout << " i: " << i << " j: " << j <<" k: " << k << " l: " << l << " w: " << now_W << " v: " << V[0][i] + V[1][j] + V[2][k] + V[3][l] <<endl;
  		if(now_W <= W) ans = max(ans, V[0][i] + V[1][j] + V[2][k] + V[3][l]);
  	}
  	cout << ans << endl;
  }
  
problem_description: Statement
  
  You have N items and a bag of strength W. The i-th item has a weight of w_i
  and a value of v_i.
  
  You will select some of the items and put them in the bag. Here, the total
  weight of the selected items needs to be at most W.
  
  Your objective is to maximize the total value of the selected items.
samples: [{"input": "4 6\n    2 1\n    3 4\n    4 10\n    3 4", "output": "11\n    \n\nThe first and third items should be selected.\n\n* * *"}, {"input": "4 6\n    2 1\n    3 7\n    4 10\n    3 6", "output": "13\n    \n\nThe second and fourth items should be selected.\n\n* * *"}, {"input": "4 10\n    1 100\n    1 100\n    1 100\n    1 100", "output": "400\n    \n\nYou can take everything.\n\n* * *"}, {"input": "4 1\n    10 100\n    10 100\n    10 100\n    10 100", "output": "0\n    \n\nYou can take nothing."}]