#include <bits/stdc++.h>
using namespace std;
long long arr[1000005];
int main() {
  long long ans = 0;
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%I64d", &arr[i]);
  ans = (arr[n - 1] - arr[0]) * 2;
  int l = n / 2;
  int len = l / m;
  if (l % m) len++;
  int ren = (n - 1 - l) / m;
  if ((n - 1 - l) % m) ren++;
  int tmpl = 0;
  int tmpr = n - 1;
  while (len > 1) {
    tmpl += m;
    len--;
    ans += (arr[l] - arr[tmpl]) * 2;
  }
  while (ren > 1) {
    tmpr -= m;
    ren--;
    ans += (arr[tmpr] - arr[l]) * 2;
  }
  printf("%I64d\n", ans);
  return 0;
}
