Gamdar
GAMDARTM is the newest technology for quantum particle mapping, invented by its namesake Glenn "gamucf" Martin. This technology is useful for mapping High-Speed Particle Trajectories (HSPTs); however, with quantum particles, we can never be certain where the particles actually are.
When planning HSPTs, one useful measurement that GAMDAR needs to supply is the Manhattan distance between two particles. GAMDAR has narrowed down the possible locations for the particles to a set of three-dimensional points, so it will report the expected Manhattan distance between two randomly selected points.
Each point selection is independent, meaning:
- The same point can be selected twice.
- Selecting points in different orders counts as different pairs.
- Each point is equally likely to be chosen.
You are asked to compute this expected Manhattan distance.
Note:
In three dimensions, the Manhattan distance between two points
\((x_1, y_1, z_1)\) and \((x_2, y_2, z_2)\) is:
\(|x_2 - x_1| + |y_2 - y_1| + |z_2 - z_1|\)
Input Specification
The first line contains the integer \(n\)
\((1 ≤ n ≤ 10^5)\) — the number of points.
Each of the next n lines contains three integers \(x\), \(y\), \(z\) \((-10^9 ≤ x, y, z ≤ 10^9)\) representing a point in 3D space.
Output Specification
Output one real number: the expected Manhattan distance between two randomly chosen points.
Your answer must be accurate to an absolute or relative error of \(10^{-6}\).
Sample Input 1
3
0 0 0
1 1 1
2 2 2
Sample Output 1
2.666666666667
Sample Input 2
3
0 1 0
5 2 3
6 1 4
Sample Output 2
4.888888888889
Comments