#include <bits/stdc++.h>
using namespace std;
int n, k, v[1 << 20];
long long st[1 << 20], dr[1 << 20];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) cin >> v[i];
  long long sol = 1LL << 60;
  for (int i = 2; i <= n; ++i)
    st[i] =
        st[i - 1] + 2LL * (v[i] - v[i - 1]) * ((i - 1) / k + ((i - 1) % k > 0));
  for (int i = n - 1; i > 0; --i)
    dr[i] =
        dr[i + 1] + 2LL * (v[i + 1] - v[i]) * ((n - i) / k + ((n - i) % k > 0));
  for (int i = 1; i <= n; ++i) sol = min(sol, st[i] + dr[i]);
  cout << sol;
  return 0;
}
