#include using namespace std; int main() { int N; cin >> N; vector a( N ); for( int i = 0; i < N; i++ ) cin >> a[i]; typedef pair P; vector

p( N ); for( int i = 0; i < N; i++ ) p[i] = P( a[i], i + 1 ); sort( p.begin(), p.end() ); vector acc( N + 1 ); for( int i = 0; i < N; i++ ) { acc[i + 1] = acc[i] + p[i].second; } long long ans = 0; for( int i = N - 1; i >= 0; i-- ) { long long a = -p[i].second; if( i - 1 >= 0 ) a += acc[i]; ans = max( ans, max( a, 0LL ) ); } cout << ans << endl; }