#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;
const double EPS = 1e-8;
const double PI = acos(-1);
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &t) {
  os << "[";
  for (__typeof((t).begin()) it = (t).begin(); it != (t).end(); ++it) {
    if (it != t.begin()) os << ",";
    os << *it;
  }
  os << "]";
  return os;
}
template <class T>
ostream &operator<<(ostream &os, const set<T> &t) {
  os << "{";
  for (__typeof((t).begin()) it = (t).begin(); it != (t).end(); ++it) {
    if (it != t.begin()) os << ",";
    os << *it;
  }
  os << "}";
  return os;
}
template <class S, class T>
ostream &operator<<(ostream &os, const pair<S, T> &t) {
  return os << "(" << t.first << "," << t.second << ")";
}
template <int N, class Tuple>
void out(ostream &, const Tuple &) {}
template <int N, class Tuple, class, class... Ts>
void out(ostream &os, const Tuple &t) {
  if (N) os << ",";
  os << get<N>(t);
  out<N + 1, Tuple, Ts...>(os, t);
}
template <class... Ts>
ostream &operator<<(ostream &os, const tuple<Ts...> &t) {
  os << "(";
  out<0, tuple<Ts...>, Ts...>(os, t);
  os << ")";
  return os;
}
template <class T>
void output(T *a, int n) {
  for (int i = 0; i < (int)(n); ++i) {
    if (i) cout << ",";
    cout << a[i];
  }
  cout << endl;
}
template <class T>
void output(T *a, int n, int m) {
  for (int i = 0; i < (int)(n); ++i) output(a[i], m);
}
const int N = 1000002;
int a[N];
long long L[N];
long long LC[N];
long long R[N];
long long RC[N];
int main() {
  int n, m;
  while (cin >> n >> m) {
    for (int i = 0; i < (int)(n); ++i) scanf("%d", a + i);
    int cnt = 0;
    for (int i = 0; i < (int)(n); ++i) {
      L[i] = i ? L[i - 1] : 1;
      if (++cnt > m) {
        L[i]++;
        cnt = 1;
      }
      LC[i] = i ? LC[i - 1] + 2 * L[i - 1] * (a[i] - a[i - 1]) : 0;
    }
    cnt = 0;
    for (int i = n - 1; i >= 0; --i) {
      R[i] = i != n - 1 ? R[i + 1] : 1;
      if (++cnt > m) {
        R[i]++;
        cnt = 1;
      }
      RC[i] = i != n - 1 ? RC[i + 1] + 2 * R[i + 1] * (a[i + 1] - a[i]) : 0;
    }
    long long ans = 1LL << 62;
    for (int i = 0; i < (int)(n); ++i) {
      chmin(ans, LC[i] + RC[i]);
    }
    cout << ans << endl;
  }
}
