#include <bits/stdc++.h>
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  std::vector<long long> v(n), l(n, 0), r(n, 0);
  for (long long &i : v) scanf("%I64d", &i);
  long long res = 0, cur = 0;
  for (int i = 1; i < n; ++i) {
    if (cur == 0) cur = m, res++;
    cur--;
    l[i] = l[i - 1] + res * (v[i] - v[i - 1]);
  }
  res = 0, cur = 0;
  for (int i = n - 2; i >= 0; --i) {
    if (cur == 0) cur = m, res++;
    cur--;
    r[i] = r[i + 1] + res * (v[i + 1] - v[i]);
  }
  long long ans = 1E17;
  for (int i = 0; i < n; ++i)
    if (ans > l[i] + r[i]) ans = l[i] + r[i];
  printf("%I64d", ans * 2);
}
