#include <bits/stdc++.h>
using namespace std;
long long n, m, s, mid, a[1000001];
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (long long i = 0; i < n; ++i) cin >> a[i];
  mid = (n >> 1);
  for (long long i = n - 1; i > mid; i -= m) s += a[i] - a[mid];
  for (long long i = 0; i < mid; i += m) s += a[mid] - a[i];
  cout << (s << 1);
  return 0;
}
