#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
int n, m;
unsigned long long a[maxn];
unsigned long long s1[maxn], s2[maxn];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  unsigned long long ct = 1;
  for (int i = 1; i <= n; ++i) {
    if (i != 1) s1[i] += s1[i - 1] + ct * (a[i] - a[i - 1]);
    if ((i - 1) % m == 0 && i != 1) {
      ct++;
    }
  }
  ct = 1;
  for (int i = n; i >= 1; --i) {
    if (i != n) s2[i] += ct * (a[i + 1] - a[i]) + s2[i + 1];
    if ((n - i) % m == 0 && i != n) {
      ++ct;
    }
  }
  unsigned long long ans = 1e18;
  for (int i = 1; i <= n; ++i) {
    ans = min(ans, s1[i] + s2[i]);
  }
  cout << ans * 2ll << endl;
  return 0;
}
