Problem:
Score : 400 points

Problem 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.

Constraints

1 ≤ N ≤ 100

1 ≤ W ≤ 10^9

1 ≤ w_i ≤ 10^9

For each i = 2,3,...,N, w_1 ≤ w_i ≤ w_1 + 3.

1 ≤ v_i ≤ 10^7

W, each w_i and v_i are integers.

Input

Input is given from Standard Input in the following format:

N W
w_1 v_1
w_2 v_2
:
w_N v_N

Output

Print the maximum possible total value of the selected items.

Sample Input 1

4 6
2 1
3 4
4 10
3 4

Sample Output 1

11

The first and third items should be selected.

Sample Input 2

4 6
2 1
3 7
4 10
3 6

Sample Output 2

13

The second and fourth items should be selected.

Sample Input 3

4 10
1 100
1 100
1 100
1 100

Sample Output 3

400

You can take everything.

Sample Input 4

4 1
10 100
10 100
10 100
10 100

Sample Output 4

0

You can take nothing.

Solution in C# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		long W0 = W.Min();
		List<long>[] L = new List<long>[4];
		for(int i=0;i<4;i++) L[i] = new List<long>();
		for(int i=0;i<N;i++){
			L[W[i] - W0].Add(V[i]);
		}
		
		for(int i=0;i<4;i++){
			L[i].Sort();
			L[i].Reverse();
		}
		
		
		long[][] Ls = new long[4][];
		for(int i=0;i<4;i++){
			Ls[i] = new long[N+1];
			for(int j=0;j<L[i].Count;j++){
				Ls[i][j+1] = L[i][j] + Ls[i][j];
			}
		}
		
		long max = 0;
		for(int i=0;i<N;i++){
			for(int j=0;j<N;j++){
				if( i+j > N || (W0 * i + (W0+1) * j) > Wl) break;
				for(int k=0;k<N;k++){
					if( i+j+k > N || (W0 * i + (W0+1) * j + (W0+2) * k) > Wl) break;
					int rest = (int) Math.Min(N - i - j - k, ((Wl - (W0 * i + (W0+1) * j + (W0+2) * k)) / (W0+3) ));
					long val = Ls[0][i] + Ls[1][j] + Ls[2][k] + Ls[3][rest];
					max = Math.Max(max,val);
				}
			}
		}
		
		Console.WriteLine(max);
		
		
		
		
		
		
		
	}
	int N;
	long Wl;
	long[] W,V;
	public Sol(){
		var d = ria();
		N = d[0]; Wl = d[1];
		W = new long[N];
		V = new long[N];
		for(int i=0;i<N;i++){
			d = ria();
			W[i] = d[0];
			V[i] = d[1];
		}
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}