#include <bits/stdc++.h>
using namespace std;
long long dp1[1000005], dp2[1000005];
int a[1000005];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  int cnt = 1;
  for (int i = 2; i <= n; i++) {
    if (cnt < m) {
      dp1[i] = dp1[i - 1] + (a[i] - a[i - 1]) * 2;
    } else {
      int dy = (cnt + m - 1) / m;
      int md = cnt % m;
      if (md == 0) md += m;
      dp1[i] = dp1[i - md] + (long long)(a[i] - a[i - md]) * 2 * dy;
    }
    cnt++;
  }
  cnt = 1;
  for (int i = n - 1; i >= 1; i--) {
    if (cnt < m) {
      dp2[i] = dp2[i + 1] + (a[i + 1] - a[i]) * 2;
    } else {
      int dy = (cnt + m - 1) / m;
      int md = cnt % m;
      if (md == 0) md += m;
      dp2[i] = dp2[i + md] + (long long)(a[i + md] - a[i]) * 2 * dy;
    }
    cnt++;
  }
  long long ans = 1e18;
  for (int i = 1; i <= n; i++) {
    ans = min(ans, dp1[i] + dp2[i]);
  }
  printf("%lld\n", ans);
}
