#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1000000 + 100;
int n, m;
int arr[MAX_N];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%d", &arr[i]);
  int mid = n >> 1;
  long long res = 0;
  for (int i = n - 1; i > mid; i -= m) res += arr[i] - arr[mid];
  for (int i = 0; i < mid; i += m) res += arr[mid] - arr[i];
  res = res << 1;
  printf("%I64d\n", res);
  return 0;
}
