#include <bits/stdc++.h>
using namespace std;
int n, m, cnt = 0;
int cri[1000010];
long long calc(int x) {
  long long ret = 0;
  for (int i = 0; i < x; i += m) ret += cri[x] - cri[i];
  for (int i = n - 1; i > x; i -= m) ret += cri[i] - cri[x];
  return ret << 1;
}
void solve() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%d", &cri[i]);
  int index = n / 2;
  cout << calc(index) << endl;
}
int main() {
  solve();
  return 0;
}
