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: Accepted)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define IN freopen("nocross.in","r",stdin)
#define OUT freopen("nocross.out","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define INF 2000000000000000000LL
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define LOG 19
#define off 2

#define mod 1000000007LL

using namespace __gnu_pbds;
using namespace std ;

typedef tree< i64, null_type, less< i64 >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define maxn 200005

i64 dp1[maxn] , dp2[maxn] ;

vector < pair<int,int> > vp ;
vector < pair<int,int> > zero ;

bool comp( pair<int,int> a , pair<int,int> b )
{
    return 1LL*a.xx*(b.yy+1) > 1LL*b.xx*(a.yy+1) ;
}

int main()
{
    int n , T ;

    scanf("%d %d",&n,&T) ;

    for(int i=1 ; i<=n ; i++)
    {
        int a , b ;
        scanf("%d %d",&a,&b) ;
        if(a!=0) vp.pb( mp( a , b ) ) ;
        else zero.pb(mp(a,b)) ;
    }

    sort( vp.begin() , vp.end() , comp ) ;
    sort( zero.begin() , zero.end() ) ;

    int mx1 = 35 ;

    for(int i=0 ; i<=mx1+2 ; i++) dp1[i] = T+1 ;

    dp1[0] = 0 ;

    for(int i=0 ; i<vp.size() ; i++)
    {
        for(int j=mx1 ; j>=1 ; j--)
        {
            if( 1LL*(dp1[j-1]+1)*vp[i].xx + vp[i].yy + dp1[j-1] + 1 < dp1[j] )
            {
                dp1[j] = 1LL*(dp1[j-1]+1)*vp[i].xx + vp[i].yy + dp1[j-1] + 1 ;
            }
        }
    }

    for(int i=0 ; i<zero.size() ; i++)
    {
        dp2[i+1] = dp2[i] + zero[i].yy+1 ;
    }

    int ans = 0 ;

    for(int i=0 ; dp1[i] <= T ; i++)
    {
        for(int j=0 ; j<= (int)zero.size() ; j++)
        {
            if( dp1[i] + dp2[j] <= T ) ans = max(ans,i+j) ;
        }
    }

    printf("%d\n",ans) ;

    return 0 ;
}