#include <bits/stdc++.h>   using namespace std;   const int N = 2004;   int dp[N], dq[N], a[N], n;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= n; i++) {       dp[i] = 1;       for (int j = 1; j < i; j++)         if (a[i] >= a[j]) dp[i] = max(dp[i], dp[j] + 1);     }     for (int i = n; i >= 1; i--) {       dq[i] = 1;       for (int j = n; j > i; j--)         if (a[i] <= a[j]) dq[i] = max(dq[i], dq[j] + 1);     }     int ans = dp[n];     for (int i = 1; i <= n; i++) ans = max(ans, dp[i] + dq[i + 1]);     printf( %d n , ans);   }   