Problem:
Score : 1000 points

Problem Statement

Given are N points on the circumference of a circle centered at (0,0) in an xy-plane.
The coordinates of the i-th point are (\cos(\frac{2\pi T_i}{L}),\sin(\frac{2\pi T_i}{L})).

Three distinct points will be chosen uniformly at random from these N points.
Find the expected x- and y-coordinates of the center of the circle inscribed in the triangle formed by the chosen points.

Constraints

3 \leq N \leq 3000

N \leq L \leq 10^9

0 \leq T_i \leq L-1

T_i<T_{i+1}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N L
T_1
:
T_N

Output

Print the expected x- and y-coordinates of the center of the circle inscribed in the triangle formed by the chosen points.
Your output will be considered correct when the absolute or relative error is at most 10^{-9}.

Sample Input 1

3 4
0
1
3

Sample Output 1

0.414213562373095 -0.000000000000000

The three points have the coordinates (1,0), (0,1), and (0,-1). The center of the circle inscribed in the triangle formed by these points is (\sqrt{2}-1,0).

Sample Input 2

4 8
1
3
5
6

Sample Output 2

-0.229401949926902 -0.153281482438188

Sample Input 3

10 100
2
11
35
42
54
69
89
91
93
99

Sample Output 3

0.352886583546338 -0.109065017701873

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <iostream>
#include <cmath>
using namespace std;

int N, L, A[9009];
double x[9009], y[9009];
double rx[9009], ry[9009];

double SIN(double I) {
	return sin(3.141592653589793238 * 2.0 * I);
}

long double COS(double I) {
	return cos(3.141592653589793238 * 2.0 * I);
}

int main() {
	cin >> N >> L;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		x[i] = COS(1.0 * A[i] / L);
		y[i] = SIN(1.0 * A[i] / L);
		rx[i + 1] = rx[i] + COS(0.5 * A[i] / L);
		ry[i + 1] = ry[i] + SIN(0.5 * A[i] / L);
	}
	for (int i = N; i < 3 * N; i++) {
		A[i] = A[i - N] + L;
		rx[i + 1] = rx[i] + COS(0.5 * A[i] / L);
		ry[i + 1] = ry[i] + SIN(0.5 * A[i] / L);
	}

	double ex = 0, ey = 0;

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			if (i == j) continue;
			int s1 = j, s2 = i; if (j > i) s2 += N;
			if (s2 - s1 == 1) continue;

			// ① 最初の座標を求める
			double sx = rx[s2] - rx[s1 + 1]; sx /= (1.0 * (s2 - s1 - 1));
			double sy = ry[s2] - ry[s1 + 1]; sy /= (1.0 * (s2 - s1 - 1));

			// 回転座標を求める
			double ave = (A[s1] + A[s2]) / (2.0 * L);
			ave -= 0.50;

			// ② 座標を回転させる
			double COS1 = COS(0.25 + ave / 2.0);
			double SIN1 = SIN(0.25 + ave / 2.0);
			double tx = COS1 * sx - SIN1 * sy;
			double ty = SIN1 * sx + COS1 * sy;

			// ③ 座標を平行移動させる
			double lx = COS(ave);
			double ly = SIN(ave);
			double vx = tx + lx;
			double vy = ty + ly;

			// ④ 座標を拡大させる
			double bairitsu = sqrtl((lx - x[i]) * (lx - x[i]) + (ly - y[i]) * (ly - y[i]));
			double ax = lx + (vx - lx) * bairitsu;
			double ay = ly + (vy - ly) * bairitsu;
			ex += ax * (1.0L * (s2 - s1 - 1));
			ey += ay * (1.0L * (s2 - s1 - 1));
		}
	}

	double Total = 0.5L * N * (1.0L * N - 1.0L) * (1.0L * N - 2.0L);
	printf("%.12lf %.12lf\n", ex / Total, ey / Total);
	return 0;
}