p02322 Knapsack Problem with Limitations II_32111
You have $N$ items that you want to put them into a knapsack. Item $i$ has value $v_i$, weight $w_i$ and limitation $m_i$.

You want to find a subset of items to put such that:

* The total value of the items is as large as possible.
* The items have combined weight at most $W$, that is capacity of the knapsack.
* You can select at most $m_i$ items for $i$-th item.



Find the maximum total value of items in the knapsack.

Constraints

* $1 \le N \le 50$
* $1 \le v_i \le 50$
* $1 \le w_i \le 10^9$
* $1 \le m_i \le 10^9$
* $1 \le W \le 10^9$

Input


$N$ $W$
$v_1$ $w_1$ $m_1$
$v_2$ $w_2$ $m_2$
:
$v_N$ $w_N$ $m_N$


The first line consists of the integers $N$ and $W$. In the following $N$ lines, the value, weight and limitation of the $i$-th item are given.

Output

Print the maximum total values of the items in a line.

Examples

Input

4 8
4 3 2
2 1 1
1 2 4
3 2 2


Output

12


Input

2 100
1 1 100
2 1 50


Output

150


Input

5 1000000000
3 5 1000000000
7 6 1000000000
4 4 1000000000
6 8 1000000000
2 5 1000000000


Output

1166666666
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
ll v[55], w[55], m[55];
ll dp[2505];

int main() {
    init();
    ll N,W;
    cin >> N >> W;
    rep(i, N) cin >> v[i] >> w[i] >> m[i];
    
    ll v_max = *max_element(v, v + N);
    if(v_max==0){
        cout << 0 << endl;
        return 0;
    }

    vc<ll> m1(N, v_max - 1), m2(N);
    rep(i, N){
        chmin(m1[i], m[i]);
        m2[i] = m[i] - m1[i];
    }

    // 各荷物をmin(m[i], v_max - 1)個としてdp
    ll WQ = N * v_max;
    fill(dp + 1, dp + WQ + 1, INF);

    vl deq(WQ + 1), deqv(WQ + 1);

    rep(i,N){
        rep(r, v[i]){
            ll s = 0, t = 0;
            rep(j, (WQ - r)/v[i]+1){
                if(dp[j * v[i] + r] != INF){
                    ll val = dp[j * v[i] + r] - j * w[i];
                    while (s < t and deqv[t - 1] >= val) t--;
                    deq[t] = j, deqv[t] = val;
                    t++;
                }
                if(s<t){
                    dp[j * v[i] + r] = deqv[s] + j * w[i];
                    if (deq[s] == j - m1[i]) s++;
                }
            }
        }
    }

    ll ans = 0;
    vl id(N);
    iota(all(id), 0ll), sort(all(id), [&](ll i1, ll i2) { return v[i1] * w[i2] > v[i2] * w[i1]; });

    rep(i, WQ + 1){
        if (dp[i] > W) continue;
        ll rest = W - dp[i], cost = i;
        repa(d, id){
            ll usem = min(max(m2[d], m[d] - dp[i]/w[d]), rest / w[d]);
            // err(i, m2[d], rest / w[d], usem);
            if (usem == 0) continue;
            cost += usem * v[d], rest -= usem * w[d];
        }

        chmax(ans, cost);
    }

    cout << ans << endl;
}
