#include <bits/stdc++.h>
using namespace std;
using ld = long double;
using ll = long long;
const ll INF = 3e18, MOD = 1e9 + 7;
void rotate(std::vector<int> t, int x);
void energy(int n, std::vector<int> v) {
vector<pair<int, int>> a;
for (int i = 0; i < n; i++) {
a.emplace_back(v[i], i);
}
sort(a.begin(), a.end());
ll m = n / 2;
for (ll i = 0; i < m; i++) {
if (a[i].first == 0) continue;
vector<int> t = {a[i].second};
int x = 50000 - a[i].first;
rotate(t, x);
}
for (ll i = m; i < n; i++) {
if (a[i].first == 25000) continue;
vector<int> t = {a[i].second};
int x = 25000 - a[i].first;
rotate(t, x);
}
}