#include #include #include using namespace std; using i64 = long long; #define rep(i,n) for(int i=0; i<(int)(n); i++) int N; int P[3000]; int I[3001][3001]; int dp[3001] = {}; int ans[3001] = {}; int main(){ int N; cin >> N; rep(i,N){ cin >> P[i]; P[i]--; } rep(i,N) rep(j,i) if(P[j] > P[i]) I[j][i+1]++; rep(r,N+1) for(int l=r-1; l>=0; l--) I[l][r] += I[l+1][r]; rep(r,N+1) for(int l=r-1; l>=0; l--) I[l][r] += I[l][r-1]; for(int k=0; k