#include <bits/stdc++.h>
using namespace std;
const int M = 1e6 + 5;
const int inf = 1e9 + 5;
int a[M], b[M];
int32_t main() {
  int n, m, mx = -inf;
  cin >> n >> m;
  for (int i = 0; i < n; i++) scanf("%d", a + i), ((mx) = max((mx), (a[i])));
  sort(a, a + n);
  a[n] = inf;
  vector<int> vecl, vecr;
  long long val = 0;
  for (int i = 0; i < n; i++) vecl.push_back(i);
  for (int i = 0; i < n; i += m) val += inf - a[i];
  long long ans = val;
  for (int i = n - 1; ~i; i--) {
    long long dis = a[i + 1] - a[i];
    val -= dis * ((vecl.size() + m - 1) / m);
    val += dis * ((vecr.size() + m - 1) / m);
    long long p = vecl.back();
    vecr.push_back(p);
    vecl.pop_back();
    ((ans) = min((ans), (val)));
  }
  return cout << ans * 2ll << endl, 0;
}
