#include <bits/stdc++.h>
using namespace std;
void setup() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout.precision(15);
}
const int MAXN = 1000005;
int N, M;
int loc[MAXN];
long long lc[MAXN], rc[MAXN];
int main() {
  setup();
  cin >> N >> M;
  for (int i = 0; i < N; i++) cin >> loc[i];
  long long C = 0, L = 0;
  for (int i = 0; i < N; i++) {
    if (i) {
      lc[i] = (loc[i] - loc[i - 1]) * C;
      lc[i] += lc[i - 1];
    }
    if (L == 0) C++;
    L = (L + 1) % M;
  }
  C = 0, L = 0;
  for (int i = N - 1; i >= 0; i--) {
    if (i < N - 1) {
      rc[i] = (loc[i + 1] - loc[i]) * C;
      rc[i] += rc[i + 1];
    }
    if (L == 0) C++;
    L = (L + 1) % M;
  }
  long long minc = 1e17;
  for (int i = 0; i < N; i++) minc = min(minc, 2 * (lc[i] + rc[i]));
  cout << minc << endl;
}
