#include <bits/stdc++.h>
using namespace std;
long long pre[1000005];
long long nex[1000005];
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, m;
  cin >> n >> m;
  long long a[n + 5];
  a[0] = 0;
  long long ans[n + 5], ans2[n + 5];
  memset(ans, 0, sizeof(ans));
  memset(ans2, 0, sizeof(ans2));
  for (long long i = 1; i <= n; i++) cin >> a[i];
  for (long long i = 2; i <= n; i++) {
    long long u = max(1ll, i - m);
    long long x = ceil(1.0 * (i - 1) / m);
    ans[i] = 2 * abs(a[i - 1] - a[i]) * x;
    ans[i] += ans[i - 1];
  }
  for (long long i = n - 1; i >= 1; i--) {
    long long u = min(n, i + m);
    long long x = ceil(1.0 * (n - i) / m);
    ans2[i] += 2 * abs(a[i + 1] - a[i]) * x;
    ans2[i] += ans2[i + 1];
  }
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }
  long long mn = pow(10, 18);
  for (long long i = 1; i <= n; i++) {
    long long cnt = ans[i] + ans2[i];
    mn = min(mn, cnt);
  }
  cout << mn << endl;
}
