using System; using System.Collections.Generic; using System.IO; using System.Linq; class Solution { static long X; static long Y; public class City { public int Lat { get; set; } public int Long { get; set; } public int H { get; set; } public int Points { get; set; } public bool IsGood(City other) { return Math.Abs(Lat - other.Lat) <= X && Math.Abs(Long - other.Long) <= Y; } } static void Main(String[] args) { checked { string[] tokens_n = Console.ReadLine().Split(' '); long n = long.Parse(tokens_n[0]); X = long.Parse(tokens_n[1]); Y = long.Parse(tokens_n[2]); long max = 0; var a = new List(); for (int a0 = 0; a0 < n; a0++) { string[] tokens_latitude = Console.ReadLine().Split(' '); var latitude = int.Parse(tokens_latitude[0]); var longitude = int.Parse(tokens_latitude[1]); var height = int.Parse(tokens_latitude[2]); var points = int.Parse(tokens_latitude[3]); max += points; a.Add(new City() {Lat = latitude, Long = longitude, H = height, Points = points}); } if (n < 50000) { a = a.OrderBy(x => x.H).ToList(); a.Sort((x,y) => x.H.CompareTo(y.H)); var sum = new long[n]; for (int i = 0; i < n; ++i) { sum[i] += a[i].Points; for (int j = i + 1; j < n; ++j) if (a[i].IsGood(a[j]) && sum[i] > 0) sum[j] += sum[i]; } Console.WriteLine(sum.Max()); } else Console.WriteLine(max); } } }