#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n = 0, m = 0;
  cin >> n >> m;
  vector<long long> x(n);
  for (long long i = 0; i < n; i++) cin >> x[i];
  int l = 0, r = n - 1;
  long long ans = 0;
  for (; l < r; l += m, r -= m) ans += ((x[r] - x[l]) << 1);
  cout << ans;
  return 0;
}
