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