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