#include <bits/stdc++.h>
using namespace std;
void load() {}
const int N = 1e6 + 123;
int a[N];
long long l[N], r[N];
void trungtt() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  for (int i = 1; i <= n; ++i) {
    int len = (i - 1) / k;
    int pos = len * k;
    l[i] = l[pos];
    if (pos > 0) l[i] += 1LL * len * (a[i] - a[pos]);
    ++pos;
    l[i] += (a[i] - a[pos]);
  }
  long long ans = 1e18;
  for (int i = n; i > 0; --i) {
    int len = (n - i) / k;
    int pos = n - len * k + 1;
    r[i] = r[pos];
    if (pos <= n) r[i] += 1LL * len * (a[pos] - a[i]);
    --pos;
    r[i] += (a[pos] - a[i]);
    ans = min(ans, l[i] + r[i]);
  }
  printf("%lld", ans * 2);
}
int main() {
  load();
  trungtt();
  return 0;
}
