#include <bits/stdc++.h>
using namespace std;
const int MAXINT = 0x6fffffff;
const long long MAXLONG = (long long)1 << 60;
const int MAXN = 1e6 + 5;
int n, m;
int arr[MAXN];
int main() {
  while (scanf("%d %d", &n, &m) != -1) {
    for (long long i = (0); i < (n); i += 1) {
      scanf("%d", &arr[i]);
    }
    int md = n / 2;
    int mpos = arr[md];
    long long res = 0;
    for (int i = 0; i < md; i += m) {
      res += mpos - arr[i];
    }
    for (int i = n - 1; i > md; i -= m) {
      res += arr[i] - mpos;
    }
    res *= 2;
    cout << res << endl;
  }
  return 0;
}
