#include <bits/stdc++.h>
long long a[1001005];
int main() {
  int n, m;
  int i;
  long long road;
  int mid;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) scanf("%I64d", a + i);
  road = 0;
  mid = n / 2 + 1;
  for (i = n; i >= mid; i = i - m) road = road + a[i] - a[mid];
  for (i = 1; i < mid; i = i + m) road = road + a[mid] - a[i];
  road = road * 2;
  printf("%I64d\n", road);
}
