#include #include template std::vector vec(int len, T elem) { return std::vector(len, elem); } constexpr int X = 500; constexpr int W = X * 4 + 1; using lint = long long; void solve() { int n, m; std::cin >> n >> m; auto xss = vec(W, vec(W, 0LL)); while (n--) { int x, y; std::cin >> x >> y; std::cin >> xss[x + X][y + X]; } auto yss = vec(W, vec(W, 0LL)); while (m--) { int x, y, h, w, d; std::cin >> x >> y >> h >> w >> d; x += X, y += X, ++h, ++w; yss[x][y] += d; yss[x + h][y] -= d; yss[x][y + w] -= d; yss[x + h][y + w] += d; } for (int x = 0; x < W; ++x) { for (int y = 1; y < W; ++y) { yss[x][y] += yss[x][y - 1]; } } for (int x = 1; x < W; ++x) { for (int y = 0; y < W; ++y) { yss[x][y] += yss[x - 1][y]; } } lint ans = 0; for (int x = 0; x < W; ++x) { for (int y = 0; y < W; ++y) { ans += std::max(0LL, xss[x][y] - yss[x][y]); } } std::cout << ans << "\n"; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }