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 C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define lcm hddalkwjeidjjhasda
#define random_shuffle asdasdd

int f1(int tm) {
  return tm + 3 * tm + 2;
}
int f2(int tm) {
  return tm + 0 * tm + 3;
}

const int MAXN = 2 * 105000;

int n, t;
int a[MAXN], b[MAXN];
vector<int> v;

long long f(int idx, long long tm) {
  return tm + 1ll * a[idx] * tm + b[idx];
}

long long invF(int idx, long long tm) {
  long long initTm = tm;
  tm -= b[idx];
  if (tm <= 0) {
    return -1;
  }
  tm = tm / (1 + a[idx]);
  if (f(idx, tm) > initTm) {
    return -1;
  }
  return tm - 1;
}

long long calc(int a, int b) {
  return f(b, f(a, 1) + 1);
}

bool cmp(const int& a, const int& b) {
  return calc(a, b) < calc(b, a);
}

// bool cmp(const int& a, const int& b) {
//   return f(a, 1) < f(b, 1);
// }

int ans = 0;

void solve1() {
  vector <pair<int, long long>> st;
  st.push_back({-1, 0});
  for (int i = 0; i < n; i++) {
    while (true) {
      // cerr << "SZ " << sz(st) << endl;
      long long newTm = f(v[i], st.back().second + 1);
      if (newTm <= t) {
        st.push_back({v[i], newTm});
        break;
      }
      int len = sz(st);
      if (len >= 2 && f(v[i], st[len - 2].second + 1) <= st.back().second) {
        st.pop_back();
      } else {
        break;
      }
    }
    ans = max(ans, sz(st) - 1);
  }
}

void solve2() {
  reverse(all(v));
  vector <pair<int, long long>> st;
  st.push_back({-1, t});
  for (int i = 0; i < n; i++) {
    while (true) {
      // cerr << "SZ " << sz(st) << endl;
      long long newTm = invF(v[i], st.back().second);
      if (newTm >= 0) {
        st.push_back({v[i], newTm});
        break;
      }
      int len = sz(st);
      if (len >= 2 && invF(v[i], st[len - 2].second + 1) >= st.back().second) {
        st.pop_back();
      } else {
        break;
      }
    }
    ans = max(ans, sz(st) - 1);
  }
}

int main() { 

  // for (int i = 0; i <= 200; i++) {
  //   int a = f2(f1(i) + 1);
  //   int b = f1(f2(i) + 1);
  //   cout << i << " " << a << " " << b << " " << abs(a - b) << " " << (a < b ? "<" : ">") << endl;
  // }

  scanf("%d %d", &n, &t);
  for (int i = 0; i < n; i++) {
    scanf("%d %d", &a[i], &b[i]);
  }

  for (int i = 0; i < n; i++) {
    v.push_back(i);
  }
  sort(all(v), cmp);
  // reverse(all(v));
  // for (int i = 0; i < n; i++) {
  //   cout << v[i] << " ";
  // }
  // cout << endl;

  // cout << calc(v[0], v[1]) << endl;
  // cout << calc(v[0], v[2]) << endl;
  // cout << calc(v[0], v[3]) << endl;
  // cout << calc(v[2], v[3]) << endl;

  // cout << f(v[2], f(v[0], 1) + 1) << endl;
  // cout << f(v[3], f(v[0], 1) + 1) << endl;
  
  // cout << "---" << endl;

  // cout << cmp(v[0], v[1]) << endl;
  // cout << cmp(v[1], v[2]) << endl;
  // cout << cmp(v[2], v[3]) << endl;
  // cout << cmp(v[0], v[2]) << endl;
  // cout << cmp(v[2], v[1]) << endl;

  // long long tm = 0;
  // long long ans = 0;
  // for (int i = 0; i < n; i++) {
  //   long long newTm = f(v[i], tm + 1);
  //   cerr << v[i] << " " << newTm << endl;
  //   if (newTm <= t) {
  //     tm = newTm;
  //     ans++;
  //   } else {
  //     // break;
  //   }
  // }

  // int ans = 0;
  // vector <pair<int, long long>> st;
  // st.push_back({-1, 0});
  // for (int i = 0; i < n; i++) {
  //   while (true) {
  //     // cerr << "SZ " << sz(st) << endl;
  //     long long newTm = f(v[i], st.back().second + 1);
  //     if (newTm <= t) {
  //       st.push_back({v[i], newTm});
  //       break;
  //     }
  //     int len = sz(st);
  //     if (len >= 2 && f(v[i], st[len - 2].second + 1) <= st.back().second) {
  //       st.pop_back();
  //     } else {
  //       break;
  //     }
  //   }
  //   ans = max(ans, sz(st) - 1);
  // }

  // reverse(all(v));
  // int ans = 0;
  // vector <pair<int, long long>> st;
  // st.push_back({-1, t});
  // for (int i = 0; i < n; i++) {
  //   while (true) {
  //     // cerr << "SZ " << sz(st) << endl;
  //     long long newTm = invF(v[i], st.back().second);
  //     if (newTm >= 0) {
  //       st.push_back({v[i], newTm});
  //       break;
  //     }
  //     int len = sz(st);
  //     if (len >= 2 && invF(v[i], st[len - 2].second + 1) >= st.back().second) {
  //       st.pop_back();
  //     } else {
  //       break;
  //     }
  //   }
  //   ans = max(ans, sz(st) - 1);
  // }

  solve1();
  solve2();

  // long long ans = 0;
  // long long tm = t;
  // for (int i = n - 1; i >= 0; i--) {
  //   long long newTm = invF(v[i], tm);
  //   cerr << v[i] << " " << newTm << endl;
  //   if (newTm >= 0) {
  //     ans++;
  //     tm = newTm;
  //   }
  // }

  cout << ans << endl;

  return 0;
}