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 Rust (1.15.1) (judge verdict: Accepted)

// https://atcoder.jp/contests/agc039/tasks/agc039_d
//
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, [ next / $t:tt ]) => {
        {
            let len = read_value!($iter, usize);
            (0..len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
        }
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! dvec {
    ($t:expr ; $len:expr) => {
        vec![$t; $len]
    };

    ($t:expr ; $len:expr, $($rest:expr),*) => {
        vec![dvec!($t; $($rest),*); $len]
    };
}

#[allow(unused_macros)]
macro_rules! ifv {
    ($t:expr, $a:expr, $b: expr) => {
        if $t { $a } else { $b }
    }
}

#[allow(unused_macros)]
macro_rules! fill {
    ($t:expr, $v:expr) => {
        for i in 0..$t.len() {
            $t[i] = $v;
        }
    };
}

#[allow(unused_macros)]
macro_rules! join {
    ($t:expr, $glue:expr) => {
        $t.into_iter().map(|w| w.to_string()).collect::<Vec<_>>().join($glue)
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

use std::f64::consts::PI;

fn pt(x: i64, l: i64) -> (f64, f64) {
    let rad = 2f64 * PI * (x as f64) / (l as f64);
    (rad.cos(), rad.sin())
}

fn main() {
    input! {
        n: usize, l: i64,
        t: [i64; n]
    };


    let mut total_x = 0f64;
    let mut total_y = 0f64;

    let mut ptn = 0f64;
    for i in 0..n {
        for j in i+1..n {
            let inner_num = (j - i - 1) as f64;
            let outer_num = (n - 1 + i - j) as f64;
            let (inx, iny) = pt(t[i] + t[j], l*2);
            let (oux, ouy) = pt(t[i] + t[j] + l, l*2);

            total_x += inx * outer_num + oux * inner_num;
            total_y += iny * outer_num + ouy * inner_num;
            ptn += inner_num;
            ptn += outer_num;
        }
    }
    ptn /= 3f64;

    println!("{} {}", total_x / ptn, total_y / ptn);
}