#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 #include #include #ifdef LOCAL # include "debug_print.hpp" # define debug(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__) #else # define debug(...) (static_cast(0)) #endif using namespace std; #define rep(i,n) for(decltype(n) i=0; i<(n); i++) #define rrep(i,n) for(decltype(n) i=(n)-1; i>=0; i--) #define FOR(i,a,b) for(decltype(a) i=(a); i<(b); i++) #define RFOR(i,a,b) for(decltype(b) i=(b-1); i>=(a); i--) #define ALL(v) v.begin(), v.end() #define RALL(v) v.rbegin(), v.rend() #define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ); #define pb push_back using ll = long long; using D = double; using LD = long double; using P = pair; template using PQ = priority_queue>; template using minPQ = priority_queue, greater>; templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b ostream &operator<<(ostream &os, const pair &p) { os << p.first << " " << p.second; return os; } template istream &operator>>(istream &is, pair &p) { is >> p.first >> p.second; return is; } template ostream &operator<<(ostream &os, const vector &v) { int s = (int)v.size(); for (int i = 0; i < s; i++) os << (i ? " " : "") << v[i]; return os; } template istream &operator>>(istream &is, vector &v) { for (auto &x : v) is >> x; return is; } void in() {} template void in(T &t, U &...u) { cin >> t; in(u...); } void out() { cout << "\n"; } template void out(const T &t, const U &...u) { cout << t; if (sizeof...(u)) cout << sep; out(u...); } void outr() {} template void outr(const T &t, const U &...u) { cout << t; outr(u...); } int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); ll h,w,n,m; in(h,w,n,m); vector t(n),u(n),r(n),l(n),a(n),x(m),y(m),b(m),c(m); rep(i,n) in(t[i], u[i], l[i], r[i], a[i]); rep(i,n){ t[i]--; l[i]--; } rep(i,m) in(x[i], y[i], b[i], c[i]); rep(i,m){ x[i]--; y[i]--; } ll s[h+1][w+1]; rep(i,h+1)rep(j,w+1) s[i][j] = 0; rep(i,m){ int h1 = max(0LL, x[i]-b[i])+1, h2 = min(h, x[i]+b[i]+1)+1; int w1 = max(0LL, y[i]-b[i])+1, w2 = min(w, y[i]+b[i]+1)+1; s[h1][w1] += c[i]; if(h2 <= h && w2 <= w) s[h2][w2] += c[i]; if(w2 <= w) s[h1][w2] -= c[i]; if(h2 <= h) s[h2][w1] -= c[i]; } rep(i,h+1){ rep(j,w) s[i][j+1] += s[i][j]; } rep(j,w+1){ rep(i,h) s[i+1][j] += s[i][j]; } rep(i,h+1){ rep(j,w) s[i][j+1] += s[i][j]; } rep(j,w+1){ rep(i,h) s[i+1][j] += s[i][j]; } int ans = 0; rep(i,n){ int h1 = t[i], h2 = u[i], w1 = l[i], w2 = r[i]; ll dmg = s[h2][w2] - s[h1][w2] - s[h2][w1] + s[h1][w1]; if(dmg < a[i]) ans++; } out(ans); }