#include <bits/stdc++.h>
using namespace std;
long long ss[1001000];
int main(void) {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%I64d", &ss[i]);
  }
  int s = (n / 2) + 1;
  long long ans = 0;
  for (int i = n; i > s; i -= m) {
    ans += ss[i] - ss[s];
  }
  for (int i = 1; i < s; i += m) {
    ans += ss[s] - ss[i];
  }
  ans *= 2;
  printf("%I64d\n", ans);
  return 0;
}
