#include <bits/stdc++.h>
using namespace std;
int n, m, a[1000010], mid;
long long ans;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  mid = (1 + n) >> 1;
  for (int i = 1; i <= mid; i += m) ans += a[mid] - a[i];
  for (int i = n; i >= mid; i -= m) ans += a[i] - a[mid];
  printf("%I64d\n", ans << 1);
}
