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