You are given an array of network towers towers, where towers[i] = [xi, yi, qi] denotes the ith network tower with location (xi, yi) and quality factor qi. All the coordinates are integral coordinates on the X-Y plane, and the distance between the two coordinates is the Euclidean distance.

You are also given an integer radius where a tower is reachable if the distance is less than or equal to radius. Outside that distance, the signal becomes garbled, and the tower is not reachable.

The signal quality of the ith tower at a coordinate (x, y) is calculated with the formula ⌊qi / (1 + d)⌋, where d is the distance between the tower and the coordinate. The network quality at a coordinate is the sum of the signal qualities from all the reachable towers.

Return the array [cx, cy] representing the integral coordinate (cx, cy) where the network quality is maximum. If there are multiple coordinates with the same network quality, return the lexicographically minimum non-negative coordinate.

Note:


	A coordinate (x1, y1) is lexicographically smaller than (x2, y2) if either:

	
		x1 &lt; x2, or
		x1 == x2 and y1 &lt; y2.
	
	
	⌊val⌋ is the greatest integer less than or equal to val (the floor function).


&nbsp;
Example 1:

Input: towers = [[1,2,5],[2,1,7],[3,1,9]], radius = 2
Output: [2,1]
Explanation: At coordinate (2, 1) the total quality is 13.
- Quality of 7 from (2, 1) results in ⌊7 / (1 + sqrt(0)⌋ = ⌊7⌋ = 7
- Quality of 5 from (1, 2) results in ⌊5 / (1 + sqrt(2)⌋ = ⌊2.07⌋ = 2
- Quality of 9 from (3, 1) results in ⌊9 / (1 + sqrt(1)⌋ = ⌊4.5⌋ = 4
No other coordinate has a higher network quality.

Example 2:

Input: towers = [[23,11,21]], radius = 9
Output: [23,11]
Explanation: Since there is only one tower, the network quality is highest right at the tower's location.


Example 3:

Input: towers = [[1,2,13],[2,1,7],[0,1,9]], radius = 2
Output: [1,2]
Explanation: Coordinate (1, 2) has the highest network quality.


&nbsp;
Constraints:


	1 &lt;= towers.length &lt;= 50
	towers[i].length == 3
	0 &lt;= xi, yi, qi &lt;= 50
	1 &lt;= radius &lt;= 50


class Solution:
    def bestCoordinate(self, towers: List[List[int]], radius: int) -> List[int]:
        return max(
            (
                (sum(qi // (1 + dist) for xi, yi, qi in towers if (dist := sqrt((xi - x) ** 2 + (yi - y) ** 2)) <= radius),
                 [x, y]) for x in range(51) for y in range(51)
            ),
            key=lambda x: (x[0], -x[1][0], -x[1][1])
        )[1]
class Solution {
    public int[] bestCoordinate(int[][] towers, int radius) {
        int minX = 51, maxX = 0, minY = 51, maxY = 0, max = 0;
        int[] res = new int[2];
        for(int[] t : towers) {
            minX = Math.min(minX, t[0]);
            maxX = Math.max(maxX, t[0]);
            minY = Math.min(minY, t[1]);
            maxY = Math.max(maxY, t[1]);
        }
        for(int i = minX; i <= maxX; i++) {
            for(int j = minY; j <= maxY; j++) {
                int sum = 0;
                for(int[] t : towers) {
                    int d = (t[0] - i) *(t[0] - i) + (t[1] - j) *(t[1] - j);
                    if(d <= radius * radius) {
                        sum += t[2] /(1+ Math.sqrt(d));    
                    }
                }
                if(sum > max) {
                    max = sum;
                    res = new int[]{i,j};
                }
            }
        }
        return res;
    }
}
class Solution {
public:
    vector<int> bestCoordinate(vector<vector<int>>& towers, int radius) {
        int n = towers.size();
        int sum;
        int ans = 0;
        pair<int,int> ansCoor;
		// Calculate for every 'x's and 'y's 
        for(int x = 0; x <= 50; x++){
            for(int y = 0; y <= 50; y++){
                sum = 0;
                for(const auto it : towers){
                    int xa = it[0];
                    int ya = it[1];
                    int qa = it[2];
					// get the distance between the two points
                    int distance = pow(x - xa, 2) + pow(y - ya, 2);
                    if(distance > radius * radius) {
                        continue;
                    }
					// increment the quality value
                    sum += (int)(qa / (1 + sqrt(distance)));
                }
				// store the maximum ans
                if(sum > ans){
                    ans = sum;
                    ansCoor = {x,y};
                }
            }
        }
        return vector<int>{{ansCoor.first, ansCoor.second}};
    }
};
var bestCoordinate = function(towers, radius) {
    const n = towers.length;
    const grid = [];
    
    for (let i = 0; i <= 50; i++) {
        grid[i] = new Array(51).fill(0);
    }
    
    
    for (let i = 0; i < n; i++) {
        const [x1, y1, quality1] = towers[i];
        
        for (let x2 = 0; x2 <= 50; x2++) {
            for (let y2 = 0; y2 <= 50; y2++) {
                const dist = Math.sqrt((x1 - x2)**2 + (y1 - y2)**2);

                if (dist > radius) continue;

                const network = Math.floor(quality1 / (1 + dist));
                
                grid[x2][y2] += network;
            }
        }
    }
    
	
    let maxX = 0;
    let maxY = 0;
    let maxVal = grid[0][0];
    
    for (let i = 0; i <= 50; i++) {
        for (let j = 0; j <= 50; j++) {
            const val = grid[i][j];
            
            if (val > maxVal) {
                maxVal = val;
                maxX = i;
                maxY = j;
            }
            else if (val === maxVal) {
                if (i < maxX || (i === maxX && j < maxY)) {
                    maxVal = val;
                    maxX = i;
                    maxY = j;
                }
            }
        }
    }
    
    return [maxX, maxY];
};
Coordinate With Maximum Network Quality