#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 7;
int p[N];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) scanf("%d", p + i);
  sort(p, p + n);
  long long ans(0);
  for (int i = n - 1; i > 0; i -= m) ans += (p[i] - p[0]);
  long long minV = ans;
  for (int i = 1, l = 0, r = n - 1; i < n; ++i) {
    int det = p[i] - p[i - 1];
    ++l;
    ans += (long long)((l + m - 1) / m) * (long long)det;
    ans -= (long long)((r + m - 1) / m) * (long long)det;
    --r;
    minV = min(minV, ans);
  }
  cout << minV * 2;
  return 0;
}
