Problem:
Score : 800 points

Problem Statement

There are N stores called Store 1, Store 2, \cdots, Store N. Takahashi, who is at his house at time 0, is planning to visit some of these stores.

It takes Takahashi one unit of time to travel from his house to one of the stores, or between any two stores.

If Takahashi reaches Store i at time t, he can do shopping there after standing in a queue for a_i \times t + b_i units of time. (We assume that it takes no time other than waiting.)

All the stores close at time T + 0.5. If Takahashi is standing in a queue for some store then, he cannot do shopping there.

Takahashi does not do shopping more than once in the same store.

Find the maximum number of times he can do shopping before time T + 0.5.

Constraints

All values in input are integers.

1 \leq N \leq 2 \times 10^5

0 \leq a_i \leq 10^9

0 \leq b_i \leq 10^9

0 \leq T \leq 10^9

Input

Input is given from Standard Input in the following format:

N T
a_1 b_1
a_2 b_2
\vdots
a_N b_N

Output

Print the answer.

Sample Input 1

3 7
2 0
3 2
0 3

Sample Output 1

2

Here is one possible way to visit stores:

From time 0 to time 1: in 1 unit of time, he travels from his house to Store 1.

From time 1 to time 3: for 2 units of time, he stands in a queue for Store 1 to do shopping.

From time 3 to time 4: in 1 unit of time, he travels from Store 1 to Store 3.

From time 4 to time 7: for 3 units of time, he stands in a queue for Store 3 to do shopping.

In this way, he can do shopping twice before time 7.5.

Sample Input 2

1 3
0 3

Sample Output 2

0

Sample Input 3

5 21600
2 14
3 22
1 3
1 10
1 9

Sample Output 3

5

Sample Input 4

7 57
0 25
3 10
2 4
5 15
3 22
2 14
1 15

Sample Output 4

3

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 main() {
    input! {
        n: usize,
        t: i64,
        mut ab: [(i64, i64); n],
    }

    let mut zero = vec![];
    let mut non_zero = vec![];

    for (a, b) in ab {
        if a == 0 {
            zero.push((a, b));
        } else {
            non_zero.push((a, b));
        }
    }

    zero.sort();
    non_zero.sort_by(|y, x| (x.0 * (y.1 + 1)).cmp(&(y.0 * (x.1 + 1))));

    let mut ans = 0;

    for i in 0..=30 {
        let ct = solve(non_zero.len(), i, &non_zero);
        if let Some(mut ct) = ct.option() {
            if ct > t {
                continue;
            }
            let mut cur = i;
            for &(_, b) in zero.iter() {
                let nt = ct + 1 + b;
                if nt <= t {
                    cur += 1;
                } else {
                    break;
                }
                ct = nt;
            }
            ans = max(ans, cur);
        }
    }

    echo!(ans);
}

#[memoise(cur, rest)]
fn solve(cur: usize, rest: usize, ab: &[(i64, i64)]) -> MaybeInf<i64> {
    if rest == 0 {
        return NonInf(0);
    }
    if cur == 0 {
        return Inf;
    }

    min(solve(cur - 1, rest, ab), {
        let t = solve(cur - 1, rest - 1, ab);
        let w = (t + 1) * ab[cur - 1].0 + ab[cur - 1].1;
        if t > NonInf(10000000000) {
            Inf
        } else {
            t + 1 + w
        }
    })
}
*/

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