#include <bits/stdc++.h>
using namespace std;
long long a[1000005];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
  }
  sort(a + 1, a + 1 + n);
  int x = 1;
  int y = n;
  long long ans = 0;
  while (x < y) {
    ans += abs(a[y] - a[x]) * 2;
    x += m;
    y -= m;
  }
  printf("%lld", ans);
  return 0;
}
