You are given n segments [l_1, r_1], [l_2, r_2], ..., [l_n, r_n]. Each segment has one of two colors: the i-th segment's color is t_i.

Let's call a pair of segments i and j bad if the following two conditions are met:

  * t_i ≠ t_j; 
  * the segments [l_i, r_i] and [l_j, r_j] intersect, embed or touch, i. e. there exists an integer x such that x ∈ [l_i, r_i] and x ∈ [l_j, r_j]. 



Calculate the maximum number of segments that can be selected from the given ones, so that there is no bad pair among the selected ones.

Input

The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^5) — number of segments.

The next n lines contains three integers l_i, r_i, t_i (1 ≤ l_i ≤ r_i ≤ 10^9; t_i ∈ \{1, 2\}) — description of the i-th segment.

Output

Print the maximum number of segments that can be selected, so that there is no bad pair among the selected segments.

Examples

Input


3
1 3 1
4 6 2
2 5 1


Output


2


Input


5
5 8 1
1 3 2
3 4 2
6 6 1
2 10 2


Output


4


Input


7
19 20 1
13 15 2
6 11 2
4 10 1
14 17 1
13 13 2
5 9 1


Output


5
/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
What do you think? What do you think?
1st on Billboard, what do you think of it
Next is a Grammy, what do you think of it
However you think, I’m sorry, but shit, I have no fcking interest
*******************************
I'm standing on top of my Monopoly board
That means I'm on top of my game and it don't stop
til my hip don't hop anymore
https://www.a2oj.com/Ladder16.html
*******************************
300iq as writer = Sad!
*/
import java.util.*;
import java.io.*;
import java.math.*;

   public class x1389F
   {
      public static void main(String hi[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         int[][] arr = new int[N][3];
         for(int i=0; i < N; i++)
         {
            st = new StringTokenizer(infile.readLine());
            arr[i][0] = Integer.parseInt(st.nextToken());
            arr[i][1] = Integer.parseInt(st.nextToken());
            arr[i][2] = Integer.parseInt(st.nextToken())-1;
         }
         PriorityQueue<Event> pq = new PriorityQueue<Event>();
         for(int i=0; i < N; i++)
         {
            pq.add(new Event(arr[i][0], i, false));
            pq.add(new Event(arr[i][1], i, true));
         }
         TreeMap<Integer, Integer>[] active = new TreeMap[2];
         active[0] = new TreeMap<Integer, Integer>();
         active[1] = new TreeMap<Integer, Integer>();
         int res = N;
         while(pq.size() > 0)
         {
            Event curr = pq.poll();
            int i = curr.dex;
            if(!curr.end)
               push(active[arr[i][2]], arr[i][1]);
            else
            {
               int other = arr[i][2]^1;
               if(active[other^1].containsKey(curr.time))
               {
                  if(active[other].size() > 0)
                  {
                     pull(active[other], active[other].firstKey());
                     res--;
                  }
                  pull(active[other^1], curr.time);
               }
            }
         }
         System.out.println(res);
      }
      public static void push(TreeMap<Integer, Integer> map, int k)
      {
         if(!map.containsKey(k))
            map.put(k, 0);
         map.put(k, map.get(k)+1);
      }
      public static void pull(TreeMap<Integer, Integer> map, int k)
      {
         map.put(k, map.get(k)-1);
         if(map.get(k) == 0)
            map.remove(k);
      }
   }
   class Event implements Comparable<Event>
   {
      public int time;
      public int dex;
      public boolean end;
      
      public Event(int a, int b, boolean c)
      {
         time = a;
         dex = b;
         end = c;
      }
      public int compareTo(Event oth)
      {
         if(time == oth.time)
         {
            if(!end && oth.end)
               return -1;
            if(end && !oth.end)
               return 1;
            return 0;
         }
         return time-oth.time;
      }
   }