#include <bits/stdc++.h>
using namespace std;
int v[1000005];
long long int l[1000005];
long long int r[1000005];
int main(void) {
  int n, m;
  int sum;
  scanf(" %d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf(" %d", &v[i]);
  }
  l[0] = 0;
  sum = 0;
  for (int i = 1; i < n; i++) {
    sum++;
    int trip = (sum + m - 1) / m;
    l[i] = l[i - 1] + 1LL * trip * (v[i] - v[i - 1]);
  }
  r[n - 1] = 0;
  sum = 0;
  for (int i = n - 2; i >= 0; i--) {
    sum++;
    int trip = (sum + m - 1) / m;
    r[i] = r[i + 1] + 1LL * trip * (v[i + 1] - v[i]);
  }
  long long int res = l[0] + r[0];
  for (int i = 0; i < n; i++) {
    res = min(res, l[i] + r[i]);
  }
  printf("%lld\n", 2 * res);
  return 0;
}
