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 competitive::prelude::*;

fn cum_sum(v: &Vec<usize>) -> Vec<usize> {
    let mut cumsum = Vec::new();
    let mut sum = 0;
    cumsum.push(0);
    for elem in v.iter().rev() {
        sum += elem;
        cumsum.push(sum);
    }
    cumsum
}

fn main() {
    input! {
        n: usize,
        w: usize,
        wv: [(usize, usize); n],
    }
    // wは高々四種類
    // w1, w2, w3, w4からそれぞれいくつずつ使うかの全探索 -> 高々10^4
    let w1 = wv[0].0;
    let mut v1 = Vec::new();
    let mut v2 = Vec::new();
    let mut v3 = Vec::new();
    let mut v4 = Vec::new();
    for pair in wv {
        match pair.0 - w1 {
            0 => v1.push(pair.1),
            1 => v2.push(pair.1),
            2 => v3.push(pair.1),
            3 => v4.push(pair.1),
            _ => println!("Error")
        }
    }
    v1.sort();
    v2.sort();
    v3.sort();
    v4.sort();
    let cumsum1 = cum_sum(&v1);
    let cumsum2 = cum_sum(&v2);
    let cumsum3 = cum_sum(&v3);
    let cumsum4 = cum_sum(&v4);
    let mut ans = 0;
    for i in 0..v1.len() + 1 {
        for j in 0..v2.len() + 1 {
            for k in 0..v3.len() + 1 {
                for l in 0..v4.len() + 1 {
                    let weight = i * w1 + j * (w1 + 1) + k * (w1 + 2) + l * (w1 + 3);
                    if weight > w { break; }
                    let value = cumsum1[i] + cumsum2[j] + cumsum3[k] + cumsum4[l];
                    ans = max(ans, value);
                }
            }
        }
    }
    println!("{}", ans);
}
*/

fn main() {
    let exe = "/tmp/bin0DFD5C07";
    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>";