namespace AtCoder; #nullable enable using System.Numerics; static class Extensions { public static T[] Repeat(this int time, Func F) => Enumerable.Range(0, time).Select(_ => F()).ToArray(); } class UnionFind { (int parent, int size)[] Verticals { get; set; } public UnionFind(int verticals) { Verticals = new (int, int)[verticals]; for (int i = 0; i < verticals; i++) Verticals[i] = (i, 1); } public int Union(int x, int y) { (x, y) = (Find(x), Find(y)); if (Size(x) < Size(y)) (x, y) = (y, x); if (x == y) return x; Verticals[x].size += Verticals[y].size; Verticals[y].parent = x; return x; } public int Find(int x) => Parent(x).parent; public int Size(int x) => Parent(x).size; (int parent, int size) Parent(int x) { var parentId = Verticals[x].parent; if (parentId == x) return Verticals[x]; var parent = Parent(parentId); Verticals[x].parent = parent.parent; return parent; } } class AtCoder { object? Solve() { var h = Int(); var w = Int(); var n = Int(); var d = Int(); var g = new int[h, w]; for (var i = 0; i < h; i++) for (var j = 0; j < w; j++) g[i, j] = -1; for (var i = 0; i < n; i++) { var x = Int() - 1; var y = Int() - 1; g[x, y] = i; } bool Inside(int x, int y) => 0 <= x && x < h && 0 <= y && y < w; var uf = new UnionFind(n); for (var x = 0; x < h; x++) for (var y = 0; y < w; y++) if (g[x, y] >= 0) { var v = g[x, y]; for (var ds = 1; ds <= d; ds++) for (var dx = 0; dx <= ds; dx++) { var dy = ds - dx; var dc = new[]{ (x + dx, y + dy), (x + dx, y - dy), (x - dx, y + dy), (x - dx, y - dy) }; foreach (var (nx, ny) in dc) { if (!Inside(nx, ny)) continue; var nv = g[nx, ny]; if (nv < 0) continue; var u = uf.Union(v, nv); g[x, y] = g[nx, ny] = u; } } } int o; { var s = new HashSet(); for (var x = 0; x < h; x++) for (var y = 0; y < w; y++) if (g[x, y] >= 0) { var v = g[x, y]; var par = uf.Find(v); if (uf.Size(par) == 1) continue; s.Add(par); } o = s.Count; } var min = int.MaxValue / 2; var max = int.MinValue / 2; for (var x = 0; x < h; x++) for (var y = 0; y < w; y++) if (g[x, y] < 0) { var s = new HashSet(); var os = new HashSet(); for (var ds = 1; ds <= d; ds++) for (var dx = 0; dx <= ds; dx++) { var dy = ds - dx; var dc = new[]{ (x + dx, y + dy), (x + dx, y - dy), (x - dx, y + dy), (x - dx, y - dy) }; foreach (var (nx, ny) in dc) { if (!Inside(nx, ny)) continue; var nv = g[nx, ny]; if (nv < 0) continue; var par = uf.Find(nv); if (uf.Size(par) == 1) os.Add(par); else s.Add(par); } } var c = s.Count - 1; if (c < 0) c = 0; if (os.Count > 0) c--; min = Math.Min(min, o - c); max = Math.Max(max, o - c); } return min + " " + max; } public static void Main() => new AtCoder().Run(); public void Run() { var res = Solve(); if (res != null) { if (res is bool yes) res = yes ? "Yes" : "No"; sw.WriteLine(res); } sw.Flush(); } string[] input = Array.Empty(); int iter = 0; readonly StreamWriter sw = new(Console.OpenStandardOutput()) { AutoFlush = false }; #pragma warning disable IDE0051 string String() { while (iter >= input.Length) (input, iter) = (Console.ReadLine()!.Split(' '), 0); return input[iter++]; } T Input() where T : IParsable => T.Parse(String(), null); int Int() => Input(); void Out(object? x, string? separator = null) { separator ??= Environment.NewLine; if (x is System.Collections.IEnumerable obj and not string) { var firstLine = true; foreach (var item in obj) { if (!firstLine) sw.Write(separator); firstLine = false; sw.Write(item); } } else sw.Write(x); sw.WriteLine(); } #pragma warning restore IDE0051 }