stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include<bits/stdc++.h>

#define rep(i,a,b) for(int i=int(a);i<int(b);++i)

using namespace std;

typedef long long ll;

int INF = (1LL << 30) - 1;

int MOD = 1e9+7;

main(){

    int N,C;

    cin >> N >> C;

    int cnt[C][100010] = {};

    vector<int> S(N),T(N),P(N);

    rep(i,0,N){

        cin >> S[i] >> T[i] >> P[i];

        cnt[P[i]-1][S[i]-1]++;

        cnt[P[i]-1][T[i]]--;

    }

    rep(i,1,100000)rep(j,0,C){

        cnt[j][i] += cnt[j][i-1];

    }

    int maxi = 0;

    rep(i,0,100000){

        int c = 0;

        rep(j,0,C){

            c += (cnt[j][i] > 0);

        }

        maxi = max(maxi, c);

    }

    cout << maxi << endl;

}

// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

#define rep(i,a,b) for(int i=int(a);i<int(b);++i)

using namespace std;

typedef long long ll;

int INF = (1LL << 30) - 1;

int MOD = 1e9+7;

int imos[30][100010];

main(){

    int N,C;

    cin >> N >> C;

    vector<int> S(N),T(N),R(N);

    rep(i,0,N)cin >> S[i] >> T[i] >> R[i];

    rep(i,0,N){

        imos[R[i]-1][S[i]]++;

        imos[R[i]-1][T[i]+1]--;

    }

    rep(i,0,C)rep(j,0,100001)imos[i][j+1] += imos[i][j];

    int maxi = 0;

    //rep(i,0,C)rep(j,0,20)cout << imos[i][j] << " \n"[j==19];

    rep(i,0,100002){

        int cnt = 0;

        rep(j,0,C)if(imos[j][i])cnt++;

        maxi = max(maxi, cnt);

    }

    cout << maxi << endl;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define inf 1LL<<62





ll a[100010],cha[32][100010];

int main() {

	ll n ,C;

	cin>>n>>C;

	for(int i=0;i<n;i++){

		int l,r,c;

		cin>>l>>r>>c;

		c--;

		for(int j=l;j<=r;j++){

			cha[c][j]=1;

		}

	}

	for(int i=0;i<C;i++){

		for(int j=0;j<100010;j++){

			if(cha[i][j]==1){

				a[j]++;

			}

		}

	}

	ll ans=0;

	for(int i=0;i<100010;i++ ){

		ans=max(ans,a[i]);

	}

	cout <<ans;

	return 0;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define INF 1LL<<62

#define inf 1000000007



ll ch[100010];

ll same[32][100010];

int main() {

	ll n,c;

	cin>>n>>c;

	ll sum=0;

	for(ll i=0;i<n;i++){

		ll l,r,z;

		cin>>l>>r>>z;

		ch[l]++;

		ch[r+1]--;

		same[z][l]++;

		same[z][r]++;

		if(same[z][l]==2){

			ch[l]--;

			ch[l+1]++;

		}

		if(same[z][r]==2){

			ch[r]--;

			ch[r+1]++;

		}

	}

	ll ans=ch[0];

	for(ll i=1;i<100010;i++){

		ch[i]=ch[i-1]+ch[i];

		ans=max(ans,ch[i]);

	}

	cout <<ans-sum;

	// your code goes here

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define INF 1LL<<62

#define inf 1000000007 



ll a[32][100010];

ll b[100010];

int main() {

	ll n,c;

	cin>>n>>c;

	for(int i=0;i<n;i++){

		ll x,y,z;

		cin>>x>>y>>z;

		z--;

		a[z][x]++;

		a[z][y]--;

	}

	for(int i=0;i<c;i++){

		for(int j=0;j<100010;j++){

			a[i][j+1]=a[i][j]+a[i][j+1];

		}

	}

	for(int i=0;i<100010;i++){

		ll now=0;

		for(int j=0;j<c;j++){

			if(a[j][i]==0&&a[j][i+1]==1){

				now++;

				continue;

			}

			now+=a[j][i];

		}

		b[i]=now;

	}

	ll ans=0;

	for(int i=0;i<100010;i++){

		ans=max(ans,b[i]);

	}

	cout <<ans;

	// your code goes here

	return 0;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define INF 1LL<<62

#define inf 1000000007



ll ch[100010];

ll same[32][100010];

int main() {

	ll n,c;

	cin>>n>>c;

	ll sum=0;

	for(ll i=0;i<n;i++){

		ll l,r,z;

		cin>>l>>r>>z;

		ch[l]++;

		ch[r+1]--;

		same[z][l]++;

		same[z][r]++;

		if(same[z][l]==2){

			ch[l]--;

			ch[l+1]++;

		}

		if(same[z][r]==2){

			ch[r]--;

			ch[r+1]++;

		}

	}

	ll ans=ch[0];

	for(ll i=1;i<100010;i++){

		ch[i]=ch[i-1]+ch[i];

		ans=max(ans,ch[i]);

	}

	cout <<ans-sum;

	// your code goes here

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <vector>

#include <string>

#include <algorithm>

#include <cstdio>

#include <cstring>

#include <cmath>

using namespace std;



int main() {

    ios::sync_with_stdio(false);

    cin.tie(0);



    int n, c;

    cin >> n >> c;



    const int T = (int)1e5 + 1;



    vector<int> a[30];

    for (int k = 0; k < c; k++) {

        a[k] = vector<int>(T);

    }

    for (int i = 0; i < n; i++) {

        int s, t, c;

        cin >> s >> t >> c;

        c--;



        for (int j = s; j < t; j++) {

            a[c][j] = 1;

        }

    }

    for (int k = 0; k < c; k++) {

        for (int j = 1; j < T; j++) {

            if (a[k][j] == 1 && a[k][j - 1] == 0) a[k][j - 1] = 1;

        }

    }

    int r = 0;

    for (int j = 0; j < T; j++) {

        int s = 0;

        for (int k = 0; k < c; k++) {

            s += a[k][j];

        }

        r = max(r, s);

    }



    cout << r << endl;



    return 0;

}

// Optimized solution to the same problem (faster):
#include <iostream>

#include <vector>

#include <string>

#include <algorithm>

#include <cstdio>

#include <cstring>

#include <cmath>

using namespace std;



int main() {

    ios::sync_with_stdio(false);

    cin.tie(0);



    int n, c;

    cin >> n >> c;



    const int T = (int)1e5;



    vector<int> a(T);

    for (int i = 0; i < n; i++) {

        int s, t, c;

        cin >> s >> t >> c;

        c--;



        for (int j = s; j < t; j++) {

            a[j] ^= 1 << c;

        }

    }



    for (int j = 0; j < T - 1; j++) {

        a[j] ^= ~a[j] & a[j + 1];

    }



    int r = 0;

    for (int j = 0; j < T; j++) {

        int s = a[j];

        s = (s & 0x55555555) + (s >> 1 & 0x55555555);

        s = (s & 0x33333333) + (s >> 2 & 0x33333333);

        s = (s & 0x0f0f0f0f) + (s >> 4 & 0x0f0f0f0f);

        s = (s & 0x00ff00ff) + (s >> 8 & 0x00ff00ff);

        s = (s & 0x0000ffff) + (s >> 16);

        r = max(r, s);

    }



    cout << r << endl;



    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>



using namespace std;



struct segtree

{

	vector<int> t;

	segtree(int n) :t(n * 2 - 1, 0) {}

	void add(int a, int b, int o, int l, int r)

	{

		if (a >= r || b <= l)

			return;

		if (a <= l && b >= r) {

			t[o]++;

			return;

		}

		int m = (l + r) / 2;

		add(a, b, o + 1, l, m);

		add(a, b, o + (m - l) * 2, m, r);

	}

	int min(int o, int l, int r)

	{

		if (l + 1 == r)

			return t[o];

		int m = (l + r) / 2;

		int p = min(o + 1, l, m);

		int q = min(o + (m - l) * 2, m, r);

		return max(p, q) + t[o];

	}

};



pair<int, pair<int, int>> p[111111];

int main()

{

	int N, C;

	cin >> N >> C;

	for (int i = 0; i < N; i++)

		scanf("%d%d%d", &p[i].second.first, &p[i].second.second, &p[i].first);

	sort(p, p + N);

	segtree s(111000);

	int c = 0, d = 0;

	for (int i = 0; i < N; i++) {

		if (p[i].first != c || p[i].second.first != d) {

			c = p[i].first;

			s.add(p[i].second.first - 1, p[i].second.first, 0, 0, 111000);

		}

		d = p[i].second.second;

		s.add(p[i].second.first, p[i].second.second, 0, 0, 111000);

	}

	cout << s.min(0, 0, 111000) << endl;

	return 0;

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>



using namespace std;



int p[111111], q[30][111111];

int main()

{

	int N, m, n = 0;

	cin >> N >> m;

	for (int i = 0; i < N; i++) {

		int s, t, c;

		scanf("%d%d%d", &s, &t, &c);

		n = max(n, t);

		if (!q[--c][s])

			q[c][s--] = 1;

		if (q[c][t]) t--;

		else q[c][t] = 1;

		while (s < t) p[s++]++;

	}

	m = 0;

	for (int i = 1; i <= n; i++)

		m = max(m, p[i]);

	cout << m << endl;

	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

typedef signed long long ll;



#undef _P

#define _P(...) (void)printf(__VA_ARGS__)

#define FOR(x,to) for(x=0;x<(to);x++)

#define FORR(x,arr) for(auto& x:arr)

#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)

#define ALL(a) (a.begin()),(a.end())

#define ZERO(a) memset(a,0,sizeof(a))

#define MINUS(a) memset(a,0xff,sizeof(a))

//-------------------------------------------------------



int N,CC;

int S[101010],T[101010],C[101010],did[101010];

vector<int> st[201010];



int pre[101010];



void solve() {

	int i,j,k,l,r,x,y; string s;

	

	cin>>N>>CC;

	FOR(i,N) {

		cin>>S[i]>>T[i]>>C[i];

		S[i]*=2;

		T[i]*=2;

		C[i]--;

		st[S[i]].push_back(i);

	}

	

	int num=0;

	MINUS(pre);

	FOR(i,201000) {

		

		FORR(e,st[i]) {

			if(pre[C[e]]!=-1) {

				pre[C[e]]=T[e];

				did[e]++;

			}

		}

		FORR(e,st[i]) if(did[e]==0) {

			FOR(j,CC) {

				if(pre[j]!=-1 && pre[j]<S[e]-1) {

					pre[j]=-1;

					pre[C[e]]=T[e];

					break;

				}

			}

			if(j==CC) {

				pre[C[e]]=T[e];

				num++;

			}

		}

	}

	

	

	

	cout<<num<<endl;

	

	

}





int main(int argc,char** argv){

	string s;int i;

	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);

	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);

	cout.tie(0); solve(); return 0;

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;

typedef signed long long ll;



#undef _P

#define _P(...) (void)printf(__VA_ARGS__)

#define FOR(x,to) for(x=0;x<(to);x++)

#define FORR(x,arr) for(auto& x:arr)

#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)

#define ALL(a) (a.begin()),(a.end())

#define ZERO(a) memset(a,0,sizeof(a))

#define MINUS(a) memset(a,0xff,sizeof(a))

//-------------------------------------------------------



int N,CC;

int S[101010],T[101010],C[101010],did[101010];

vector<int> st[201010];



int pre[101010];



void solve() {

	int i,j,k,l,r,x,y; string s;

	

	cin>>N>>CC;

	FOR(i,N) {

		cin>>S[i]>>T[i]>>C[i];

		C[i]--;

		st[S[i]].push_back(i);

	}

	

	int num=0;

	FOR(i,CC) pre[i]=202020;

	FOR(i,101000) {

		

		FORR(e,st[i]) {

			if(pre[C[e]]<=S[e]) {

				pre[C[e]]=T[e];

				did[e]++;

			}

		}

		FORR(e,st[i]) if(did[e]==0) {

			FOR(j,CC) {

				if(pre[j]<S[e]) {

					pre[j]=202020;

					pre[C[e]]=T[e];

					break;

				}

			}

			if(j==CC) {

				pre[C[e]]=T[e];

				num++;

			}

		}

	}

	

	

	

	cout<<num<<endl;

	

	

}





int main(int argc,char** argv){

	string s;int i;

	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);

	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);

	cout.tie(0); solve(); return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>



using namespace std;

 

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)

#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)

#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)

#define all(c) (c).begin(),(c).end()

#define sz(v) (int)(v).size()



typedef int64_t ll; typedef vector<int> VI; typedef pair<int,int> pii;

const ll mod = 1e9+7;



void dbg(){ cerr << "\n"; }  

template <typename T,typename ...T2>

void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }



int main()

{

 

	//cin.tie(0); ios_base::sync_with_stdio(false);

	const int MX=200001;

	int n, ch;

	cin >>n >>ch;

	vector<vector<pii>> dt(ch);

	//VI s(n), t(n), c(n);

	

	rep(i, n){

		int s,t,c;

		cin >>s >> t >>c;

		dt[c-1].push_back(pii(2*s-1, 2*t));

	}

	rep(i,ch) sort(all(dt[i]));

	vector<int> usd(MX+20);



	rep(i,ch){

		int fr=0, to=0;

		rep(j, sz(dt[i])){

			if(dt[i][j].first > to || to==0){

				if(to >0){

					usd[fr] +=1;

					usd[to] -=1;

					//dbg(i,fr,to);

				}

				tie(fr,to) = dt[i][j];

			}

			if(dt[i][j].first <= to){

				to = max(to, dt[i][j].second);

			}

		}

		usd[fr] +=1;

		usd[to] -=1;

		//dbg(i,fr,to);

	}

	rep(i, MX) usd[i+1] += usd[i];

	//rep(i,100) printf("%d, ",usd[i]); puts("");

	cout << *max_element(all(usd)) <<"\n";

	

	return 0;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>





#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)

#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)

#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)

#define all(c) (c).begin(),(c).end()

#define sz(v) (int)(v).size()



using namespace std;

typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;

const int MD = (int)1e9 + 7; typedef vector<ll> VL;

void dbg(){ cerr << "\n"; }  template <class T, class ...T2>

void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}



int main()

{

	cin.tie(0); ios_base::sync_with_stdio(false);

	int n, c;

	cin >>n >>c;

	vector<VI> dt(n, VI(4)), dt2; 

	rep(i, n) cin >>dt[i][1] >>dt[i][2] >>dt[i][0];

	sort(all(dt));

	VI ccr = dt[0];

	rep2(i, 1, n){

		if(ccr[0] == dt[i][0] && ccr[2]==dt[i][1]){

			ccr[2] = dt[i][2];

		}else{

			dt2.push_back(ccr);

			ccr = dt[i];

		}

	}

	dt2.push_back(ccr);

	sort(all(dt2), [](auto& l, auto& r){return l[1] < r[1];});

	VI vdr; int ans = 0;

	for(const auto& x: dt2){

		int add = 1;

		for(auto& z: vdr){

			if( z < x[1]){

				z = x[2]; add = 0; break;

			}

		}

		if(add==1){

			vdr.push_back(x[2]);

			ans = max(ans, sz(vdr));

		}

	}

	cout <<ans <<"\n";

	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#include <vector>



using namespace std;

 

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)

#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)

#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)

#define all(c) (c).begin(),(c).end()

#define sz(v) (int)(v).size()



typedef int64_t ll; typedef vector<int> VI; typedef pair<int,int> pii;

const ll mod = 1e9+7;



void dbg(){ cerr << "\n"; }  

template <typename T,typename ...T2>

void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }









int main()

{

 

	//cin.tie(0); ios_base::sync_with_stdio(false);

	int n, c;

	cin >> n >>c;

	vector<vector<pii>> dt(c);

	

	rep(i, n){

		int s,t,z;

		cin >>s >>t >>z;

		dt[z-1].emplace_back(2*s-1, 2*t);

	}

	rep(i, c) sort(all(dt[i]));

	

	rep(i, c) if(sz(dt[i])>0){

		vector<pii> vp ={ dt[i][0] };

		rep2(j, 1, sz(dt[i])){

			if(vp.back().second >= dt[i][j].first){

				vp.back().second = dt[i][j].second;

			}else vp.push_back(dt[i][j]);

		}

		dt[i] = vp;

	}

	

	const int MXS=200100;

	vector<int> tm(MXS+100);

	rep(i, c) for(auto z: dt[i]){

		tm[z.first]++; tm[z.second + 1]--;

	}

	rep(i, MXS) tm[i+1] += tm[i];

	int ans =0;

	rep(i, MXS) ans = max(ans, tm[i]);

	cout << ans <<"\n";

	

	return 0;

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>





#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)

#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)

#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)

#define all(c) (c).begin(),(c).end()

#define sz(v) (int)(v).size()



using namespace std;

typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;

const int MD = (int)1e9 + 7; typedef vector<ll> VL;

void dbg(){ cerr << "\n"; }  template <class T, class ...T2>

void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}



int main()

{

	cin.tie(0); ios_base::sync_with_stdio(false);

	int n, c;

	cin >>n >>c;

	vector<VI> dt(n, VI(4)), dt2; 

	rep(i, n) cin >>dt[i][1] >>dt[i][2] >>dt[i][0];

	sort(all(dt));

	VI ccr = dt[0];

	rep2(i, 1, n){

		if(ccr[0] == dt[i][0] && ccr[2]==dt[i][1]){

			ccr[2] = dt[i][2];

		}else{

			dt2.push_back(ccr);

			ccr = dt[i];

		}

	}

	dt2.push_back(ccr);

	sort(all(dt2), [](auto& l, auto& r){return l[1] < r[1];});

	VI vdr; int ans = 0;

	for(const auto& x: dt2){

		int add = 1;

		for(auto& z: vdr){

			if( z < x[1]){

				z = x[2]; add = 0; break;

			}

		}

		if(add==1){

			vdr.push_back(x[2]);

			ans = max(ans, sz(vdr));

		}

	}

	cout <<ans <<"\n";

	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>



using namespace std;

const int MAXN=100001;

int n,m,st[MAXN],et[MAXN],c[MAXN],pre[2*MAXN],res[2*MAXN];



int main()

{

	cin >> n >> m;

	for(int i=1;i<=n;i++) cin >>st[i] >>et[i] >>c[i];

	for(int i=1;i<=m;i++)

	{

		memset(pre,0,sizeof(pre));

		for(int j=1;j<=n;j++) if(c[j]==i) pre[st[j]*2-1]++,pre[et[j]*2]--;

		for(int j=1;j<=2*MAXN-2;j++) pre[j]+=pre[j-1];

		for(int j=1;j<=2*MAXN-2;j++) if(pre[j]>0) res[j]++;

	}

	

	int ans=0;

	for(int i=1;i<=2*MAXN-2;i++) ans=max(ans,res[i]);

	cout << ans;

	return 0;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>



using namespace std;

const int MAXN=100001;

int n,m,st[MAXN],et[MAXN],c[MAXN],pre[MAXN],res[MAXN];



int main()

{

	cin >> n >> m;

	for(int i=1;i<=n;i++) cin >>st[i] >>et[i] >>c[i];

	for(int i=1;i<=m;i++)

	{

		memset(pre,0,sizeof(pre));

		for(int j=1;j<=n;j++) if(c[j]==i) pre[st[j]]++,pre[et[j]+1]--;

		for(int j=1;j<MAXN;j++) pre[j]+=pre[j-1];

		for(int j=1;j<MAXN;j++) if(pre[j]>0) res[j]++; //因为i,j属于一个频道，所以只能算一次 

	}

	

	int ans=0;

	for(int i=1;i<MAXN;i++) ans=max(ans,res[i]);

	cout << ans;

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>



using namespace std;

const int MAXN=100001;

int n,m,st[MAXN],et[MAXN],c[MAXN],pre[2*MAXN],res[2*MAXN];



int main()

{

	cin >> n >> m;

	for(int i=1;i<=n;i++) cin >>st[i] >>et[i] >>c[i];

	for(int i=1;i<=m;i++)

	{

		memset(pre,0,sizeof(pre));

		for(int j=1;j<=n;j++) if(c[j]==i) pre[st[j]]++,pre[et[j]+1]--;

		for(int j=1;j<=MAXN;j++) pre[j]+=pre[j-1];

		for(int j=1;j<=MAXN;j++) if(pre[j]>0) res[j]++;

	}

	

	int ans=0;

	for(int i=1;i<=2*MAXN-2;i++) ans=max(ans,res[i]);

	cout << ans;

	return 0;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>



using namespace std;

const int MAXN=100001;

int n,m,st[MAXN],et[MAXN],c[MAXN],pre[MAXN],res[MAXN];



int main()

{

	cin >> n >> m;

	for(int i=1;i<=n;i++) cin >>st[i] >>et[i] >>c[i];

	for(int i=1;i<=m;i++)

	{

		memset(pre,0,sizeof(pre));

		for(int j=1;j<=n;j++) if(c[j]==i) pre[st[j]]++,pre[et[j]+1]--;

		for(int j=1;j<MAXN;j++) pre[j]+=pre[j-1];

		for(int j=1;j<MAXN;j++) if(pre[j]>0) res[j]++; //因为i,j属于一个频道，所以只能算一次 

	}

	

	int ans=0;

	for(int i=1;i<MAXN;i++) ans=max(ans,res[i]);

	cout << ans;

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

using ll=long long;

const ll MOD=(ll)1e9+7;



int main(){

    int N,C; cin>>N>>C;

    vector<vector<bool>> used(C,vector<bool>(200011,false));

    for (int i = 0; i < N; ++i) {

        int s,t,c;

        cin>>s>>t>>c;

        s=s*2-1; t*=2; c--;

        for(;s<=t;s++){

            used[c][s]=true;

        }

    }



    int ans=0;

    for (int i = 0; i < 200005; ++i) {

        int cnt=0;

        for (int j = 0; j < C; ++j) {

            if(used[j][i]) cnt++;

        }

        ans=max(ans,cnt);

    }



    cout<<ans<<endl;



    return 0;

}




// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;

using ll=long long;

const ll MOD=(ll)1e9+7;

//const ll MOD=(ll)998244353;

const ll INF=(ll)1e18+10;

const double PI = 2.0*acos(0);

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }

template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

int dy[]={-1,1,0,0};

int dx[]={0,0,-1,1};



void solve(int ca){

    int N,C; cin>>N>>C;

    vector<vector<bool>> used(C,vector<bool>(100010,false));

    int s,t,c;

    for (int i = 0; i < N; ++i) {

        cin>>s>>t>>c; --s; --c;

        for (int j = s; j < t; ++j) {

            used[c][j]=true;

        }

    }



    int ans=0;

    for (int i = 0; i <= 100000; ++i) {

        int cnt=0;

        for (int j = 0; j < C; ++j) {

            if(used[j][i]) cnt++;

        }

        //if(cnt==3) cout<<i<<endl;

        chmax(ans,cnt);

    }

    cout<<ans<<endl;



}



//#define MULTI

int main() {

#ifdef MULTI

    int N; cin>>N;

    for (int i = 0; i < N; ++i) {

        solve(i+1);

    }

#else

    solve(0);

#endif

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<vector>

#include<map>

#include<algorithm>

#include<cmath>

#include<string>

#include<cstdlib>



#define FOR(i,a,b) for(int i=(a);i<(b);++i)

#define REP(i,n)   FOR(i,0,n)

#define MOD 1000000007



using namespace std;

 

typedef long long int ll;



const ll INF=(ll)1e18;



int N,C;



int main(){

    cin >> N >> C;



    vector<pair<int, int> > st[31],st2[31];



    REP(i,N){

        int ss,tt,cc;

        cin >> ss >> tt >> cc;

        st[cc].push_back(make_pair(ss,tt));

    }

    FOR(i,1,C+1){

        sort(st[i].begin(),st[i].end());

    }

    FOR(i,1,C+1){

        int ss = -1;

        int tt = -1;

        REP(j,st[i].size()){

            if(ss == -1)ss=st[i][j].first;

            if(tt == -1){

                tt=st[i][j].second;

            }else{

                if(tt == st[i][j].first){

                    tt=st[i][j].second;

                }else{

                    st2[i].push_back(make_pair(ss,tt));

                    ss=st[i][j].first;

                    tt=st[i][j].second;

                }

            }

        }

        if(ss != -1)st2[i].push_back(make_pair(ss,tt));

    }



    // FOR(i,1,C+1){

    //     REP(j,st[i].size()){

    //         cout << st[i][j].first << " " << st[i][j].second << endl;

    //     }

    // }

    // FOR(i,1,C+1){

    //     REP(j,st2[i].size()){

    //         cout << st2[i][j].first << "  " << st2[i][j].second << endl;

    //     }

    // }



    int rec[300000] = {0};

//    FOR(i,300001)rec[i] = 0;



    FOR(i,1,C+1){

        REP(j,st2[i].size()){

            rec[st2[i][j].first * 2 - 1] += 1;

            rec[st2[i][j].second * 2] -= 1;

        }

    }



    // REP(i,30){

    //     cout << i << " " << rec[i] << endl;

    // }

    int ans = 0;

    REP(i,300000-1){

        rec[i+1] = rec[i+1] + rec[i];

        ans = max(ans, rec[i+1]);

    }



    // REP(i,30){

    //     cout << i << " " << rec[i] << endl;

    // }

    cout << ans << endl;



}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;



#define FOR(i,a,b) for(int i=(a);i<(b);++i)

#define REP(i,n)   FOR(i,0,n)

#define ALL(a)     (a).begin(),(a).end()

#define MOD 1000000007



typedef long long int ll;



const ll INF=(ll)1e19;

//const int INF=(1<<30);







int main(){

  int N,C;

  cin >> N >> C;



  vector<vector<pair<int, int>>> st(C+1);



  REP(i,N){

    int s,t,c;

    cin >> s >> t>> c;

    st[c].push_back(make_pair(s,t));

  }



  vector<int> sum(200001,0);



  FOR(i,1,C+1){

    sort(ALL(st[i]));

    REP(j,st[i].size()){

      if(j>0 && st[i][j-1].second == st[i][j].first){

        sum[st[i][j].first*2+1] += 1;

        sum[st[i][j].second*2+1] -= 1;        

      }else{

        sum[st[i][j].first*2-1] += 1;

        sum[st[i][j].second*2+1] -= 1;        

      }

    }



  }



  FOR(i,1,sum.size()){

    sum[i] += sum[i-1];

  }



  int ans=0;

  FOR(i,1,sum.size()){

    ans = max(ans,sum[i]);

  }

  cout << ans << endl;

}




// Fastest known solution for this problem: