func_code_string: #include <bits/stdc++.h>   using namespace std;   int dp[2][2005];   int a[2005];   int cnt2[2005];   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = n; i >= 1; i--) {       cnt2[i] = cnt2[i + 1];       if (a[i] == 2) cnt2[i]++;     }     for (int i = 0; i <= 2; i++) dp[i][0] = 1;     for (int i = 1; i <= n; i++) {       dp[0][i] = dp[1][i] = 1;       for (int j = 1; j <= i - 1; j++) {         if (a[i] >= a[j]) dp[0][i] = max(dp[0][j] + 1, dp[0][i]);         if (a[i] <= a[j]) dp[1][i] = max(max(dp[0][j], dp[1][j]) + 1, dp[1][i]);       }     }     int ans = 0;     for (int i = 1; i <= n; i++) {       ans = max(dp[1][i] + cnt2[i + 1], ans);     }     cout << ans << endl;     return 0;   }   