#include template struct CumulativeSum2D { private: const int h, w; std::vector> cum; public: CumulativeSum2D() = default; CumulativeSum2D(const int n) : cum(n + 2, std::vector(n + 2)), h(n + 2), w(n + 2) {} CumulativeSum2D(const int h, const int w) : cum(h + 2, std::vector(w + 2)), h(h + 2), w(w + 2) {} CumulativeSum2D(const std::vector> &vec) { h = vec.size() + 2, w = vec.front().size() + 2; cum.assign(h, std::vector(w)); for(int i = 0; i < h - 2; i++) for(int j = 0; j < w - 2; j++) cum[i + 1][j + 1] = vec[i][j]; }; void add(const int x, const int y, const T val) { add(x, y, x + 1, y + 1, val); } void add(const int sx, const int sy, const int gx, const int gy, const T val) { assert(sx <= gx); assert(sy <= gy); assert(0 <= sx and sx < h); assert(0 <= sy and sy < w); assert(0 <= gx and gx < h); assert(0 <= gy and gy < w); cum[sx + 1][sy + 1] += val; cum[sx + 1][gy + 1] -= val; cum[gx + 1][sy + 1] -= val; cum[gx + 1][gy + 1] += val; } void build() { for(int i = 0; i < h - 1; i++) for(int j = 0; j < w - 1; j++) cum[i + 1][j + 1] += cum[i + 1][j] + cum[i][j + 1] - cum[i][j]; for(int i = 0; i < h - 1; i++) for(int j = 0; j < w - 1; j++) cum[i + 1][j + 1] += cum[i + 1][j] + cum[i][j + 1] - cum[i][j]; } //return [sx, gx) × [sy, gy) T query(const int sx, const int sy, const int gx, const int gy) const { assert(sx <= gx); assert(sy <= gy); assert(0 <= sx and sx < h); assert(0 <= sy and sy < w); assert(0 <= gx and gx < h); assert(0 <= gy and gy < w); return cum[gx][gy] - cum[sx][gy] - cum[gx][sy] + cum[sx][sy]; } T query(const int x, const int y) const { return query(x, y, x + 1, y + 1); } }; using namespace std; using T = tuple; int res, h, w, n, m, t, u, l, r, a, x, y, b, c; int main() { cin >> h >> w >> n >> m; CumulativeSum2D cs(h, w); vector slimes(n); for(int i = 0; i < n; i++) { cin >> t >> u >> l >> r >> a; slimes[i] = T(--t, u, --l, r, a); } while(m--) { cin >> x >> y >> b >> c; --x, --y; cs.add(max(x - b, 0), max(y - b, 0), min(x + b + 1, h), min(y + b + 1, w), c); } cs.build(); for(auto [sx, gx, sy, gy, a] : slimes) res += cs.query(sx, sy, gx, gy) < a; cout << res << '\n'; return 0; }