There are many ways you might approach this problem, but a simple one is to find the pair of circles that contain all the given points while minimizing the area of the intersection. A naive solution tries all ~\(50^5\) possible pairs of circles and does an \(O(N)\) check to confirm that all of the points lie in the intersection of that pair of circles. Even if we downsample to \(500\) points (the minimum guaranteed by the problem), that's still too slow. We can do some precomputing to make this much faster: for each possible circle center \((x, y)\), the only radius \(R\) we would ever want to use is the smallest one that contains all of the points. This gives us at most \(51^2 \approx 2{,}500\) possible circles to use, and sometimes fewer because \(R\) will be greater than \(50\) for some choices of \((x, y)\). Now we can simply compute the area of the intersection of each of these \(2{,}500^2 \approx 6{,}000{,}000\) pairs, and select the pair with the smallest intersection. If we encounter a tie, we break it arbitrarily. Once we've decided which pair of circles to use, we need to decide which one is \(A\) and which one is \(B\). While the function for generating tree locations may look like it spreads trees evenly across a given circle, it's actually biased towards placing trees towards the center of \(A\). The function generates \(r\) uniformly from \([0, R)\), which means (for example) that half of the points will land within a radius of \(R/2\) which is only a quarter of the area of the whole circle. If we compute the sum of distances from each point to the centers of the two circles, the circle with the lower sum is more likely to be \(A\). Empirically, this approach correctly predicts approximately \(90\%\) of the cases when \(500\) points are sampled.