using System; using System.Collections.Generic; using System.IO; using System.Linq; class Solution { static void Main(String[] args) { string[] tokens_n = Console.ReadLine().Split(' '); int n = Convert.ToInt32(tokens_n[0]); int x = Convert.ToInt32(tokens_n[1]); int y = Convert.ToInt32(tokens_n[2]); var cities = new City[n]; for(int a0 = 0; a0 < n; a0++){ string[] tokens_latitude = Console.ReadLine().Split(' '); int latitude = Convert.ToInt32(tokens_latitude[0]); int longitude = Convert.ToInt32(tokens_latitude[1]); int height = Convert.ToInt32(tokens_latitude[2]); int points = Convert.ToInt32(tokens_latitude[3]); cities[a0] = new City(latitude, longitude, height, points); } Array.Sort(cities, new HeightSort()); int totalPoints = 0; City last = null; for(int i = 0; i < n; i++){ var curr = cities[i]; if(i == 0 || (Math.Abs(curr.lat - last.lat) >= x && Math.Abs(curr.lg - last.lg) >= y)){ totalPoints += curr.points; } last == curr; } Console.WriteLine(totalPoints); } } public class City{ public int lat; public int lg; public int height; public int points; public City(int lat, int lg, int h, int p){ this.lat = lat; this.lg = lg; this.height = h; this.points = p; } } public class HeightSort : IComparer{ public int Compare(City x, City y){ return x.height.CompareTo(y.height); } }