#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } //constexpr long long MAX = 5100000; constexpr long long INF = 1LL << 60; constexpr int inf = 1000000007; constexpr long long mod = 1000000007LL; //constexpr long long mod = 998244353LL; const long double PI = acos((long double)(-1)); using namespace std; typedef unsigned long long ull; typedef long long ll; typedef long double ld; constexpr int D = 500; template struct imos2D { vector> data; int H, W; imos2D() :H(0), W(0) {} imos2D(int _H, int _W) :H(_H), W(_W) { data.assign(H, vector(W)); } void add(int sh, int sw, int gh, int gw, T x) { data[sh][sw] += x; if(gw < W) data[sh][gw] -= x; if(gh < H) data[gh][sw] -= x; if(gh & operator[](int i) { return data[i]; } }; int main() { /* cin.tie(nullptr); ios::sync_with_stdio(false); */ constexpr int H = 1001, W = 1001; vector> a(H, vector(W)); int n, kkt; scanf("%d %d", &n, &kkt); for (int i = 0; i < n; i++) { int x, y, HP; scanf("%d %d %d", &x, &y, &HP); x += D, y += D; a[x][y] += HP; } imos2D imos(H, W); while (kkt--) { int sh, sw, gh, gw, d; scanf("%d %d %d %d %d", &sh, &sw, &gh, &gw, &d); sh += D, sw += D, gh += sh, gw += sw; imos.add(sh, sw, gh + 1, gw + 1, -d); } imos.build(); ll res = 0; for (int i = 0; i < H; i++)for (int j = 0; j < W; j++) res += max(0LL, imos[i][j] + a[i][j]); cout << res << endl; return 0; }