#include <bits/stdc++.h>
using namespace std;
const int maxn = 10e6 + 5;
int arr[maxn];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%d", arr + i);
  }
  long long ans = 0;
  if (k >= n - 1) {
    ans = arr[n - 1] - arr[0];
  } else {
    int cnt = n >> 1;
    for (int i = 0; i < cnt; i += k) {
      ans += arr[cnt] - arr[i];
      ;
    }
    for (int i = n - 1; i > cnt; i -= k) {
      ans += arr[i] - arr[cnt];
      ;
    }
  }
  printf("%I64d\n", ans << 1);
  return 0;
}
