#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#define You_ss_ef ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pi 3.141592654
#define tc int T; cin >> T; while (T--)
#define FP(_) fixed << std::setprecision(_)
#define Gaza main
#define ll long long
#define ld long double
#define ss << ' '
#define el << '\n'
#define all(_) _.begin(), _.end()
#define rall(_) _.rbegin(), _.rend()
#define uni(_) _.erase(unique(all(_)), _.end())
using namespace std;
void IO() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
} 
int n;   
vector <int> v;
int dp[2][2001][2001];
int solve(int t, int i, int w)
{
    if(i == n) return 0;
    int &ret = dp[t][i][w];
    if(~ret) return ret; 
    int x = 0, y = 0, z = 0, o = 0, p = 0; 
    if(w == 0) {
        o = solve(0,v[i],v[i]) + 1; 
        p = solve(1,v[i],v[i]) + 1;
    }
    else {
        if(!t and v[i] > w) x = solve(t,i+1,v[i]) + 1; 
        if(t and v[i] < w) y = solve(t,i+1,v[i]) + 1;
    }
    z = solve(t,i+1,w);
    return ret = max({x,y,z,o,p});
}
void answer() 
{   
    cin >> n;
    v.resize(n);
    for(auto &i : v) cin >> i; 
    memset(dp,-1,sizeof(dp));
    cout << solve(0,0,0);
}
int Gaza()
{   You_ss_ef   
    IO();
    int TC = 1;
    cin >> TC;
    do {
        answer();
        TC--;
        // if (TC)
            cout el;
    } while (TC != 0);
    return 0;
}