#include <bits/stdc++.h>
using namespace std;
const int MN = 1000111;
int n, m, a[MN];
long long f(long long x) {
  long long res = 0;
  if (x >= a[1]) {
    int from = 1, to = 1;
    for (int i = (1), _b = (n); i <= _b; i++)
      if (a[i] <= x) to = i;
    int cur = from;
    while (cur <= to) {
      res += llabs(x - a[cur]) * 2LL;
      cur += m;
    }
  }
  if (x <= a[n]) {
    int from, to = n;
    for (int i = (n), _b = (1); i >= _b; i--)
      if (a[i] >= x) from = i;
    int cur = to;
    while (cur >= from) {
      res += llabs(x - a[cur]) * 2LL;
      cur -= m;
    }
  }
  return res;
}
long long get(long long l, long long r) {
  long long res = min(f(l), f(r));
  while (l < r) {
    long long x1 = (l + l + r) / 3;
    long long x2 = (l + r + r) / 3;
    long long y1 = f(x1), y2 = f(x2);
    res = min(res, min(y1, y2));
    if (y1 < y2)
      r = x2 - 1;
    else
      l = x1 + 1;
  }
  return res;
}
int main() {
  ios ::sync_with_stdio(false);
  while (cin >> n >> m) {
    for (int i = (1), _b = (n); i <= _b; i++) cin >> a[i];
    sort(a + 1, a + n + 1);
    cout << get(-(1e9 + 5), 1e9 + 5) << endl;
  }
  return 0;
}
