#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <queue>
#include <stack>
#include <sstream>
#include <cstring>
#include <numeric>
#include <ctime>
#include <cassert>

#define re return
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int) (x).size())
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define y0 y32479
#define y1 y95874
#define fill(x, y) memset(x, y, sizeof(x))
#define sqr(x) ((x) * (x))
#define sqrt(x) sqrt(abs(x))
#define unq(x) (x.resize(unique(all(x)) - x.begin()))
#define spc(i,n) " \n"[i == n - 1]
#define next next239
#define prev prev239

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef double D;
typedef long double LD;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;

template<class T> T abs(T x) { return x > 0 ? x : -x;}

const ll mod = 1000000000 + 7;

int m;
int n;
ll ans;

int nint() {
	int x;
	scanf("%d", &x);
	re x;
}

ll maxhp[100500];
ll lasttime[100500];
ll lasthp[100500];
ll regen[100500];
ll bounty, inc;
ll damage;
ll curt;

ll getHp(int i) {
	re min(maxhp[i], lasthp[i] + regen[i] * (curt - lasttime[i]));
}

ll getTime(int i) {
	if (regen[i] == 0)
		re 2 * mod + 1;
	ll d = damage + 1 - getHp(i);
	ll ans = curt + (d + regen[i]) / regen[i];
	re ans;
}

bool f(int a, int b) {
	ll t1 = getTime(a);
	ll t2 = getTime(b);
	if (t1 != t2)
		re t1 < t2;
	re a < b;
}

set<int, bool (*) (int, int)> s1(f);
set<int> s2;

void check() {
	//cout << "check: " << curt << endl;
	ans = max(ans, (bounty + curt * inc) * sz(s1));
}

void setHp(int i, ll hp, bool opa = false) {
	if (!opa) {
		if (s2.count(i))
			s2.erase(i);
		else
			s1.erase(i);
	}

	lasthp[i] = hp;
	lasttime[i] = curt;
	if (hp <= damage) {
		if (regen[i] == 0 && inc) {
			cout << -1;
			exit(0);
		}
		s1.insert(i);
	}
	else
		s2.insert(i);
}

void updateS1() {
	int x = *s1.begin();
	ll tt = getTime(x);
	vi v;
	for (int o : s1) {
		if (getTime(o) != tt)
			break;
		v.pb(o);
	}
	if (curt < tt) {
		curt = tt - 1;
		check();
	}
	for (int x : v) {
		s1.erase(x);
		s2.insert(x);
	}
	curt = tt;
}

void tryUpdate(ll nt) {
	while (sz(s1)) {
		int x = *s1.begin();
		ll tt = getTime(x);
		if (tt <= nt)
			updateS1();
		else
			break;
	}
	curt = nt;
}

int main() {
#ifdef LOCAL_BOBER
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#else
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif

	cin >> n >> m;
	cin >> bounty >> inc >> damage;
	rep(i, n) {
		maxhp[i] = nint();
		lasthp[i] = nint();
		regen[i] = nint();
		if (damage >= maxhp[i] && inc) {
			cout << -1;
			re 0;
		}
		setHp(i, lasthp[i], true);
	}
	check();

	vector<pair<int, ii> > q;
	rep(i, m) {
		pair<int, ii> x;
		x.fi = nint();
		x.se.fi = nint();
		x.se.se = nint();
		q.pb(x);
	}

	sort(all(q));
	for (auto o : q) {
		int tt = o.fi;
		int id = o.se.fi - 1;
		int hp = o.se.se;
		if (curt != tt) {
			tryUpdate(tt - 1);
			check();
		}
		setHp(id, hp);
	}
	tryUpdate(2 * mod);

	cout << ans;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <queue>
#include <stack>
#include <sstream>
#include <cstring>
#include <numeric>
#include <ctime>
#include <cassert>

#define re return
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int) (x).size())
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define y0 y32479
#define y1 y95874
#define fill(x, y) memset(x, y, sizeof(x))
#define sqr(x) ((x) * (x))
#define sqrt(x) sqrt(abs(x))
#define unq(x) (x.resize(unique(all(x)) - x.begin()))
#define spc(i,n) " \n"[i == n - 1]
#define next next239
#define prev prev239

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef double D;
typedef long double LD;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;

template<class T> T abs(T x) { return x > 0 ? x : -x;}

const ll mod = 1000000000 + 7;

int m;
int n;
ll ans;

int nint() {
	int x;
	scanf("%d", &x);
	re x;
}

ll maxhp[100500];
ll lasttime[100500];
ll lasthp[100500];
ll regen[100500];
ll bounty, inc;
ll damage;
ll curt;

ll getHp(int i) {
	re min(maxhp[i], lasthp[i] + regen[i] * (curt - lasttime[i]));
}

ll getTime(int i) {
	if (regen[i] == 0)
		re 2 * mod + 1;
	ll d = damage + 1 - getHp(i);
	ll ans = curt + (d + regen[i]) / regen[i];
	re ans;
}

bool f(int a, int b) {
	ll t1 = getTime(a);
	ll t2 = getTime(b);
	if (t1 != t2)
		re t1 < t2;
	re a < b;
}

set<int, bool (*) (int, int)> s1(f);
set<int> s2;

void check() {
	//cout << "check: " << curt << endl;
	ans = max(ans, (bounty + curt * inc) * sz(s1));
}

void setHp(int i, ll hp, bool opa = false) {
	if (!opa) {
		if (s2.count(i))
			s2.erase(i);
		else
			s1.erase(i);
	}

	lasthp[i] = hp;
	lasttime[i] = curt;
	if (hp <= damage) {
		if (regen[i] == 0 && inc) {
			cout << -1;
			exit(0);
		}
		s1.insert(i);
	}
	else
		s2.insert(i);
}

void updateS1() {
	int x = *s1.begin();
	ll tt = getTime(x);
	vi v;
	for (int o : s1) {
		if (getTime(o) != tt)
			break;
		v.pb(o);
	}
	curt = tt - 1;
	check();
	for (int x : v) {
		s1.erase(x);
		s2.insert(x);
	}
	curt = tt;
}

void tryUpdate(ll nt) {
	while (sz(s1)) {
		int x = *s1.begin();
		ll tt = getTime(x);
		if (tt <= nt)
			updateS1();
		else
			break;
	}
	curt = nt;
}

int main() {
#ifdef LOCAL_BOBER
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#else
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif

	cin >> n >> m;
	cin >> bounty >> inc >> damage;
	rep(i, n) {
		maxhp[i] = nint();
		lasthp[i] = nint();
		regen[i] = nint();
		if (damage >= maxhp[i] && inc) {
			cout << -1;
			re 0;
		}
		setHp(i, lasthp[i], true);
	}
	check();

	vector<pair<int, ii> > q;
	rep(i, m) {
		pair<int, ii> x;
		x.fi = nint();
		x.se.fi = nint();
		x.se.se = nint();
		q.pb(x);
	}

	sort(all(q));
	for (auto o : q) {
		int tt = o.fi;
		int id = o.se.fi - 1;
		int hp = o.se.se;
		if (curt < tt)
			tryUpdate(tt);
		setHp(id, hp);
	}
	tryUpdate(2 * mod);

	cout << ans;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <queue>
#include <stack>
#include <sstream>
#include <cstring>
#include <numeric>
#include <ctime>
#include <cassert>

#define re return
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int) (x).size())
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define y0 y32479
#define y1 y95874
#define fill(x, y) memset(x, y, sizeof(x))
#define sqr(x) ((x) * (x))
#define sqrt(x) sqrt(abs(x))
#define unq(x) (x.resize(unique(all(x)) - x.begin()))
#define spc(i,n) " \n"[i == n - 1]
#define next next239
#define prev prev239

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef double D;
typedef long double LD;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;

template<class T> T abs(T x) { return x > 0 ? x : -x;}

const ll mod = 1000000000 + 7;

int m;
int n;
ll ans;

int nint() {
	int x;
	scanf("%d", &x);
	re x;
}

ll maxhp[100500];
ll lasttime[100500];
ll lasthp[100500];
ll regen[100500];
ll bounty, inc;
ll damage;
ll curt;

ll getHp(int i) {
	re min(maxhp[i], lasthp[i] + regen[i] * (curt - lasttime[i]));
}

ll getTime(int i) {
	if (regen[i] == 0)
		re 2 * mod + 1;
	ll d = damage + 1 - getHp(i);
	ll ans = curt + (d + regen[i]) / regen[i];
	re ans;
}

bool f(int a, int b) {
	ll t1 = getTime(a);
	ll t2 = getTime(b);
	if (t1 != t2)
		re t1 < t2;
	re a < b;
}

set<int, bool (*) (int, int)> s1(f);
set<int> s2;

void check() {
	//cout << "check: " << curt << endl;
	ans = max(ans, (bounty + curt * inc) * sz(s1));
}

void setHp(int i, ll hp, bool opa = false) {
	if (!opa) {
		if (s2.count(i))
			s2.erase(i);
		else
			s1.erase(i);
	}

	lasthp[i] = hp;
	lasttime[i] = curt;
	if (hp <= damage) {
		if (regen[i] == 0 && inc) {
			cout << -1;
			exit(0);
		}
		s1.insert(i);
	}
	else
		s2.insert(i);
}

void updateS1() {
	int x = *s1.begin();
	ll tt = getTime(x);
	vi v;
	for (int o : s1) {
		if (getTime(o) != tt)
			break;
		v.pb(o);
	}
	curt = tt - 1;
	check();
	for (int x : v) {
		s1.erase(x);
		s2.insert(x);
	}
	curt = tt;
}

void tryUpdate(ll nt) {
	while (sz(s1)) {
		int x = *s1.begin();
		ll tt = getTime(x);
		if (tt <= nt)
			updateS1();
		else
			break;
	}
	if (curt != nt) {
		curt = nt - 1;
		check();
	}
	curt = nt;
}

int main() {
#ifdef LOCAL_BOBER
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#else
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif

	cin >> n >> m;
	cin >> bounty >> inc >> damage;
	rep(i, n) {
		maxhp[i] = nint();
		lasthp[i] = nint();
		regen[i] = nint();
		if (damage >= maxhp[i] && inc) {
			cout << -1;
			re 0;
		}
		setHp(i, lasthp[i], true);
	}
	check();

	vector<pair<int, ii> > q;
	rep(i, m) {
		pair<int, ii> x;
		x.fi = nint();
		x.se.fi = nint();
		x.se.se = nint();
		q.pb(x);
	}

	sort(all(q));
	for (auto o : q) {
		int tt = o.fi;
		int id = o.se.fi - 1;
		int hp = o.se.se;
		if (curt < tt)
			tryUpdate(tt);
		setHp(id, hp);
	}
	tryUpdate(2 * mod);

	cout << ans;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <queue>
#include <stack>
#include <sstream>
#include <cstring>
#include <numeric>
#include <ctime>
#include <cassert>

#define re return
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int) (x).size())
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define y0 y32479
#define y1 y95874
#define fill(x, y) memset(x, y, sizeof(x))
#define sqr(x) ((x) * (x))
#define sqrt(x) sqrt(abs(x))
#define unq(x) (x.resize(unique(all(x)) - x.begin()))
#define spc(i,n) " \n"[i == n - 1]
#define next next239
#define prev prev239

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef double D;
typedef long double LD;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;

template<class T> T abs(T x) { return x > 0 ? x : -x;}

const ll mod = 1000000000 + 7;

int m;
int n;
ll ans;

int nint() {
	int x;
	scanf("%d", &x);
	re x;
}

ll maxhp[100500];
ll lasttime[100500];
ll lasthp[100500];
ll regen[100500];
ll bounty, inc;
ll damage;
ll curt;

ll getHp(int i) {
	re min(maxhp[i], lasthp[i] + regen[i] * (curt - lasttime[i]));
}

ll getTime(int i) {
	if (regen[i] == 0)
		re 2 * mod + 1;
	ll d = damage + 1 - getHp(i);
	ll ans = curt + (d + regen[i]) / regen[i];
	re ans;
}

bool f(int a, int b) {
	ll t1 = getTime(a);
	ll t2 = getTime(b);
	if (t1 != t2)
		re t1 < t2;
	re a < b;
}

set<int, bool (*) (int, int)> s1(f);
set<int> s2;

void check() {
	//cout << "check: " << curt << endl;
	ans = max(ans, (bounty + curt * inc) * sz(s1));
}

void setHp(int i, ll hp, bool opa = false) {
	if (!opa) {
		if (s2.count(i))
			s2.erase(i);
		else
			s1.erase(i);
	}

	lasthp[i] = hp;
	lasttime[i] = curt;
	if (hp <= damage) {
		if (regen[i] == 0 && inc) {
			cout << -1;
			exit(0);
		}
		s1.insert(i);
	}
	else
		s2.insert(i);
}

void updateS1() {
	int x = *s1.begin();
	ll tt = getTime(x);
	vi v;
	for (int o : s1) {
		if (getTime(o) != tt)
			break;
		v.pb(o);
	}
	curt = tt - 1;
	check();
	for (int x : v) {
		s1.erase(x);
		s2.insert(x);
	}
	curt = tt;
}

void tryUpdate(ll nt, bool ch) {
	while (sz(s1)) {
		int x = *s1.begin();
		ll tt = getTime(x);
		if (tt <= nt)
			updateS1();
		else
			break;
	}
	curt = nt;
	if (ch)
		check();
}

int main() {
#ifdef LOCAL_BOBER
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#else
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif

	cin >> n >> m;
	cin >> bounty >> inc >> damage;
	rep(i, n) {
		maxhp[i] = nint();
		lasthp[i] = nint();
		regen[i] = nint();
		if (damage >= maxhp[i] && inc) {
			cout << -1;
			re 0;
		}
		setHp(i, lasthp[i], true);
	}
	check();

	vector<pair<int, ii> > q;
	rep(i, m) {
		pair<int, ii> x;
		x.fi = nint();
		x.se.fi = nint();
		x.se.se = nint();
		q.pb(x);
	}

	sort(all(q));
	for (auto o : q) {
		int tt = o.fi;
		int id = o.se.fi - 1;
		int hp = o.se.se;
		if (curt < tt)
			tryUpdate(tt - 1, true);
		tryUpdate(tt, false);
		setHp(id, hp);
		check();
	}
	tryUpdate(2 * mod, false);

	cout << ans;
}


#include <bits/stdc++.h>

typedef long long ll ;

using namespace std;
vector<vector<ll> > enemydetails,updated;
ll n,m,bounty,increase,damge;
map<ll,set<ll> > maap;
ll timedie(int in)
{
    ll x=enemydetails[in][0];
    ll y=enemydetails[in][1];
    ll z=enemydetails[in][2],r;
    ll st=0,en=1e15;
    while(st<=en)
    {
        ll mid=(st+en)/2;
        r=min(x,y+mid*z);
        if(r<=damge)
        {
            st=mid+1;
        }
        else
            en=mid-1;
    }
    st--;
    r=min(x,y+st*z);
    if(r<=damge)
        return st;
    return -1;
}
ll out=0,counter=0;
void getmax(ll time)
{
    if(maap.size()==0)
        return;
    if(time==-2)
    {
        map<ll,set<ll> > ::iterator it=maap.end();
        it--;
        it=maap.begin();
        out=max(out,counter*bounty+counter*increase*it->first);
        counter-=it->second.size();
        maap.erase(maap.begin());
    }
    else
    {
        if(time ==-1)
            return ;
        out=max(out,counter*bounty+counter*increase*time);
    }
}

int main()
{
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ll x,y,z;
    cin >> n>>m;
    enemydetails.resize(n);
    updated.resize(m);
    cin >> bounty>> increase>> damge;
    for(int i =0; i<n; i++)
    {
        cin >> x>>y>>z;
        enemydetails[i].push_back(x);
        enemydetails[i].push_back(y);
        enemydetails[i].push_back(z);
        enemydetails[i].push_back(timedie(i));
        if(enemydetails[i][3]!=-1)
        {
            counter++;
            maap[enemydetails[i][3]].insert(i);
        }
    }
    for(int i =0; i<m; i++)
    {
        cin >> x>>y>>z;
        y--;
        updated[i].push_back(x);
        updated[i].push_back(y);
        updated[i].push_back(z);
    }
    sort(updated.begin(),updated.end());
    ll inupdate=0;
    while(inupdate<updated.size())
    {
        if(maap.size()==0||updated[inupdate][0]<maap.begin()->first)
        {
            x=updated[inupdate][0];
            y=updated[inupdate][1];
            z=updated[inupdate][2];
            getmax(x-1);
            if(enemydetails[y][3]>=x)
            {
                counter--;
                maap[enemydetails[y][3]].erase(y);
                if(maap[enemydetails[y][3]].size()==0)
                    maap.erase(enemydetails[y][3]);
            }
            enemydetails[y][1]=z;
            enemydetails[y][3]=timedie(y);
            if(enemydetails[y][3]!=-1)
            {
                counter++;
                enemydetails[y][3]+=x;
                maap[enemydetails[y][3]].insert(y);
            }
            inupdate++;
            continue;
        }
        getmax(-2);
    }
    while(maap.size())
        getmax(-2);
    if(out>=1e15)
        cout << -1 <<endl;
    else
        cout << out << endl;
    return 0;
}


#include <bits/stdc++.h>

typedef long long ll ;

using namespace std;
vector<vector<ll> > enemydetails,updated;
ll n,m,bounty,increase,damge;
map<ll,set<ll> > maap;
ll timedie(int in)
{
    ll x=enemydetails[in][0];
    ll y=enemydetails[in][1];
    ll z=enemydetails[in][2],r;
    ll st=0,en=1e10;
    while(st<=en)
    {
        ll mid=(st+en)/2;
        r=min(x,y+mid*z);
        if(r<=damge)
        {
            st=mid+1;
        }
        else
            en=mid-1;
    }
    st--;
    r=min(x,y+st*z);
    if(r<=damge)
        return st;
    return -1;
}
ll out=0,counter=0;
void getmax(ll time)
{
    if(maap.size()==0)
        return;
    if(time==-2)
    {
        map<ll,set<ll> > ::iterator it=maap.end();
        it--;
        it=maap.begin();

        if(out!=-1)
        out=max(out,counter*bounty+counter*increase*it->first);
        counter-=it->second.size();
        maap.erase(maap.begin());
    }
    else
    {
        if(time ==-1)
            return ;
        if(time>=1e10&&increase!=0)
            out=-1;
        if(out!=-1)
        out=max(out,counter*bounty+counter*increase*time);
    }
}

int main()
{
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ll x,y,z;
    cin >> n>>m;
    enemydetails.resize(n);
    updated.resize(m);
    cin >> bounty>> increase>> damge;
    for(int i =0; i<n; i++)
    {
        cin >> x>>y>>z;
        enemydetails[i].push_back(x);
        enemydetails[i].push_back(y);
        enemydetails[i].push_back(z);
        enemydetails[i].push_back(timedie(i));
        if(enemydetails[i][3]!=-1)
        {
            counter++;
            maap[enemydetails[i][3]].insert(i);
        }
    }
    for(int i =0; i<m; i++)
    {
        cin >> x>>y>>z;
        y--;
        updated[i].push_back(x);
        updated[i].push_back(y);
        updated[i].push_back(z);
    }
    sort(updated.begin(),updated.end());
    ll inupdate=0;
    while(inupdate<updated.size())
    {
        if(maap.size()==0||updated[inupdate][0]<maap.begin()->first)
        {
            x=updated[inupdate][0];
            y=updated[inupdate][1];
            z=updated[inupdate][2];
            getmax(x-1);
            if(enemydetails[y][3]>=x)
            {
                counter--;
                maap[enemydetails[y][3]].erase(y);
                if(maap[enemydetails[y][3]].size()==0)
                    maap.erase(enemydetails[y][3]);
            }
            enemydetails[y][1]=z;
            enemydetails[y][3]=timedie(y);
            if(enemydetails[y][3]!=-1)
            {
                counter++;
                enemydetails[y][3]+=x;
                maap[enemydetails[y][3]].insert(y);
            }
            inupdate++;
            continue;
        }
        getmax(-2);
    }
    while(maap.size())
        getmax(-2);
        cout << out << endl;
    return 0;
}


#include <bits/stdc++.h>

typedef long long ll ;

using namespace std;
vector<vector<ll> > enemydetails,updated;
ll n,m,bounty,increase,damge;
map<ll,set<ll> > maap;
ll timedie(int in)
{
    ll x=enemydetails[in][0];
    ll y=enemydetails[in][1];
    ll z=enemydetails[in][2],r;
    ll st=0,en=1e14;
    while(st<=en)
    {
        ll mid=(st+en)/2;
        r=min(x,y+mid*z);
        if(r<=damge)
        {
            st=mid+1;
        }
        else
            en=mid-1;
    }
    st--;
    r=min(x,y+st*z);
    if(r<=damge)
        return st;
    return -1;
}
ll out=0,counter=0;
void getmax()
{
    if(maap.size()==0)
        return;
    map<ll,set<ll> > ::iterator it=maap.end();
    it--;
     it=maap.begin();
    out=max(out,counter*bounty+counter*increase*it->first);
    counter-=it->second.size();
    maap.erase(maap.begin());
}
int main()
{
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ll x,y,z;
    cin >> n>>m;
    enemydetails.resize(n);
    updated.resize(m);
    cin >> bounty>> increase>> damge;
    for(int i =0; i<n; i++)
    {
        cin >> x>>y>>z;
        enemydetails[i].push_back(x);
        enemydetails[i].push_back(y);
        enemydetails[i].push_back(z);
        enemydetails[i].push_back(timedie(i));
        if(enemydetails[i][3]!=-1)
        {
            counter++;
            maap[enemydetails[i][3]].insert(i);
        }
    }
    for(int i =0; i<m; i++)
    {
        cin >> x>>y>>z;
        y--;
        updated[i].push_back(x);
        updated[i].push_back(y);
        updated[i].push_back(z);
    }
    sort(updated.begin(),updated.end());
    ll inupdate=0;
    while(inupdate<updated.size())
    {
        if(maap.size()==0||updated[inupdate][0]<maap.begin()->first)
        {
            x=updated[inupdate][0];
            y=updated[inupdate][1];
            z=updated[inupdate][2];
            if(enemydetails[y][3]>=x)
            {
                counter--;
                maap[enemydetails[y][3]].erase(y);
                if(maap[enemydetails[y][3]].size()==0)
                    maap.erase(enemydetails[y][3]);
            }
            enemydetails[y][1]=z;
            enemydetails[y][3]=timedie(y);
            if(enemydetails[y][3]!=-1)
            {
                counter++;
                enemydetails[y][3]+=x;
                maap[enemydetails[y][3]].insert(y);
            }
            inupdate++;
            continue;
        }
        getmax();
    }
    while(maap.size())
    getmax();
    if(out>=1e14)
        cout << -1 <<endl;
    else
    cout << out << endl;
    return 0;
}


#include <bits/stdc++.h>

typedef long long ll ;

using namespace std;
vector<vector<ll> > enemydetails,updated;
ll n,m,bounty,increase,damge;
map<ll,set<ll> > maap;
ll timedie(int in)
{
    ll x=enemydetails[in][0];
    ll y=enemydetails[in][1];
    ll z=enemydetails[in][2],r;
    ll st=0,en=1e14;
    while(st<=en)
    {
        ll mid=(st+en)/2;
        r=min(x,y+mid*z);
        if(r<=damge)
        {
            st=mid+1;
        }
        else
            en=mid-1;
    }
    st--;
    r=min(x,y+st*z);
    if(r<=damge)
        return st;
    return -1;
}
ll out=0,counter=0;
void getmax(ll time)
{
    if(maap.size()==0)
        return;
    if(time==-2)
    {
        map<ll,set<ll> > ::iterator it=maap.end();
        it--;
        it=maap.begin();
        out=max(out,counter*bounty+counter*increase*it->first);
        counter-=it->second.size();
        maap.erase(maap.begin());
    }
    else
    {
        if(time ==-1)
            return ;
        out=max(out,counter*bounty+counter*increase*time);
    }
}

int main()
{
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ll x,y,z;
    cin >> n>>m;
    enemydetails.resize(n);
    updated.resize(m);
    cin >> bounty>> increase>> damge;
    for(int i =0; i<n; i++)
    {
        cin >> x>>y>>z;
        enemydetails[i].push_back(x);
        enemydetails[i].push_back(y);
        enemydetails[i].push_back(z);
        enemydetails[i].push_back(timedie(i));
        if(enemydetails[i][3]!=-1)
        {
            counter++;
            maap[enemydetails[i][3]].insert(i);
        }
    }
    for(int i =0; i<m; i++)
    {
        cin >> x>>y>>z;
        y--;
        updated[i].push_back(x);
        updated[i].push_back(y);
        updated[i].push_back(z);
    }
    sort(updated.begin(),updated.end());
    ll inupdate=0;
    while(inupdate<updated.size())
    {
        if(maap.size()==0||updated[inupdate][0]<maap.begin()->first)
        {
            x=updated[inupdate][0];
            y=updated[inupdate][1];
            z=updated[inupdate][2];
            getmax(x-1);
            if(enemydetails[y][3]>=x)
            {
                counter--;
                maap[enemydetails[y][3]].erase(y);
                if(maap[enemydetails[y][3]].size()==0)
                    maap.erase(enemydetails[y][3]);
            }
            enemydetails[y][1]=z;
            enemydetails[y][3]=timedie(y);
            if(enemydetails[y][3]!=-1)
            {
                counter++;
                enemydetails[y][3]+=x;
                maap[enemydetails[y][3]].insert(y);
            }
            inupdate++;
            continue;
        }
        getmax(-2);
    }
    while(maap.size())
        getmax(-2);
    if(out>=1e14)
        cout << -1 <<endl;
    else
        cout << out << endl;
    return 0;
}


#include <bits/stdc++.h>

typedef long long ll ;

using namespace std;
vector<vector<ll> > enemydetails,updated;
ll n,m,bounty,increase,damge;
map<ll,set<ll> > maap;
ll timedie(int in)
{
    ll x=enemydetails[in][0];
    ll y=enemydetails[in][1];
    ll z=enemydetails[in][2],r;
    ll st=0,en=1e10;
    while(st<=en)
    {
        ll mid=(st+en)/2;
        r=min(x,y+mid*z);
        if(r<=damge)
        {
            st=mid+1;
        }
        else
            en=mid-1;
    }
    st--;
    r=min(x,y+st*z);
    if(r<=damge)
        return st;
    return -1;
}
ll out=0,counter=0;
void getmax(ll time)
{
    if(maap.size()==0)
        return;
    if(time==-2)
    {
        map<ll,set<ll> > ::iterator it=maap.end();
        it--;
        it=maap.begin();
        if(it->first>=1e10&&increase!=0)
            out=-1;
        if(out!=-1)
            out=max(out,counter*bounty+counter*increase*it->first);
        counter-=it->second.size();
        maap.erase(maap.begin());
    }
    else
    {
        if(time ==-1)
            return ;
        if(time>=1e10&&increase!=0)
            out=-1;
        if(out!=-1)
            out=max(out,counter*bounty+counter*increase*time);
    }
}

int main()
{
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ll x,y,z;
    cin >> n>>m;
    enemydetails.resize(n);
    updated.resize(m);
    cin >> bounty>> increase>> damge;
    for(int i =0; i<n; i++)
    {
        cin >> x>>y>>z;
        enemydetails[i].push_back(x);
        enemydetails[i].push_back(y);
        enemydetails[i].push_back(z);
        enemydetails[i].push_back(timedie(i));
        if(enemydetails[i][3]!=-1)
        {
            counter++;
            maap[enemydetails[i][3]].insert(i);
        }
    }
    for(int i =0; i<m; i++)
    {
        cin >> x>>y>>z;
        y--;
        updated[i].push_back(x);
        updated[i].push_back(y);
        updated[i].push_back(z);
    }
    sort(updated.begin(),updated.end());
    ll inupdate=0;
    while(inupdate<updated.size())
    {
        if(maap.size()==0||updated[inupdate][0]<maap.begin()->first)
        {
            x=updated[inupdate][0];
            y=updated[inupdate][1];
            z=updated[inupdate][2];
            getmax(x-1);
            if(enemydetails[y][3]>=x)
            {
                counter--;
                maap[enemydetails[y][3]].erase(y);
                if(maap[enemydetails[y][3]].size()==0)
                    maap.erase(enemydetails[y][3]);
            }
            enemydetails[y][1]=z;
            enemydetails[y][3]=timedie(y);
            if(enemydetails[y][3]!=-1)
            {
                counter++;
                enemydetails[y][3]+=x;
                maap[enemydetails[y][3]].insert(y);
            }
            inupdate++;
            continue;
        }
        getmax(-2);
    }
    while(maap.size())
        getmax(-2);
    cout << out << endl;
    return 0;
}


#include <bits/stdc++.h>

typedef long long ll ;

using namespace std;
vector<vector<ll> > enemydetails,updated;
ll n,m,bounty,increase,damge;
map<ll,set<ll> > maap;
ll timedie(int in)
{
    ll x=enemydetails[in][0];
    ll y=enemydetails[in][1];
    ll z=enemydetails[in][2],r;
    ll st=0,en=1e11;
    while(st<=en)
    {
        ll mid=(st+en)/2;
        r=min(x,y+mid*z);
        if(r<=damge)
        {
            st=mid+1;
        }
        else
            en=mid-1;
    }
    st--;
    r=min(x,y+st*z);
    if(r<=damge)
        return st;
    return -1;
}
ll out=0,counter=0;
void getmax()
{
    if(maap.size()==0|| out==-1)
        return;
    map<ll,set<ll> > ::iterator it=maap.end();
    it--;
    if(it->first>1e9)
    {
        out=-1;
        return;
    }
     it=maap.begin();
    out=max(out,counter*bounty+counter*increase*it->first);
    counter-=it->second.size();
    maap.erase(maap.begin());
}
int main()
{
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ll x,y,z;
    cin >> n>>m;
    enemydetails.resize(n);
    updated.resize(m);
    cin >> bounty>> increase>> damge;
    for(int i =0; i<n; i++)
    {
        cin >> x>>y>>z;
        enemydetails[i].push_back(x);
        enemydetails[i].push_back(y);
        enemydetails[i].push_back(z);
        enemydetails[i].push_back(timedie(i));
        if(enemydetails[i][3]!=-1)
        {
            counter++;
            maap[enemydetails[i][3]].insert(i);
        }
    }
    for(int i =0; i<m; i++)
    {
        cin >> x>>y>>z;
        y--;
        updated[i].push_back(x);
        updated[i].push_back(y);
        updated[i].push_back(z);
    }
    sort(updated.begin(),updated.end());
    ll inupdate=0;
    while(inupdate<updated.size())
    {
        if(maap.size()==0||updated[inupdate][0]<maap.begin()->first)
        {
            x=updated[inupdate][0];
            y=updated[inupdate][1];
            z=updated[inupdate][2];
            if(enemydetails[y][3]>=x)
            {
                counter--;
                maap[enemydetails[y][3]].erase(y);
                if(maap[enemydetails[y][3]].size()==0)
                    maap.erase(enemydetails[y][3]);
            }
            enemydetails[y][1]=z;
            enemydetails[y][3]=timedie(y);
            if(enemydetails[y][3]!=-1)
            {
                counter++;
                enemydetails[y][3]+=x;
                maap[enemydetails[y][3]].insert(y);
            }
            inupdate++;
            continue;
        }
        getmax();
    }
    getmax();
    cout << out << endl;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<set>
#include<map>
using namespace std;
int n,m;
int bou,inc,dam;
int sh[100010],eh[100010],reg[100010];
int nd[100010];
multiset<pair<int,int> >st;
bool f[100010];
int cnt;
map<int,pair<int,int> >mp;
long long ans;
int main()
{
	scanf("%d%d",&n,&m);
	scanf("%d%d%d",&bou,&inc,&dam);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d%d",eh+i,sh+i,reg+i);
		if(eh[i]<=dam)
		{
			printf("-1");
			return 0;
		}
		if(sh[i]<=dam)
		{
			cnt++;if(reg[i]==0)nd[i]=2e9+10;else nd[i]=(dam-sh[i])/reg[i];
			st.insert(make_pair(nd[i],i));
		}
		else f[i]=true;
	}
	ans=1LL*cnt*bou;
	for(int i=1;i<=m;i++)
	{
		int t,ene,num;
		scanf("%d%d%d",&t,&ene,&num);
		mp[t]=make_pair(ene,num);
		st.insert(make_pair(t,-1));
	}
	while(st.size())
	{
		multiset<pair<int,int> >::iterator it=st.begin();
		int t=(*it).first;
		int nx=-1,ny=-1;
		if(t==2e9+10 && cnt>0)
		{
			printf("-1");
			return 0;
		}
		if((*it).second==-1)
		{
			int ene=mp[t].first,num=mp[t].second;
			if(reg[ene]==0)nd[ene]==2e9+10;else nd[ene]=t+(dam-num)/reg[ene];
			if(!f[ene])
			{
				st.erase(st.find(make_pair(nd[ene],ene)));
			}
			if(num<=dam)
			{
				nx=nd[ene],ny=ene;
				if(f[ene])
				{
					f[ene]=false;
					cnt++;
				}
			}
			else
			{
				if(!f[ene])
				{
					f[ene]=true;
					cnt--;
				}
			}
		}
		ans=max(ans,1LL*cnt*(bou+1LL*t*inc));
		if((*it).second!=-1)
		{
			f[(*it).second]=true;
			cnt--;
		}
		st.erase(it);
		if(nx!=-1)st.insert(make_pair(nx,ny));
	}
	printf("%lld",ans);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<set>
#include<map>
using namespace std;
int n,m;
int bou,inc,dam;
int sh[100010],eh[100010],reg[100010];
int nd[100010];
multiset<pair<int,int> >st;
bool f[100010];
int cnt;
map<int,pair<int,int> >mp;
long long ans;
int main()
{
	scanf("%d%d",&n,&m);
	scanf("%d%d%d",&bou,&inc,&dam);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d%d",eh+i,sh+i,reg+i);
		if(eh[i]<=dam)
		{
			printf("-1");
			return 0;
		}
		if(sh[i]<=dam)cnt++;else f[i]=true;
		nd[i]=(dam-sh[i])/reg[i];
		if(sh[i]<=dam)st.insert(make_pair(nd[i],i));
	}
	ans=1LL*cnt*bou;
	for(int i=1;i<=m;i++)
	{
		int t,ene,num;
		scanf("%d%d%d",&t,&ene,&num);
		mp[t]=make_pair(ene,num);
		st.insert(make_pair(t,-1));
	}
	while(st.size())
	{
		multiset<pair<int,int> >::iterator it=st.begin();
		int t=(*it).first;
		if((*it).second==-1)
		{
			int ene=mp[(*it).first].first,num=mp[(*it).first].second;
			nd[ene]=t+(dam-num)/reg[ene];
			if(num<=dam)
			{
				st.insert(make_pair(nd[ene],ene));
				if(f[ene])
				{
					f[ene]=false;
					cnt++;
				}
			}
			else
			{
				if(!f[ene])
				{
					f[ene]=true;
					cnt--;
				}
			}
		}
		ans=max(ans,1LL*cnt*(bou+1LL*t*inc));
		if((*it).second!=-1)
		{
			f[(*it).second]=true;
			cnt--;
		}
		st.erase(it);
	}
	printf("%lld",ans);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<set>
#include<map>
using namespace std;
int n,m;
int bou,inc,dam;
int sh[100010],eh[100010],reg[100010];
int nd[100010];
multiset<pair<int,int> >st;
bool f[100010];
int cnt;
map<int,pair<int,int> >mp;
long long ans;
int main()
{
	scanf("%d%d",&n,&m);
	scanf("%d%d%d",&bou,&inc,&dam);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d%d",eh+i,sh+i,reg+i);
		if(eh[i]<=dam)
		{
			printf("-1");
			return 0;
		}
		if(sh[i]<=dam)cnt++;else f[i]=true;
		nd[i]=(dam-sh[i])/reg[i];
		if(sh[i]<=dam)st.insert(make_pair(nd[i],i));
	}
	ans=1LL*cnt*bou;
	for(int i=1;i<=m;i++)
	{
		int t,ene,num;
		scanf("%d%d%d",&t,&ene,&num);
		mp[t]=make_pair(ene,num);
		st.insert(make_pair(t,-1));
	}
	while(st.size())
	{
		multiset<pair<int,int> >::iterator it=st.begin();
		int t=(*it).first;
		int nx=-1,ny=-1;
		if((*it).second==-1)
		{
			int ene=mp[(*it).first].first,num=mp[(*it).first].second;
			nd[ene]=t+(dam-num)/reg[ene];
			if(num<=dam)
			{
				nx=nd[ene],ny=ene;
				if(f[ene])
				{
					f[ene]=false;
					cnt++;
				}
			}
			else
			{
				if(!f[ene])
				{
					f[ene]=true;
					cnt--;
				}
			}
		}
		ans=max(ans,1LL*cnt*(bou+1LL*t*inc));
		if((*it).second!=-1)
		{
			f[(*it).second]=true;
			cnt--;
		}
		st.erase(it);
		if(nx!=-1)st.insert(make_pair(nx,ny));
	}
	printf("%lld",ans);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<set>
#include<map>
#include<vector>
using namespace std;
int n,m;
int bou,inc,dam;
int sh[100010],eh[100010],reg[100010];
int nd[100010];
multiset<pair<int,int> >st;
bool f[100010];
int cnt;
map<int,vector<pair<int,int> > >mp;
long long ans;
int main()
{
	scanf("%d%d",&n,&m);
	scanf("%d%d%d",&bou,&inc,&dam);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d%d",eh+i,sh+i,reg+i);
		if(eh[i]<=dam)
		{
			printf("-1");
			return 0;
		}
		if(sh[i]<=dam)
		{
			cnt++;if(reg[i]==0)nd[i]=2e9+10;else nd[i]=(dam-sh[i])/reg[i];
			st.insert(make_pair(nd[i],i));
		}
		else f[i]=true;
	}
	ans=1LL*cnt*bou;
	for(int i=1;i<=m;i++)
	{
		int t,ene,num;
		scanf("%d%d%d",&t,&ene,&num);
		mp[t].push_back(make_pair(ene,num));
		if(st.find(make_pair(t,-1))==st.end())st.insert(make_pair(t,-1));
	}
	while(st.size())
	{
		multiset<pair<int,int> >::iterator it=st.begin();
		int t=(*it).first;
		if((*it).second==-1)
		{
			for(int i=0;i<mp[t].size();i++)
			{
				int ene=mp[t][i].first,num=mp[t][i].second;
				if(!f[ene])
				{
					st.erase(st.find(make_pair(nd[ene],ene)));
				}
				sh[ene]=num;
				if(num<=dam)
				{
					if(reg[ene]==0)nd[ene]=2e9+10;else nd[ene]=t+(dam-num)/reg[ene];
					st.insert(make_pair(nd[ene],ene));
					if(f[ene])
					{
						f[ene]=false;
						cnt++;
					}
				}
				else
				{
					if(!f[ene])
					{
						f[ene]=true;
						cnt--;
					}
				}
			}
		}
		ans=max(ans,1LL*cnt*(bou+1LL*t*inc));
		if((*it).second!=-1)
		{
			f[(*it).second]=true;
			cnt--;
		}
		st.erase(it);
	}
	for(int i=1;i<=n;i++)if(reg[i]==0 && sh[i]<=dam){printf("-1");return 0;}
	printf("%lld",ans);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<set>
#include<map>
using namespace std;
int n,m;
int bou,inc,dam;
int sh[100010],eh[100010],reg[100010];
int nd[100010];
multiset<pair<int,int> >st;
bool f[100010];
int cnt;
map<int,pair<int,int> >mp;
long long ans;
int main()
{
	scanf("%d%d",&n,&m);
	scanf("%d%d%d",&bou,&inc,&dam);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d%d",eh+i,sh+i,reg+i);
		if(eh[i]<=dam)
		{
			printf("-1");
			return 0;
		}
		if(sh[i]<=dam)
		{
			cnt++;if(reg[i]==0)nd[i]=2e9+10;else nd[i]=(dam-sh[i])/reg[i];
			st.insert(make_pair(nd[i],i));
		}
		else f[i]=true;
	}
	ans=1LL*cnt*bou;
	for(int i=1;i<=m;i++)
	{
		int t,ene,num;
		scanf("%d%d%d",&t,&ene,&num);
		mp[t]=make_pair(ene,num);
		st.insert(make_pair(t,-1));
	}
	while(st.size())
	{
		multiset<pair<int,int> >::iterator it=st.begin();
		int t=(*it).first;
		int nx=-1,ny=-1;
		if((*it).second==-1)
		{
			int ene=mp[t].first,num=mp[t].second;
			if(reg[ene]==0)nd[ene]==2e9+10;else nd[ene]=t+(dam-num)/reg[ene];
			sh[ene]=num;
			if(!f[ene])
			{
				st.erase(st.find(make_pair(nd[ene],ene)));
			}
			if(num<=dam)
			{
				nx=nd[ene],ny=ene;
				if(f[ene])
				{
					f[ene]=false;
					cnt++;
				}
			}
			else
			{
				if(!f[ene])
				{
					f[ene]=true;
					cnt--;
				}
			}
		}
		ans=max(ans,1LL*cnt*(bou+1LL*t*inc));
		if((*it).second!=-1)
		{
			f[(*it).second]=true;
			cnt--;
		}
		st.erase(it);
		if(nx!=-1)st.insert(make_pair(nx,ny));
	}
	for(int i=1;i<=n;i++)if(reg[i]==0 && sh[i]<=dam){printf("-1");return 0;}
	printf("%lld",ans);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<set>
#include<map>
#include<vector>
using namespace std;
int n,m;
int bou,inc,dam;
int sh[100010],eh[100010],reg[100010];
int nd[100010];
set<pair<int,int> >st;
bool f[100010];
int cnt;
map<int,vector<pair<int,int> > >mp;
long long ans;
int main()
{
	scanf("%d%d",&n,&m);
	scanf("%d%d%d",&bou,&inc,&dam);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d%d",eh+i,sh+i,reg+i);
		if(eh[i]<=dam)
		{
			printf("-1");
			return 0;
		}
		if(sh[i]<=dam)
		{
			cnt++;if(reg[i]==0)nd[i]=2e9+10;else nd[i]=(dam-sh[i])/reg[i];
			st.insert(make_pair(nd[i],i));
		}
		else f[i]=true;
	}
	ans=1LL*cnt*bou;
	for(int i=1;i<=m;i++)
	{
		int t,ene,num;
		scanf("%d%d%d",&t,&ene,&num);
		mp[t].push_back(make_pair(ene,num));
		if(st.find(make_pair(t,-1))==st.end())st.insert(make_pair(t,-1));
	}
	while(st.size())
	{
		set<pair<int,int> >::iterator it=st.begin();
		int t=(*it).first;
		if((*it).second==-1)
		{
			for(int i=0;i<mp[t].size();i++)
			{
				int ene=mp[t][i].first,num=mp[t][i].second;
				if(!f[ene])
				{
					st.erase(st.find(make_pair(nd[ene],ene)));
				}
				sh[ene]=num;
				if(num<=dam)
				{
					if(reg[ene]==0)nd[ene]=2e9+10;else nd[ene]=t+(dam-num)/reg[ene];
					st.insert(make_pair(nd[ene],ene));
					if(f[ene])
					{
						f[ene]=false;
						cnt++;
					}
				}
				else
				{
					if(!f[ene])
					{
						f[ene]=true;
						cnt--;
					}
				}
			}
		}
		ans=max(ans,1LL*cnt*(bou+1LL*t*inc));
		if((*it).second!=-1)
		{
			f[(*it).second]=true;
			cnt--;
		}
		st.erase(it);
	}
	for(int i=1;i<=n;i++)if(reg[i]==0 && sh[i]<=dam){printf("-1");return 0;}
	printf("%lld",ans);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<set>
#include<map>
#include<vector>
using namespace std;
int n,m;
int bou,inc,dam;
int sh[100010],eh[100010],reg[100010];
int nd[100010];
set<pair<int,int> >st;
bool f[100010];
int cnt;
map<int,vector<pair<int,int> > >mp;
long long ans;
int main()
{
	scanf("%d%d",&n,&m);
	scanf("%d%d%d",&bou,&inc,&dam);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d%d",eh+i,sh+i,reg+i);
		if(eh[i]<=dam)
		{
			printf("-1");
			return 0;
		}
		if(sh[i]<=dam)
		{
			cnt++;if(reg[i]==0)nd[i]=2e9+10;else nd[i]=(dam-sh[i])/reg[i];
			st.insert(make_pair(nd[i],i));
		}
		else f[i]=true;
	}
	ans=1LL*cnt*bou;
	for(int i=1;i<=m;i++)
	{
		int t,ene,num;
		scanf("%d%d%d",&t,&ene,&num);
		mp[t].push_back(make_pair(ene,num));
		if(st.find(make_pair(t,-1))==st.end())st.insert(make_pair(t,-1));
	}
	while(st.size())
	{
		set<pair<int,int> >::iterator it=st.begin();
		int t=(*it).first;
		if((*it).second==-1)
		{
			for(int i=0;i<mp[t].size();i++)
			{
				int ene=mp[t][i].first,num=mp[t][i].second;
				if(!f[ene])
				{
					st.erase(st.find(make_pair(nd[ene],ene)));
				}
				sh[ene]=num;
				if(num<=dam)
				{
					if(reg[ene]==0)nd[ene]=2e9+10;else nd[ene]=t+(dam-num)/reg[ene];
					st.insert(make_pair(nd[ene],ene));
					if(f[ene])
					{
						f[ene]=false;
						cnt++;
					}
				}
				else
				{
					if(!f[ene])
					{
						f[ene]=true;
						cnt--;
					}
				}
			}
		}
		ans=max(ans,1LL*cnt*(bou+1LL*t*inc));
		if((*it).second!=-1)
		{
			f[(*it).second]=true;
			cnt--;
		}
		st.erase(it);
	}
	for(int i=1;i<=n;i++)if(reg[i]==0 && sh[i]<=dam && inc!=0){printf("-1");return 0;}
	printf("%lld",ans);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<set>
#include<map>
#include<vector>
using namespace std;
int n,m;
int bou,inc,dam;
int sh[100010],eh[100010],reg[100010];
int nd[100010];
multiset<pair<int,int> >st;
bool f[100010];
int cnt;
map<int,vector<pair<int,int> > >mp;
long long ans;
int main()
{
	scanf("%d%d",&n,&m);
	scanf("%d%d%d",&bou,&inc,&dam);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d%d",eh+i,sh+i,reg+i);
		if(eh[i]<=dam)
		{
			printf("-1");
			return 0;
		}
		if(sh[i]<=dam)
		{
			cnt++;if(reg[i]==0)nd[i]=2e9+10;else nd[i]=(dam-sh[i])/reg[i];
			st.insert(make_pair(nd[i],i));
		}
		else f[i]=true;
	}
	ans=1LL*cnt*bou;
	for(int i=1;i<=m;i++)
	{
		int t,ene,num;
		scanf("%d%d%d",&t,&ene,&num);
		mp[t].push_back(make_pair(ene,num));
		if(st.find(make_pair(t,-1))==st.end())st.insert(make_pair(t,-1));
	}
	while(st.size())
	{
		multiset<pair<int,int> >::iterator it=st.begin();
		int t=(*it).first;
		if((*it).second==-1)
		{
			for(int i=0;i<mp[t].size();i++)
			{
				int ene=mp[t][i].first,num=mp[t][i].second;
				if(!f[ene])
				{
					st.erase(st.find(make_pair(nd[ene],ene)));
				}
				if(reg[ene]==0)nd[ene]=2e9+10;else nd[ene]=t+(dam-num)/reg[ene];
				sh[ene]=num;
				if(num<=dam)
				{
					st.insert(make_pair(nd[ene],ene));
					if(f[ene])
					{
						f[ene]=false;
						cnt++;
					}
				}
				else
				{
					if(!f[ene])
					{
						f[ene]=true;
						cnt--;
					}
				}
			}
		}
		ans=max(ans,1LL*cnt*(bou+1LL*t*inc));
		if((*it).second!=-1)
		{
			f[(*it).second]=true;
			cnt--;
		}
		st.erase(it);
	}
	for(int i=1;i<=n;i++)if(reg[i]==0 && sh[i]<=dam){printf("-1");return 0;}
	printf("%lld",ans);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<set>
#include<map>
#include<vector>
using namespace std;
int n,m;
int bou,inc,dam;
int sh[100010],eh[100010],reg[100010];
int nd[100010];
set<pair<int,int> >st;
bool f[100010];
int cnt;
map<int,vector<pair<int,int> > >mp;
long long ans;
int main()
{
	scanf("%d%d",&n,&m);
	scanf("%d%d%d",&bou,&inc,&dam);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d%d",eh+i,sh+i,reg+i);
		if(eh[i]<=dam && inc>0)
		{
			printf("-1");
			return 0;
		}
		if(sh[i]<=dam)
		{
			cnt++;if(reg[i]==0)nd[i]=2e9+10;else nd[i]=(dam-sh[i])/reg[i];
			st.insert(make_pair(nd[i],i));
		}
		else f[i]=true;
	}
	ans=1LL*cnt*bou;
	for(int i=1;i<=m;i++)
	{
		int t,ene,num;
		scanf("%d%d%d",&t,&ene,&num);
		mp[t].push_back(make_pair(ene,num));
		if(st.find(make_pair(t,-1))==st.end())st.insert(make_pair(t,-1));
	}
	while(st.size())
	{
		set<pair<int,int> >::iterator it=st.begin();
		int t=(*it).first;
		ans=max(ans,1LL*cnt*(bou+1LL*(t-1)*inc));
		if((*it).second==-1)
		{
			for(int i=0;i<mp[t].size();i++)
			{
				int ene=mp[t][i].first,num=mp[t][i].second;
				if(!f[ene])
				{
					st.erase(st.find(make_pair(nd[ene],ene)));
				}
				sh[ene]=num;
				if(num<=dam)
				{
					if(reg[ene]==0)nd[ene]=2e9+10;else nd[ene]=t+(dam-num)/reg[ene];
					st.insert(make_pair(nd[ene],ene));
					if(f[ene])
					{
						f[ene]=false;
						cnt++;
					}
				}
				else
				{
					if(!f[ene])
					{
						f[ene]=true;
						cnt--;
					}
				}
			}
		}
		ans=max(ans,1LL*cnt*(bou+1LL*t*inc));
		if((*it).second!=-1)
		{
			f[(*it).second]=true;
			cnt--;
		}
		st.erase(it);
	}
	for(int i=1;i<=n;i++)if(reg[i]==0 && sh[i]<=dam && inc!=0){printf("-1");return 0;}
	printf("%lld",ans);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<set>
#include<map>
#include<vector>
using namespace std;
int n,m;
int bou,inc,dam;
int sh[100010],eh[100010],reg[100010];
int nd[100010];
set<pair<int,int> >st;
bool f[100010];
int cnt;
map<int,vector<pair<int,int> > >mp;
long long ans;
int main()
{
	scanf("%d%d",&n,&m);
	scanf("%d%d%d",&bou,&inc,&dam);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d%d",eh+i,sh+i,reg+i);
		if(eh[i]<=dam)
		{
			printf("-1");
			return 0;
		}
		if(sh[i]<=dam)
		{
			cnt++;if(reg[i]==0)nd[i]=2e9+10;else nd[i]=(dam-sh[i])/reg[i];
			st.insert(make_pair(nd[i],i));
		}
		else f[i]=true;
	}
	ans=1LL*cnt*bou;
	for(int i=1;i<=m;i++)
	{
		int t,ene,num;
		scanf("%d%d%d",&t,&ene,&num);
		mp[t].push_back(make_pair(ene,num));
		if(st.find(make_pair(t,-1))==st.end())st.insert(make_pair(t,-1));
	}
	while(st.size())
	{
		set<pair<int,int> >::iterator it=st.begin();
		int t=(*it).first;
		ans=max(ans,1LL*cnt*(bou+1LL*(t-1)*inc));
		if((*it).second==-1)
		{
			for(int i=0;i<mp[t].size();i++)
			{
				int ene=mp[t][i].first,num=mp[t][i].second;
				if(!f[ene])
				{
					st.erase(st.find(make_pair(nd[ene],ene)));
				}
				sh[ene]=num;
				if(num<=dam)
				{
					if(reg[ene]==0)nd[ene]=2e9+10;else nd[ene]=t+(dam-num)/reg[ene];
					st.insert(make_pair(nd[ene],ene));
					if(f[ene])
					{
						f[ene]=false;
						cnt++;
					}
				}
				else
				{
					if(!f[ene])
					{
						f[ene]=true;
						cnt--;
					}
				}
			}
		}
		ans=max(ans,1LL*cnt*(bou+1LL*t*inc));
		if((*it).second!=-1)
		{
			f[(*it).second]=true;
			cnt--;
		}
		st.erase(it);
	}
	for(int i=1;i<=n;i++)if(reg[i]==0 && sh[i]<=dam && inc!=0){printf("-1");return 0;}
	printf("%lld",ans);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<set>
#include<map>
#include<vector>
using namespace std;
int n,m;
int bou,inc,dam;
int sh[100010],eh[100010],reg[100010];
int nd[100010];
multiset<pair<int,int> >st;
bool f[100010];
int cnt;
map<int,vector<pair<int,int> > >mp;
long long ans;
int main()
{
	scanf("%d%d",&n,&m);
	scanf("%d%d%d",&bou,&inc,&dam);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d%d",eh+i,sh+i,reg+i);
		if(eh[i]<=dam)
		{
			printf("-1");
			return 0;
		}
		if(sh[i]<=dam)
		{
			cnt++;if(reg[i]==0)nd[i]=2e9+10;else nd[i]=(dam-sh[i])/reg[i];
			st.insert(make_pair(nd[i],i));
		}
		else f[i]=true;
	}
	ans=1LL*cnt*bou;
	for(int i=1;i<=m;i++)
	{
		int t,ene,num;
		scanf("%d%d%d",&t,&ene,&num);
		mp[t].push_back(make_pair(ene,num));
		if(st.find(make_pair(t,-1))==st.end())st.insert(make_pair(t,-1));
	}
	while(st.size())
	{
		multiset<pair<int,int> >::iterator it=st.begin();
		int t=(*it).first;
		if((*it).second==-1)
		{
			for(int i=0;i<mp[t].size();i++)
			{
				int ene=mp[t][i].first,num=mp[t][i].second;
				if(!f[ene])
				{
					st.erase(st.find(make_pair(nd[ene],ene)));
				}
				if(reg[ene]==0)nd[ene]==2e9+10;else nd[ene]=t+(dam-num)/reg[ene];
				sh[ene]=num;
				if(num<=dam)
				{
					st.insert(make_pair(nd[ene],ene));
					if(f[ene])
					{
						f[ene]=false;
						cnt++;
					}
				}
				else
				{
					if(!f[ene])
					{
						f[ene]=true;
						cnt--;
					}
				}
			}
		}
		ans=max(ans,1LL*cnt*(bou+1LL*t*inc));
		if((*it).second!=-1)
		{
			f[(*it).second]=true;
			cnt--;
		}
		st.erase(it);
	}
	for(int i=1;i<=n;i++)if(reg[i]==0 && sh[i]<=dam){printf("-1");return 0;}
	printf("%lld",ans);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<set>
#include<map>
#include<vector>
using namespace std;
int n,m;
int bou,inc,dam;
int sh[100010],eh[100010],reg[100010];
int nd[100010];
multiset<pair<int,int> >st;
bool f[100010];
int cnt;
map<int,vector<pair<int,int> > >mp;
long long ans;
int main()
{
	scanf("%d%d",&n,&m);
	scanf("%d%d%d",&bou,&inc,&dam);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d%d",eh+i,sh+i,reg+i);
		if(eh[i]<=dam)
		{
			printf("-1");
			return 0;
		}
		if(sh[i]<=dam)
		{
			cnt++;if(reg[i]==0)nd[i]=2e9+10;else nd[i]=(dam-sh[i])/reg[i];
			st.insert(make_pair(nd[i],i));
		}
		else f[i]=true;
	}
	ans=1LL*cnt*bou;
	for(int i=1;i<=m;i++)
	{
		int t,ene,num;
		scanf("%d%d%d",&t,&ene,&num);
		mp[t].push_back(make_pair(ene,num));
		if(st.find(make_pair(t,-1))==st.end())st.insert(make_pair(t,-1));
	}
	while(st.size())
	{
		multiset<pair<int,int> >::iterator it=st.begin();
		int t=(*it).first;
		int nx=-1,ny=-1;
		if((*it).second==-1)
		{
			for(int i=0;i<mp[t].size();i++)
			{
				int ene=mp[t][i].first,num=mp[t][i].second;
				if(reg[ene]==0)nd[ene]==2e9+10;else nd[ene]=t+(dam-num)/reg[ene];
				sh[ene]=num;
				if(!f[ene])
				{
					st.erase(st.find(make_pair(nd[ene],ene)));
				}
				if(num<=dam)
				{
					st.insert(make_pair(nd[ene],ene));
					if(f[ene])
					{
						f[ene]=false;
						cnt++;
					}
				}
				else
				{
					if(!f[ene])
					{
						f[ene]=true;
						cnt--;
					}
				}
			}
		}
		ans=max(ans,1LL*cnt*(bou+1LL*t*inc));
		if((*it).second!=-1)
		{
			f[(*it).second]=true;
			cnt--;
		}
		st.erase(it);
		if(nx!=-1)st.insert(make_pair(nx,ny));
	}
	for(int i=1;i<=n;i++)if(reg[i]==0 && sh[i]<=dam){printf("-1");return 0;}
	printf("%lld",ans);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<set>
#include<map>
using namespace std;
int n,m;
int bou,inc,dam;
int sh[100010],eh[100010],reg[100010];
int nd[100010];
multiset<pair<int,int> >st;
bool f[100010];
int cnt;
map<int,pair<int,int> >mp;
long long ans;
int main()
{
	scanf("%d%d",&n,&m);
	scanf("%d%d%d",&bou,&inc,&dam);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d%d",eh+i,sh+i,reg+i);
		if(eh[i]<=dam)
		{
			printf("-1");
			return 0;
		}
		if(sh[i]<=dam)
		{
			cnt++;if(reg[i]==0)nd[i]=2e9+10;else nd[i]=(dam-sh[i])/reg[i];
			st.insert(make_pair(nd[i],i));
		}
		else f[i]=true;
	}
	ans=1LL*cnt*bou;
	for(int i=1;i<=m;i++)
	{
		int t,ene,num;
		scanf("%d%d%d",&t,&ene,&num);
		mp[t]=make_pair(ene,num);
		st.insert(make_pair(t,-1));
	}
	while(st.size())
	{
		multiset<pair<int,int> >::iterator it=st.begin();
		int t=(*it).first;
		int nx=-1,ny=-1;
		if(t==2e9+10 && cnt)
		{
			printf("-1");
			return 0;
		}
		if((*it).second==-1)
		{
			int ene=mp[t].first,num=mp[t].second;
			if(reg[ene]==0)nd[ene]==2e9+10;else nd[ene]=t+(dam-num)/reg[ene];
			if(num<=dam)
			{
				nx=nd[ene],ny=ene;
				if(f[ene])
				{
					f[ene]=false;
					cnt++;
				}
			}
			else
			{
				if(!f[ene])
				{
					f[ene]=true;
					cnt--;
				}
			}
		}
		ans=max(ans,1LL*cnt*(bou+1LL*t*inc));
		if((*it).second!=-1)
		{
			f[(*it).second]=true;
			cnt--;
		}
		st.erase(it);
		if(nx!=-1)st.insert(make_pair(nx,ny));
	}
	printf("%lld",ans);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<set>
#include<map>
using namespace std;
int n,m;
int bou,inc,dam;
int sh[100010],eh[100010],reg[100010];
int nd[100010];
multiset<pair<int,int> >st;
bool f[100010];
int cnt;
map<int,pair<int,int> >mp;
long long ans;
int main()
{
	scanf("%d%d",&n,&m);
	scanf("%d%d%d",&bou,&inc,&dam);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d%d",eh+i,sh+i,reg+i);
		if(eh[i]<=dam)
		{
			printf("-1");
			return 0;
		}
		if(sh[i]<=dam)
		{
			cnt++;nd[i]=(dam-sh[i])/reg[i];
			st.insert(make_pair(nd[i],i));
		}
		else f[i]=true;
	}
	ans=1LL*cnt*bou;
	for(int i=1;i<=m;i++)
	{
		int t,ene,num;
		scanf("%d%d%d",&t,&ene,&num);
		mp[t]=make_pair(ene,num);
		st.insert(make_pair(t,-1));
	}
	while(st.size())
	{
		multiset<pair<int,int> >::iterator it=st.begin();
		int t=(*it).first;
		int nx=-1,ny=-1;
		if((*it).second==-1)
		{
			int ene=mp[t].first,num=mp[t].second;
			nd[ene]=t+(dam-num)/reg[ene];
			if(num<=dam)
			{
				nx=nd[ene],ny=ene;
				if(f[ene])
				{
					f[ene]=false;
					cnt++;
				}
			}
			else
			{
				if(!f[ene])
				{
					f[ene]=true;
					cnt--;
				}
			}
		}
		ans=max(ans,1LL*cnt*(bou+1LL*t*inc));
		if((*it).second!=-1)
		{
			f[(*it).second]=true;
			cnt--;
		}
		st.erase(it);
		if(nx!=-1)st.insert(make_pair(nx,ny));
	}
	printf("%lld",ans);
	return 0;
}


//{{{By oToToT
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <bitset>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <random>
#include <utility>
#include <stack>
#include <sstream>
#include <functional>
#include <deque>
#include <cassert>
using namespace std;
/* include everything for Kotori~ <3 */

typedef long long lld;
typedef unsigned long long llu;
typedef long double llf;
typedef pair<int,int> PII;
typedef pair<int,lld> PIL;
typedef pair<lld,int> PLI;
typedef pair<lld,lld> PLL;
template<typename T>
using maxHeap = priority_queue<T,vector<T>,less<T>>;
template<typename T>
using minHeap = priority_queue<T,vector<T>,greater<T>>;
/* define some types for Ruby! */

#define FF first
#define SS second
#define SZ(x) (int)(x.size())
#define ALL(x) begin(x), end(x)
#define PB push_back
#define WC(x) while(x--)
/* make code shorter for Di~a~ */

template<typename Iter>
ostream& _out(ostream &s, Iter b, Iter e) {
	s<<"[";
	for ( auto it=b; it!=e; it++ ) s<<(it==b?"":" ")<<*it;
	s<<"]";
	return s;
}
template<typename A, typename B>
ostream& operator <<( ostream &s, const pair<A,B> &p ) { return s<<"("<<p.FF<<","<<p.SS<<")"; }
template<typename T>
ostream& operator <<( ostream &s, const vector<T> &c ) { return _out(s,ALL(c)); }
template<typename T>
ostream& operator <<( ostream &s, const set<T> &c ) { return _out(s,ALL(c)); }
/* make output easier for Ainyan~n~ */

bool debug = 0;
#define DUMP(x) if(debug) cerr<<__PRETTY_FUNCTION__<<":"<<__LINE__<<" - "<<#x<<"="<<x<<'\n'
template<typename T>
void DEBUG(const T& x){if(debug) cerr<<x;}
template<typename T, typename... Args>
void DEBUG(const T& head,const Args& ...tail){
	if(debug){cerr<<head; DEBUG(tail...);}
}
/* Let's debug with Nico~Nico~Ni */
//}}}
const int N = 100000 + 5;
const lld INF = 1LL<<60;

inline void end(int x){cout << x << '\n'; exit(0);}
template<typename T>
inline void mini(T& a, const T& b){if(b < a) a = b;}

struct Mon{
	lld mx, jie, xie;
} arr[2*N];
int pre[2*N];
lld pop[2*N], push[2*N];

struct Obj{
	lld t, id, jie;
	bool operator<(const Obj& x) const {return t < x.t;}
};
vector<Obj> tmp;

map<lld, vector<pair<int,int>>> mp;

int main(int argc, char* argv[]){
	if(argc>1 and string(argv[1])=="-D") debug=1;
	if(!debug){ios_base::sync_with_stdio(0);cin.tie(0);}
	int n, m; cin>>n>>m;
	fill_n(pop, n+m, INF);
	fill_n(push, n+m, INF);
	// inc*time + bty
	lld bty, inc, dmg; cin>>bty>>inc>>dmg;
	for(int i=0;i<n;i++){
		lld mx, jie, xie; cin>>mx>>jie>>xie;
		if(inc!=0 and mx <= dmg) end(-1);
		if(xie != 0) mini(pop[i], (dmg-jie+xie)/xie);
		if(jie > dmg) pop[i] = 0;
		arr[i] = {mx, jie, xie};
		pre[i] = i;
		push[i] = 0;
	}
	for(int i=0;i<m;i++){
		lld t, id, jie; cin>>t>>id>>jie;
		tmp.PB({t, id, jie});
	}
	sort(ALL(tmp));
	for(int i=0;i<m;i++){
		lld t=tmp[i].t, id=tmp[i].id, jie=tmp[i].jie;
		int &p = pre[id-1]; mini(pop[p], t);
		DUMP(dmg-jie);
		if(arr[p].xie != 0) mini(pop[i+n], t+(dmg-jie+arr[p].xie)/arr[p].xie);
		if(jie > dmg) pop[i+n] = t;
		arr[i+n] = {arr[p].mx, jie, arr[p].xie};
		push[i+n] = t;
		p = i+n;
	}
	for(int i=0;i<n+m;i++){
		if(pop[i] <= push[i]) continue;
		if(push[i]!=INF){
			mp[push[i]-1].PB({-7122, 2});
			mp[push[i]].PB({i, 1});
			mp[push[i]+1].PB({-7122, 2});
		}
		if(pop[i]!=INF){
			mp[pop[i]-1].PB({-7122, 2});
			mp[pop[i]].PB({i, 0});
			mp[pop[i]+1].PB({-7122, 2});
		}
		DEBUG(i, ": [", push[i], ", ", pop[i], ")\n");
	}
	lld ans = 0;
	set<int> con;
	for(auto i: mp){
		for(auto j: i.SS){
			if(j.SS==1) con.insert(j.FF);
			else if(j.SS==0) con.erase(j.FF);
		}
		DEBUG("at ", i.FF, ": ", con, '\n');
		ans = max(ans, 1LL*SZ(con)*(i.FF*inc + bty));
	}
	end(ans);
	return 0;
}


//{{{By oToToT
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <bitset>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <random>
#include <utility>
#include <stack>
#include <sstream>
#include <functional>
#include <deque>
#include <cassert>
using namespace std;
/* include everything for Kotori~ <3 */

typedef long long lld;
typedef unsigned long long llu;
typedef long double llf;
typedef pair<int,int> PII;
typedef pair<int,lld> PIL;
typedef pair<lld,int> PLI;
typedef pair<lld,lld> PLL;
template<typename T>
using maxHeap = priority_queue<T,vector<T>,less<T>>;
template<typename T>
using minHeap = priority_queue<T,vector<T>,greater<T>>;
/* define some types for Ruby! */

#define FF first
#define SS second
#define SZ(x) (int)(x.size())
#define ALL(x) begin(x), end(x)
#define PB push_back
#define WC(x) while(x--)
/* make code shorter for Di~a~ */

template<typename Iter>
ostream& _out(ostream &s, Iter b, Iter e) {
	s<<"[";
	for ( auto it=b; it!=e; it++ ) s<<(it==b?"":" ")<<*it;
	s<<"]";
	return s;
}
template<typename A, typename B>
ostream& operator <<( ostream &s, const pair<A,B> &p ) { return s<<"("<<p.FF<<","<<p.SS<<")"; }
template<typename T>
ostream& operator <<( ostream &s, const vector<T> &c ) { return _out(s,ALL(c)); }
template<typename T>
ostream& operator <<( ostream &s, const set<T> &c ) { return _out(s,ALL(c)); }
/* make output easier for Ainyan~n~ */

bool debug = 0;
#define DUMP(x) if(debug) cerr<<__PRETTY_FUNCTION__<<":"<<__LINE__<<" - "<<#x<<"="<<x<<'\n'
template<typename T>
void DEBUG(const T& x){if(debug) cerr<<x;}
template<typename T, typename... Args>
void DEBUG(const T& head,const Args& ...tail){
	if(debug){cerr<<head; DEBUG(tail...);}
}
/* Let's debug with Nico~Nico~Ni */
//}}}
const int N = 100000 + 5;
const lld INF = 1LL<<60;

inline void end(int x){cout << x << '\n'; exit(0);}
template<typename T>
inline void mini(T& a, const T& b){if(b < a) a = b;}

struct Mon{
	lld mx, jie, xie;
} arr[2*N];
int pre[2*N];
lld pop[2*N], push[2*N];

map<lld, vector<pair<int,int>>> mp;

int main(int argc, char* argv[]){
	if(argc>1 and string(argv[1])=="-D") debug=1;
	if(!debug){ios_base::sync_with_stdio(0);cin.tie(0);}
	int n, m; cin>>n>>m;
	fill_n(pop, n+m, INF);
	fill_n(push, n+m, INF);
	// inc*time + bty
	lld bty, inc, dmg; cin>>bty>>inc>>dmg;
	for(int i=0;i<n;i++){
		lld mx, jie, xie; cin>>mx>>jie>>xie;
		if(inc!=0 and mx <= dmg) end(-1);
		if(xie != 0) mini(pop[i], (dmg-jie+xie)/xie);
		if(jie > dmg) pop[i] = 0;
		arr[i] = {mx, jie, xie};
		if(jie <= dmg) pre[i] = i;
		push[i] = 0;
	}
	for(int i=0;i<m;i++){
		lld t, id, jie; cin>>t>>id>>jie;
		int &p = pre[id-1]; mini(pop[p], t);
		if(arr[p].xie != 0) mini(pop[i+n], t+(dmg-jie+arr[p].xie)/arr[p].xie);
		if(jie > dmg) pop[i+n] = t;
		arr[i+n] = {arr[p].mx, jie, arr[p].xie};
		if(jie <= dmg) push[i+n] = t;
		p = i+n;
	}
	for(int i=0;i<n+m;i++){
		if(push[i]!=INF){
			mp[push[i]-1].PB({-7122, 2});
			mp[push[i]].PB({i, 1});
			mp[push[i]+1].PB({-7122, 2});
		}
		if(pop[i]!=INF){
			mp[pop[i]-1].PB({-7122, 2});
			mp[pop[i]].PB({i, 0});
			mp[pop[i]+1].PB({-7122, 2});
		}
		DEBUG(i, ": [", push[i], ", ", pop[i], ")\n");
	}
	lld ans = -1;
	set<int> con;
	for(auto i: mp){
		for(auto j: i.SS){
			if(j.SS==1) con.insert(j.FF);
			else if(j.SS==0) con.erase(j.FF);
		}
		DEBUG("at ", i.FF, ": ", con, '\n');
		ans = max(ans, SZ(con)*(i.FF*inc + bty));
	}
	end(ans);
	return 0;
}


//{{{By oToToT
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <bitset>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <random>
#include <utility>
#include <stack>
#include <sstream>
#include <functional>
#include <deque>
#include <cassert>
using namespace std;
/* include everything for Kotori~ <3 */

typedef long long lld;
typedef unsigned long long llu;
typedef long double llf;
typedef pair<int,int> PII;
typedef pair<int,lld> PIL;
typedef pair<lld,int> PLI;
typedef pair<lld,lld> PLL;
template<typename T>
using maxHeap = priority_queue<T,vector<T>,less<T>>;
template<typename T>
using minHeap = priority_queue<T,vector<T>,greater<T>>;
/* define some types for Ruby! */

#define FF first
#define SS second
#define SZ(x) (int)(x.size())
#define ALL(x) begin(x), end(x)
#define PB push_back
#define WC(x) while(x--)
/* make code shorter for Di~a~ */

template<typename Iter>
ostream& _out(ostream &s, Iter b, Iter e) {
	s<<"[";
	for ( auto it=b; it!=e; it++ ) s<<(it==b?"":" ")<<*it;
	s<<"]";
	return s;
}
template<typename A, typename B>
ostream& operator <<( ostream &s, const pair<A,B> &p ) { return s<<"("<<p.FF<<","<<p.SS<<")"; }
template<typename T>
ostream& operator <<( ostream &s, const vector<T> &c ) { return _out(s,ALL(c)); }
template<typename T>
ostream& operator <<( ostream &s, const set<T> &c ) { return _out(s,ALL(c)); }
/* make output easier for Ainyan~n~ */

bool debug = 0;
#define DUMP(x) if(debug) cerr<<__PRETTY_FUNCTION__<<":"<<__LINE__<<" - "<<#x<<"="<<x<<'\n'
template<typename T>
void DEBUG(const T& x){if(debug) cerr<<x;}
template<typename T, typename... Args>
void DEBUG(const T& head,const Args& ...tail){
	if(debug){cerr<<head; DEBUG(tail...);}
}
/* Let's debug with Nico~Nico~Ni */
//}}}
const int N = 100000 + 5;
const lld INF = 1LL<<60;

inline void end(int x){cout << x << '\n'; exit(0);}
template<typename T>
inline void mini(T& a, const T& b){if(b < a) a = b;}

struct Mon{
	lld mx, jie, xie;
} arr[2*N];
int pre[2*N];
lld pop[2*N], push[2*N];

struct Obj{
	lld t, id, jie;
	bool operator<(const Obj& x) const {return t < x.t;}
};
vector<Obj> tmp;

map<lld, vector<pair<int,int>>> mp;

int main(int argc, char* argv[]){
	if(argc>1 and string(argv[1])=="-D") debug=1;
	if(!debug){ios_base::sync_with_stdio(0);cin.tie(0);}
	int n, m; cin>>n>>m;
	fill_n(pop, n+m, INF);
	fill_n(push, n+m, INF);
	// inc*time + bty
	lld bty, inc, dmg; cin>>bty>>inc>>dmg;
	for(int i=0;i<n;i++){
		lld mx, jie, xie; cin>>mx>>jie>>xie;
		if(inc!=0 and mx <= dmg) end(-1);
		if(xie != 0) mini(pop[i], (dmg-jie+xie)/xie);
		if(jie > dmg) pop[i] = 0;
		arr[i] = {mx, jie, xie};
		pre[i] = i;
		push[i] = 0;
	}
	for(int i=0;i<m;i++){
		lld t, id, jie; cin>>t>>id>>jie;
		tmp.PB({t, id, jie});
	}
	sort(ALL(tmp));
	for(int i=0;i<m;i++){
		lld t=tmp[i].t, id=tmp[i].id, jie=tmp[i].jie;
		int &p = pre[id-1]; mini(pop[p], t);
		DUMP(dmg-jie);
		if(arr[p].xie != 0) mini(pop[i+n], t+(dmg-jie+arr[p].xie)/arr[p].xie);
		if(jie > dmg) pop[i+n] = t;
		arr[i+n] = {arr[p].mx, jie, arr[p].xie};
		push[i+n] = t;
		p = i+n;
	}
	for(int i=0;i<n+m;i++){
		if(pop[i] <= push[i]) continue;
		if(push[i]!=INF){
			mp[push[i]-1].PB({-7122, 2});
			mp[push[i]].PB({i, 1});
			mp[push[i]+1].PB({-7122, 2});
		}
		if(pop[i]!=INF){
			mp[pop[i]-1].PB({-7122, 2});
			mp[pop[i]].PB({i, 0});
			mp[pop[i]+1].PB({-7122, 2});
		}
		DEBUG(i, ": [", push[i], ", ", pop[i], ")\n");
	}
	lld ans = 0;
	set<int> con;
	for(auto i: mp){
		for(auto j: i.SS){
			if(j.SS==1) con.insert(j.FF);
			else if(j.SS==0) con.erase(j.FF);
		}
		DEBUG("at ", i.FF, ": ", con, '\n');
		ans = max(ans, SZ(con)*(i.FF*inc + bty));
	}
	end(ans);
	return 0;
}


//{{{By oToToT
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <bitset>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <random>
#include <utility>
#include <stack>
#include <sstream>
#include <functional>
#include <deque>
#include <cassert>
using namespace std;
/* include everything for Kotori~ <3 */

typedef long long lld;
typedef unsigned long long llu;
typedef long double llf;
typedef pair<int,int> PII;
typedef pair<int,lld> PIL;
typedef pair<lld,int> PLI;
typedef pair<lld,lld> PLL;
template<typename T>
using maxHeap = priority_queue<T,vector<T>,less<T>>;
template<typename T>
using minHeap = priority_queue<T,vector<T>,greater<T>>;
/* define some types for Ruby! */

#define FF first
#define SS second
#define SZ(x) (int)(x.size())
#define ALL(x) begin(x), end(x)
#define PB push_back
#define WC(x) while(x--)
/* make code shorter for Di~a~ */

template<typename Iter>
ostream& _out(ostream &s, Iter b, Iter e) {
	s<<"[";
	for ( auto it=b; it!=e; it++ ) s<<(it==b?"":" ")<<*it;
	s<<"]";
	return s;
}
template<typename A, typename B>
ostream& operator <<( ostream &s, const pair<A,B> &p ) { return s<<"("<<p.FF<<","<<p.SS<<")"; }
template<typename T>
ostream& operator <<( ostream &s, const vector<T> &c ) { return _out(s,ALL(c)); }
template<typename T>
ostream& operator <<( ostream &s, const set<T> &c ) { return _out(s,ALL(c)); }
/* make output easier for Ainyan~n~ */

bool debug = 0;
#define DUMP(x) if(debug) cerr<<__PRETTY_FUNCTION__<<":"<<__LINE__<<" - "<<#x<<"="<<x<<'\n'
template<typename T>
void DEBUG(const T& x){if(debug) cerr<<x;}
template<typename T, typename... Args>
void DEBUG(const T& head,const Args& ...tail){
	if(debug){cerr<<head; DEBUG(tail...);}
}
/* Let's debug with Nico~Nico~Ni */
//}}}
const int N = 100000 + 5;
const lld INF = 1LL<<60;

inline void end(int x){cout << x << '\n'; exit(0);}
template<typename T>
inline void mini(T& a, const T& b){if(b < a) a = b;}

struct Mon{
	lld mx, jie, xie;
} arr[2*N];
int pre[2*N];
lld pop[2*N], push[2*N];

map<lld, vector<pair<int,int>>> mp;

int main(int argc, char* argv[]){
	if(argc>1 and string(argv[1])=="-D") debug=1;
	if(!debug){ios_base::sync_with_stdio(0);cin.tie(0);}
	int n, m; cin>>n>>m;
	fill_n(pop, n+m, INF);
	fill_n(push, n+m, INF);
	// inc*time + bty
	lld bty, inc, dmg; cin>>bty>>inc>>dmg;
	for(int i=0;i<n;i++){
		lld mx, jie, xie; cin>>mx>>jie>>xie;
		if(inc!=0 and mx <= dmg) end(-1);
		if(xie != 0) mini(pop[i], (dmg-jie+xie)/xie);
		if(jie > dmg) pop[i] = 0;
		arr[i] = {mx, jie, xie};
		pre[i] = i;
		if(jie <= dmg) push[i] = 0;
	}
	for(int i=0;i<m;i++){
		lld t, id, jie; cin>>t>>id>>jie;
		int &p = pre[id-1]; mini(pop[p], t);
		DUMP(dmg-jie);
		if(arr[p].xie != 0) mini(pop[i+n], t+(dmg-jie+arr[p].xie)/arr[p].xie);
		if(jie > dmg) pop[i+n] = t;
		arr[i+n] = {arr[p].mx, jie, arr[p].xie};
		if(jie <= dmg) push[i+n] = t;
		p = i+n;
	}
	for(int i=0;i<n+m;i++){
		if(push[i]!=INF){
			mp[push[i]-1].PB({-7122, 2});
			mp[push[i]].PB({i, 1});
			mp[push[i]+1].PB({-7122, 2});
		}
		if(pop[i]!=INF){
			mp[pop[i]-1].PB({-7122, 2});
			mp[pop[i]].PB({i, 0});
			mp[pop[i]+1].PB({-7122, 2});
		}
		DEBUG(i, ": [", push[i], ", ", pop[i], ")\n");
	}
	lld ans = -1;
	set<int> con;
	for(auto i: mp){
		for(auto j: i.SS){
			if(j.SS==1) con.insert(j.FF);
			else if(j.SS==0) con.erase(j.FF);
		}
		DEBUG("at ", i.FF, ": ", con, '\n');
		ans = max(ans, SZ(con)*(i.FF*inc + bty));
	}
	end(ans);
	return 0;
}


//{{{By oToToT
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <bitset>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <random>
#include <utility>
#include <stack>
#include <sstream>
#include <functional>
#include <deque>
#include <cassert>
using namespace std;
/* include everything for Kotori~ <3 */

typedef long long lld;
typedef unsigned long long llu;
typedef long double llf;
typedef pair<int,int> PII;
typedef pair<int,lld> PIL;
typedef pair<lld,int> PLI;
typedef pair<lld,lld> PLL;
template<typename T>
using maxHeap = priority_queue<T,vector<T>,less<T>>;
template<typename T>
using minHeap = priority_queue<T,vector<T>,greater<T>>;
/* define some types for Ruby! */

#define FF first
#define SS second
#define SZ(x) (int)(x.size())
#define ALL(x) begin(x), end(x)
#define PB push_back
#define WC(x) while(x--)
/* make code shorter for Di~a~ */

template<typename Iter>
ostream& _out(ostream &s, Iter b, Iter e) {
	s<<"[";
	for ( auto it=b; it!=e; it++ ) s<<(it==b?"":" ")<<*it;
	s<<"]";
	return s;
}
template<typename A, typename B>
ostream& operator <<( ostream &s, const pair<A,B> &p ) { return s<<"("<<p.FF<<","<<p.SS<<")"; }
template<typename T>
ostream& operator <<( ostream &s, const vector<T> &c ) { return _out(s,ALL(c)); }
template<typename T>
ostream& operator <<( ostream &s, const set<T> &c ) { return _out(s,ALL(c)); }
/* make output easier for Ainyan~n~ */

bool debug = 0;
#define DUMP(x) if(debug) cerr<<__PRETTY_FUNCTION__<<":"<<__LINE__<<" - "<<#x<<"="<<x<<'\n'
template<typename T>
void DEBUG(const T& x){if(debug) cerr<<x;}
template<typename T, typename... Args>
void DEBUG(const T& head,const Args& ...tail){
	if(debug){cerr<<head; DEBUG(tail...);}
}
/* Let's debug with Nico~Nico~Ni */
//}}}
const int N = 100000 + 5;
const lld INF = 1LL<<60;

inline void end(int x){cout << x << '\n'; exit(0);}
template<typename T>
inline void mini(T& a, const T& b){if(b < a) a = b;}

struct Mon{
	lld mx, jie, xie;
} arr[2*N];
int pre[2*N];
lld pop[2*N], push[2*N];

map<lld, vector<pair<int,int>>> mp;

int main(int argc, char* argv[]){
	if(argc>1 and string(argv[1])=="-D") debug=1;
	if(!debug){ios_base::sync_with_stdio(0);cin.tie(0);}
	int n, m; cin>>n>>m;
	fill_n(pop, n+m, INF);
	fill_n(push, n+m, INF);
	// inc*time + bty
	lld bty, inc, dmg; cin>>bty>>inc>>dmg;
	for(int i=0;i<n;i++){
		lld mx, jie, xie; cin>>mx>>jie>>xie;
		if(inc!=0 and mx <= dmg) end(-1);
		if(xie != 0) mini(pop[i], (dmg-jie+xie)/xie);
		if(jie > dmg) pop[i] = 0;
		arr[i] = {mx, jie, xie};
		pre[i] = i;
		push[i] = 0;
	}
	for(int i=0;i<m;i++){
		lld t, id, jie; cin>>t>>id>>jie;
		int &p = pre[id-1]; mini(pop[p], t);
		DUMP(dmg-jie);
		if(arr[p].xie != 0) mini(pop[i+n], t+(dmg-jie+arr[p].xie)/arr[p].xie);
		if(jie > dmg) pop[i+n] = t;
		arr[i+n] = {arr[p].mx, jie, arr[p].xie};
		push[i+n] = t;
		p = i+n;
	}
	for(int i=0;i<n+m;i++){
		if(push[i]!=INF){
			mp[push[i]-1].PB({-7122, 2});
			mp[push[i]].PB({i, 1});
			mp[push[i]+1].PB({-7122, 2});
		}
		if(pop[i]!=INF){
			mp[pop[i]-1].PB({-7122, 2});
			mp[pop[i]].PB({i, 0});
			mp[pop[i]+1].PB({-7122, 2});
		}
		DEBUG(i, ": [", push[i], ", ", pop[i], ")\n");
	}
	lld ans = -1;
	set<int> con;
	for(auto i: mp){
		for(auto j: i.SS){
			if(j.SS==1) con.insert(j.FF);
			else if(j.SS==0) con.erase(j.FF);
		}
		DEBUG("at ", i.FF, ": ", con, '\n');
		ans = max(ans, SZ(con)*(i.FF*inc + bty));
	}
	end(ans);
	return 0;
}


//{{{By oToToT
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <bitset>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <random>
#include <utility>
#include <stack>
#include <sstream>
#include <functional>
#include <deque>
#include <cassert>
using namespace std;
/* include everything for Kotori~ <3 */

typedef long long lld;
typedef unsigned long long llu;
typedef long double llf;
typedef pair<int,int> PII;
typedef pair<int,lld> PIL;
typedef pair<lld,int> PLI;
typedef pair<lld,lld> PLL;
template<typename T>
using maxHeap = priority_queue<T,vector<T>,less<T>>;
template<typename T>
using minHeap = priority_queue<T,vector<T>,greater<T>>;
/* define some types for Ruby! */

#define FF first
#define SS second
#define SZ(x) ((int)(x.size()))
#define ALL(x) begin(x), end(x)
#define PB push_back
#define WC(x) while(x--)
/* make code shorter for Di~a~ */

template<typename Iter>
ostream& _out(ostream &s, Iter b, Iter e) {
	s<<"[";
	for ( auto it=b; it!=e; it++ ) s<<(it==b?"":" ")<<*it;
	s<<"]";
	return s;
}
template<typename A, typename B>
ostream& operator <<( ostream &s, const pair<A,B> &p ) { return s<<"("<<p.FF<<","<<p.SS<<")"; }
template<typename T>
ostream& operator <<( ostream &s, const vector<T> &c ) { return _out(s,ALL(c)); }
template<typename T>
ostream& operator <<( ostream &s, const set<T> &c ) { return _out(s,ALL(c)); }
/* make output easier for Ainyan~n~ */

bool debug = 0;
#define DUMP(x) if(debug) cerr<<__PRETTY_FUNCTION__<<":"<<__LINE__<<" - "<<#x<<"="<<x<<'\n'
template<typename T>
void DEBUG(const T& x){if(debug) cerr<<x;}
template<typename T, typename... Args>
void DEBUG(const T& head,const Args& ...tail){
	if(debug){cerr<<head; DEBUG(tail...);}
}
/* Let's debug with Nico~Nico~Ni */
//}}}
const int N = 100000 + 5;
const lld INF = 1LL<<60;

inline void end(lld x){cout << x << '\n'; exit(0);}
template<typename T>
inline void mini(T& a, const T& b){if(b < a) a = b;}

struct Mon{
	lld mx, jie, xie;
} arr[2*N];
int pre[2*N];
lld pop[2*N], push[2*N];

struct Obj{
	lld t, id, jie;
	bool operator<(const Obj& x) const {return t < x.t;}
};
vector<Obj> tmp;

map<lld, vector<pair<int,int>>> mp;

int main(int argc, char* argv[]){
	if(argc>1 and string(argv[1])=="-D") debug=1;
	if(!debug){ios_base::sync_with_stdio(0);cin.tie(0);}
	int n, m; cin>>n>>m;
	fill_n(pop, n+m, INF);
	fill_n(push, n+m, INF);
	// inc*time + bty
	lld bty, inc, dmg; cin>>bty>>inc>>dmg;
	for(int i=0;i<n;i++){
		lld mx, jie, xie; cin>>mx>>jie>>xie;
		if(inc!=0 and mx <= dmg) end(-1);
		if(xie != 0) mini(pop[i], (dmg-jie+xie)/xie);
		if(jie > dmg) pop[i] = 0;
		arr[i] = {mx, jie, xie};
		pre[i] = i;
		push[i] = 0;
	}
	for(int i=0;i<m;i++){
		lld t, id, jie; cin>>t>>id>>jie;
		tmp.PB({t, id, jie});
	}
	sort(ALL(tmp));
	for(int i=0;i<m;i++){
		lld t=tmp[i].t, id=tmp[i].id, jie=tmp[i].jie;
		int &p = pre[id-1]; mini(pop[p], t);
		if(arr[p].xie != 0) mini(pop[i+n], t+(dmg-jie+arr[p].xie)/arr[p].xie);
		if(jie > dmg) pop[i+n] = t;
		arr[i+n] = {arr[p].mx, jie, arr[p].xie};
		push[i+n] = t;
		p = i+n;
	}
	for(int i=0;i<n+m;i++){
		if(pop[i] <= push[i]) continue;
		if(push[i]!=INF) mp[push[i]].PB({i, 1});
		if(pop[i]!=INF){
			mp[pop[i]-1].PB({-7122, 2});
			mp[pop[i]].PB({i, 0});
		}
	}
	lld ans = 0;
	set<int> con;
	for(auto &i: mp){
		sort(ALL(i.SS));
		for(auto j: i.SS){
			if(j.SS==1) con.insert(j.FF);
			else if(j.SS==0) con.erase(j.FF);
		}
		ans = max(ans, 1LL*SZ(con)*1LL*(1LL*i.FF*inc + bty));
	}
	if(!con.empty() and inc!=0) end(-1);
	end(ans);
	return 0;
}


//{{{By oToToT
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <bitset>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <random>
#include <utility>
#include <stack>
#include <sstream>
#include <functional>
#include <deque>
#include <cassert>
using namespace std;
/* include everything for Kotori~ <3 */

typedef long long lld;
typedef unsigned long long llu;
typedef long double llf;
typedef pair<int,int> PII;
typedef pair<int,lld> PIL;
typedef pair<lld,int> PLI;
typedef pair<lld,lld> PLL;
template<typename T>
using maxHeap = priority_queue<T,vector<T>,less<T>>;
template<typename T>
using minHeap = priority_queue<T,vector<T>,greater<T>>;
/* define some types for Ruby! */

#define FF first
#define SS second
#define SZ(x) (int)(x.size())
#define ALL(x) begin(x), end(x)
#define PB push_back
#define WC(x) while(x--)
/* make code shorter for Di~a~ */

template<typename Iter>
ostream& _out(ostream &s, Iter b, Iter e) {
	s<<"[";
	for ( auto it=b; it!=e; it++ ) s<<(it==b?"":" ")<<*it;
	s<<"]";
	return s;
}
template<typename A, typename B>
ostream& operator <<( ostream &s, const pair<A,B> &p ) { return s<<"("<<p.FF<<","<<p.SS<<")"; }
template<typename T>
ostream& operator <<( ostream &s, const vector<T> &c ) { return _out(s,ALL(c)); }
template<typename T>
ostream& operator <<( ostream &s, const set<T> &c ) { return _out(s,ALL(c)); }
/* make output easier for Ainyan~n~ */

bool debug = 0;
#define DUMP(x) if(debug) cerr<<__PRETTY_FUNCTION__<<":"<<__LINE__<<" - "<<#x<<"="<<x<<'\n'
template<typename T>
void DEBUG(const T& x){if(debug) cerr<<x;}
template<typename T, typename... Args>
void DEBUG(const T& head,const Args& ...tail){
	if(debug){cerr<<head; DEBUG(tail...);}
}
/* Let's debug with Nico~Nico~Ni */
//}}}
const int N = 100000 + 5;
const lld INF = 1LL<<60;

inline void end(int x){cout << x << '\n'; exit(0);}
template<typename T>
inline void mini(T& a, const T& b){if(b < a) a = b;}

struct Mon{
	lld mx, jie, xie;
} arr[2*N];
int pre[2*N];
lld pop[2*N], push[2*N];

map<lld, vector<pair<int,int>>> mp;

int main(int argc, char* argv[]){
	if(argc>1 and string(argv[1])=="-D") debug=1;
	if(!debug){ios_base::sync_with_stdio(0);cin.tie(0);}
	int n, m; cin>>n>>m;
	fill_n(pop, n+m, INF);
	fill_n(push, n+m, INF);
	// inc*time + bty
	lld bty, inc, dmg; cin>>bty>>inc>>dmg;
	for(int i=0;i<n;i++){
		lld mx, jie, xie; cin>>mx>>jie>>xie;
		if(inc!=0 and mx <= dmg) end(-1);
		if(xie != 0) mini(pop[i], (dmg-jie+xie)/xie);
		if(jie > dmg) pop[i] = 0;
		arr[i] = {mx, jie, xie};
		pre[i] = i;
		push[i] = 0;
	}
	for(int i=0;i<m;i++){
		lld t, id, jie; cin>>t>>id>>jie;
		int &p = pre[id-1]; mini(pop[p], t);
		DUMP(dmg-jie);
		if(arr[p].xie != 0) mini(pop[i+n], t+(dmg-jie+arr[p].xie)/arr[p].xie);
		if(jie > dmg) pop[i+n] = t;
		arr[i+n] = {arr[p].mx, jie, arr[p].xie};
		push[i+n] = t;
		p = i+n;
	}
	for(int i=0;i<n+m;i++){
		if(push[i]!=INF){
			mp[push[i]-1].PB({-7122, 2});
			mp[push[i]].PB({i, 1});
			mp[push[i]+1].PB({-7122, 2});
		}
		if(pop[i]!=INF){
			mp[pop[i]-1].PB({-7122, 2});
			mp[pop[i]].PB({i, 0});
			mp[pop[i]-1].PB({-7122, 2});
		}
		DEBUG(i, ": [", push[i], ", ", pop[i], ")\n");
	}
	lld ans = -1;
	set<int> con;
	for(auto i: mp){
		for(auto j: i.SS){
			if(j.SS==1) con.insert(j.FF);
			else if(j.SS==0) con.erase(j.FF);
		}
		DEBUG("at ", i.FF, ": ", con, '\n');
		ans = max(ans, SZ(con)*(i.FF*inc + bty));
	}
	end(ans);
	return 0;
}


//{{{By oToToT
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <bitset>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <random>
#include <utility>
#include <stack>
#include <sstream>
#include <functional>
#include <deque>
#include <cassert>
using namespace std;
/* include everything for Kotori~ <3 */

typedef long long lld;
typedef unsigned long long llu;
typedef long double llf;
typedef pair<int,int> PII;
typedef pair<int,lld> PIL;
typedef pair<lld,int> PLI;
typedef pair<lld,lld> PLL;
template<typename T>
using maxHeap = priority_queue<T,vector<T>,less<T>>;
template<typename T>
using minHeap = priority_queue<T,vector<T>,greater<T>>;
/* define some types for Ruby! */

#define FF first
#define SS second
#define SZ(x) ((int)(x.size()))
#define ALL(x) begin(x), end(x)
#define PB push_back
#define WC(x) while(x--)
/* make code shorter for Di~a~ */

template<typename Iter>
ostream& _out(ostream &s, Iter b, Iter e) {
	s<<"[";
	for ( auto it=b; it!=e; it++ ) s<<(it==b?"":" ")<<*it;
	s<<"]";
	return s;
}
template<typename A, typename B>
ostream& operator <<( ostream &s, const pair<A,B> &p ) { return s<<"("<<p.FF<<","<<p.SS<<")"; }
template<typename T>
ostream& operator <<( ostream &s, const vector<T> &c ) { return _out(s,ALL(c)); }
template<typename T>
ostream& operator <<( ostream &s, const set<T> &c ) { return _out(s,ALL(c)); }
/* make output easier for Ainyan~n~ */

bool debug = 0;
#define DUMP(x) if(debug) cerr<<__PRETTY_FUNCTION__<<":"<<__LINE__<<" - "<<#x<<"="<<x<<'\n'
template<typename T>
void DEBUG(const T& x){if(debug) cerr<<x;}
template<typename T, typename... Args>
void DEBUG(const T& head,const Args& ...tail){
	if(debug){cerr<<head; DEBUG(tail...);}
}
/* Let's debug with Nico~Nico~Ni */
//}}}
const int N = 100000 + 5;
const lld INF = 1LL<<60;

inline void end(lld x){cout << x << '\n'; exit(0);}
template<typename T>
inline void mini(T& a, const T& b){if(b < a) a = b;}

struct Mon{
	lld mx, jie, xie;
} arr[2*N];
int pre[2*N];
lld pop[2*N], push[2*N];

struct Obj{
	lld t, id, jie;
	bool operator<(const Obj& x) const {return t < x.t;}
};
vector<Obj> tmp;

map<lld, vector<pair<int,int>>> mp;

int main(int argc, char* argv[]){
	if(argc>1 and string(argv[1])=="-D") debug=1;
	if(!debug){ios_base::sync_with_stdio(0);cin.tie(0);}
	int n, m; cin>>n>>m;
	fill_n(pop, n+m, INF);
	fill_n(push, n+m, INF);
	// inc*time + bty
	lld bty, inc, dmg; cin>>bty>>inc>>dmg;
	for(int i=0;i<n;i++){
		lld mx, jie, xie; cin>>mx>>jie>>xie;
		if(inc!=0 and mx <= dmg) end(-1);
		if(xie != 0) mini(pop[i], (dmg-jie+xie)/xie);
		if(jie > dmg) pop[i] = 0;
		arr[i] = {mx, jie, xie};
		pre[i] = i;
		push[i] = 0;
	}
	for(int i=0;i<m;i++){
		lld t, id, jie; cin>>t>>id>>jie;
		tmp.PB({t, id, jie});
	}
	sort(ALL(tmp));
	for(int i=0;i<m;i++){
		lld t=tmp[i].t, id=tmp[i].id, jie=tmp[i].jie;
		int &p = pre[id-1]; mini(pop[p], t);
		DUMP(dmg-jie);
		if(arr[p].xie != 0) mini(pop[i+n], t+(dmg-jie+arr[p].xie)/arr[p].xie);
		if(jie > dmg) pop[i+n] = t;
		arr[i+n] = {arr[p].mx, jie, arr[p].xie};
		push[i+n] = t;
		p = i+n;
	}
	for(int i=0;i<n+m;i++){
		if(pop[i] <= push[i]) continue;
		if(push[i]!=INF){
			mp[push[i]-1].PB({-7122, 2});
			mp[push[i]].PB({i, 1});
			mp[push[i]+1].PB({-7122, 2});
		}
		if(pop[i]!=INF){
			mp[pop[i]-1].PB({-7122, 2});
			mp[pop[i]].PB({i, 0});
			mp[pop[i]+1].PB({-7122, 2});
		}
		DEBUG(i, ": [", push[i], ", ", pop[i], ")\n");
	}
	lld ans = 0;
	set<int> con;
	for(auto &i: mp){
		sort(ALL(i.SS));
		for(auto j: i.SS){
			if(j.SS==1) con.insert(j.FF);
			else if(j.SS==0) con.erase(j.FF);
		}
		DEBUG("at ", i.FF, ": ", con, '\n');
		ans = max(ans, 1LL*SZ(con)*1LL*(1LL*i.FF*inc + bty));
		DUMP(ans);
	}
	end(ans);
	return 0;
}


//{{{By oToToT
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <bitset>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <random>
#include <utility>
#include <stack>
#include <sstream>
#include <functional>
#include <deque>
#include <cassert>
using namespace std;
/* include everything for Kotori~ <3 */

typedef long long lld;
typedef unsigned long long llu;
typedef long double llf;
typedef pair<int,int> PII;
typedef pair<int,lld> PIL;
typedef pair<lld,int> PLI;
typedef pair<lld,lld> PLL;
template<typename T>
using maxHeap = priority_queue<T,vector<T>,less<T>>;
template<typename T>
using minHeap = priority_queue<T,vector<T>,greater<T>>;
/* define some types for Ruby! */

#define FF first
#define SS second
#define SZ(x) ((int)(x.size()))
#define ALL(x) begin(x), end(x)
#define PB push_back
#define WC(x) while(x--)
/* make code shorter for Di~a~ */

template<typename Iter>
ostream& _out(ostream &s, Iter b, Iter e) {
	s<<"[";
	for ( auto it=b; it!=e; it++ ) s<<(it==b?"":" ")<<*it;
	s<<"]";
	return s;
}
template<typename A, typename B>
ostream& operator <<( ostream &s, const pair<A,B> &p ) { return s<<"("<<p.FF<<","<<p.SS<<")"; }
template<typename T>
ostream& operator <<( ostream &s, const vector<T> &c ) { return _out(s,ALL(c)); }
template<typename T>
ostream& operator <<( ostream &s, const set<T> &c ) { return _out(s,ALL(c)); }
/* make output easier for Ainyan~n~ */

bool debug = 0;
#define DUMP(x) if(debug) cerr<<__PRETTY_FUNCTION__<<":"<<__LINE__<<" - "<<#x<<"="<<x<<'\n'
template<typename T>
void DEBUG(const T& x){if(debug) cerr<<x;}
template<typename T, typename... Args>
void DEBUG(const T& head,const Args& ...tail){
	if(debug){cerr<<head; DEBUG(tail...);}
}
/* Let's debug with Nico~Nico~Ni */
//}}}
const int N = 100000 + 5;
const lld INF = 1LL<<60;

inline void end(lld x){cout << x << '\n'; exit(0);}
template<typename T>
inline void mini(T& a, const T& b){if(b < a) a = b;}

struct Mon{
	lld mx, jie, xie;
} arr[2*N];
int pre[2*N];
lld pop[2*N], push[2*N];

struct Obj{
	lld t, id, jie;
	bool operator<(const Obj& x) const {return t < x.t;}
};
vector<Obj> tmp;

map<lld, vector<pair<int,int>>> mp;

int main(int argc, char* argv[]){
	if(argc>1 and string(argv[1])=="-D") debug=1;
	if(!debug){ios_base::sync_with_stdio(0);cin.tie(0);}
	int n, m; cin>>n>>m;
	fill_n(pop, n+m, INF);
	fill_n(push, n+m, INF);
	// inc*time + bty
	lld bty, inc, dmg; cin>>bty>>inc>>dmg;
	for(int i=0;i<n;i++){
		lld mx, jie, xie; cin>>mx>>jie>>xie;
		if(inc!=0 and mx <= dmg) end(-1);
		if(xie != 0) mini(pop[i], (dmg-jie+xie)/xie);
		if(jie > dmg) pop[i] = 0;
		arr[i] = {mx, jie, xie};
		pre[i] = i;
		push[i] = 0;
	}
	for(int i=0;i<m;i++){
		lld t, id, jie; cin>>t>>id>>jie;
		tmp.PB({t, id, jie});
	}
	sort(ALL(tmp));
	for(int i=0;i<m;i++){
		lld t=tmp[i].t, id=tmp[i].id, jie=tmp[i].jie;
		int &p = pre[id-1]; mini(pop[p], t);
		DUMP(dmg-jie);
		if(arr[p].xie != 0) mini(pop[i+n], t+(dmg-jie+arr[p].xie)/arr[p].xie);
		if(jie > dmg) pop[i+n] = t;
		arr[i+n] = {arr[p].mx, jie, arr[p].xie};
		push[i+n] = t;
		p = i+n;
	}
	for(int i=0;i<n+m;i++){
		if(pop[i] <= push[i]) continue;
		if(push[i]!=INF){
			mp[push[i]-1].PB({-7122, 2});
			mp[push[i]].PB({i, 1});
			mp[push[i]+1].PB({-7122, 2});
		}
		if(pop[i]!=INF){
			mp[pop[i]-1].PB({-7122, 2});
			mp[pop[i]].PB({i, 0});
			mp[pop[i]+1].PB({-7122, 2});
		}
		DEBUG(i, ": [", push[i], ", ", pop[i], ")\n");
	}
	lld ans = 0;
	set<int> con;
	for(auto &i: mp){
		sort(ALL(i.SS));
		for(auto j: i.SS){
			if(j.SS==1) con.insert(j.FF);
			else if(j.SS==0) con.erase(j.FF);
		}
		DEBUG("at ", i.FF, ": ", con, '\n');
		ans = max(ans, 1LL*SZ(con)*1LL*(1LL*i.FF*inc + bty));
		// DUMP(ans);
	}
	if(!con.empty() and inc!=0) end(-1);
	end(ans);
	return 0;
}


//{{{By oToToT
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <bitset>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <random>
#include <utility>
#include <stack>
#include <sstream>
#include <functional>
#include <deque>
#include <cassert>
using namespace std;
/* include everything for Kotori~ <3 */

typedef long long lld;
typedef unsigned long long llu;
typedef long double llf;
typedef pair<int,int> PII;
typedef pair<int,lld> PIL;
typedef pair<lld,int> PLI;
typedef pair<lld,lld> PLL;
template<typename T>
using maxHeap = priority_queue<T,vector<T>,less<T>>;
template<typename T>
using minHeap = priority_queue<T,vector<T>,greater<T>>;
/* define some types for Ruby! */

#define FF first
#define SS second
#define SZ(x) ((int)(x.size()))
#define ALL(x) begin(x), end(x)
#define PB push_back
#define WC(x) while(x--)
/* make code shorter for Di~a~ */

template<typename Iter>
ostream& _out(ostream &s, Iter b, Iter e) {
	s<<"[";
	for ( auto it=b; it!=e; it++ ) s<<(it==b?"":" ")<<*it;
	s<<"]";
	return s;
}
template<typename A, typename B>
ostream& operator <<( ostream &s, const pair<A,B> &p ) { return s<<"("<<p.FF<<","<<p.SS<<")"; }
template<typename T>
ostream& operator <<( ostream &s, const vector<T> &c ) { return _out(s,ALL(c)); }
template<typename T>
ostream& operator <<( ostream &s, const set<T> &c ) { return _out(s,ALL(c)); }
/* make output easier for Ainyan~n~ */

bool debug = 0;
#define DUMP(x) if(debug) cerr<<__PRETTY_FUNCTION__<<":"<<__LINE__<<" - "<<#x<<"="<<x<<'\n'
template<typename T>
void DEBUG(const T& x){if(debug) cerr<<x;}
template<typename T, typename... Args>
void DEBUG(const T& head,const Args& ...tail){
	if(debug){cerr<<head; DEBUG(tail...);}
}
/* Let's debug with Nico~Nico~Ni */
//}}}
const int N = 100000 + 5;
const lld INF = 1LL<<60;

inline void end(lld x){cout << x << '\n'; exit(0);}
template<typename T>
inline void mini(T& a, const T& b){if(b < a) a = b;}

struct Mon{
	lld mx, jie, xie;
} arr[2*N];
int pre[2*N];
lld pop[2*N], push[2*N];

struct Obj{
	lld t, id, jie;
	bool operator<(const Obj& x) const {return t < x.t;}
};
vector<Obj> tmp;

map<lld, vector<pair<int,int>>> mp;

int main(int argc, char* argv[]){
	if(argc>1 and string(argv[1])=="-D") debug=1;
	if(!debug){ios_base::sync_with_stdio(0);cin.tie(0);}
	int n, m; cin>>n>>m;
	fill_n(pop, n+m, INF);
	fill_n(push, n+m, INF);
	// inc*time + bty
	lld bty, inc, dmg; cin>>bty>>inc>>dmg;
	for(int i=0;i<n;i++){
		lld mx, jie, xie; cin>>mx>>jie>>xie;
		if(inc!=0 and mx <= dmg) end(-1);
		if(xie != 0) mini(pop[i], (dmg-jie+xie)/xie);
		if(jie > dmg) pop[i] = 0;
		arr[i] = {mx, jie, xie};
		pre[i] = i;
		push[i] = 0;
	}
	for(int i=0;i<m;i++){
		lld t, id, jie; cin>>t>>id>>jie;
		tmp.PB({t, id, jie});
	}
	sort(ALL(tmp));
	for(int i=0;i<m;i++){
		lld t=tmp[i].t, id=tmp[i].id, jie=tmp[i].jie;
		int &p = pre[id-1]; mini(pop[p], t);
		DUMP(dmg-jie);
		if(arr[p].xie != 0) mini(pop[i+n], t+(dmg-jie+arr[p].xie)/arr[p].xie);
		if(jie > dmg) pop[i+n] = t;
		arr[i+n] = {arr[p].mx, jie, arr[p].xie};
		push[i+n] = t;
		p = i+n;
	}
	for(int i=0;i<n+m;i++){
		if(pop[i] <= push[i]) continue;
		if(push[i]!=INF){
			mp[push[i]-1].PB({-7122, 2});
			mp[push[i]].PB({i, 1});
			mp[push[i]+1].PB({-7122, 2});
		}
		if(pop[i]!=INF){
			mp[pop[i]-1].PB({-7122, 2});
			mp[pop[i]].PB({i, 0});
			mp[pop[i]+1].PB({-7122, 2});
		}
		DEBUG(i, ": [", push[i], ", ", pop[i], ")\n");
	}
	lld ans = 0;
	set<int> con;
	for(auto &i: mp){
		sort(ALL(i.SS));
		for(auto j: i.SS){
			if(j.SS==1) con.insert(j.FF);
			else if(j.SS==0) con.erase(j.FF);
		}
		DEBUG("at ", i.FF, ": ", con, '\n');
		ans = max(ans, 1LL*SZ(con)*1LL*(1LL*i.FF*inc + bty));
		DUMP(ans);
	}
	if(!con.empty()) end(-1);
	end(ans);
	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 - pp;
            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>
#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 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 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});
        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 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()){
        kkkk = max(kkkk, (bounty + en[j]*inc)*cnt);
        j++;
        cnt--;
    }

    cout<<kkkk;

    return 0;
}