#include #include #include using namespace std; using ll = long long; int main(){ int n; cin >> n; vector p(n); for(auto &it: p){ cin >> it; it--; } vector a(n+1); for(int i = 0; i < n; i++) a[p[i]] = i; ll ans = 0; ll tot = -(a[0]+1); for(int i = 0; i < n-1; i++){ tot += (a[i]+1)*2; tot -= a[i+1]+1; ans = max(ans, tot); } cout << ans << endl; return 0; }