#include "bits/stdc++.h" #include "atcoder/all" using namespace std; using namespace atcoder; using ll=long long; using mint=modint998244353; #define rep3(i,a,b) for(int i=a;i<(b);i++) #define rep2(i,n) rep3(i,0,n) #define overload(a,b,c,d,...) d #define rep(...) overload(__VA_ARGS__,rep3,rep2)(__VA_ARGS__) #define all(x) x.begin(),x.end() template istream&operator>>(istream&is,vector&a){ for(T&x:a)is>>x; return is; } template ostream&operator<<(ostream&os,const vector&a){ os<<'{'; for(const T&x:a)os< void operator++(vector&a,int){ for(T&x:a)x++; } templatebool chmin(T&a,T b){ if(a>b){ a=b; return true; } return false; } templatebool chmax(T&a,T b){ if(a void debug_rec(T a){ cerr<<' '< void debug_rec(T1 a,T2... b){ cerr<<' '< void debug(T1 a,T2... b){ cerr<<"debug"; debug_rec(a,b...); } #else #define debug(...) #endif struct dat{ ll c,l,x; bool operator<(const dat&rhs)const{ return x>n>>y>>z; vectorstop(n+1); vectora(n); rep(i,n){ ll c,l,x; cin>>c>>l>>x; a[i]={c,l,x}; stop[i]=l; } stop[n]=z; sort(all(stop)); stop.erase(unique(all(stop)),stop.end()); sort(all(a),[&](dat lhs,dat rhs){ return lhs.lque; int ptr1=0,ptr2=0; ll ans=0; while(y=stop[ptr2])ptr2++; ll border=stop[ptr2]; while(!que.empty()){ auto [c,l,x]=que.top(); que.pop(); if(y+safe_mul(c,x)>=border){ ll d=(border-y+x-1)/x; c-=d; y+=x*d; if(c)que.push({c,l,x}); ans+=d; break; } else{ y+=c*x; ans+=c; } } } cout<