A dragon symbolizes wisdom, power and wealth. On Lunar New Year's Day, people model a dragon with bamboo strips and clothes, raise them with rods, and hold the rods high and low to resemble a flying dragon.

A performer holding the rod low is represented by a 1, while one holding it high is represented by a 2. Thus, the line of performers can be represented by a sequence a1, a2, ..., an.

Little Tommy is among them. He would like to choose an interval [l, r] (1 ≤ l ≤ r ≤ n), then reverse al, al + 1, ..., ar so that the length of the longest non-decreasing subsequence of the new sequence is maximum.

A non-decreasing subsequence is a sequence of indices p1, p2, ..., pk, such that p1 < p2 < ... < pk and ap1 ≤ ap2 ≤ ... ≤ apk. The length of the subsequence is k.

Input

The first line contains an integer n (1 ≤ n ≤ 2000), denoting the length of the original sequence.

The second line contains n space-separated integers, describing the original sequence a1, a2, ..., an (1 ≤ ai ≤ 2, i = 1, 2, ..., n).

Output

Print a single integer, which means the maximum possible length of the longest non-decreasing subsequence of the new sequence.

Examples

Input

4
1 2 1 2


Output

4


Input

10
1 1 2 2 2 1 1 2 2 1


Output

9

Note

In the first example, after reversing [2, 3], the array will become [1, 1, 2, 2], where the length of the longest non-decreasing subsequence is 4.

In the second example, after reversing [3, 7], the array will become [1, 1, 1, 1, 2, 2, 2, 2, 2, 1], where the length of the longest non-decreasing subsequence is 9.
import java.util.*;
import java.io.*;

public class E {

	public static class RangeTree {
		
		RangeTree left;
		RangeTree right;
		int l;
		int r;
		int val;
		
		public RangeTree(int[] score, int l, int r) {
			this.l = l;
			this.r = r;
			if (l == r) val = score[l];
			else {
				int pivot = (l + r) / 2;
				left = new RangeTree(score, l, pivot);
				right = new RangeTree(score, pivot+1, r);
				val = left.val > right.val ? left.val : right.val;
			}
		}
		
		public int maxf(int l, int r) {
			if(this.l == l && this.r == r) return val;
			if(r <= left.r) return left.maxf(l, r);
			if(l >= right.l) return right.maxf(l, r);
			int lmax = left.maxf(l, left.r);
			int rmax = right.maxf(right.l, r);
			return lmax > rmax ? lmax : rmax;
		}
	}

	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String[] ree = in.readLine().split("\\s++");
		int n = Integer.parseInt(ree[0]);
		n += 2;
		String[] qwq = in.readLine().split("\\s++");
		char[] vals = new char[qwq.length];
		for(int i = 0; i < vals.length; i++) vals[i] = qwq[i].charAt(0);
		char[] nvals = new char[n];
		for(int i = 0; i < n - 2; i++) {
			nvals[i + 1] = vals[i];
		}
		nvals[0] = '0';
		nvals[n - 1] = '0';
		vals = nvals;
		int[] oneL2R = new int[n];
		int[] oneR2L = new int[n];
		int[] twoL2R = new int[n];
		int[] twoR2L = new int[n];
		int[] score = new int[n];
		int ones = 0;
		int twos = 0;
		for(int i = 0; i < n; i++) {
			if(vals[i] == '1') ones++;
			else if(vals[i] == '2') twos++;
			oneL2R[i] = ones;
			twoL2R[i] = twos;
		}
		ones = 0;
		twos = 0;
		for(int i = n - 1; i >= 0; i--) {
			if(vals[i] == '1') ones++;
			else if(vals[i] == '2')twos++;
			oneR2L[i] = ones;
			twoR2L[i] = twos;
		}
		for(int i = 0; i < n; i++) {
			score[i] = twoL2R[i] + oneR2L[i];
		}
		/*for(int i = 0; i < n; i++) {
			System.out.print(vals[i] + " " );
			System.out.print(oneL2R[i] + " ");
			System.out.print(twoL2R[i] + " ");
			System.out.print(oneR2L[i] + " ");
			System.out.print(twoR2L[i] + " ");
			System.out.println(score[i] + " ");
		}*/
		RangeTree rt = new RangeTree(score, 0, score.length - 1);
		int best = 0;
		for(int l = 1; l < n - 1; l++) {
			for(int r = l; r < n - 1; r++) {
				int val = oneL2R[l-1] + twoR2L[r+1] + rt.maxf(l, r) - oneR2L[r+1] - twoL2R[l-1];
				if(val > best) best = val;
			}
		}
		System.out.println(best);
	}
}