#include "bits/stdc++.h" using namespace std; #define DEBUG(x) cout<<#x<<": "< #define vl vector #define vii vector< vector > #define vll vector< vector > #define vs vector #define pii pair #define pis pair #define psi pair #define pll pair #define fi first #define se second #define rep(i,n) for(int i=0;i<(int)(n);i++) #define rep1(i,n) for(int i=1;i<=(int)(n);i++) #define all(c) c.begin(),c.end() const int inf = 1000000001; const ll INF = 2e18; const ll MOD = 1000000007; const ll mod = 1000000009; const double pi = 3.14159265358979323846; #define Sp(p) cout<> n >> k; vll sum(1510, vl(1510)); rep(i, n) { int x, y, h; cin >> x >> y >> h; x += 500; y += 500; sum[y][x + 1] += h; sum[y][x + 2] += -h; } /* for (int i = 490; i <= 510; i++) { for (int j = 490; j <= 510; j++) { cout << sum[i][j] << " "; } cout << endl; } cout << endl; //*/ rep(i, k) { int x, y, w, h, d; cin >> x >> y >> w >> h >> d; x += 500; y += 500; for (int j = y; j <= y + h; j++) { sum[j][x + 1] += -d; sum[j][x + w + 2] += d; } } /* for (int i = 490; i <= 510; i++) { for (int j = 490; j <= 510; j++) { cout << sum[i][j] << " "; } cout << endl; } cout << endl; //*/ rep(i,1010) { rep1(j,1010) { sum[i][j] += sum[i][j - 1]; } } int ans = 0; rep(i,1010) { rep(j,1010) { if (sum[i][j] >= 0) { ans += sum[i][j]; } } } cout << ans << endl; }