#include <bits/stdc++.h>
#define pb push_back
#define MOD 1000000000000

using namespace std;
typedef long long ll;
typedef long double ld;

int main(int argc, char const *argv[]) {
    ios::sync_with_stdio(false);

    #ifdef DBG
        freopen("in", "r", stdin);
    #endif

    int n, m;
    cin>>n>>m;
    ll bounty, inc, dam;
    cin>>bounty>>inc>>dam;

    vector<ll> enm(n);
    vector<vector<pair<ll, ll> > > upd(n);
    for(int i = 0 ; i < n; i++){
       ll a, b, c;
       cin>>a>>b>>c;
       if(a < dam){
        cout<<"-1";
        return 0;
       }
       enm[i] = c;
       upd[i].push_back({0, b});

    }
    for(int i = 0; i < m; i++){
        ll a, b, c;
        cin>>a>>b>>c;
        // if(c > dam) continue;
        upd[b-1].push_back({a, c});
    }

    for(int i = 0; i < n; i++){
        upd[i].push_back({MOD, dam+1});
        sort(upd[i].begin(), upd[i].end());
    }
    vector<pair<ll, ll> > ans;
    for(int i = 0; i < n; i++){
        // sort(upd[i].begin(), upd[i].end());
        int j = 0;
        while(j < upd[i].size() - 1){
            if(upd[i][j].second > dam){
                j++; continue;
            }
            pair<ll, ll> tm;
            tm.first = upd[i][j].first;
            ll pp;
            if(enm[i] == 0) pp = MOD;
            else pp = upd[i][j].first + (dam - upd[i][j].second) / enm[i];
            while(j < upd[i].size() - 1 and pp >= upd[i][j+1].first){
                if(upd[i][j+1].second > dam){
                    pp = upd[i][j+1].first;
                    break;
                }
                j++;
                if(enm[i] == 0) pp = MOD+1;
                else pp = upd[i][j].first + (dam - upd[i][j].second) / enm[i];
            }
            j++;
            tm.second = pp;
            ans.push_back(tm);
        }
    }

    vector<ll> st(ans.size()), en(ans.size());
    for(int i = 0; i <ans.size(); i++){
        st[i] = ans[i].first;
        en[i] = ans[i].second;
    }
    sort(st.begin(), st.end());
    sort(en.begin(), en.end());

    int i = 0, j = 0;

    ll kkkk = 0, cnt = 0;
    while(i < st.size() and j < en.size()){
        if(st[i] <= en[j]){
            cnt++;
            i++;
        }
        else{
            kkkk = max(kkkk, (bounty + en[j]*inc)*cnt);
            j++;
            cnt--;
        }
    }

    while(j < en.size()){
        kkkk = max(kkkk, (bounty + en[j]*inc)*cnt);
        j++;
        cnt--;
    }

    cout<<kkkk;

    return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define MOD 1000000000000

using namespace std;
typedef long long ll;
typedef long double ld;

int main(int argc, char const *argv[]) {
    ios::sync_with_stdio(false);

    #ifdef DBG
        freopen("in", "r", stdin);
    #endif

    int n, m;
    cin>>n>>m;
    ll bounty, inc, dam;
    cin>>bounty>>inc>>dam;

    vector<ll> enm(n);
    vector<vector<pair<ll, ll> > > upd(n);
    for(int i = 0 ; i < n; i++){
       ll a, b, c;
       cin>>a>>b>>c;
       if(a < dam){
        cout<<"-1";
        return 0;
       }
       enm[i] = c;
       upd[i].push_back({0, b});

    }
    for(int i = 0; i < m; i++){
        ll a, b, c;
        cin>>a>>b>>c;
        // if(c > dam) continue;
        upd[b-1].push_back({a, c});
    }

    for(int i = 0; i < n; i++){
        upd[i].push_back({MOD, dam+1});
        sort(upd[i].begin(), upd[i].end());
    }
    vector<pair<ll, ll> > ans;
    for(int i = 0; i < n; i++){
        // sort(upd[i].begin(), upd[i].end());
        int j = 0;
        while(j < upd[i].size() - 1){
            if(upd[i][j].second > dam){
                j++; continue;
            }
            pair<ll, ll> tm;
            tm.first = upd[i][j].first;
            ll pp;
            if(enm[i] == 0) pp = MOD;
            else pp = upd[i][j].first + (dam - upd[i][j].second) / enm[i];
            while(j < upd[i].size() - 1 and pp >= upd[i][j+1].first){
                if(upd[i][j+1].second > dam){
                    pp = upd[i][j+1].first - 1;
                    break;
                }
                j++;
                if(enm[i] == 0) pp = MOD+1;
                else pp = upd[i][j].first + (dam - upd[i][j].second) / enm[i];
            }
            j++;
            tm.second = pp;
            ans.push_back(tm);
        }
    }

    vector<ll> st(ans.size()), en(ans.size());
    for(int i = 0; i <ans.size(); i++){
        st[i] = ans[i].first;
        en[i] = ans[i].second;
    }
    sort(st.begin(), st.end());
    sort(en.begin(), en.end());

    int i = 0, j = 0;

    ll kkkk = 0, cnt = 0;
    while(i < st.size() and j < en.size()){
        if(st[i] <= en[j]){
            cnt++;
            i++;
        }
        else{
            kkkk = max(kkkk, (bounty + en[j]*inc)*cnt);
            j++;
            cnt--;
        }
    }

    while(j < en.size()){
        if(en[j] >= MOD - 1){
            cout<<"-1\n";
            return 0;
        }
        kkkk = max(kkkk, (bounty + en[j]*inc)*cnt);
        j++;
        cnt--;
    }

    cout<<kkkk;

    return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define MOD 1000000000000

using namespace std;
typedef long long ll;
typedef long double ld;

int main(int argc, char const *argv[]) {
    ios::sync_with_stdio(false);

    #ifdef DBG
        freopen("in", "r", stdin);
    #endif

    int n, m;
    cin>>n>>m;
    ll bounty, inc, dam;
    cin>>bounty>>inc>>dam;

    vector<ll> enm(n), mx(n);
    vector<vector<pair<ll, ll> > > upd(n);
    for(int i = 0 ; i < n; i++){
       ll a, b, c;
       cin>>a>>b>>c;
       if(a < dam){
        cout<<"-1";
        return 0;
       }
       mx[i] = a;
       enm[i] = c;
       upd[i].push_back({0, b});

    }
    for(int i = 0; i < m; i++){
        ll a, b, c;
        cin>>a>>b>>c;
        // if(c > dam) continue;
        upd[b-1].push_back({a, c});
    }

    for(int i = 0; i < n; i++){
        upd[i].push_back({MOD, dam+1});
        sort(upd[i].begin(), upd[i].end());
    }
    vector<pair<ll, ll> > ans;
    for(int i = 0; i < n; i++){
        // sort(upd[i].begin(), upd[i].end());
        int j = 0;
        while(j < upd[i].size() - 1){
            if(upd[i][j].second > dam){
                j++; continue;
            }
            pair<ll, ll> tm;
            tm.first = upd[i][j].first;
            ll pp;
            if(enm[i] == 0 or mx[i] == dam) pp = MOD;
            else pp = upd[i][j].first + (dam - upd[i][j].second) / enm[i];
            while(j < upd[i].size() - 1 and pp >= upd[i][j+1].first){
                if(upd[i][j+1].second > dam){
                    pp = upd[i][j+1].first - 1;
                    break;
                }
                j++;
                if(enm[i] == 0 or mx[i] == dam) pp = MOD+1;
                else pp = upd[i][j].first + (dam - upd[i][j].second) / enm[i];
            }
            j++;
            tm.second = pp;
            ans.push_back(tm);
        }
    }

    vector<ll> st(ans.size()), en(ans.size());
    for(int i = 0; i <ans.size(); i++){
        st[i] = ans[i].first;
        en[i] = ans[i].second;
    }
    sort(st.begin(), st.end());
    sort(en.begin(), en.end());

    int i = 0, j = 0;

    ll kkkk = 0, cnt = 0;
    while(i < st.size() and j < en.size()){
        if(st[i] <= en[j]){
            cnt++;
            i++;
        }
        else{
            kkkk = max(kkkk, (bounty + en[j]*inc)*cnt);
            j++;
            cnt--;
        }
    }

    while(j < en.size()){
        if(en[j] >= MOD - 1 and inc != 0){
            cout<<"-1\n";
            return 0;
        }
        kkkk = max(kkkk, (bounty + en[j]*inc)*cnt);
        j++;
        cnt--;
    }

    cout<<kkkk;

    return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define MOD 1000000009

using namespace std;
typedef long long ll;
typedef long double ld;

int main(int argc, char const *argv[]) {
    ios::sync_with_stdio(false);

    #ifdef DBG
        freopen("in", "r", stdin);
    #endif

    int n, m;
    cin>>n>>m;
    ll bounty, inc, dam;
    cin>>bounty>>inc>>dam;

    vector<ll> enm(n);
    vector<vector<pair<ll, ll> > > upd(n);
    for(int i = 0 ; i < n; i++){
       ll a, b, c;
       cin>>a>>b>>c;
       if(a < dam){
        cout<<"-1";
        return 0;
       }
       enm[i] = c;
       upd[i].push_back({0, b});

    }
    for(int i = 0; i < m; i++){
        ll a, b, c;
        cin>>a>>b>>c;
        if(c > dam) continue;
        upd[b-1].push_back({a, c});
    }

    for(int i = 0; i < n; i++){
        upd[i].push_back({10000000000000000, dam+1});
        sort(upd[i].begin(), upd[i].end());
    }
    vector<pair<ll, ll> > ans;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < upd[i].size() - 1; j++){
            if(upd[i][j].first == 10000000000000000) continue;
            pair<ll, ll> tm;
            tm.first = upd[i][j].first;
            ll pp = (dam - min(dam, upd[i][j].second)) / enm[i];
            pp = tm.first + pp;
            while(j < upd[i].size() - 1 and pp >= upd[i][j+1].first){
                j++;
                pp = (dam - min(dam, upd[i][j].second)) / enm[i];
                pp = upd[i][j].first + pp;
            }
            if(pp == 0) continue;
            tm.second = pp;
            ans.push_back(tm);
        }
    }

    vector<ll> st(ans.size()), en(ans.size());
    for(int i = 0; i <ans.size(); i++){
        st[i] = ans[i].first;
        en[i] = ans[i].second;
    }
    sort(st.begin(), st.end());
    sort(en.begin(), en.end());

    int i = 0, j = 0;

    ll kkkk = 0, cnt = 0;
    while(i < st.size() and j < en.size()){
        if(st[i] <= en[j]){
            cnt++;
            i++;
        }
        else{
            kkkk = max(kkkk, (bounty + en[j]*inc)*cnt);
            j++;
            cnt--;
        }
    }

    while(j < en.size()){
        kkkk = max(kkkk, (bounty + en[j]*inc)*cnt);
        j++;
        cnt--;
    }

    cout<<kkkk;

    return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define MOD 1000000000000

using namespace std;
typedef long long ll;
typedef long double ld;

int main(int argc, char const *argv[]) {
    ios::sync_with_stdio(false);

    #ifdef DBG
        freopen("in", "r", stdin);
    #endif

    int n, m;
    cin>>n>>m;
    ll bounty, inc, dam;
    cin>>bounty>>inc>>dam;

    vector<ll> enm(n), mx(n);
    vector<vector<pair<ll, ll> > > upd(n);
    for(int i = 0 ; i < n; i++){
       ll a, b, c;
       cin>>a>>b>>c;
       if(a < dam and inc > 0){
        cout<<"-1";
        return 0;
       }
       mx[i] = a;
       enm[i] = c;
       upd[i].push_back({0, b});

    }
    for(int i = 0; i < m; i++){
        ll a, b, c;
        cin>>a>>b>>c;
        // if(c > dam) continue;
        upd[b-1].push_back({a, c});
    }

    for(int i = 0; i < n; i++){
        upd[i].push_back({MOD-1, dam+1});
        sort(upd[i].begin(), upd[i].end());
    }
    vector<pair<ll, ll> > ans;
    for(int i = 0; i < n; i++){
        // sort(upd[i].begin(), upd[i].end());
        int j = 0;
        while(j < upd[i].size() - 1){
            if(upd[i][j].second > dam){
                j++; continue;
            }
            pair<ll, ll> tm;
            tm.first = upd[i][j].first;
            ll pp;
            if(enm[i] == 0 or mx[i] == dam){
                if(inc == 0) pp = MOD - 2;
                else pp = MOD;
            }
            else pp = upd[i][j].first + (dam - upd[i][j].second) / enm[i];
            while(j < upd[i].size() - 1 and pp >= upd[i][j+1].first){
                if(upd[i][j+1].second > dam){
                    pp = upd[i][j+1].first - 1;
                    break;
                }
                j++;
                if(enm[i] == 0 or mx[i] == dam){
                    if(inc == 0) pp = MOD - 2;
                    else pp = MOD + 1;
                }
                else pp = upd[i][j].first + (dam - upd[i][j].second) / enm[i];
            }
            j++;
            tm.second = pp;
            ans.push_back(tm);
        }
    }

    vector<ll> st(ans.size()), en(ans.size());
    for(int i = 0; i <ans.size(); i++){
        st[i] = ans[i].first;
        en[i] = ans[i].second;
    }
    sort(st.begin(), st.end());
    sort(en.begin(), en.end());

    int i = 0, j = 0;

    ll kkkk = 0, cnt = 0;
    while(i < st.size() and j < en.size()){
        if(st[i] <= en[j]){
            cnt++;
            i++;
        }
        else{
            kkkk = max(kkkk, (bounty + en[j]*inc)*cnt);
            j++;
            cnt--;
        }
    }

    while(j < en.size()){
        if(en[j] >= MOD and inc != 0){
            cout<<"-1\n";
            return 0;
        }
        kkkk = max(kkkk, (bounty + en[j]*inc)*cnt);
        j++;
        cnt--;
    }

    cout<<kkkk;

    return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define MOD 1000000009

using namespace std;
typedef long long ll;
typedef long double ld;

int main(int argc, char const *argv[]) {
    ios::sync_with_stdio(false);

    #ifdef DBG
        freopen("in", "r", stdin);
    #endif

    int n, m;
    cin>>n>>m;
    ll bounty, inc, dam;
    cin>>bounty>>inc>>dam;

    vector<ll> enm(n);
    vector<vector<pair<ll, ll> > > upd(n);
    for(int i = 0 ; i < n; i++){
       ll a, b, c;
       cin>>a>>b>>c;
       if(a < dam){
        cout<<"-1";
        return 0;
       }
       enm[i] = c;
       upd[i].push_back({0, b});

    }
    for(int i = 0; i < m; i++){
        ll a, b, c;
        cin>>a>>b>>c;
        if(c > dam) continue;
        upd[b-1].push_back({a, c});
    }

    for(int i = 0; i < n; i++){
        upd[i].push_back({10000000000000000, dam+1});
        sort(upd[i].begin(), upd[i].end());
    }
    vector<pair<ll, ll> > ans;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < upd[i].size() - 1; j++){
            if(upd[i][j].first == 10000000000000000) continue;
            pair<ll, ll> tm;
            tm.first = upd[i][j].first;
            ll pp;
            if( enm[i] == 0 ) pp = 10000000000000000 - 1;
            else pp = (dam - min(dam, upd[i][j].second)) / enm[i];
            pp = tm.first + pp;
            while(j < upd[i].size() - 1 and pp >= upd[i][j+1].first){
                j++;
                pp = (dam - min(dam, upd[i][j].second)) / enm[i];
                pp = upd[i][j].first + pp;
            }
            if(pp == 0) continue;
            tm.second = pp;
            ans.push_back(tm);
        }
    }

    vector<ll> st(ans.size()), en(ans.size());
    for(int i = 0; i <ans.size(); i++){
        st[i] = ans[i].first;
        en[i] = ans[i].second;
    }
    sort(st.begin(), st.end());
    sort(en.begin(), en.end());

    int i = 0, j = 0;

    ll kkkk = 0, cnt = 0;
    while(i < st.size() and j < en.size()){
        if(st[i] <= en[j]){
            cnt++;
            i++;
        }
        else{
            kkkk = max(kkkk, (bounty + en[j]*inc)*cnt);
            j++;
            cnt--;
        }
    }

    while(j < en.size()){
        kkkk = max(kkkk, (bounty + en[j]*inc)*cnt);
        j++;
        cnt--;
    }

    cout<<kkkk;

    return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define MOD 1000000000000

using namespace std;
typedef long long ll;
typedef long double ld;

int main(int argc, char const *argv[]) {
    ios::sync_with_stdio(false);

    #ifdef DBG
        freopen("in", "r", stdin);
    #endif

    int n, m;
    cin>>n>>m;
    ll bounty, inc, dam;
    cin>>bounty>>inc>>dam;

    vector<ll> enm(n);
    vector<vector<pair<ll, ll> > > upd(n);
    for(int i = 0 ; i < n; i++){
       ll a, b, c;
       cin>>a>>b>>c;
       if(a < dam){
        cout<<"-1";
        return 0;
       }
       enm[i] = c;
       upd[i].push_back({0, b});

    }
    for(int i = 0; i < m; i++){
        ll a, b, c;
        cin>>a>>b>>c;
        // if(c > dam) continue;
        upd[b-1].push_back({a, c});
    }

    for(int i = 0; i < n; i++){
        upd[i].push_back({MOD, dam+1});
        sort(upd[i].begin(), upd[i].end());
    }
    vector<pair<ll, ll> > ans;
    for(int i = 0; i < n; i++){
        // sort(upd[i].begin(), upd[i].end());
        int j = 0;
        while(j < upd[i].size() - 1){
            if(upd[i][j].second > dam){
                j++; continue;
            }
            pair<ll, ll> tm;
            tm.first = upd[i][j].first;
            ll pp;
            if(enm[i] == 0) pp = MOD;
            else pp = upd[i][j].first + (dam - upd[i][j].second) / enm[i];
            while(j < upd[i].size() - 1 and pp >= upd[i][j+1].first){
                if(upd[i][j+1].second > dam){
                    pp = upd[i][j+1].first - 1;
                    break;
                }
                j++;
                if(enm[i] == 0) pp = MOD+1;
                else pp = upd[i][j].first + (dam - upd[i][j].second) / enm[i];
            }
            j++;
            tm.second = pp;
            ans.push_back(tm);
        }
    }

    vector<ll> st(ans.size()), en(ans.size());
    for(int i = 0; i <ans.size(); i++){
        st[i] = ans[i].first;
        en[i] = ans[i].second;
    }
    sort(st.begin(), st.end());
    sort(en.begin(), en.end());

    int i = 0, j = 0;

    ll kkkk = 0, cnt = 0;
    while(i < st.size() and j < en.size()){
        if(st[i] <= en[j]){
            cnt++;
            i++;
        }
        else{
            kkkk = max(kkkk, (bounty + en[j]*inc)*cnt);
            j++;
            cnt--;
        }
    }

    while(j < en.size()){
        if(en[j] >= MOD){
            cout<<"-1\n";
            return 0;
        }
        kkkk = max(kkkk, (bounty + en[j]*inc)*cnt);
        j++;
        cnt--;
    }

    cout<<kkkk;

    return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define MOD 1000000009

using namespace std;
typedef long long ll;
typedef long double ld;

int main(int argc, char const *argv[]) {
    ios::sync_with_stdio(false);

    #ifdef DBG
        freopen("in", "r", stdin);
    #endif

    int n, m;
    cin>>n>>m;
    ll bounty, inc, dam;
    cin>>bounty>>inc>>dam;

    vector<ll> enm(n);
    vector<vector<pair<ll, ll> > > upd(n);
    for(int i = 0 ; i < n; i++){
       ll a, b, c;
       cin>>a>>b>>c;
       if(a < dam){
        cout<<"-1";
        return 0;
       }
       enm[i] = c;
       upd[i].push_back({0, b});

    }
    for(int i = 0; i < m; i++){
        ll a, b, c;
        cin>>a>>b>>c;
        if(c > dam) continue;
        upd[b-1].push_back({a, c});
    }

    for(int i = 0; i < n; i++){
        upd[i].push_back({10000000000000000, dam+1});
        sort(upd[i].begin(), upd[i].end());
    }
    vector<pair<ll, ll> > ans;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < upd[i].size() - 1; j++){
            if(upd[i][j].first == 10000000000000000) continue;
            pair<ll, ll> tm;
            tm.first = upd[i][j].first;
            ll pp;
            if( enm[i] == 0 ) pp = 10000000000000000 - 1;
            else pp = (dam - min(dam, upd[i][j].second)) / enm[i];
            pp = tm.first + pp;
            while(j < upd[i].size() - 1 and pp >= upd[i][j+1].first){
                j++;
                pp = (dam - min(dam, upd[i][j].second)) / enm[i];
                pp = upd[i][j].first + pp;
            }
            if(pp == 0 and upd[i][j].second != dam) continue;
            tm.second = pp;
            ans.push_back(tm);
        }
    }

    vector<ll> st(ans.size()), en(ans.size());
    for(int i = 0; i <ans.size(); i++){
        st[i] = ans[i].first;
        en[i] = ans[i].second;
    }
    sort(st.begin(), st.end());
    sort(en.begin(), en.end());

    int i = 0, j = 0;

    ll kkkk = 0, cnt = 0;
    while(i < st.size() and j < en.size()){
        if(st[i] <= en[j]){
            cnt++;
            i++;
        }
        else{
            kkkk = max(kkkk, (bounty + en[j]*inc)*cnt);
            j++;
            cnt--;
        }
    }

    while(j < en.size()){
        kkkk = max(kkkk, (bounty + en[j]*inc)*cnt);
        j++;
        cnt--;
    }

    cout<<kkkk;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

struct Node{
	int t, h;
};

typedef pair <int, int> P;

const int N = 1e5 + 10;
const int INF = 2e9;

vector <Node> sav[N];
vector <P> rec;
vector <int> dct;
map <int, int> _hash;
int maxh[N], reg[N], cnt[N << 3];

bool cmp(const Node& p, const Node& q){
	return p.t < q.t;
}

int main(){
	int n, m, bty, inc, dmg, t, id, h, sz, sz2;
	long long ans, temp;
	scanf("%d %d",&n,&m);
	scanf("%d %d %d",&bty,&inc,&dmg);
	for (int i = 1; i <= n; i++){
		scanf("%d %d %d",&maxh[i],&h,&reg[i]);
		sav[i].push_back({0, h});
	}
	for (int i = 1; i <= m; i++){
		scanf("%d %d %d",&t,&id,&h);
		sav[id].push_back({t, h});
	}
	for (int i = 1; i <= n; i++){
		sort(sav[i].begin(), sav[i].end(), cmp);
		sz = (int)sav[i].size();
		if (inc > 0 && ((maxh[i] <= dmg) || (reg[i] == 0 && sav[i][sz - 1].h <= dmg))){
			printf("-1\n");
			return 0;
		}
		sav[i].push_back({INF, 0});
		for (int j = 0; j < sz; j++){
			if (sav[i][j].h > dmg) continue;
			if (reg[i] == 0 || maxh[i] <= dmg){
				rec.emplace_back(sav[i][j].t, sav[i][j + 1].t);
				dct.push_back(sav[i][j].t);
				dct.push_back(sav[i][j + 1].t - 1);
				dct.push_back(sav[i][j + 1].t);
			}
			else{
				t = (dmg - sav[i][j].h) / reg[i] + sav[i][j].t + 1;
				t = min(t, sav[i][j + 1].t);
				rec.emplace_back(sav[i][j].t, t);
				dct.push_back(sav[i][j].t);
				dct.push_back(t - 1);
				dct.push_back(t);
			}
		}
	}
	sort(dct.begin(), dct.end());
	sz = unique(dct.begin(), dct.end()) - dct.begin();
	for (int i = 0; i < sz; i++) _hash.insert(make_pair(dct[i], i + 1));
	sz2 = (int)rec.size();
	memset(cnt, 0, sizeof(cnt));
	for (int i = 0; i < sz2; i++){
		cnt[_hash[rec[i].first]]++;
		cnt[_hash[rec[i].second]]--;
	}
	for (int i = 2; i <= sz; i++) cnt[i] += cnt[i - 1];
	ans = 0;
	for (int i = 1; i <= sz; i++){
		temp = 1LL * dct[i - 1] * inc + bty;
		ans = max(ans, temp * cnt[i]);
	}
	printf("%I64d\n", ans);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

struct Node{
	int t, h;
};

typedef pair <int, int> P;

const int N = 1e5 + 10;
const int INF = 2e9;

vector <Node> sav[N];
vector <P> rec;
vector <int> dct;
map <int, int> _hash;
int maxh[N], reg[N], cnt[N << 2];

int main(){
	int n, m, bty, inc, dmg, t, id, h, sz, sz2;
	long long ans;
	scanf("%d %d",&n,&m);
	scanf("%d %d %d",&bty,&inc,&dmg);
	for (int i = 1; i <= n; i++){
		scanf("%d %d %d",&maxh[i],&h,&reg[i]);
		sav[i].push_back({0, h});
	}
	for (int i = 1; i <= m; i++){
		scanf("%d %d %d",&t,&id,&h);
		sav[id].push_back({t, h});
	}
	for (int i = 1; i <= n; i++){
		sz = (int)sav[i].size();
		if (inc > 0 && ((maxh[i] <= dmg) || (reg[i] == 0 && sav[i][sz - 1].h <= dmg))){
			printf("-1\n");
			return 0;
		}
		sav[i].push_back({INF, 0});
		for (int j = 0; j < sz; j++){
			if (sav[i][j].h > dmg) continue;
			if (reg[i] == 0 || maxh[i] <= dmg){
				rec.emplace_back(sav[i][j].t, sav[i][j + 1].t);
				dct.push_back(sav[i][j].t);
				dct.push_back(sav[i][j + 1].t - 1);
				dct.push_back(sav[i][j + 1].t);
			}
			else{
				t = (dmg - sav[i][j].h) / reg[i] + sav[i][j].t + 1;
				t = min(t, sav[i][j + 1].t);
				rec.emplace_back(sav[i][j].t, t);
				dct.push_back(sav[i][j].t);
				dct.push_back(t - 1);
				dct.push_back(t);
			}
		}
	}
	sort(dct.begin(), dct.end());
	sz = unique(dct.begin(), dct.end()) - dct.begin();
	for (int i = 0; i < sz; i++) _hash.insert(make_pair(dct[i], i + 1));
	sz2 = (int)rec.size();
	memset(cnt, 0, sizeof(cnt));
	for (int i = 0; i < sz2; i++){
		cnt[_hash[rec[i].first]]++;
		cnt[_hash[rec[i].second]]--;
	}
	for (int i = 2; i <= sz; i++) cnt[i] += cnt[i - 1];
	ans = 0;
	for (int i = 1; i <= sz; i++){
		t = dct[i - 1];
		ans = max(ans, 1LL * cnt[i] * (bty + 1LL * t * inc));
	}
	printf("%I64d\n", ans);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

struct Node{
	int t, h;
};

typedef pair <int, int> P;

const int N = 1e5 + 10;
const int INF = 2e9;

vector <Node> sav[N];
vector <P> rec;
vector <int> dct;
map <int, int> _hash;
int maxh[N], reg[N], cnt[N << 2];

bool cmp(const Node& p, const Node& q){
	return p.t < q.t;
}

int main(){
	int n, m, bty, inc, dmg, t, id, h, sz, sz2;
	long long ans;
	scanf("%d %d",&n,&m);
	scanf("%d %d %d",&bty,&inc,&dmg);
	for (int i = 1; i <= n; i++){
		scanf("%d %d %d",&maxh[i],&h,&reg[i]);
		sav[i].push_back({0, h});
	}
	for (int i = 1; i <= m; i++){
		scanf("%d %d %d",&t,&id,&h);
		sav[id].push_back({t, h});
	}
	for (int i = 1; i <= n; i++){
		sort(sav[i].begin(), sav[i].end(), cmp);
		sz = (int)sav[i].size();
		if (inc > 0 && ((maxh[i] <= dmg) || (reg[i] == 0 && sav[i][sz - 1].h <= dmg))){
			printf("-1\n");
			return 0;
		}
		sav[i].push_back({INF, 0});
		for (int j = 0; j < sz; j++){
			if (sav[i][j].h > dmg) continue;
			if (reg[i] == 0 || maxh[i] <= dmg){
				rec.emplace_back(sav[i][j].t, sav[i][j + 1].t);
				dct.push_back(sav[i][j].t);
				dct.push_back(sav[i][j + 1].t - 1);
				dct.push_back(sav[i][j + 1].t);
			}
			else{
				t = (dmg - sav[i][j].h) / reg[i] + sav[i][j].t + 1;
				t = min(t, sav[i][j + 1].t);
				rec.emplace_back(sav[i][j].t, t);
				dct.push_back(sav[i][j].t);
				dct.push_back(t - 1);
				dct.push_back(t);
			}
		}
	}
	sort(dct.begin(), dct.end());
	sz = unique(dct.begin(), dct.end()) - dct.begin();
	for (int i = 0; i < sz; i++) _hash.insert(make_pair(dct[i], i + 1));
	sz2 = (int)rec.size();
	memset(cnt, 0, sizeof(cnt));
	for (int i = 0; i < sz2; i++){
		cnt[_hash[rec[i].first]]++;
		cnt[_hash[rec[i].second]]--;
	}
	for (int i = 2; i <= sz; i++) cnt[i] += cnt[i - 1];
	ans = 0;
	for (int i = 1; i <= sz; i++){
		t = dct[i - 1];
		ans = max(ans, 1LL * cnt[i] * (bty + 1LL * t * inc));
	}
	printf("%I64d\n", ans);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<vector>
using namespace std;
int n,m,b,k,d,rx[2000010],h[100010],r[100010];
struct node{int t,x;}a[2000010];
vector<node>e[100010];
inline bool cmp(node a,node b){return a.t<b.t;}
int main()
{
  cin>>n>>m;
  cin>>b>>k>>d;
  for(int i=1,x;i<=n;i++)
  {
    scanf("%d%d%d",&h[i],&x,&r[i]),e[i].push_back((node){0,x});
    if(h[i]<=d && m!=0){cout<<-1<<endl; return 0;}
  }
  for(int i=1,x,t,y;i<=m;i++)
    scanf("%d%d%d",&t,&x,&y),e[x].push_back((node){t,y});
  int tot=0;
  for(int w=1;w<=n;w++)
  {
    sort(e[w].begin(),e[w].end(),cmp);
    for(int i=0,s=0;i<e[w].size();i++)
    {
      if(e[w][i].x<=d) a[++tot]=(node){e[w][i].t,1-s},s=1;
      else a[++tot]=(node){e[w][i].t,0-s},s=0;
	  if(h[w]>d && e[w][i].x<=d && r[w]!=0)
	  {
	    int out=(int)ceil(1.0*(d+1-e[w][i].x)/r[w])+e[w][i].t;
	    if(i==e[w].size()-1 || out<e[w][i+1].t) a[++tot]=(node){out,0-s},s=0;
	  }
	}
  }
  sort(a+1,a+tot+1,cmp);
  int cnt=0;
  for(int i=1;i<=tot;i++) rx[++cnt]=a[i].t,rx[++cnt]=a[i].t-1;
  sort(rx+1,rx+cnt+1);
  cnt=unique(rx+1,rx+cnt+1)-rx-1;
  int X=0;
  long long ans=0;
  for(int i=1,j=1;i<=cnt;i++)
  {
  	while(j<=cnt && a[j].t<=rx[i]){X+=a[j].x; j++;}
	ans=max(ans,1ll*(b+1ll*k*rx[i])*X);
  }
  cout<<ans<<endl;
  return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<vector>
using namespace std;
int n,m,b,k,d,rx[2000010],h[100010],r[100010];
struct node{int t,x;}a[2000010];
vector<node>e[100010];
inline bool cmp(node a,node b){return a.t<b.t;}
int main()
{
  cin>>n>>m;
  cin>>b>>k>>d;
  for(int i=1,x;i<=n;i++)
  {
    scanf("%d%d%d",&h[i],&x,&r[i]),e[i].push_back((node){0,x});
    if(h[i]<=d){cout<<-1<<endl; return 0;}
  }
  for(int i=1,x,t,y;i<=m;i++)
    scanf("%d%d%d",&t,&x,&y),e[x].push_back((node){t,y});
  int tot=0;
  for(int w=1;w<=n;w++)
  {
    sort(e[w].begin(),e[w].end(),cmp);
    for(int i=0,s=0;i<e[w].size();i++)
    {
      if(e[w][i].x<=d) a[++tot]=(node){e[w][i].t,1-s},s=1;
      else a[++tot]=(node){e[w][i].t,0-s},s=0;
	  if(h[w]>d && e[w][i].x<=d && r[w]!=0)
	  {
	    int out=(int)ceil(1.0*(d+1-e[w][i].x)/r[w])+e[w][i].t;
	    if(i==e[w].size()-1 || out<e[w][i+1].t) a[++tot]=(node){out,0-s},s=0;
	  }
	}
  }
  sort(a+1,a+tot+1,cmp);
  int cnt=0;
  for(int i=1;i<=tot;i++) rx[++cnt]=a[i].t,rx[++cnt]=a[i].t-1;
  sort(rx+1,rx+cnt+1);
  cnt=unique(rx+1,rx+cnt+1)-rx-1;
  int X=0;
  long long ans=0;
  for(int i=1,j=1;i<=cnt;i++)
  {
  	while(j<=cnt && a[j].t<=rx[i]){X+=a[j].x; j++;}
	ans=max(ans,1ll*(b+1ll*k*rx[i])*X);
  }
  cout<<ans<<endl;
  return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<vector>
using namespace std;
int n,m,b,k,d,rx[2000010],h[100010],r[100010];
struct node{int t,x;}a[2000010];
vector<node>e[100010];
inline bool cmp(node a,node b){return a.t<b.t;}
int main()
{
  cin>>n>>m;
  cin>>b>>k>>d;
  for(int i=1,x;i<=n;i++)
    scanf("%d%d%d",&h[i],&x,&r[i]),e[i].push_back((node){0,x});
  for(int i=1,x,t,y;i<=m;i++)
    scanf("%d%d%d",&t,&x,&y),e[x].push_back((node){t,y});
  int tot=0;
  for(int w=1;w<=n;w++)
  {
    sort(e[w].begin(),e[w].end(),cmp);
    if( k!=0 && ((r[w]==0  && e[w][e[w].size()-1].x<=d) || h[w]<=d)){printf("-1\n"); return 0;}
    for(int i=0,s=0;i<e[w].size();i++)
    {
      if(e[w][i].x<=d) a[++tot]=(node){e[w][i].t,1-s},s=1;
      else a[++tot]=(node){e[w][i].t,0-s},s=0;
	  if(h[w]>d && e[w][i].x<=d && r[w]!=0)
	  {
	    int out=(int)ceil(1.0*(d+1-e[w][i].x)/r[w])+e[w][i].t;
	    if(i==e[w].size()-1 || out<e[w][i+1].t) a[++tot]=(node){out,0-s},s=0;
	  }
    }
  }
  sort(a+1,a+tot+1,cmp);
  int cnt=0;
  for(int i=1;i<=tot;i++) rx[++cnt]=a[i].t,rx[++cnt]=a[i].t-1;
  sort(rx+1,rx+cnt+1);
  cnt=unique(rx+1,rx+cnt+1)-rx-1;
  int X=0;
  long long ans=0;
  for(int i=1,j=1;i<=cnt;i++)
  {
  	while(j<=cnt && a[j].t<=rx[i]){X+=a[j].x; j++;}
	ans=max(ans,1ll*(b+1ll*k*rx[i])*X);
  }
  cout<<ans<<endl;
  return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<vector>
using namespace std;
int n,m,b,k,d,rx[2000010],h[100010],r[100010];
struct node{int t,x;}a[2000010];
vector<node>e[100010];
inline bool cmp(node a,node b){return a.t<b.t;}
int main()
{
  cin>>n>>m;
  cin>>b>>k>>d;
  for(int i=1,x;i<=n;i++)
    scanf("%d%d%d",&h[i],&x,&r[i]),e[i].push_back((node){0,x});
  for(int i=1,x,t,y;i<=m;i++)
    scanf("%d%d%d",&t,&x,&y),e[x].push_back((node){t,y});
  int tot=0;
  for(int w=1;w<=n;w++)
  {
    sort(e[w].begin(),e[w].end(),cmp);
    if(k!=0 && ((r[w]==0  && e[w][e[w].size()-1].x<=d) || h[w]<=d)){printf("-1\n"); return 0;}
    for(int i=0,s=0;i<e[w].size();i++)
    {
      if(e[w][i].x<=d) a[++tot]=(node){e[w][i].t,1-s},s=1;
	  else a[++tot]=(node){e[w][i].t,0-s},s=0;
	  if(h[w]>d && e[w][i].x<=d && r[w]!=0)
	  {
	    int out=(int)ceil(1.0*(d+1-e[w][i].x)/r[w])+e[w][i].t;
	    if(i==e[w].size()-1 || out<e[w][i+1].t) a[++tot]=(node){out,0-s},s=0;
	  }
    }
  }
  sort(a+1,a+tot+1,cmp);
  int cnt=0;
  for(int i=1;i<=tot;i++) rx[++cnt]=a[i].t,rx[++cnt]=a[i].t-1;
  sort(rx+1,rx+cnt+1);
  cnt=unique(rx+1,rx+cnt+1)-rx-1;
  int X=0;
  long long ans=0;
  for(int i=1,j=1;i<=cnt;i++)
  {
  	while(j<=tot && a[j].t<=rx[i]){X+=a[j].x; j++;}
	ans=max(ans,1ll*(b+1ll*k*rx[i])*X);
  }
  cout<<ans<<endl;
  return 0;
}


#include <cstdio>
#include <algorithm>

using namespace std;

const int Nmax = 1e5 + 5;

struct Node {
    int mh, re, t, nh;
};

struct Sta {
    int t, cnt;
};

bool operator < (const Sta &lhs, const Sta &rhs) {
    return lhs.t < rhs.t || (lhs.t == rhs.t && lhs.cnt < rhs.cnt);
}

struct Change {
    int id, t, nh;
};

bool operator < (const Change &lhs, const Change &rhs) {
    return lhs.t < rhs.t;
}

inline long long max(long long t1, long long t2) {
    return t1 > t2 ? t1 : t2;
}

int main() {
    Node data[Nmax];
    int n, m;
    scanf("%d%d", &n, &m);
    int base, inc, dam, cnt = 0;
    scanf("%d%d%d", &base, &inc, &dam);
    for(int i = 0; i < n; i++) {
        scanf("%d%d%d", &data[i].mh, &data[i].nh, &data[i].re);
        if(inc > 0 && (data[i].mh <= dam || (data[i].nh <= dam && data[i].re == 0))) {
            printf("-1\n");
            return 0;
        }
        if(data[i].nh <= dam) cnt++;
    }
    Change change[Nmax];
    for(int i = 0; i < m; i++) {
        scanf("%d%d%d", &change[i].t, &change[i].id, &change[i].nh);
        change[i].id--;
    }
    sort(change, change + m);
    Sta time[Nmax << 1];
    int tCnt = 0;
    for(int i = 0; i < m; i++) {
        int id = change[i].id, t = change[i].t, nh = change[i].nh;
        if(data[id].nh <= dam) {
            if(data[id].re * (t - data[id].t) + data[id].nh > dam) {
                time[tCnt].t = (dam - data[id].nh) / data[id].re + 1;
                time[tCnt++].cnt = -1;
                if(nh <= dam) {
                    time[tCnt].t = t;
                    time[tCnt++].cnt = 1;
                }
            }
            else if(nh > dam) {
                time[tCnt].t = t;
                time[tCnt++].cnt = -1;
            }
        }
        else if(nh <= dam) {
            time[tCnt].t = t;
            time[tCnt++].cnt = 1;
        }
        data[id].t = t;
        data[id].nh = nh;
    }
    for(int i = 0; i < n; i++) {
        if(data[i].nh <= dam && data[i].re > 0) {
            time[tCnt].t = (dam - data[i].nh) / data[i].re + data[i].t + 1;
            time[tCnt++].cnt = -1;
        }
    }
    sort(time, time + tCnt);
    long long ans = 0;
    for(int i = 0; i < tCnt; i++) {
        if(time[i].cnt == -1)
            ans = max(ans, (long long)cnt * (inc * (long long)(time[i].t - 1) + base));
        cnt += time[i].cnt;
    }
    printf("%I64d\n", ans);
    return 0;
}


#include <cstdio>
#include <algorithm>

using namespace std;

const int Nmax = 1e5 + 5;

struct Node {
    int mh, re, t, nh;
};

struct Sta {
    int t, cnt;
};

bool operator < (const Sta &lhs, const Sta &rhs) {
    return lhs.t < rhs.t || (lhs.t == rhs.t && lhs.cnt < rhs.cnt);
}

struct Change {
    int id, t, nh;
};

bool operator < (const Change &lhs, const Change &rhs) {
    return lhs.t < rhs.t;
}

inline long long max(long long t1, long long t2) {
    return t1 > t2 ? t1 : t2;
}

int main() {
    Node data[Nmax];
    int n, m;
    scanf("%d%d", &n, &m);
    int base, inc, dam, cnt = 0;
    scanf("%d%d%d", &base, &inc, &dam);
    for(int i = 0; i < n; i++) {
        scanf("%d%d%d", &data[i].mh, &data[i].nh, &data[i].re);
        if(inc > 0 && (data[i].mh <= dam || (data[i].nh <= dam && data[i].re == 0))) {
            printf("-1\n");
            return 0;
        }
        data[i].t = 0;
        if(data[i].nh <= dam) cnt++;
    }
    Change change[Nmax];
    for(int i = 0; i < m; i++) {
        scanf("%d%d%d", &change[i].t, &change[i].id, &change[i].nh);
        change[i].id--;
    }
    sort(change, change + m);
    Sta time[Nmax * 3];
    int tCnt = 0;
    for(int i = 0; i < m; i++) {
        int id = change[i].id, t = change[i].t, nh = change[i].nh;
        if(data[id].mh > dam) {
            if(data[id].nh <= dam) {
                if(data[id].re * (long long)(t - data[id].t) > dam - data[id].nh) {
                    time[tCnt].t = (dam - data[id].nh) / data[id].re + 1;
                    time[tCnt++].cnt = -1;
                    if(nh <= dam) {
                        time[tCnt].t = t;
                        time[tCnt++].cnt = 1;
                    }
                }
                else if(nh > dam) {
                    time[tCnt].t = t;
                    time[tCnt++].cnt = -1;
                }
            }
            else if(nh <= dam) {
                time[tCnt].t = t;
                time[tCnt++].cnt = 1;
            }
            data[id].t = t;
            data[id].nh = nh;
        }
    }
    for(int i = 0; i < n; i++) {
        if(data[i].mh > dam && data[i].nh <= dam && data[i].re > 0) {
            time[tCnt].t = (dam - data[i].nh) / data[i].re + data[i].t + 1;
            time[tCnt++].cnt = -1;
        }
    }
    sort(time, time + tCnt);
    long long ans = 0;
    for(int i = 0; i < tCnt; i++) {
        if(time[i].cnt == -1)
            ans = max(ans, cnt * ((long long)inc * (long long)(time[i].t - 1) + (long long)base));
        cnt += time[i].cnt;
    }
    printf("%I64d\n", ans);
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

typedef pair<int, int> Pair;

struct Node {
    int mh, re, nh, t;
};

bool operator < (const Pair &lhs, const Pair &rhs) {
    return lhs.first < rhs.first || (lhs.first == rhs.first && lhs.second < rhs.second);
}

struct Time {
    int t, id, nh;
};

bool operator < (const Time &lhs, const Time &rhs) {
    return lhs.t < rhs.t;
}

inline long long max(long long t1, long long t2) {
    return t1 > t2 ? t1 : t2;
}

inline int min(int t1, int t2) {
    return t1 < t2 ? t1 : t2;
}

int main() {
    int n, m;
    cin >> n >> m;
    int base, inc, dam;
    cin >> base >> inc >> dam;
    vector<Node> data(n);
    bool flag = false;
    for(int i = 0; i < n; i++) {
        Node &temp = data[i];
        cin >> temp.mh >> temp.nh >> temp.re;
        if(!flag) flag = temp.mh <= dam || (temp.re == 0 && temp.nh <= dam && inc > 0);
        temp.t = 0;
    }
    vector<Time> time(m);
    for(int i = 0; i < m; i++) {
        Time &temp = time[i];
        cin >> temp.t >> temp.id >> temp.nh;
        --temp.id;
    }
    if(flag) {
        cout << -1 << endl;
        return 0;
    }
    sort(time.begin(), time.end());
    vector<Pair> resultTime;
    int cnt = 0;
    for(int i = 0; i < n; i++)
        if(data[i].nh <= dam) cnt++;
    for(int i = 0; i < m; i++) {
        Node &now = data[time[i].id];
        if(now.nh <= dam) {
            if(now.re > 0 && now.nh + now.re * (time[i].t - now.t) > dam)
                resultTime.push_back(Pair((dam - now.nh) / now.re + now.t, -1));
            else if(time[i].nh > dam)
                resultTime.push_back(Pair(time[i].t - 1, -1));
        }
        now.nh = time[i].nh;
        now.t = time[i].t;
        if(now.nh <= dam) resultTime.push_back(Pair(now.t, 1));
    }
    for(int i = 0; i < n; i++) {
        Node &now = data[i];
        if(dam >= now.nh && now.re > 0)
            resultTime.push_back(Pair((dam - now.nh) / now.re + now.t, -1));
    }
    sort(resultTime.begin(), resultTime.end());
    long long ans = 0;
    for(int i = 0; i < (int)resultTime.size(); i++) {
        Pair &now = resultTime[i];
        if(cnt > 0 && now.second < 0)
            ans = max(ans, (now.first * inc + base) * cnt);
        cnt += now.second;
    }
    cout << ans << endl;
    return 0;
}


#include <cstdio>
#include <algorithm>

using namespace std;

const int Nmax = 1e5 + 5;

struct Node {
    int mh, re, t, nh;
};

struct Sta {
    int t, cnt;
};

bool operator < (const Sta &lhs, const Sta &rhs) {
    return lhs.t < rhs.t || (lhs.t == rhs.t && lhs.cnt < rhs.cnt);
}

struct Change {
    int id, t, nh;
};

bool operator < (const Change &lhs, const Change &rhs) {
    return lhs.t < rhs.t;
}

inline long long max(long long t1, long long t2) {
    return t1 > t2 ? t1 : t2;
}

Sta myTime[Nmax * 3];
Node data[Nmax];
Change change[Nmax];

int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    int base, inc, dam, cnt = 0;
    scanf("%d%d%d", &base, &inc, &dam);
    for(int i = 0; i < n; i++) {
        scanf("%d%d%d", &data[i].mh, &data[i].nh, &data[i].re);
        if(inc > 0 && (data[i].mh <= dam || (data[i].nh <= dam && data[i].re == 0))) {
            printf("-1\n");
            return 0;
        }
        data[i].t = 0;
        if(data[i].nh <= dam) cnt++;
    }
    for(int i = 0; i < m; i++) {
        scanf("%d%d%d", &change[i].t, &change[i].id, &change[i].nh);
        change[i].id--;
    }
    sort(change, change + m);
    int tCnt = 0;
    for(int i = 0; i < m; i++) {
        int id = change[i].id, t = change[i].t, nh = change[i].nh;
        if(data[id].mh > dam) {
            if(data[id].nh <= dam) {
                if(data[id].re * (long long)(t - data[id].t) > dam - data[id].nh) {
                    myTime[tCnt].t = (dam - data[id].nh) / data[id].re + data[id].t + 1;
                    myTime[tCnt++].cnt = -1;
                    if(nh <= dam) {
                        myTime[tCnt].t = t;
                        myTime[tCnt++].cnt = 1;
                    }
                }
                else if(nh > dam) {
                    myTime[tCnt].t = t;
                    myTime[tCnt++].cnt = -1;
                }
            }
            else if(nh <= dam) {
                myTime[tCnt].t = t;
                myTime[tCnt++].cnt = 1;
            }
            data[id].t = t;
            data[id].nh = nh;
        }
    }
    for(int i = 0; i < n; i++) {
        if(data[i].mh > dam && data[i].nh <= dam && data[i].re > 0) {
            myTime[tCnt].t = (dam - data[i].nh) / data[i].re + data[i].t + 1;
            myTime[tCnt++].cnt = -1;
        }
    }
    sort(myTime, myTime + tCnt);
    long long ans = 0;
    for(int i = 0; i < tCnt; i++) {
        if(myTime[i].cnt == -1)
            ans = max(ans, cnt * ((long long)inc * (long long)(myTime[i].t - 1) + base));
        cnt += myTime[i].cnt;
    }
    printf("%I64d\n", ans);
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

typedef pair<int, int> Pair;

struct Node {
    int mh, re, nh, t;
};

bool operator < (const Pair &lhs, const Pair &rhs) {
    return lhs.first < rhs.first || (lhs.first == rhs.first && lhs.second < rhs.second);
}

struct Time {
    int t, id, nh;
};

bool operator < (const Time &lhs, const Time &rhs) {
    return lhs.t < rhs.t;
}

inline long long max(long long t1, long long t2) {
    return t1 > t2 ? t1 : t2;
}

int main() {
    int n, m;
    cin >> n >> m;
    int base, inc, dam;
    cin >> base >> inc >> dam;
    vector<Node> data(n);
    bool flag = false;
    for(int i = 0; i < n; i++) {
        Node &temp = data[i];
        cin >> temp.mh >> temp.nh >> temp.re;
        if(!flag) flag = temp.mh <= dam || (temp.re == 0 && temp.nh <= dam && inc > 0);
        temp.t = 0;
    }
    vector<Time> time(m);
    for(int i = 0; i < m; i++) {
        Time &temp = time[i];
        cin >> temp.t >> temp.id >> temp.nh;
        --temp.id;
    }
    if(flag) {
        cout << -1 << endl;
        return 0;
    }
    sort(time.begin(), time.end());
    vector<Pair> resultTime;
    int cnt = 0;
    for(int i = 0; i < n; i++)
        if(data[i].nh <= dam) cnt++;
    for(int i = 0; i < m; i++) {
        Node &now = data[time[i].id];
        if(now.nh <= dam && now.re > 0 && now.nh + now.re * (time[i].t - now.t) > dam)
            resultTime.push_back(Pair((dam - now.nh) / now.re + now.t, -1));
        now.nh = time[i].nh;
        now.t = time[i].t;
        if(now.nh <= dam) resultTime.push_back(Pair(now.t, 1));
    }
    for(int i = 0; i < n; i++) {
        Node &now = data[i];
        if(dam >= now.nh && now.re > 0)
            resultTime.push_back(Pair((dam - now.nh) / now.re + now.t, -1));
    }
    sort(resultTime.begin(), resultTime.end());
    long long ans = 0;
    for(int i = 0; i < (int)resultTime.size(); i++) {
        Pair &now = resultTime[i];
        if(cnt > 0 && now.second < 0)
            ans = max(ans, (now.first * inc + base) * cnt);
        cnt += now.second;
    }
    cout << ans << endl;
    return 0;
}


#include <cstdio>
#include <algorithm>

using namespace std;

const int Nmax = 1e5 + 5;

struct Node {
    int mh, re, t, nh;
};

struct Sta {
    int t, cnt;
};

bool operator < (const Sta &lhs, const Sta &rhs) {
    return lhs.t < rhs.t || (lhs.t == rhs.t && lhs.cnt < rhs.cnt);
}

struct Change {
    int id, t, nh;
};

bool operator < (const Change &lhs, const Change &rhs) {
    return lhs.t < rhs.t;
}

inline long long max(long long t1, long long t2) {
    return t1 > t2 ? t1 : t2;
}

Sta myTime[Nmax * 3];
Node data[Nmax];
Change change[Nmax];

int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    int base, inc, dam, cnt = 0;
    scanf("%d%d%d", &base, &inc, &dam);
    for(int i = 0; i < n; i++) {
        scanf("%d%d%d", &data[i].mh, &data[i].nh, &data[i].re);
        if(inc > 0 && (data[i].mh <= dam || (data[i].nh <= dam && data[i].re == 0))) {
            printf("-1\n");
            return 0;
        }
        data[i].t = 0;
        if(data[i].nh <= dam) cnt++;
    }
    for(int i = 0; i < m; i++) {
        scanf("%d%d%d", &change[i].t, &change[i].id, &change[i].nh);
        change[i].id--;
    }
    sort(change, change + m);
    int tCnt = 0;
    for(int i = 0; i < m; i++) {
        int id = change[i].id, t = change[i].t, nh = change[i].nh;
        if(data[id].mh > dam) {
            if(data[id].nh <= dam) {
                if(data[id].re * (long long)(t - data[id].t) > dam - data[id].nh) {
                    myTime[tCnt].t = (dam - data[id].nh) / data[id].re + data[id].t + 1;
                    myTime[tCnt++].cnt = -1;
                    if(nh <= dam) {
                        myTime[tCnt].t = t;
                        myTime[tCnt++].cnt = 1;
                    }
                }
                else if(nh > dam) {
                    myTime[tCnt].t = t;
                    myTime[tCnt++].cnt = -1;
                }
            }
            else if(nh <= dam) {
                myTime[tCnt].t = t;
                myTime[tCnt++].cnt = 1;
            }
            data[id].t = t;
            data[id].nh = nh;
        }
    }
    for(int i = 0; i < n; i++) {
        if(data[i].mh >= dam && data[i].nh <= dam && data[i].re > 0) {
            myTime[tCnt].t = (dam - data[i].nh) / data[i].re + data[i].t + 1;
            myTime[tCnt++].cnt = -1;
        }
        else if(data[i].nh == dam) {
            myTime[tCnt].t = data[i].t + 1;
            myTime[tCnt++].cnt = -1;
        }
    }
    sort(myTime, myTime + tCnt);
    long long ans = 0;
    for(int i = 0; i < tCnt; i++) {
        if(myTime[i].cnt == -1)
            ans = max(ans, cnt * ((long long)inc * (long long)(myTime[i].t - 1) + base));
        cnt += myTime[i].cnt;
    }
    printf("%I64d\n", ans);
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

typedef pair<int, int> Pair;

struct Node {
    int mh, re, nh, t;
};

bool operator < (const Pair &lhs, const Pair &rhs) {
    return lhs.first < rhs.first || (lhs.first == rhs.first && lhs.second < rhs.second);
}

struct Time {
    int t, id, nh;
};

bool operator < (const Time &lhs, const Time &rhs) {
    return lhs.t < rhs.t;
}

inline long long max(long long t1, long long t2) {
    return t1 > t2 ? t1 : t2;
}

int main() {
    int n, m;
    cin >> n >> m;
    int base, inc, dam;
    cin >> base >> inc >> dam;
    vector<Node> data(n);
    bool flag = false;
    for(int i = 0; i < n; i++) {
        Node &temp = data[i];
        cin >> temp.mh >> temp.nh >> temp.re;
        if(!flag) flag = temp.mh <= dam;
        temp.t = 0;
    }
    vector<Time> time(m);
    for(int i = 0; i < m; i++) {
        Time &temp = time[i];
        cin >> temp.t >> temp.id >> temp.nh;
    }
    if(flag) {
        cout << -1 << endl;
        return 0;
    }
    sort(time.begin(), time.end());
    vector<Pair> resultTime;
    int cnt = 0;
    for(int i = 0; i < n; i++)
        if(data[i].nh <= dam) cnt++;
    for(int i = 0; i < m; i++) {
        Node &now = data[time[i].id];
        if(now.nh <= dam && now.nh + now.re * (time[i].t - now.t) > dam)
            resultTime.push_back(Pair((dam - now.nh) / now.re + 1 + now.t, -1));
        now.nh = time[i].nh;
        now.t = time[i].t;
        if(now.nh <= dam) resultTime.push_back(Pair(now.t, 1));
    }
    for(int i = 0; i < n; i++) {
        Node &now = data[i];
        if(dam >= now.nh)
            resultTime.push_back(Pair((dam - now.nh) / now.re + 1 + now.t, -1));
    }
    sort(resultTime.begin(), resultTime.end());
    long long ans = 0;
    int last = 1;
    for(int i = 0; i < (int)resultTime.size(); i++) {
        Pair &now = resultTime[i];
        if(cnt > 0)
            ans = max(ans, ((now.first - last) * inc + base) * cnt);
        cnt += now.second;
        last = now.first;
    }
    cout << ans << endl;
    return 0;
}


#include <cstdio>
#include <algorithm>

using namespace std;

const int Nmax = 1e5 + 5;

struct Node {
    int mh, re, t, nh;
};

struct Sta {
    int t, cnt;
};

bool operator < (const Sta &lhs, const Sta &rhs) {
    return lhs.t < rhs.t || (lhs.t == rhs.t && lhs.cnt < rhs.cnt);
}

struct Change {
    int id, t, nh;
};

bool operator < (const Change &lhs, const Change &rhs) {
    return lhs.t < rhs.t;
}

inline long long max(long long t1, long long t2) {
    return t1 > t2 ? t1 : t2;
}

Sta myTime[Nmax * 3];
Node data[Nmax];
Change change[Nmax];

int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    int base, inc, dam, cnt = 0;
    scanf("%d%d%d", &base, &inc, &dam);
    for(int i = 0; i < n; i++) {
        scanf("%d%d%d", &data[i].mh, &data[i].nh, &data[i].re);
        if(inc > 0 && (data[i].mh <= dam || (data[i].nh <= dam && data[i].re == 0))) {
            printf("-1\n");
            return 0;
        }
        data[i].t = 0;
        if(data[i].nh <= dam) cnt++;
    }
    for(int i = 0; i < m; i++) {
        scanf("%d%d%d", &change[i].t, &change[i].id, &change[i].nh);
        change[i].id--;
    }
    sort(change, change + m);
    int tCnt = 0;
    for(int i = 0; i < m; i++) {
        int id = change[i].id, t = change[i].t, nh = change[i].nh;
        if(data[id].mh > dam) {
            if(data[id].nh <= dam) {
                if(data[id].re * (long long)(t - data[id].t) > dam - data[id].nh) {
                    myTime[tCnt].t = (dam - data[id].nh) / data[id].re + data[id].t + 1;
                    myTime[tCnt++].cnt = -1;
                    if(nh <= dam) {
                        myTime[tCnt].t = t;
                        myTime[tCnt++].cnt = 1;
                    }
                }
                else if(nh > dam) {
                    myTime[tCnt].t = t;
                    myTime[tCnt++].cnt = -1;
                }
            }
            else if(nh <= dam) {
                myTime[tCnt].t = t;
                myTime[tCnt++].cnt = 1;
            }
            data[id].t = t;
            data[id].nh = nh;
        }
    }
    for(int i = 0; i < n; i++) {
        if(data[i].mh >= dam && data[i].nh <= dam && data[i].re > 0) {
            myTime[tCnt].t = (dam - data[i].nh) / data[i].re + data[i].t + 1;
            myTime[tCnt++].cnt = -1;
        }
    }
    sort(myTime, myTime + tCnt);
    long long ans = 0;
    for(int i = 0; i < tCnt; i++) {
        if(myTime[i].cnt == -1)
            ans = max(ans, cnt * ((long long)inc * (long long)(myTime[i].t - 1) + base));
        cnt += myTime[i].cnt;
    }
    printf("%I64d\n", ans);
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

typedef pair<int, int> Pair;

struct Node {
    int mh, re, nh, t;
};

bool operator < (const Pair &lhs, const Pair &rhs) {
    return lhs.first < rhs.first || (lhs.first == rhs.first && lhs.second < rhs.second);
}

struct Time {
    int t, id, nh;
};

bool operator < (const Time &lhs, const Time &rhs) {
    return lhs.t < rhs.t;
}

inline long long max(long long t1, long long t2) {
    return t1 > t2 ? t1 : t2;
}

int main() {
    int n, m;
    cin >> n >> m;
    int base, inc, dam;
    cin >> base >> inc >> dam;
    vector<Node> data(n);
    bool flag = false;
    for(int i = 0; i < n; i++) {
        Node &temp = data[i];
        cin >> temp.mh >> temp.nh >> temp.re;
        if(!flag) flag = temp.mh <= dam;
        temp.t = 0;
    }
    vector<Time> time(m);
    for(int i = 0; i < m; i++) {
        Time &temp = time[i];
        cin >> temp.t >> temp.id >> temp.nh;
        --temp.id;
    }
    if(flag) {
        cout << -1 << endl;
        return 0;
    }
    sort(time.begin(), time.end());
    vector<Pair> resultTime;
    int cnt = 0;
    for(int i = 0; i < n; i++)
        if(data[i].nh <= dam) cnt++;
    for(int i = 0; i < m; i++) {
        Node &now = data[time[i].id];
        if(now.nh <= dam && now.nh + now.re * (time[i].t - now.t) > dam)
            resultTime.push_back(Pair((dam - now.nh) / now.re + now.t, -1));
        now.nh = time[i].nh;
        now.t = time[i].t;
        if(now.nh <= dam) resultTime.push_back(Pair(now.t, 1));
    }
    for(int i = 0; i < n; i++) {
        Node &now = data[i];
        if(dam >= now.nh)
            resultTime.push_back(Pair((dam - now.nh) / now.re + now.t, -1));
    }
    sort(resultTime.begin(), resultTime.end());
    long long ans = 0;
    for(int i = 0; i < (int)resultTime.size(); i++) {
        Pair &now = resultTime[i];
        if(cnt > 0 && now.second < 0)
            ans = max(ans, (now.first * inc + base) * cnt);
        cnt += now.second;
    }
    cout << ans << endl;
    return 0;
}


#include <cstdio>
#include <algorithm>

using namespace std;

const int Nmax = 1e5 + 5;

struct Node {
    int mh, re, t, nh;
};

struct Sta {
    int t, cnt;
};

bool operator < (const Sta &lhs, const Sta &rhs) {
    return lhs.t < rhs.t || (lhs.t == rhs.t && lhs.cnt < rhs.cnt);
}

struct Change {
    int id, t, nh;
};

bool operator < (const Change &lhs, const Change &rhs) {
    return lhs.t < rhs.t;
}

inline long long max(long long t1, long long t2) {
    return t1 > t2 ? t1 : t2;
}

Sta myTime[Nmax * 3];
Node data[Nmax];
Change change[Nmax];

int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    int base, inc, dam, cnt = 0;
    scanf("%d%d%d", &base, &inc, &dam);
    for(int i = 0; i < n; i++) {
        scanf("%d%d%d", &data[i].mh, &data[i].nh, &data[i].re);
        if(inc > 0 && (data[i].mh <= dam || (data[i].nh <= dam && data[i].re == 0))) {
            printf("-1\n");
            return 0;
        }
        data[i].t = 0;
        if(data[i].nh <= dam) cnt++;
    }
    for(int i = 0; i < m; i++) {
        scanf("%d%d%d", &change[i].t, &change[i].id, &change[i].nh);
        change[i].id--;
    }
    sort(change, change + m);
    int tCnt = 0;
    for(int i = 0; i < m; i++) {
        int id = change[i].id, t = change[i].t, nh = change[i].nh;
        if(data[id].mh > dam) {
            if(data[id].nh <= dam) {
                if(data[id].re * (long long)(t - data[id].t) > dam - data[id].nh) {
                    myTime[tCnt].t = (dam - data[id].nh) / data[id].re + data[id].t + 1;
                    myTime[tCnt++].cnt = -1;
                    if(nh <= dam) {
                        myTime[tCnt].t = t;
                        myTime[tCnt++].cnt = 1;
                    }
                }
                else if(nh > dam) {
                    myTime[tCnt].t = t;
                    myTime[tCnt++].cnt = -1;
                }
            }
            else if(nh <= dam) {
                myTime[tCnt].t = t;
                myTime[tCnt++].cnt = 1;
            }
            data[id].t = t;
            data[id].nh = nh;
        }
    }
    for(int i = 0; i < n; i++) {
        if(data[i].mh >= dam && data[i].nh <= dam && data[i].re > 0) {
            myTime[tCnt].t = (dam - data[i].nh) / data[i].re + data[i].t + 1;
            myTime[tCnt++].cnt = -1;
        }
        else if(data[i].nh == dam) {
            myTime[tCnt].t = data[i].t + 1;
            myTime[tCnt++].cnt = -1;
        }
    }
    sort(myTime, myTime + tCnt);
    long long ans = cnt * base;
    for(int i = 0; i < tCnt; i++) {
        if(cnt > 0)
            ans = max(ans, cnt * ((long long)inc * (long long)(myTime[i].t - 1) + base));
        cnt += myTime[i].cnt;
    }
    printf("%I64d\n", ans);
    return 0;
}


#include <cstdio>
#include <algorithm>

using namespace std;

const int Nmax = 1e5 + 5;

struct Node {
    long long mh, re, t, nh;
};

struct Sta {
    long long t, cnt;
};

bool operator < (const Sta &lhs, const Sta &rhs) {
    return lhs.t < rhs.t || (lhs.t == rhs.t && lhs.cnt < rhs.cnt);
}

struct Change {
    long long id, t, nh;
};

bool operator < (const Change &lhs, const Change &rhs) {
    return lhs.t < rhs.t;
}

inline long long max(long long t1, long long t2) {
    return t1 > t2 ? t1 : t2;
}

int main() {
    Node data[Nmax];
    int n, m;
    scanf("%d%d", &n, &m);
    long long base, inc, dam, cnt = 0;
    scanf("%I64d%I64d%I64d", &base, &inc, &dam);
    for(int i = 0; i < n; i++) {
        scanf("%I64d%I64d%I64d", &data[i].mh, &data[i].nh, &data[i].re);
        if(inc > 0 && (data[i].mh <= dam || (data[i].nh <= dam && data[i].re == 0))) {
            printf("-1\n");
            return 0;
        }
        if(data[i].nh <= dam) cnt++;
    }
    Change change[Nmax];
    for(int i = 0; i < m; i++) {
        scanf("%I64d%I64d%I64d", &change[i].t, &change[i].id, &change[i].nh);
        change[i].id--;
    }
    sort(change, change + m);
    Sta time[Nmax << 1];
    int tCnt = 0;
    for(int i = 0; i < m; i++) {
        long long id = change[i].id, t = change[i].t, nh = change[i].nh;
        if(data[id].nh <= dam) {
            if(data[id].re * (t - data[id].t) + data[id].nh > dam) {
                time[tCnt].t = (dam - data[id].nh) / data[id].re + 1;
                time[tCnt++].cnt = -1;
                if(nh <= dam) {
                    time[tCnt].t = t;
                    time[tCnt++].cnt = 1;
                }
            }
            else if(nh > dam) {
                time[tCnt].t = t;
                time[tCnt++].cnt = -1;
            }
        }
        else if(nh <= dam) {
            time[tCnt].t = t;
            time[tCnt++].cnt = 1;
        }
        data[id].t = t;
        data[id].nh = nh;
    }
    for(int i = 0; i < n; i++) {
        if(data[i].nh <= dam && data[i].re > 0) {
            time[tCnt].t = (dam - data[i].nh) / data[i].re + data[i].t + 1;
            time[tCnt++].cnt = -1;
        }
    }
    sort(time, time + tCnt);
    long long ans = 0;
    for(int i = 0; i < tCnt; i++) {
        if(time[i].cnt == -1)
            ans = max(ans, cnt * (inc * (time[i].t - 1) + base));
        cnt += time[i].cnt;
    }
    printf("%I64d\n", ans);
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

typedef pair<int, int> Pair;

struct Node {
    int mh, re, nh, t;
};

bool operator < (const Pair &lhs, const Pair &rhs) {
    return lhs.first < rhs.first || (lhs.first == rhs.first && lhs.second < rhs.second);
}

struct Time {
    int t, id, nh;
};

bool operator < (const Time &lhs, const Time &rhs) {
    return lhs.t < rhs.t;
}

inline long long max(long long t1, long long t2) {
    return t1 > t2 ? t1 : t2;
}

inline int min(int t1, int t2) {
    return t1 < t2 ? t1 : t2;
}

const int Nmax = 1e5 + 5;

int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    int base, inc, dam;
    scanf("%d%d%d", &base, &inc, &dam);
    Node data[Nmax];
    bool flag = false;
    for(int i = 0; i < n; i++) {
        Node &temp = data[i];
        scanf("%d%d%d", &temp.mh, &temp.nh, &temp.re);
        if(!flag) flag = temp.mh <= dam || (temp.re == 0 && temp.nh <= dam && inc > 0);
        temp.t = 0;
    }
    Time time[Nmax];
    for(int i = 0; i < m; i++) {
        Time &temp = time[i];
        scanf("%d%d%d", &temp.t, &temp.id, &temp.nh);
        --temp.id;
    }
    if(flag) {
        printf("-1\n");
        return 0;
    }
    sort(time, time + m);
    vector<Pair> resultTime; resultTime.reserve(Nmax);
    int cnt = 0;
    for(int i = 0; i < n; i++)
        if(data[i].nh <= dam) cnt++;
    for(int i = 0; i < m; i++) {
        Node &now = data[time[i].id];
        if(now.nh <= dam && now.mh >= dam) {
            if(now.re > 0 && now.nh + now.re * (time[i].t - now.t) > dam)
                resultTime.push_back(Pair((dam - now.nh) / now.re + now.t, -1));
            else if(time[i].nh > dam)
                resultTime.push_back(Pair(time[i].t - 1, -1));
        }
        now.nh = time[i].nh;
        now.t = time[i].t;
        if(now.nh <= dam) resultTime.push_back(Pair(now.t, 1));
    }
    for(int i = 0; i < n; i++) {
        Node &now = data[i];
        if(dam >= now.nh && now.re > 0)
            resultTime.push_back(Pair((dam - now.nh) / now.re + now.t, -1));
    }
    sort(resultTime.begin(), resultTime.end());
    long long ans = 0;
    for(int i = 0; i < (int)resultTime.size(); i++) {
        Pair &now = resultTime[i];
        if(cnt > 0 && now.second < 0)
            ans = max(ans, (now.first * inc + base) * cnt);
        cnt += now.second;
    }
    printf("%I64d\n", ans);
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

typedef pair<int, int> Pair;

struct Node {
    int mh, re, nh, t;
};

bool operator < (const Pair &lhs, const Pair &rhs) {
    return lhs.first < rhs.first || (lhs.first == rhs.first && lhs.second < rhs.second);
}

struct Time {
    int t, id, nh;
};

bool operator < (const Time &lhs, const Time &rhs) {
    return lhs.t < rhs.t;
}

inline long long max(long long t1, long long t2) {
    return t1 > t2 ? t1 : t2;
}

int main() {
    int n, m;
    cin >> n >> m;
    int base, inc, dam;
    cin >> base >> inc >> dam;
    vector<Node> data(n);
    bool flag = false;
    for(int i = 0; i < n; i++) {
        Node &temp = data[i];
        cin >> temp.mh >> temp.re >> temp.nh;
        if(!flag) flag = temp.mh <= dam;
        temp.t = 0;
    }
    vector<Time> time(m);
    for(int i = 0; i < m; i++) {
        Time &temp = time[i];
        cin >> temp.t >> temp.id >> temp.nh;
    }
    if(flag) {
        cout << -1 << endl;
        return 0;
    }
    sort(time.begin(), time.end());
    vector<Pair> resultTime;
    int cnt = 0;
    for(int i = 0; i < n; i++)
        if(data[i].nh <= dam) cnt++;
    for(int i = 0; i < m; i++) {
        Node &now = data[time[i].id];
        if(now.nh <= dam && now.nh + now.re * (time[i].t - now.t) > dam)
            resultTime.push_back(Pair((dam - now.nh) / now.re + 1 + now.t, -1));
        now.nh = time[i].nh;
        now.t = time[i].t;
        if(now.nh <= dam) resultTime.push_back(Pair(now.t, 1));
    }
    for(int i = 0; i < n; i++) {
        Node &now = data[i];
        if(dam >= now.nh)
            resultTime.push_back(Pair((dam - now.nh) / now.re + 1 + now.t, -1));
    }
    sort(resultTime.begin(), resultTime.end());
    long long ans = 0;
    int last = 1;
    for(int i = 0; i < (int)resultTime.size(); i++) {
        Pair &now = resultTime[i];
        ans = max(ans, ((now.first - last) * inc + base) * cnt);
        cnt += now.second;
        last = now.first;
    }
    cout << ans << endl;
    return 0;
}


#include <cstdio>
#include <algorithm>

using namespace std;

const int Nmax = 1e5 + 5;

struct Node {
    int mh, re, t, nh;
};

struct Sta {
    int t, cnt;
};

bool operator < (const Sta &lhs, const Sta &rhs) {
    return lhs.t < rhs.t || (lhs.t == rhs.t && lhs.cnt < rhs.cnt);
}

struct Change {
    int id, t, nh;
};

bool operator < (const Change &lhs, const Change &rhs) {
    return lhs.t < rhs.t;
}

inline long long max(long long t1, long long t2) {
    return t1 > t2 ? t1 : t2;
}

int main() {
    Node data[Nmax];
    int n, m;
    scanf("%d%d", &n, &m);
    int base, inc, dam, cnt = 0;
    scanf("%d%d%d", &base, &inc, &dam);
    for(int i = 0; i < n; i++) {
        scanf("%d%d%d", &data[i].mh, &data[i].nh, &data[i].re);
        if(inc > 0 && (data[i].mh <= dam || (data[i].nh <= dam && data[i].re == 0))) {
            printf("-1\n");
            return 0;
        }
        if(data[i].nh <= dam) cnt++;
    }
    Change change[Nmax];
    for(int i = 0; i < m; i++) {
        scanf("%d%d%d", &change[i].t, &change[i].id, &change[i].nh);
        change[i].id--;
    }
    sort(change, change + m);
    Sta time[Nmax * 3];
    int tCnt = 0;
    for(int i = 0; i < m; i++) {
        int id = change[i].id, t = change[i].t, nh = change[i].nh;
        if(data[id].mh > dam) {
            if(data[id].nh <= dam) {
                if(data[id].re * (long long)(t - data[id].t) > dam - data[id].nh) {
                    time[tCnt].t = (dam - data[id].nh) / data[id].re + 1;
                    time[tCnt++].cnt = -1;
                    if(nh <= dam) {
                        time[tCnt].t = t;
                        time[tCnt++].cnt = 1;
                    }
                }
                else if(nh > dam) {
                    time[tCnt].t = t;
                    time[tCnt++].cnt = -1;
                }
            }
            else if(nh <= dam) {
                time[tCnt].t = t;
                time[tCnt++].cnt = 1;
            }
            data[id].t = t;
            data[id].nh = nh;
        }
    }
    for(int i = 0; i < n; i++) {
        if(data[i].mh > dam && data[i].nh <= dam && data[i].re > 0) {
            time[tCnt].t = (dam - data[i].nh) / data[i].re + data[i].t + 1;
            time[tCnt++].cnt = -1;
        }
    }
    sort(time, time + tCnt);
    long long ans = 0;
    for(int i = 0; i < tCnt; i++) {
        if(time[i].cnt == -1)
            ans = max(ans, cnt * ((long long)inc * (long long)(time[i].t - 1) + (long long)base));
        cnt += time[i].cnt;
    }
    printf("%I64d\n", ans);
    return 0;
}


#include <cstdio>
#include <algorithm>

using namespace std;

const int Nmax = 1e5 + 5;

struct Node {
    int mh, re, t, nh;
};

struct Sta {
    int t, cnt;
};

bool operator < (const Sta &lhs, const Sta &rhs) {
    return lhs.t < rhs.t || (lhs.t == rhs.t && lhs.cnt < rhs.cnt);
}

struct Change {
    int id, t, nh;
};

bool operator < (const Change &lhs, const Change &rhs) {
    return lhs.t < rhs.t;
}

inline long long max(long long t1, long long t2) {
    return t1 > t2 ? t1 : t2;
}

int main() {
    Node data[Nmax];
    int n, m;
    scanf("%d%d", &n, &m);
    int base, inc, dam, cnt = 0;
    scanf("%d%d%d", &base, &inc, &dam);
    for(int i = 0; i < n; i++) {
        scanf("%d%d%d", &data[i].mh, &data[i].nh, &data[i].re);
        if(inc > 0 && (data[i].mh <= dam || (data[i].nh <= dam && data[i].re == 0))) {
            printf("-1\n");
            return 0;
        }
        if(data[i].nh <= dam) cnt++;
    }
    Change change[Nmax];
    for(int i = 0; i < m; i++) {
        scanf("%d%d%d", &change[i].t, &change[i].id, &change[i].nh);
        change[i].id--;
    }
    sort(change, change + m);
    Sta time[Nmax * 3];
    int tCnt = 0;
    for(int i = 0; i < m; i++) {
        int id = change[i].id, t = change[i].t, nh = change[i].nh;
        if(data[id].nh <= dam) {
            if(data[id].re * (long long)(t - data[id].t) > dam - data[id].nh) {
                time[tCnt].t = (dam - data[id].nh) / data[id].re + 1;
                time[tCnt++].cnt = -1;
                if(nh <= dam) {
                    time[tCnt].t = t;
                    time[tCnt++].cnt = 1;
                }
            }
            else if(nh > dam) {
                time[tCnt].t = t;
                time[tCnt++].cnt = -1;
            }
        }
        else if(nh <= dam) {
            time[tCnt].t = t;
            time[tCnt++].cnt = 1;
        }
        data[id].t = t;
        data[id].nh = nh;
    }
    for(int i = 0; i < n; i++) {
        if(data[i].nh <= dam && data[i].re > 0) {
            time[tCnt].t = (dam - data[i].nh) / data[i].re + data[i].t + 1;
            time[tCnt++].cnt = -1;
        }
    }
    sort(time, time + tCnt);
    long long ans = 0;
    for(int i = 0; i < tCnt; i++) {
        if(time[i].cnt == -1)
            ans = max(ans, cnt * ((long long)inc * (long long)(time[i].t - 1) + (long long)base));
        cnt += time[i].cnt;
    }
    printf("%I64d\n", ans);
    return 0;
}


#include <cstdio>
#include <algorithm>

using namespace std;

const int Nmax = 1e5 + 5;

struct Node {
    int mh, re, t, nh;
};

struct Sta {
    int t, cnt;
};

bool operator < (const Sta &lhs, const Sta &rhs) {
    return lhs.t < rhs.t || (lhs.t == rhs.t && lhs.cnt < rhs.cnt);
}

struct Change {
    int id, t, nh;
};

bool operator < (const Change &lhs, const Change &rhs) {
    return lhs.t < rhs.t;
}

inline long long max(long long t1, long long t2) {
    return t1 > t2 ? t1 : t2;
}

int main() {
    Node data[Nmax];
    int n, m;
    scanf("%d%d", &n, &m);
    int base, inc, dam, cnt = 0;
    scanf("%d%d%d", &base, &inc, &dam);
    for(int i = 0; i < n; i++) {
        scanf("%d%d%d", &data[i].mh, &data[i].nh, &data[i].re);
        if(inc > 0 && (data[i].mh <= dam || (data[i].nh <= dam && data[i].re == 0))) {
            printf("-1\n");
            return 0;
        }
        if(data[i].nh <= dam) cnt++;
    }
    Change change[Nmax];
    for(int i = 0; i < m; i++) {
        scanf("%d%d%d", &change[i].t, &change[i].id, &change[i].nh);
        change[i].id--;
    }
    sort(change, change + m);
    Sta time[Nmax << 1];
    int tCnt = 0;
    for(int i = 0; i < m; i++) {
        int id = change[i].id, t = change[i].t, nh = change[i].nh;
        if(data[id].nh <= dam) {
            if(data[id].re * (t - data[id].t) + data[id].nh > dam) {
                time[tCnt].t = (dam - data[id].nh) / data[id].re + 1;
                time[tCnt++].cnt = -1;
                if(nh <= dam) {
                    time[tCnt].t = t;
                    time[tCnt++].cnt = 1;
                }
            }
            else if(nh > dam) {
                time[tCnt].t = t;
                time[tCnt++].cnt = -1;
            }
        }
        else if(nh <= dam) {
            time[tCnt].t = t;
            time[tCnt++].cnt = 1;
        }
        data[id].t = t;
        data[id].nh = nh;
    }
    for(int i = 0; i < n; i++) {
        if(data[i].nh <= dam && data[i].re > 0) {
            time[tCnt].t = (dam - data[i].nh) / data[i].re + data[i].t + 1;
            time[tCnt++].cnt = -1;
        }
    }
    sort(time, time + tCnt);
    long long ans = 0;
    for(int i = 0; i < tCnt; i++) {
        if(time[i].cnt == -1)
            ans = max(ans, (long long)cnt * ((long long)inc * (long long)(time[i].t - 1) + (long long)base));
        cnt += time[i].cnt;
    }
    printf("%I64d\n", ans);
    return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

const int Nmax = 1e5 + 5;

struct Node {
    int mh, re, t, nh;
};

struct Sta {
    int t, cnt;
};

bool operator < (const Sta &lhs, const Sta &rhs) {
    return lhs.t < rhs.t || (lhs.t == rhs.t && lhs.cnt < rhs.cnt);
}

struct Change {
    int id, t, nh;
};

bool operator < (const Change &lhs, const Change &rhs) {
    return lhs.t < rhs.t;
}

inline long long max(long long t1, long long t2) {
    return t1 > t2 ? t1 : t2;
}

Sta myTime[Nmax * 3];
Node data[Nmax];
Change change[Nmax];

int main() {
    int n, m;
    cin >> n >> m;
    int base, inc, dam, cnt = 0;
    cin >> base >> inc >> dam;
    for(int i = 0; i < n; i++) {
        cin >> data[i].mh >> data[i].nh >> data[i].re;
        if(inc > 0 && (data[i].mh <= dam || (data[i].nh <= dam && data[i].re == 0))) {
            cout << -1 << endl;
            return 0;
        }
        data[i].t = 0;
        if(data[i].nh <= dam) cnt++;
    }
    for(int i = 0; i < m; i++) {
        cin >> change[i].t >> change[i].id >> change[i].nh;
        change[i].id--;
    }
    sort(change, change + m);
    int tCnt = 0;
    for(int i = 0; i < m; i++) {
        int id = change[i].id, t = change[i].t, nh = change[i].nh;
        if(data[id].mh > dam) {
            if(data[id].nh <= dam) {
                if(data[id].re * (long long)(t - data[id].t) > dam - data[id].nh) {
                    myTime[tCnt].t = (dam - data[id].nh) / data[id].re + data[id].t + 1;
                    myTime[tCnt++].cnt = -1;
                    if(nh <= dam) {
                        myTime[tCnt].t = t;
                        myTime[tCnt++].cnt = 1;
                    }
                }
                else if(nh > dam) {
                    myTime[tCnt].t = t;
                    myTime[tCnt++].cnt = -1;
                }
            }
            else if(nh <= dam) {
                myTime[tCnt].t = t;
                myTime[tCnt++].cnt = 1;
            }
            data[id].t = t;
            data[id].nh = nh;
        }
    }
    for(int i = 0; i < n; i++) {
        if(data[i].mh >= dam && data[i].nh <= dam && data[i].re > 0) {
            myTime[tCnt].t = (dam - data[i].nh) / data[i].re + data[i].t + 1;
            myTime[tCnt++].cnt = -1;
        }
        else if(data[i].nh == dam) {
            myTime[tCnt].t = data[i].t + 1;
            myTime[tCnt++].cnt = -1;
        }
    }
    sort(myTime, myTime + tCnt);
    long long ans = cnt * base;
    for(int i = 0; i < tCnt; i++) {
        if(cnt > 0)
            ans = max(ans, cnt * ((long long)inc * (long long)(myTime[i].t - 1) + base));
        cnt += myTime[i].cnt;
    }
    cout << ans << endl;
    return 0;
}


#include <cstdio>
#include <algorithm>

using namespace std;

const int Nmax = 1e5 + 5;

struct Node {
    int mh, re, t, nh;
};

struct Sta {
    int t, cnt;
};

bool operator < (const Sta &lhs, const Sta &rhs) {
    return lhs.t < rhs.t || (lhs.t == rhs.t && lhs.cnt < rhs.cnt);
}

struct Change {
    int id, t, nh;
};

bool operator < (const Change &lhs, const Change &rhs) {
    return lhs.t < rhs.t;
}

inline long long max(long long t1, long long t2) {
    return t1 > t2 ? t1 : t2;
}

int main() {
    Node data[Nmax];
    int n, m;
    scanf("%d%d", &n, &m);
    int base, inc, dam, cnt = 0;
    scanf("%d%d%d", &base, &inc, &dam);
    for(int i = 0; i < n; i++) {
        scanf("%d%d%d", &data[i].mh, &data[i].nh, &data[i].re);
        if(inc > 0 && (data[i].mh <= dam || (data[i].nh <= dam && data[i].re == 0))) {
            printf("-1\n");
            return 0;
        }
        if(data[i].nh <= dam) cnt++;
    }
    Change change[Nmax];
    for(int i = 0; i < m; i++) {
        scanf("%d%d%d", &change[i].t, &change[i].id, &change[i].nh);
        change[i].id--;
    }
    sort(change, change + m);
    Sta time[Nmax << 1];
    int tCnt = 0;
    for(int i = 0; i < m; i++) {
        int id = change[i].id, t = change[i].t, nh = change[i].nh;
        if(data[id].nh <= dam) {
            if(data[id].re * (t - data[id].t) + data[id].nh > dam) {
                time[tCnt].t = (dam - data[id].nh) / data[id].re + 1;
                time[tCnt++].cnt = -1;
                if(nh <= dam) {
                    time[tCnt].t = t;
                    time[tCnt++].cnt = 1;
                }
            }
            else if(nh > dam) {
                time[tCnt].t = t;
                time[tCnt++].cnt = -1;
            }
        }
        else if(nh <= dam) {
            time[tCnt].t = t;
            time[tCnt++].cnt = 1;
        }
        data[id].t = t;
        data[id].nh = nh;
    }
    for(int i = 0; i < n; i++) {
        if(data[i].nh <= dam && data[i].re > 0) {
            time[tCnt].t = (dam - data[i].nh) / data[i].re + data[i].t + 1;
            time[tCnt++].cnt = -1;
        }
    }
    sort(time, time + tCnt);
    long long ans = 0;
    for(int i = 0; i < tCnt; i++) {
        if(time[i].cnt == -1)
            ans = max(ans, cnt * (inc * (time[i].t - 1) + base));
        cnt += time[i].cnt;
    }
    printf("%I64d\n", ans);
    return 0;
}


#include <cstdio>
#include <algorithm>

using namespace std;

const int Nmax = 1e5 + 5;

struct Node {
    int mh, re, t, nh;
};

struct Sta {
    int t, cnt;
};

bool operator < (const Sta &lhs, const Sta &rhs) {
    return lhs.t < rhs.t || (lhs.t == rhs.t && lhs.cnt < rhs.cnt);
}

struct Change {
    int id, t, nh;
};

bool operator < (const Change &lhs, const Change &rhs) {
    return lhs.t < rhs.t;
}

inline long long max(long long t1, long long t2) {
    return t1 > t2 ? t1 : t2;
}

Sta myTime[Nmax * 3];
Node data[Nmax];
Change change[Nmax];

int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    int base, inc, dam, cnt = 0;
    scanf("%d%d%d", &base, &inc, &dam);
    for(int i = 0; i < n; i++) {
        scanf("%d%d%d", &data[i].mh, &data[i].nh, &data[i].re);
        if(inc > 0 && (data[i].mh <= dam || (data[i].nh <= dam && data[i].re == 0))) {
            printf("-1\n");
            return 0;
        }
        data[i].t = 0;
        if(data[i].nh <= dam) cnt++;
    }
    for(int i = 0; i < m; i++) {
        scanf("%d%d%d", &change[i].t, &change[i].id, &change[i].nh);
        change[i].id--;
    }
    sort(change, change + m);
    int tCnt = 0;
    for(int i = 0; i < m; i++) {
        int id = change[i].id, t = change[i].t, nh = change[i].nh;
        if(data[id].mh > dam) {
            if(data[id].nh <= dam) {
                if(data[id].re * (long long)(t - data[id].t) > dam - data[id].nh) {
                    myTime[tCnt].t = (dam - data[id].nh) / data[id].re + 1;
                    myTime[tCnt++].cnt = -1;
                    if(nh <= dam) {
                        myTime[tCnt].t = t;
                        myTime[tCnt++].cnt = 1;
                    }
                }
                else if(nh > dam) {
                    myTime[tCnt].t = t;
                    myTime[tCnt++].cnt = -1;
                }
            }
            else if(nh <= dam) {
                myTime[tCnt].t = t;
                myTime[tCnt++].cnt = 1;
            }
            data[id].t = t;
            data[id].nh = nh;
        }
    }
    for(int i = 0; i < n; i++) {
        if(data[i].mh > dam && data[i].nh <= dam && data[i].re > 0) {
            myTime[tCnt].t = (dam - data[i].nh) / data[i].re + data[i].t + 1;
            myTime[tCnt++].cnt = -1;
        }
    }
    sort(myTime, myTime + tCnt);
    long long ans = 0;
    for(int i = 0; i < tCnt; i++) {
        if(myTime[i].cnt == -1)
            ans = max(ans, cnt * ((long long)inc * (long long)(myTime[i].t - 1) + base));
        cnt += myTime[i].cnt;
    }
    printf("%I64d\n", ans);
    return 0;
}


#include <cstdio>
#include <algorithm>

using namespace std;

const int Nmax = 1e5 + 5;

struct Node {
    int mh, re, t, nh;
};

struct Sta {
    int t, cnt;
};

bool operator < (const Sta &lhs, const Sta &rhs) {
    return lhs.t < rhs.t || (lhs.t == rhs.t && lhs.cnt < rhs.cnt);
}

struct Change {
    int id, t, nh;
};

bool operator < (const Change &lhs, const Change &rhs) {
    return lhs.t < rhs.t;
}

inline long long max(long long t1, long long t2) {
    return t1 > t2 ? t1 : t2;
}

int main() {
    Node data[Nmax];
    int n, m;
    scanf("%d%d", &n, &m);
    int base, inc, dam, cnt = 0;
    scanf("%d%d%d", &base, &inc, &dam);
    for(int i = 0; i < n; i++) {
        scanf("%d%d%d", &data[i].mh, &data[i].nh, &data[i].re);
        if(inc > 0 && (data[i].mh <= dam || (data[i].nh <= dam && data[i].re == 0))) {
            printf("-1\n");
            return 0;
        }
        if(data[i].nh <= dam) cnt++;
    }
    Change change[Nmax];
    for(int i = 0; i < m; i++) {
        scanf("%d%d%d", &change[i].t, &change[i].id, &change[i].nh);
        change[i].id--;
    }
    sort(change, change + m);
    Sta time[Nmax << 1];
    int tCnt = 0;
    for(int i = 0; i < m; i++) {
        int id = change[i].id, t = change[i].t, nh = change[i].nh;
        if(data[id].nh <= dam) {
            if(data[id].re * (long long)(t - data[id].t) > dam - data[id].nh) {
                time[tCnt].t = (dam - data[id].nh) / data[id].re + 1;
                time[tCnt++].cnt = -1;
                if(nh <= dam) {
                    time[tCnt].t = t;
                    time[tCnt++].cnt = 1;
                }
            }
            else if(nh > dam) {
                time[tCnt].t = t;
                time[tCnt++].cnt = -1;
            }
        }
        else if(nh <= dam) {
            time[tCnt].t = t;
            time[tCnt++].cnt = 1;
        }
        data[id].t = t;
        data[id].nh = nh;
    }
    for(int i = 0; i < n; i++) {
        if(data[i].nh <= dam && data[i].re > 0) {
            time[tCnt].t = (dam - data[i].nh) / data[i].re + data[i].t + 1;
            time[tCnt++].cnt = -1;
        }
    }
    sort(time, time + tCnt);
    long long ans = 0;
    for(int i = 0; i < tCnt; i++) {
        if(time[i].cnt == -1)
            ans = max(ans, cnt * ((long long)inc * (long long)(time[i].t - 1) + (long long)base));
        cnt += time[i].cnt;
    }
    printf("%I64d\n", ans);
    return 0;
}


#include <cstdio>
#include <algorithm>

using namespace std;

const int Nmax = 1e5 + 5;

struct Node {
    int mh, re, t, nh;
};

struct Sta {
    int t, cnt;
};

bool operator < (const Sta &lhs, const Sta &rhs) {
    return lhs.t < rhs.t || (lhs.t == rhs.t && lhs.cnt < rhs.cnt);
}

struct Change {
    int id, t, nh;
};

bool operator < (const Change &lhs, const Change &rhs) {
    return lhs.t < rhs.t;
}

inline long long max(long long t1, long long t2) {
    return t1 > t2 ? t1 : t2;
}

Sta myTime[Nmax * 3];
Node data[Nmax];
Change change[Nmax];

int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    int base, inc, dam, cnt = 0;
    scanf("%d%d%d", &base, &inc, &dam);
    for(int i = 0; i < n; i++) {
        scanf("%d%d%d", &data[i].mh, &data[i].nh, &data[i].re);
        if(inc > 0 && (data[i].mh <= dam || (data[i].nh <= dam && data[i].re == 0))) {
            printf("-1\n");
            return 0;
        }
        data[i].t = 0;
        if(data[i].nh <= dam) cnt++;
    }
    for(int i = 0; i < m; i++) {
        scanf("%d%d%d", &change[i].t, &change[i].id, &change[i].nh);
        change[i].id--;
    }
    sort(change, change + m);
    int tCnt = 0;
    for(int i = 0; i < m; i++) {
        int id = change[i].id, t = change[i].t, nh = change[i].nh;
        if(data[id].mh > dam) {
            if(data[id].nh <= dam) {
                if(data[id].re * (long long)(t - data[id].t) > dam - data[id].nh) {
                    myTime[tCnt].t = (dam - data[id].nh) / data[id].re + data[id].t + 1;
                    myTime[tCnt++].cnt = -1;
                    if(nh <= dam) {
                        myTime[tCnt].t = t;
                        myTime[tCnt++].cnt = 1;
                    }
                }
                else if(nh > dam) {
                    myTime[tCnt].t = t;
                    myTime[tCnt++].cnt = -1;
                }
            }
            else if(nh <= dam) {
                myTime[tCnt].t = t;
                myTime[tCnt++].cnt = 1;
            }
            data[id].t = t;
            data[id].nh = nh;
        }
    }
    for(int i = 0; i < n; i++) {
        if(data[i].mh >= dam && data[i].nh <= dam && data[i].re > 0) {
            myTime[tCnt].t = (dam - data[i].nh) / data[i].re + data[i].t + 1;
            myTime[tCnt++].cnt = -1;
        }
        else if(data[i].nh == dam) {
            myTime[tCnt].t = data[i].t + 1;
            myTime[tCnt++].cnt = -1;
        }
    }
    sort(myTime, myTime + tCnt);
    long long ans = 0;
    for(int i = 0; i < tCnt; i++) {
        if(cnt > 0)
            ans = max(ans, cnt * ((long long)inc * (long long)(myTime[i].t - 1) + base));
        cnt += myTime[i].cnt;
    }
    printf("%I64d\n", ans);
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

typedef pair<int, int> Pair;

struct Node {
    int mh, re, nh, t;
};

bool operator < (const Pair &lhs, const Pair &rhs) {
    return lhs.first < rhs.first || (lhs.first == rhs.first && lhs.second < rhs.second);
}

struct Time {
    int t, id, nh;
};

bool operator < (const Time &lhs, const Time &rhs) {
    return lhs.t < rhs.t;
}

inline long long max(long long t1, long long t2) {
    return t1 > t2 ? t1 : t2;
}

int main() {
    int n, m;
    cin >> n >> m;
    int base, inc, dam;
    cin >> base >> inc >> dam;
    vector<Node> data(n);
    bool flag = false;
    for(int i = 0; i < n; i++) {
        Node &temp = data[i];
        cin >> temp.mh >> temp.nh >> temp.re;
        if(!flag) flag = temp.mh <= dam || (temp.re == 0 && temp.nh <= dam);
        temp.t = 0;
    }
    vector<Time> time(m);
    for(int i = 0; i < m; i++) {
        Time &temp = time[i];
        cin >> temp.t >> temp.id >> temp.nh;
        --temp.id;
    }
    if(flag) {
        cout << -1 << endl;
        return 0;
    }
    sort(time.begin(), time.end());
    vector<Pair> resultTime;
    int cnt = 0;
    for(int i = 0; i < n; i++)
        if(data[i].nh <= dam) cnt++;
    for(int i = 0; i < m; i++) {
        Node &now = data[time[i].id];
        if(now.nh <= dam && now.nh + now.re * (time[i].t - now.t) > dam)
            resultTime.push_back(Pair((dam - now.nh) / now.re + now.t, -1));
        now.nh = time[i].nh;
        now.t = time[i].t;
        if(now.nh <= dam) resultTime.push_back(Pair(now.t, 1));
    }
    for(int i = 0; i < n; i++) {
        Node &now = data[i];
        if(dam >= now.nh)
            resultTime.push_back(Pair((dam - now.nh) / now.re + now.t, -1));
    }
    sort(resultTime.begin(), resultTime.end());
    long long ans = 0;
    for(int i = 0; i < (int)resultTime.size(); i++) {
        Pair &now = resultTime[i];
        if(cnt > 0 && now.second < 0)
            ans = max(ans, (now.first * inc + base) * cnt);
        cnt += now.second;
    }
    cout << ans << endl;
    return 0;
}


#include <cstdio>
#include <algorithm>

using namespace std;

const int Nmax = 1e5 + 5;

struct Node {
    int mh, re, t, nh;
};

struct Sta {
    int t, cnt;
};

bool operator < (const Sta &lhs, const Sta &rhs) {
    return lhs.t < rhs.t || (lhs.t == rhs.t && lhs.cnt < rhs.cnt);
}

struct Change {
    int id, t, nh;
};

bool operator < (const Change &lhs, const Change &rhs) {
    return lhs.t < rhs.t;
}

inline long long max(long long t1, long long t2) {
    return t1 > t2 ? t1 : t2;
}

int main() {
    Node data[Nmax];
    int n, m;
    scanf("%d%d", &n, &m);
    int base, inc, dam, cnt = 0;
    scanf("%d%d%d", &base, &inc, &dam);
    for(int i = 0; i < n; i++) {
        scanf("%d%d%d", &data[i].mh, &data[i].nh, &data[i].re);
        if(inc > 0 && (data[i].mh <= dam || (data[i].nh <= dam && data[i].re == 0))) {
            printf("-1\n");
            return 0;
        }
        if(data[i].nh <= dam) cnt++;
    }
    Change change[Nmax];
    for(int i = 0; i < m; i++) {
        scanf("%d%d%d", &change[i].t, &change[i].id, &change[i].nh);
        change[i].id--;
    }
    sort(change, change + m);
    Sta time[Nmax << 1];
    int tCnt = 0;
    for(int i = 0; i < m; i++) {
        int id = change[i].id, t = change[i].t, nh = change[i].nh;
        if(data[id].nh <= dam) {
            if(data[id].re * (long long)(t - data[id].t) > dam - data[id].nh) {
                time[tCnt].t = (dam - data[id].nh) / (long long)data[id].re + 1;
                time[tCnt++].cnt = -1;
                if(nh <= dam) {
                    time[tCnt].t = t;
                    time[tCnt++].cnt = 1;
                }
            }
            else if(nh > dam) {
                time[tCnt].t = t;
                time[tCnt++].cnt = -1;
            }
        }
        else if(nh <= dam) {
            time[tCnt].t = t;
            time[tCnt++].cnt = 1;
        }
        data[id].t = t;
        data[id].nh = nh;
    }
    for(int i = 0; i < n; i++) {
        if(data[i].nh <= dam && data[i].re > 0) {
            time[tCnt].t = (dam - data[i].nh) / (long long)data[i].re + data[i].t + 1;
            time[tCnt++].cnt = -1;
        }
    }
    sort(time, time + tCnt);
    long long ans = 0;
    for(int i = 0; i < tCnt; i++) {
        if(time[i].cnt == -1)
            ans = max(ans, cnt * ((long long)inc * (long long)(time[i].t - 1) + (long long)base));
        cnt += time[i].cnt;
    }
    printf("%I64d\n", ans);
    return 0;
}


//============================================================================
// Name : firstTrial.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <bits/stdc++.h>
#define io  ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define file freopen("INPUT.txt", "r", stdin), freopen("OUTPUT.txt", "w", stdout);
using namespace std;
//time, idx
const int inf = 2e9 + 10, N = 1e5 + 20;
int mxH[N], stH[N], reg[N];
vector<pair<int, pair<int, int> > > mag;
vector<pair<int, int> > up[N];
int stC;
void solve(int idx, int dmg){
	if(mxH[idx] <= dmg){
		mag.push_back(make_pair(inf, make_pair(idx, -1)));
		stC++;
		return;
	}
	sort(up[idx].begin(), up[idx].end());
	int _time;
	if(stH[idx] <= dmg){
		stC++;
		if(reg[idx] != 0)
			_time = (dmg - stH[idx] + reg[idx] - 1) / reg[idx] + ((dmg - stH[idx]) % reg[idx] == 0);
		else
			_time = inf;
	}else
		_time = -inf;
	for(int i = 0; i < (int)up[idx].size(); i++){
		int t = up[idx][i].first, h = up[idx][i].second;
		if(_time != -inf && _time <= t){
			mag.push_back(make_pair(_time, make_pair(idx, -1)));
			_time = -inf;
			if(h <= dmg){
				_time = inf;
				mag.push_back(make_pair(t, make_pair(idx, 1)));
			}
		}else if(_time == -inf && h <= dmg){
			_time = inf;
			mag.push_back(make_pair(t, make_pair(idx, 1)));
		}
		if(h > dmg && _time != -inf){
			_time = -inf;
			mag.push_back(make_pair(t, make_pair(idx, -1)));
			continue;
		}
		if(reg[idx] != 0){
			if(_time != -inf)
				_time = (dmg - h + reg[idx] - 1) / reg[idx] + ((dmg - h) % reg[idx] == 0) + t;
		}else{
			_time = inf;
		}
	}
	if(_time >= 0){
		mag.push_back(make_pair(_time, make_pair(idx, -1)));
	}
}

int main(){
	int n, m, boun, inc, dmg;
	scanf("%d%d%d%d%d", &n, &m, &boun, &inc, &dmg);
	for(int i = 0; i < n; i++)
		scanf("%d%d%d", &mxH[i], &stH[i], &reg[i]);
	for(int i = 0; i < m; i++){
		//time, enemy, health
		int idx, h, t;
		scanf("%d%d%d", &t, &idx, &h);
		idx--;
		up[idx].push_back(make_pair(t, h));
	}
	for(int i = 0; i < n; i++){
		solve(i, dmg);
	}
	sort(mag.begin(), mag.end());

//	for(int i = 0; i < mag.size(); i++){
//		cout << "At time " << mag[i].first << "Enemy number "  << mag[i].second.first;
//		if(mag[i].second.second == -1)
//			cout << "Can't kiled" << endl;
//		else
//			cout << "Can killed "<< endl;
//	}

	int i = 0;
	long long ans = 0;
	while(i < (int)mag.size()){
		int _time = mag[i].first;
		if(_time == inf && inc)
			return printf("-1\n"), 0;
		_time--;
//		cout << "At time " << _time << ' ' << stC << endl;
		ans = max(ans, stC * (boun + 1ll * _time * inc));
		_time++;
		while(i < (int)mag.size() && mag[i].first == _time){
			stC += mag[i].second.second;
			i++;
		}
//		cout << "At time " << _time << ' ' << stC << endl;
		ans = max(ans, stC * (boun + 1ll * _time * inc));
	}
	printf("%I64d\n", ans);
	return 0;
}


//============================================================================
// Name : firstTrial.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <bits/stdc++.h>
#define io  ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define file freopen("INPUT.txt", "r", stdin), freopen("OUTPUT.txt", "w", stdout);
using namespace std;
//time, idx
const int inf = 2e9 + 10, N = 1e5 + 20;
int mxH[N], stH[N], reg[N];
vector<pair<int, pair<int, int> > > mag;
vector<pair<int, int> > up[N];
int stC;
void solve(int idx, int dmg){
	if(mxH[idx] <= dmg){
		mag.push_back(make_pair(inf, make_pair(idx, -1)));
		stC++;
		return;
	}
	sort(up[idx].begin(), up[idx].end());
	int _time;
	if(stH[idx] <= dmg){
		stC++;
		if(reg[idx] != 0)
			_time = (dmg - stH[idx] + reg[idx] - 1) / reg[idx] + ((dmg - stH[idx]) % reg[idx] == 0);
		else
			_time = inf;
	}else
		_time = -inf;
//	cout << idx << '@' << _time << endl;
	for(int i = 0; i < (int)up[idx].size(); i++){
		int t = up[idx][i].first, h = up[idx][i].second;
		if(_time != -inf && _time <= t){
			if(h > dmg || t != _time){
				mag.push_back(make_pair(_time, make_pair(idx, -1)));
				_time = -inf;
				if(h <= dmg){
					_time = inf;
					mag.push_back(make_pair(t, make_pair(idx, 1)));
				}
			}
		}else if(_time == -inf && h <= dmg){
			_time = inf;
			mag.push_back(make_pair(t, make_pair(idx, 1)));
		}
		if(h > dmg && _time != -inf){
			_time = -inf;
			mag.push_back(make_pair(t, make_pair(idx, -1)));
			continue;
		}
		if(reg[idx] != 0){
			_time = min(_time, (dmg - h + reg[idx] - 1) / reg[idx] + ((dmg - h) % reg[idx] == 0) + t);
		}else{
			_time = inf;
		}
	}
	if(_time >= 0){
		mag.push_back(make_pair(_time, make_pair(idx, -1)));
	}
}

int main(){
	int n, m, boun, inc, dmg;
	scanf("%d%d%d%d%d", &n, &m, &boun, &inc, &dmg);
	for(int i = 0; i < n; i++)
		scanf("%d%d%d", &mxH[i], &stH[i], &reg[i]);
	for(int i = 0; i < m; i++){
		//time, enemy, health
		int idx, h, t;
		scanf("%d%d%d", &t, &idx, &h);
		idx--;
		up[idx].push_back(make_pair(t, h));
	}
	for(int i = 0; i < n; i++){
		solve(i, dmg);
	}
	sort(mag.begin(), mag.end());

//	for(int i = 0; i < mag.size(); i++){
//		cout << "At time " << mag[i].first << "Enemy number "  << mag[i].second.first;
//		if(mag[i].second.second == -1)
//			cout << "Can't kiled" << endl;
//		else
//			cout << "Can killed "<< endl;
//	}

	int i = 0;
	long long ans = 0;
	while(i < (int)mag.size()){
		int _time = mag[i].first;
		if(_time == inf && inc)
			return printf("-1\n"), 0;
		_time--;
//		cout << "At time " << _time << ' ' << stC << endl;
		ans = max(ans, stC * (boun + 1ll * _time * inc));
		_time++;
		while(i < (int)mag.size() && mag[i].first == _time){
			stC += mag[i].second.second;
			i++;
		}
//		cout << "At time " << _time << ' ' << stC << endl;
		ans = max(ans, stC * (boun + 1ll * _time * inc));
	}
	printf("%I64d\n", ans);
	return 0;
}


//============================================================================
// Name : firstTrial.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <bits/stdc++.h>
#define io  ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define file freopen("INPUT.txt", "r", stdin), freopen("OUTPUT.txt", "w", stdout);
using namespace std;
//time, idx
const int inf = 2e9 + 10, N = 1e5 + 20;
int mxH[N], stH[N], reg[N];
vector<pair<int, pair<int, int> > > mag;
vector<pair<int, int> > up[N];
int stC;
void solve(int idx, int dmg){
	if(mxH[idx] <= dmg){
		mag.push_back(make_pair(inf, make_pair(idx, -1)));
		stC++;
		return;
	}
	sort(up[idx].begin(), up[idx].end());
	int _time;
	if(stH[idx] <= dmg){
		stC++;
		if(reg[idx] != 0)
			_time = (dmg - stH[idx] + reg[idx] - 1) / reg[idx] + ((dmg - stH[idx]) % reg[idx] == 0);
		else
			_time = inf;
	}else
		_time = -inf;
//	cout << idx << '@' << _time << endl;
	for(int i = 0; i < (int)up[idx].size(); i++){
		int t = up[idx][i].first, h = up[idx][i].second;
		if(_time != -inf && _time <= t){
			mag.push_back(make_pair(_time, make_pair(idx, -1)));
			_time = -inf;
			if(h <= dmg){
				_time = inf;
				mag.push_back(make_pair(t, make_pair(idx, 1)));
			}
		}else if(_time == -inf && h <= dmg){
			_time = inf;
			mag.push_back(make_pair(t, make_pair(idx, 1)));
		}
		if(h > dmg && _time != -inf){
			_time = -inf;
			mag.push_back(make_pair(t, make_pair(idx, -1)));
			continue;
		}
		if(reg[idx] != 0){
			_time = min(_time, (dmg - h + reg[idx] - 1) / reg[idx] + ((dmg - h) % reg[idx] == 0) + t);
		}else{
			_time = inf;
		}
	}
	if(_time >= 0){
		mag.push_back(make_pair(_time, make_pair(idx, -1)));
	}
}

int main(){
	int n, m, boun, inc, dmg;
	scanf("%d%d%d%d%d", &n, &m, &boun, &inc, &dmg);
	for(int i = 0; i < n; i++)
		scanf("%d%d%d", &mxH[i], &stH[i], &reg[i]);
	for(int i = 0; i < m; i++){
		//time, enemy, health
		int idx, h, t;
		scanf("%d%d%d", &t, &idx, &h);
		idx--;
		up[idx].push_back(make_pair(t, h));
	}
	for(int i = 0; i < n; i++){
		solve(i, dmg);
	}
	sort(mag.begin(), mag.end());

//	for(int i = 0; i < mag.size(); i++){
//		cout << "At time " << mag[i].first << "Enemy number "  << mag[i].second.first;
//		if(mag[i].second.second == -1)
//			cout << "Can't kiled" << endl;
//		else
//			cout << "Can killed "<< endl;
//	}

	int i = 0;
	long long ans = 0;
	while(i < (int)mag.size()){
		int _time = mag[i].first;
		if(_time == inf && inc)
			return printf("-1\n"), 0;
		_time--;
//		cout << "At time " << _time << ' ' << stC << endl;
		ans = max(ans, stC * (boun + 1ll * _time * inc));
		_time++;
		while(i < (int)mag.size() && mag[i].first == _time){
			stC += mag[i].second.second;
			i++;
		}
//		cout << "At time " << _time << ' ' << stC << endl;
		ans = max(ans, stC * (boun + 1ll * _time * inc));
	}
	printf("%I64d\n", ans);
	return 0;
}