#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e9 + 10, MAX = 7e5 + 1e4, MOD = 1e9 + 7, MAXL = 25;   void OUT(long double o, int x) {     cout << fixed << setprecision(x) << o;     return;   }   long long sth[MAX], mah[MAX], reg[MAX], ti[MAX], en[MAX], he[MAX], hh[MAX],       pa[MAX];   long long la[MAX];   pair<pair<long long, long long>, long long> so[MAX];   set<long long> st;   map<long long, long long> mp;   vector<pair<pair<long long, long long>, long long> > v[MAX];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, m, ans = 0, bo, da, in;     bool inff = 0;     cin >> n >> m >> bo >> in >> da;     st.insert(0);     for (int i = 1; i <= n; i++) {       cin >> mah[i] >> sth[i] >> reg[i];       if (mah[i] <= da) inff = 1;       hh[i] = sth[i];       if (hh[i] <= da && (reg[i] != 0 && mah[i] > da)) {         st.insert((da - hh[i]) / reg[i]);         st.insert(((da - hh[i]) / reg[i]) + 1);       }     }     for (int i = 1; i <= m; i++) {       cin >> ti[i] >> en[i] >> he[i];       so[i] = {{ti[i], en[i]}, he[i]};     }     so[0].first.first = -1;     sort(so + 1, so + m + 1);     for (int i = 1; i <= m; i++) {       hh[so[i].first.second] = so[i].second;       st.insert(so[i].first.first);       st.insert(so[i].first.first - 1);       if (so[i].second <= da &&           (reg[so[i].first.second] != 0 && mah[so[i].first.second] > da)) {         st.insert(so[i].first.first +                   ((da - so[i].second) / reg[so[i].first.second]));         st.insert(1 + so[i].first.first +                   ((da - so[i].second) / reg[so[i].first.second]));       }     }     for (int i = 1; i <= n; i++) {       if (reg[i] == 0 && hh[i] <= da) inff = 1;     }     if (inff == 1 && in != 0) return cout << -1, 0;     long long cnt = 0, x = 0;     for (int u : st) {       mp[u] = cnt;       cnt++;     }     for (int i = 1; i <= n; i++) {       hh[i] = sth[i];       la[i] = -1;       if (hh[i] <= da)         x++;       else         la[i] = -2;       if (hh[i] <= da && (reg[i] != 0 && mah[i] > da)) {         pa[mp[1 + ((da - hh[i]) / reg[i])]]--;         la[i] = ((da - hh[i]) / reg[i]);       }     }     for (int i = 1; i <= m; i++) {       v[mp[ti[i]]].push_back({{ti[i], en[i]}, he[i]});     }     for (int u : st) {       for (pair<pair<long long, long long>, long long> w : v[mp[u]]) {         hh[w.first.second] = w.second;         if (la[w.first.second] == -1 || la[w.first.second] >= u) {           if (la[w.first.second] != -1) pa[mp[la[w.first.second] + 1]]++;           if (hh[w.first.second] > da)             x--;           else {             if ((reg[w.first.second] != 0 && mah[w.first.second] > da)) {               pa[mp[1 + u + ((da - hh[w.first.second]) / reg[w.first.second])]]--;               la[w.first.second] =                   u + ((da - hh[w.first.second]) / reg[w.first.second]);             }           }         } else {           if (hh[w.first.second] <= da) {             x++;             if (reg[w.first.second] > 0) {               pa[mp[u + 1 + ((da - hh[w.first.second]) / reg[w.first.second])]]--;               la[w.first.second] =                   u + ((da - hh[w.first.second]) / reg[w.first.second]);             } else               la[w.first.second] = -1;           }         }       }       x += pa[mp[u]];       ans = max(ans, (x * bo) + (x * in * u));     }     cout << ans;     return 0;   }