#include <bits/stdc++.h>
using namespace std;
long long n, m;
const long long N = 1e6 + 10000;
long long a[N];
long long ans;
long long get(long long cor) {
  ans = 0;
  for (int i = 0; i < n / 2; i += m) ans += 2LL * (cor - a[i]);
  for (int i = n - 1; i > n / 2; i -= m) ans += 2LL * (a[i] - cor);
  return ans;
}
int main() {
  scanf("%I64d %I64d", &n, &m);
  if (n == 1) {
    printf("0");
    return 0;
  }
  for (long long i = 0; i < n; i++) scanf("%I64d", a + i);
  long long cor = a[n / 2];
  printf("%I64d", get(a[n / 2]));
  return 0;
}
