Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has n friends and each of them can come to the party in a specific range of days of the year from ai to bi. Of course, Famil Door wants to have as many friends celebrating together with him as possible.

Far cars are as weird as Far Far Away citizens, so they can only carry two people of opposite gender, that is exactly one male and one female. However, Far is so far from here that no other transportation may be used to get to the party.

Famil Door should select some day of the year and invite some of his friends, such that they all are available at this moment and the number of male friends invited is equal to the number of female friends invited. Find the maximum number of friends that may present at the party.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 5000) — then number of Famil Door's friends.

Then follow n lines, that describe the friends. Each line starts with a capital letter 'F' for female friends and with a capital letter 'M' for male friends. Then follow two integers ai and bi (1 ≤ ai ≤ bi ≤ 366), providing that the i-th friend can come to the party from day ai to day bi inclusive.

Output

Print the maximum number of people that may come to Famil Door's party.

Examples

Input

4
M 151 307
F 343 352
F 117 145
M 24 128


Output

2


Input

6
M 128 130
F 128 131
F 131 140
F 131 141
M 131 200
M 140 200


Output

4

Note

In the first sample, friends 3 and 4 can come on any day in range [117, 128].

In the second sample, friends with indices 3, 4, 5 and 6 can come on day 140.
import java.util.*;
import java.io.*;
import java.math.*;
import java.util.regex.Matcher;
//linkedhashmap contains the entry in the same order which we are giving and not in sorted way like in hashmaps
public class CF {
    FastScanner in;
    PrintWriter out;
    final static int M=1000001;
    public ArrayList<Integer> input(int m){
        ArrayList<Integer> li= new ArrayList<>();
        for(int i=0;i<m;i++)
            li.add(in.nextInt());
        return li;
    }
    class Pair{
        int x;
        int y;
    }
    public class pair<T,V> {
        private T x;
        private V y;

        public void setY(V y) {
            this.y = y;
        }

        public V getY() {
            return y;
        }

        public void setX(T x) {
            this.x = x;
        }

        public T getX() {
            return x;
        }
    }
    Set<Long> primeFactors(long n)
    {
        // Print the number of 2s that divide n
        Set<Long> li=new HashSet<>();

        while (n%2 == 0)
        {
            li.add(2L);
            n = n/2;
        }

        // n must be odd at this point.  So we can skip one element (Note i = i +2)
        for (long i = 3; i <= Math.sqrt(n); i = i+2)
        {
            // While i divides n, print i and divide n
            while (n%i == 0)
            {
                li.add(i);
                n = n/i;
            }
        }

        // This condition is to handle the case whien n is a prime number
        // greater than 2
        if (n > 2)
            li.add(n);
        return li;
    }
    int res[];
    void sieve(){
        res=new int[10000009];

        int p[]=new int[10000009];
        for(int i=2;i<=10000000;i++){
            if(p[i]==0){
                for(int j=i+i;j<=10000000;j+=i){
                    if(p[i]==0){
                        p[j]=i;
                    }
                    res[i]=res[i-1]+i;
                }
            }
            else{
                res[i]=res[i-1]+p[i];
            }
        }
    }
    public static HashSet<String> getAllPermutations(String str) {

        HashSet<String> permutations = new HashSet<String>();

        if(str == null || str.length() == 0) {
            permutations.add("" );
            return permutations;
        }

        char first = str.charAt(0);
        String remainingString = str.substring(1);
        HashSet<String> words = getAllPermutations(remainingString);
        for(String word: words) {
            for(int i = 0; i <= word.length(); i++) {
                String prefix = word.substring(0, i);
                String suffix = word.substring(i);
                permutations.add(prefix + first + suffix);
            }
        }
        return permutations;
    }

//    static class Pair<T> {
//        T a;
//        T b;
//
//        public Pair(T a, T b) {
//            this.a = a;
//            this.b = b;
//        }
//    }
private ArrayList<Integer> adj[];
    private boolean visited[];
   // private boolean visited1[];
    private LinkedList<Integer> q;
    private int level[];
    private int f=0;
    void initialize(){
        visited=new boolean[20001];
        //visited1=new boolean[10001];
        level =new int[20001];
        Arrays.fill(visited,false);
    }
    void solve() {
        int n =in.nextInt();
        int m[]=new int[367];
        int f[]=new int[367];
        while(n-->0){
            String s=in.next();
            int x=in.nextInt();
            int y=in.nextInt();
            if(s.equals("F")){
                for(int i=x;i<=y;i++)
                    f[i]++;
            }
            else {
                for(int i=x;i<=y;i++)
                    m[i]++;
            }
        }
        int ans=0;
        for(int i=1;i<=366;i++){
            ans=Math.max(ans,2*Math.min(m[i],f[i]));
        }
        System.out.println(ans);
    }



    void bfs1(int i){
        q=new LinkedList<>();
        q.add(i);
        visited[i]=true;
        while(!q.isEmpty()){
            int s=q.peekFirst();
            q.removeFirst();
            for(int j=0;j<adj[s].size();j++){
                if(!visited[adj[s].get(j)]){
                    level[adj[s].get(j)]=(level[s]+1);
                    q.add(adj[s].get(j));
                    visited[adj[s].get(j)]=true;
                }

            }
        }
    }
    int bfs(int i){
        q=new LinkedList<>();
        q.add(i);
        visited[i]=true;int g=0;
        while(!q.isEmpty()){
            int s=q.peekFirst();
            if(q.size()==1 && adj[s].size()==1)
            {
                g=s;
            }
            q.removeFirst();
            for(int j=0;j<adj[s].size();j++){
                if(!visited[adj[s].get(j)]){
                    //level[adj[s].get(j)]=level[s]+1;
                    q.add(adj[s].get(j));
                    visited[adj[s].get(j)]=true;
                }
            }
        }
        return g;
    }
    boolean dfs(int i,int parent){
        visited[i]=true;
        for(int j=0;j<adj[i].size();j++){
            if(adj[i].get(j)==parent && visited[i])
                continue;
            if(!visited[adj[i].get(j)]) {
                f++;
            }
            if(dfs(adj[i].get(j),i)){
                return true;
            }
        }
        return false;
    }
    static boolean isPali(StringBuilder s){
        for(int i = 0; i < (s.length() >> 1); i++)
            if(s.charAt(i) != s.charAt(s.length() - 1 - i))
                return false;
        return true;
    }
    void run(){
        try {
            in = new FastScanner(new File("B.in"));
            out = new PrintWriter(new File("B.out"));
            solve();
            out.close();
        }
        catch(FileNotFoundException e){
            e.printStackTrace();
        }
    }

    void runIO(){
        in = new FastScanner(System.in);
        out = new PrintWriter(System.out);

        solve();
        out.close();
    }
    class FastScanner{
        BufferedReader br;
        StringTokenizer st;
        public FastScanner(File f){
            try{
                br = new BufferedReader(new FileReader(f));
            }
            catch(FileNotFoundException e){
                e.printStackTrace();
            }
        }
        public FastScanner(InputStream f){
            br = new BufferedReader(new InputStreamReader(f));
        }
        String next(){
            while(st==null || !st.hasMoreTokens()){
                String s = null;
                try{
                    s= br.readLine();
                }
                catch(IOException e){
                    e.printStackTrace();
                }
                if(s==null)
                    return null;
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        boolean hasMoreTokens(){
            while(st==null || !st.hasMoreTokens()){
                String s = null;
                try{
                    s= br.readLine();
                }
                catch(IOException e){
                    e.printStackTrace();
                }
                if(s==null)
                    return false;
                st = new StringTokenizer(s);
            }
            return true;
        }
        int nextInt(){
            return Integer.parseInt(next());
        }
        long nextLong(){
            return Long.parseLong(next());
        }
        double nextDouble(){
            return Double.parseDouble(next());
        }
    }

    public static void main(String[] args) {
        new CF().runIO();
    }
}