#include #include #include #include #include #include #include #include #include #include #include #include #include #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; template vector> vec2d(int n, int m, T v){ return vector>(n, vector(m, v)); } template vector>> vec3d(int n, int m, int k, T v){ return vector>>(n, vector>(m, vector(k, v))); } template void print_vector(vector v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } template struct bit{ int n; vector data; bit(int n_){ n = 1; while(n < n_) n *= 2; data = vector(n+1); for(int i = 0; i <= n; i++) data[i] = 0; } T sum(int i){ T ret = 0; while(i > 0){ ret += data[i]; i -= i&-i; } return ret; } void add(int i, T x){ while(i <= n){ data[i] += x; i += i&-i; } } }; ll count_inversion(vector v){ int n = v.size(); bit bt(n); ll ans = 0; for(int x: v){ ans += bt.sum(n)-bt.sum(x); bt.add(x, 1); } return ans; } const ll inf = 1e18; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int n; cin >> n; vector a(n+1), pos(n+1); for(int i = 1; i <= n; i++){ cin >> a[i]; pos[a[i]] = i; } ll ans = inf; if(n%2 == 0){ vector odd, even; for(int x = 1; x <= n/2; x++) odd.push_back(pos[x]); for(int x = n/2+1; x <= n; x++) even.push_back(pos[x]); sort(even.begin(), even.end()); sort(odd.begin(), odd.end()); vector v; for(int i = 0; i < n/2; i++) { v.push_back(even[i]); v.push_back(odd[i]); } ans = count_inversion(v); ll tmp = ans; for(int i = n-2; i >= 0; i-=2){ // i, i+1を反転 if(v[i] < v[i+1]){ tmp++; }else{ tmp--; } chmin(ans, tmp); } }else{ vector odd, even; for(int x = 1; x <= n/2; x++) odd.push_back(pos[x]); for(int x = n/2+1; x <= n; x++) even.push_back(pos[x]); sort(even.begin(), even.end()); sort(odd.begin(), odd.end()); vector v; for(int i = 0; i < n/2; i++) { v.push_back(even[i]); v.push_back(odd[i]); } v.push_back(even[n/2]); chmin(ans, count_inversion(v)); } cout << n/2 << ' ' << ans << endl; }