#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]; rep(l,N+1){ rep(r,N+1) cout << I[l][r] << " "; cout << endl; } cout << endl; for(int k=0; kk; r--){ dp[r] = 0; for(int l=r-1; l>=k; l--){ dp[r] = max(dp[r], dp[l] + I[l][r]); } ans = max(ans, dp[r]); } cout << (I[0][N] - ans) << '\n'; } return 0; } struct ios_do_not_sync{ ios_do_not_sync(){ std::ios::sync_with_stdio(false); std::cin.tie(nullptr); } } ios_do_not_sync_instance;