#include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
int n, m;
long long x[N], l[N], r[N];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%I64d", &x[i]);
  }
  sort(x + 1, x + 1 + n);
  for (int i = 2; i <= n; i++) {
    int precar = (i - 2 + m - 1) / m;
    int car = (i - 1 + m - 1) / m;
    l[i] = l[i - 1];
    l[i] += (x[i] - x[i - 1]) * car * 2LL;
  }
  for (int i = n - 1; i > 0; i--) {
    int precar = (n - i - 1 + m - 1) / m;
    int car = (n - i + m - 1) / m;
    r[i] = r[i + 1];
    r[i] += (x[i + 1] - x[i]) * car * 2LL;
  }
  long long ans = 1LL << 60;
  for (int i = 1; i <= n; i++) ans = min(ans, l[i] + r[i]);
  printf("%I64d\n", ans);
  return 0;
}
