#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000010;
int n, m;
int a[maxn];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  long long ans = 0;
  int cnt = 0, x = 1, mid;
  if (n % 2)
    mid = n / 2 + 1;
  else
    mid = n / 2;
  for (int i = 1; i < mid; i++) {
    cnt++;
    if (cnt >= m) {
      ans += ((long long)a[mid] - a[x]) * 2;
      cnt = 0;
      x = i + 1;
    }
  }
  if (cnt > 0) ans += ((long long)a[mid] - a[x < 1 ? 1 : x]) * 2;
  cnt = 0;
  x = n;
  for (int i = n; i > mid; i--) {
    cnt++;
    if (cnt >= m) {
      ans += ((long long)a[x] - a[mid]) * 2;
      cnt = 0;
      x = i - 1;
    }
  }
  if (cnt > 0) ans += ((long long)a[x > n ? n : x] - a[mid]) * 2;
  printf("%I64d\n", ans);
  return 0;
}
