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 org.w3c.dom.ls.LSOutput;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.sql.SQLOutput;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.*;
import java.util.ArrayList;
import java.util.List;

public class Main {

    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static long gcd(long a,long b)
    {
        if(b==0) return a;
        return gcd(b,a%b);
    }

    public static long dist(long x,long y)
    {
        return x*x+y*y;
    }

    public static void main(String[] args)
    {
        FastReader r=new FastReader();
        int n=r.nextInt();
        int ans=1;
        int []a=new int[n+5];
        int []cnt1=new int[n+5];
        int []cnt2=new int[n+5];
        for(int i=1;i<=n;++i) a[i]=r.nextInt();
        for(int i=1;i<=n;++i)
        {
            int add=0;
            if(a[i]==1) add=1;
            else add=0;
            cnt1[i]=cnt1[i-1]+add;
        }
        for(int i=n;i>=1;--i)
        {
            int add=0;
            if(a[i]==2) add=1;
            else add=0;
            cnt2[i]=cnt2[i+1]+add;
        }
        // dont do anything
        for(int i=1;i<=n+1;++i)
        {
            ans=Math.max(ans,cnt1[i-1]+cnt2[i]);
        }
        for(int mid=1;mid<=n+1;++mid)
        {
            int sum1=0,sum2=0;
            for(int left=1;left<=mid;++left)
            {
                sum1=Math.max(sum1,cnt1[left-1]+cnt2[left]-cnt2[mid]);
            }
            for(int right=mid;right<=n+1;++right)
            {
                sum2=Math.max(sum2,cnt2[right]+cnt1[right-1]-cnt1[mid-1]);
            }
            ans=Math.max(ans,sum1+sum2);
        }
        System.out.println(ans);
    }
}
