#include <bits/stdc++.h>
using namespace std;
const int N = int(1e6 + 5);
int p[N];
long long dp[N];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%d", &p[i]);
  dp[n - 1] = 0;
  for (int i = n - 2; i >= 0; i--) {
    dp[i] = dp[i + 1];
    dp[i] += (long long)(p[i + 1] - p[i]) * ((n + m - i - 2) / m);
  }
  long long res = dp[0], now = 0;
  for (int i = 1; i < n; i++) {
    now += (long long)(p[i] - p[i - 1]) * ((i + m - 1) / m);
    res = min(res, now + dp[i]);
  }
  printf("%I64d\n", res * 2);
  return 0;
}
