#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m, dist[1000009];
  dist[1] = 0;
  scanf("%lld %lld", &n, &m);
  int div = n / m;
  div = div % 2 == 0 ? (div / 2) * m : ((div + 1) / 2) * m;
  long long answer = 0, ans_point = 999999999999999;
  if (n % m != 0) div++;
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &dist[i]);
    if (i == div) ans_point = dist[i];
  }
  if (n <= m) {
    answer += (dist[n] - dist[1]) * 2;
  } else {
    for (int i = 1; dist[i] < ans_point; i += m) {
      answer += (-dist[i] + ans_point) * 2;
    }
    for (int i = n; dist[i] > ans_point; i -= m) {
      answer += (dist[i] - ans_point) * 2;
    }
  }
  printf("%lld\n", answer);
  return 0;
}
