#include <bits/stdc++.h>
#include "rotate.h"
using namespace std;
using ll = long long;
const int md = 50000;
const int hmd = md / 2;
const int nax = 1e5;
mt19937 rng((unsigned int)chrono::steady_clock::now().time_since_epoch().count());
// int calc(vector<int> v) {
// int n = v.size();
// int res = 0;
// for(int i = 0; i < n; i++) {
// for(int j = i + 1; j < n; j++) {
// res += min(abs(v[i] - v[j]), md - abs(v[i] - v[j]));
// }
// }
// return res;
// }
// vector<int> v;
// void rotate(vector<int> t, int x) {
// for(int i : t) {
// v[i] += x;
// while(v[i] > md)
// v[i] -= md;
// }
// }
void energy(int n, vector<int> v){
// v = V;
vector<pair<int, int>> tmp(n);
for(int i = 0; i < n; i++) {
tmp[i] = {v[i], i};
}
ranges::sort(tmp);
for(int i = n / 2; i < n; i++)
rotate({tmp[i].second}, tmp[i - n / 2].first + hmd - tmp[i].first);
}
// int main() {
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// int n = 2;
// int tt = 10;
// while(tt--) {
// vector<int> tmp(n);
// for(int i = 0; i < n; i++) tmp[i] = rng() % 50 * 1000;
// if(tt == 9) tmp = {20000, 10000};
// energy(n, tmp);
// for(int &i : tmp) cout << i << " ";
// cout << "\n";
// cout << calc(v) << "\n\n\n";
// }
// return 0;
// }