#include <bits/stdc++.h>   using namespace std;   int a[4], i, n, x;   int main() {     for (cin >> n, i = 0; i < n; ++i)       cin >> x, --x, a[0] += !x, a[1] = max(a[0], a[1] + x),                                  a[2] = max(a[1], a[2] + !x),                                  a[3] = max(a[2], a[3] + x);     cout << a[3] << endl;   }   