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 Rust (1.15.1) (judge verdict: Accepted)

// This code is generated by [cargo-atcoder](https://github.com/tanakh/cargo-atcoder)
// Original source code:
/*
use algo::*;

fn solve(n: usize, w: usize, wvs: Vec<[i32; 2]>) -> i32 {
    let mut wc = vec![vec![]; 4];
    for [w, v] in wvs.clone() {
        wc[(w as i32 - wvs[0][0]) as usize].push(v);
    }

    for i in 0..4 {
        wc[i].sort_by(|v1, v2| v2.cmp(v1));
    }

    let mut r = 0;
    let w1 = wvs[0][0];
    for i in 0..=n {
        for j in 0..=n {
            for k in 0..=n {
                if i + j + k > n {
                    continue;
                }

                for l in 0..=n - (i + j + k) {
                    if w1 as usize * i
                        + (w1 as usize + 1) * j
                        + (w1 as usize + 2) * k
                        + (w1 as usize + 3) * l
                        > w
                    {
                        continue;
                    }
                    let p = wc[0].iter().take(i).sum::<i32>()
                        + wc[1].iter().take(j).sum::<i32>()
                        + wc[2].iter().take(k).sum::<i32>()
                        + wc[3].iter().take(l).sum::<i32>();
                    if r < p {
                        r = p;
                    }
                }
            }
        }
    }

    r
}

fn main() {
    input! {
        n: usize,
        w: usize,
        wvs: [[i32; 2]; n],
    }

    println!(
        "{:?}",
        solve(n, w, wvs.into_iter().map(|v| [v[0], v[1]]).collect())
    );
}
*/

fn main() {
    let exe = "/tmp/binE11CC3DB";
    std::io::Write::write_all(&mut std::fs::File::create(exe).unwrap(), &decode(BIN)).unwrap();
    std::fs::set_permissions(exe, std::os::unix::fs::PermissionsExt::from_mode(0o755)).unwrap();
    std::process::exit(std::process::Command::new(exe).status().unwrap().code().unwrap())
}

fn decode(v: &str) -> Vec<u8> {
    let mut ret = vec![];
    let mut buf = 0;
    let mut tbl = vec![64; 256];
    for i in 0..64 { tbl[TBL[i] as usize] = i as u8; }
    for (i, c) in v.bytes().filter_map(|c| { let c = tbl[c as usize]; if c < 64 { Some(c) } else { None } }).enumerate() {
        match i % 4 {
            0 => buf = c << 2,
            1 => { ret.push(buf | c >> 4); buf = c << 4; }
            2 => { ret.push(buf | c >> 2); buf = c << 6; }
            3 => ret.push(buf | c),
            _ => unreachable!(),
        }
    }
    ret
}

const TBL: &'static [u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
const BIN: &'static str = "<base64-encoded ELF executable removed>";