#include using namespace std; template ostream &operator <<(ostream &os, const vector &v) { for (T x : v) os << x << " "; return os; } vector> reduce(vector> a) { int h = a.size(); int w = a[0].size(); int r = 0; for (int j = 0; j < w && r < h; j++) { int p = r; for (int i = r + 1; i < h; i++) { if (abs(a[i][j]) > abs(a[p][j])) { p = i; } } swap(a[p], a[r]); if (abs(a[r][j]) < 1e-8) { continue; } for (int ii = 0; ii < h; ii++) { if (ii != r) { double q = a[ii][j] / a[r][j]; for (int jj = 0; jj < w; jj++) { a[ii][jj] -= q * a[r][jj]; } } } double q = a[r][j]; for (int jj = 0; jj < w; jj++) { a[r][jj] /= q; } r++; } return a; } struct SlideMin { deque> q; int width; int t = 0; SlideMin(int width) : width(width) {} void add(double x) { t++; while (!q.empty() && t - q.front().second >= width) { q.pop_front(); } while (!q.empty() && q.back().first > x) { q.pop_back(); } q.emplace_back(x, t); } double minimum() { return q.front().first; } }; int main() { int n, m; cin >> n >> m; const int M = n * 2 - 2; vector c(M * 2); for (int i = 1; i < n - 1; i++) { cin >> c[i]; } for (int i = 0; i < n - 2; i++) { c[n + i] = c[n - 2 - i]; } for (int i = 0; i < M; i++) { c[i + M] = c[i]; } const int T = 30000000 / M; double mm = 1.0 / m; vector> a(M - 1, vector(M)); for (int i = 0; i < M; i++) { if (i == n - 1) { continue; } int ii = i > n - 1 ? i - 1 : i; a[ii][ii] = 1; for (int j = 1; j <= m; j++) { int jj = (i + j) % M; if (jj != n - 1) { int jjj = jj > n - 1 ? jj - 1 : jj; a[ii][jjj] -= 1.0 / m; a[ii][M - 1] += c[jj] / m; } else { a[ii][M - 1] += c[jj] / m; } } } a = reduce(a); vector E(M * 2), EE(M * 2); for (int i = 0; i < M; i++) { if (i != n - 1) { int ii = i > n - 1 ? i - 1 : i; E[i] = EE[i] = a[ii][M - 1]; } } SlideMin q(m); for (int i = m - 1; i >= 0; i--) { q.add(EE[i] + c[i]); } double sumE = 0; double sumEE = 0; for (int i = 0; i < m; i++) { sumE += E[i] + c[i]; sumEE += EE[i] + c[i]; } for (int ii = 0; ii < T; ii++) { for (int i = 0; i < M; i++) { E[i + M] = E[i]; EE[i + M] = EE[i]; } for (int i = M - 1; i >= 0; i--) { E[i] = 0; EE[i] = 0; if (i != n - 1) { E[i] = min(sumE * mm, q.minimum()); EE[i] += sumEE * mm; } q.add(EE[i] + c[i]); sumE += E[i] + c[i]; sumEE += EE[i] + c[i]; sumE -= E[i + m] + c[i + m]; sumEE -= EE[i + m] + c[i + m]; } } printf("%.20f\n", (double)min(E[0], EE[0])); }