using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray(); public static void Main() { Solve(); } static void Solve() { var c = NList; var (h, w, n, m) = (c[0], c[1], c[2], c[3]); var sl = NArr(n); var bb = NArr(m); var cum = new long[h + 1, w + 1]; foreach (var b in bb) { var top = Math.Max(0, b[0] - b[2] - 1); var btm = Math.Min(h, b[0] + b[2]); var lft = Math.Max(0, b[1] - b[2] - 1); var rit = Math.Min(w, b[1] + b[2]); cum[top, lft] += b[3]; cum[top, rit] -= b[3]; cum[btm, lft] -= b[3]; cum[btm, rit] += b[3]; } for (var p = 0; p < 2; ++p) { for (var i = 0; i <= h; ++i) for (var j = 0; j < w; ++j) { cum[i, j + 1] += cum[i, j]; } for (var i = 0; i < h; ++i) for (var j = 0; j <= w; ++j) { cum[i + 1, j] += cum[i, j]; } } var ans = 0; foreach (var s in sl) { var dmg = 0L; if (s[0] > 1 && s[2] > 1) dmg += cum[s[0] - 2, s[2] - 2]; if (s[0] > 1) dmg -= cum[s[0] - 2, s[3] - 1]; if (s[2] > 1) dmg -= cum[s[1] - 1, s[2] - 2]; dmg += cum[s[1] - 1, s[3] - 1]; if (dmg < s[4]) ++ans; } WriteLine(ans); } static void DebugTable(T[,] table) { Console.WriteLine("{"); for (var i = 0; i < table.GetLength(0); ++i) { var s = i == 0 ? "{" : " "; for (var j = 0; j < table.GetLength(1); ++j) { s += j > 0 ? ", " : ""; s += table[i, j].ToString(); } s += i == table.GetLength(0) - 1 ? "}" : ""; Console.WriteLine(s); } Console.WriteLine("}"); } }