func_code_string: #include <bits/stdc++.h>   using namespace std;   int n, m;   int a[1000100];   long long calc(int idx) {     long long ans = 0;     int x = -1, y = -1;     for (int i = 0; i < idx; i += m) {       ans += (long long)abs(a[i] - a[idx]) * 2;       x = i;     }     for (int i = n - 1; i > idx; i -= m) {       ans += (long long)abs(a[i] - a[idx]) * 2;       y = i;     }     return ans;   }   long long solve(long long l, long long r) {     while (l < r) {       long long ml = (2 * l + r) / 3;       long long mr = (l + 2 * r + 2) / 3;       long long vl = calc(ml);       long long vr = calc(mr);       if (vl < vr)         r = mr - 1;       else if (vl > vr)         l = ml + 1;       else {         l = ml;         r = mr - 1;       }     }     return l;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     int ansid = solve(0, n - 1);     cout << calc(ansid) << endl;     return 0;   }   