Problem:
Score : 400 points

Problem Statement

Joisino is planning to record N TV programs with recorders.

The TV can receive C channels numbered 1 through C.

The i-th program that she wants to record will be broadcast from time s_i to time t_i (including time s_i but not t_i) on Channel c_i.

Here, there will never be more than one program that are broadcast on the same channel at the same time.

When the recorder is recording a channel from time S to time T (including time S but not T), it cannot record other channels from time S-0.5 to time T (including time S-0.5 but not T).

Find the minimum number of recorders required to record the channels so that all the N programs are completely recorded.

Constraints

1≤N≤10^5

1≤C≤30

1≤s_i<t_i≤10^5

1≤c_i≤C

If c_i=c_j and i≠j, either t_i≤s_j or s_i≥t_j.

All input values are integers.

Input

Input is given from Standard Input in the following format:

N C
s_1 t_1 c_1
:
s_N t_N c_N

Output

When the minimum required number of recorders is x, print the value of x.

Sample Input 1

3 2
1 7 2
7 8 1
8 12 1

Sample Output 1

2

Two recorders can record all the programs, for example, as follows:

With the first recorder, record Channel 2 from time 1 to time 7. The first program will be recorded. Note that this recorder will be unable to record other channels from time 0.5 to time 7.

With the second recorder, record Channel 1 from time 7 to time 12. The second and third programs will be recorded. Note that this recorder will be unable to record other channels from time 6.5 to time 12.

Sample Input 2

3 4
1 3 2
3 4 4
1 4 3

Sample Output 2

3

There may be a channel where there is no program to record.

Sample Input 3

9 4
56 60 4
33 37 2
89 90 3
32 43 1
67 68 3
49 51 3
31 32 3
70 71 1
11 12 3

Sample Output 3

2

Solution in Rust (1.15.1) (judge verdict: Accepted)

use std::io;
use std::collections::HashMap;
use std::mem;
use std::cmp;

fn read_line() -> String{
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn read_ints() -> Vec<i64>{
    let s = read_line();
    let split:Vec<&str> = s.split(" ").collect();
    split.iter().map(|&x| x.to_string().parse().unwrap()).collect()
}

fn main(){
    let arr = read_ints();
    let (n,nc) = (arr[0],arr[1]);
    let mut tables = Vec::new();
    let max_time = 100001 as usize;
    for i in 0..nc as usize{
        tables.push(vec![0;max_time*2]);
    }
    
    
    for i in 0..n as usize{
        let arr = read_ints();
        
        let s = (arr[0]-1) as usize;
        let t = (arr[1]-1) as usize;
        let c = (arr[2]-1) as usize;
        
        tables[c][(2*s  ) as usize]=1;
        tables[c][(2*t+1) as usize]=-1;
    }
    
    let mut ans = 0;
    let mut cnt = 0;
    
    
    for j in 0..nc as usize{
        for i in 0..max_time{
            if tables[j][2*i] == 1 && tables[j][2*i+1] == -1{
                tables[j][2*i+1] = 0;
                tables[j][2*i  ] = 0;
            }
        }
    }
    
    for i in 0..(2*max_time) as usize{
        for j in 0..nc as usize{
            cnt += tables[j][i];
        }
        ans = cmp::max(ans,cnt);
    }
    
    println!("{}",ans);
    
    /*
    let starts = Vec::new();
    let ends = Vec::new();
    let channels = Vec::new();
    
    for i in 0..n as usize{
        let arr = read_ints();
        starts.push(arr[0]);
        ends.push(arr[1]);
        channels.push(arr[2]-1);
    }*/
}

/*
struct Uf{
    n_size: usize,
    par   : Vec<i32>,
    rank  : Vec<i32>,
}

impl Uf{
    fn new(n_size:usize) -> Uf{
        Circle{
            n_size:n_size,
            par  :(0..n_size).collect(),
            rank :vec![0;n_size]
        }
    }
    
    fn find(&self, x: i64)->i64{
        let h = self.hash(x);
        
        if( par[h] == x ){
            x
        }else{
            par[h] = self.find(x);
            
        }
    }
}

*/



/*
DOCS


let mut h = HashMap::new();
let a = 5;
h.insert(a,true);
match h.get(&a){
    Some(v) => println!("{}",v),
    None    => println!("none"),
}


use std::mem;

let mut x = 5;
let mut y = 1;
mem::swap(&mut x,&mut y);


let v = vec![0;2]; // [0,0]

s.chars().nth(i as usize).unwrap();





*/