#include #include #include #include #include #include #include #include #include constexpr int DIGITS = 12; template using RowVector = std::valarray; template using Matrix = std::valarray>; template T determinant(Matrix a) { static_assert(std::is_floating_point() == true, "Use floating point numbers"); auto n = a.size(); assert(n > 0 and a[0].size() == n); for (decltype(n) i = 0; i < n; i++) { for (decltype(n) j = 0; j < n; j++) { if (i < j) { auto b = a[j][i] / a[i][i]; for (decltype(n) k = 0; k < n; k++) { a[j][k] -= a[i][k] * b; } } } } T d = 1; for (decltype(n) i = 0; i < n; i++) { d *= a[i][i]; } return d; } template T norm(RowVector v) { static_assert(std::is_floating_point() == true, "Use floating point numbers"); auto u = v.apply([](T x) {return x * x; }); return std::sqrt(u.sum()); } template RowVector cross_product3(RowVector u, RowVector v) { assert(u.size() == 3 and v.size() == 3); auto m1 = u[1] * v[2] - u[2] * v[1]; auto m2 = u[2] * v[0] - u[0] * v[2]; auto m3 = u[0] * v[1] - u[1] * v[0]; RowVector cp = { m1, m2, m3 }; return cp; } template T volume_of_trigonal_pyramid(RowVector p, RowVector q1, RowVector q2, RowVector q3) { auto v1 = q1 - p; auto v2 = q2 - p; auto v3 = q3 - p; Matrix a = { v1, v2, v3 }; return std::abs(determinant(a) / 6); } template T area_of_triangle(RowVector q1, RowVector q2, RowVector q3) { auto v2 = q2 - q1; auto v3 = q3 - q1; return norm(cross_product3(v2, v3)) / 2; } template T dist(RowVector p, RowVector q1, RowVector q2, RowVector q3) { auto v = volume_of_trigonal_pyramid(p, q1, q2, q3); auto s = area_of_triangle(q1, q2, q3); return v * 3 / s; } template T sum_of_dist(RowVector p, std::vector> qs){ auto n = qs.size(); T d = 0; for (decltype(n) i = 0; i < n; i++) { for (decltype(n) j = i + 1; j < n; j++) { for (decltype(n) k = j + 1; k < n; k++) { d += dist(p, qs[i], qs[j], qs[k]); } } } return d; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); std::cout << std::setprecision(DIGITS) << std::fixed; int n; std::cin >> n; RowVector p(3); std::cin >> p[0] >> p[1] >> p[2]; std::vector> qs; for (decltype(n) i = 0; i < n; i++) { RowVector q(3); std::cin >> q[0] >> q[1] >> q[2]; qs.push_back(q); } auto ans = sum_of_dist(p, qs); std::cout << ans << std::endl; return EXIT_SUCCESS; }