#include #include #include using namespace std; using namespace atcoder; using mint = modint998244353; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf 1000000000 int main() { int N; cin>>N; vector a(N); vector pos(2,vector()); rep(i,N){ cin>>a[i]; if(a[i]<=N/2)pos[0].push_back(i); else pos[1].push_back(i); } long long ans = 1000000000000000000; vector t; for(int j=0;j x = pos[j],y = t; long long sum = 0; rep(i,x.size())sum += abs(x[i]-y[i]); ans = min(ans,sum); rep(i,t.size()){ sum -= abs(x[i]-y[i]); y[i]++; sum += abs(x[i]-y[i]); //cout<