// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 macro_rules! input { ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char) .skip_while(|c|c.is_whitespace()) .take_while(|c|!c.is_whitespace()) .collect() }; input_inner!{next, $($r)*} }; } macro_rules! input_inner { ($next:expr) => {}; ($next:expr,) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} }; } macro_rules! read_value { ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::>() }; ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error")); } /// Complex numbers. /// Verified by: ATC001-C (http://atc001.contest.atcoder.jp/submissions/1175487) mod complex { use std::ops::{Add, Sub, Mul, Neg}; #[derive(Clone, Copy, Debug)] pub struct Complex { pub x: T, pub y: T, } impl Complex { pub fn new(x: T, y: T) -> Self { Complex { x: x, y: y } } } impl Add for Complex where T: Add { type Output = Self; fn add(self, other: Self) -> Self { Self::new(self.x + other.x, self.y + other.y) } } impl Sub for Complex where T: Sub { type Output = Self; fn sub(self, other: Self) -> Self { Self::new(self.x - other.x, self.y - other.y) } } impl Mul for Complex where T: Add + Sub + Mul { type Output = Self; fn mul(self, other: Self) -> Self { Self::new(self.x * other.x - self.y * other.y, self.x * other.y + self.y * other.x) } } impl> Complex { pub fn conj(self) -> Self { Self::new(self.x, -self.y) } } } // complex // https://yukicoder.me/problems/no/1385 (3) // 三角形の面積は 点の座標に関する線形関数 + 定数 として表せるので、累積和ができる。 // 具体的には、複素数 a, b, c に対してこれらを頂点とする三角形の面積は |Im((b-c)conj(a-c))|/2 である。 // 絶対値の中身は a, b, c が反時計回りに並んでいる時に正。 // 点列を時計回りに a[0], ..., a[N-1] として、j < k < i のときの a = a[j], b = a[k], c = a[i] としたときの和を計算することにする。 // p[i] = \sum_{j < k < i} conj(a[j])a[k] が計算できていれば、c = a[i] のときの Im 内部の和は // (p[i] - conj(a[i]) \sum_{j < i} ja[j] - a[i] \sum_{j 0 { p[i + 1] = p[i] + a[i] * r[i].conj(); } } let mut ans = Complex::new(0.0, 0.0); for i in 0..n { ans = ans + p[i] - a[i].conj() * q[i] + a[i] * q[i].conj() - a[i] * r[i].conj() * Complex::new(i as f64 - 1.0, 0.0); } let nn = n as f64; println!("{}", ans.y * 3.0 / nn / (nn - 1.0) / (nn - 2.0)); }