AtCoder Beginner Contest 080 - Recording

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-----
3 2
1 7 2
7 8 1
8 12 1

-----Sample Output-----
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.

Source: atcoder | Difficulty: MEDIUM


Solutions:
def main():
	import sys
	input = sys.stdin.readline
	from heapq import heappush
	(N, C) = map(int, input().split())
	table = [[0] * 10 ** 5 for _ in range(C)]
	for _ in range(N):
		(s, t, c) = map(int, input().split())
		s -= 1
		t -= 1
		c -= 1
		for i in range(s, t + 1):
			table[c][i] = 1
	ans = 0
	for i in range(10 ** 5):
		tmp = sum((table[j][i] for j in range(C)))
		ans = max(ans, tmp)
	print(ans)

def __starting_point():
	main()
__starting_point()


import numpy as np

def main():
	with open(0) as f:
		(N, C) = list(map(int, f.readline().split()))
		Rec = [tuple(map(int, f.readline().split())) for _ in range(N)]
	time_line_by_channel = np.array([[0] * (10 ** 5 + 1) for _ in range(C + 1)])
	for (s, t, c) in Rec:
		time_line_by_channel[c, s - 1:t] = 1
	joined_timeline = np.sum(time_line_by_channel, axis=0)
	ans = max(joined_timeline)
	print(ans)
main()


from itertools import accumulate
(N, C) = map(int, input().split())
E = [[0] * 100010 for _ in range(C)]
for _ in range(N):
	(s, t, c) = map(int, input().split())
	E[c - 1][s - 1] += 1
	E[c - 1][t - 1] -= 1
F = [0] * 100010
for e in E:
	for (i, v) in enumerate(e):
		if v == 1:
			F[i] += 1
		if v == -1:
			F[i + 1] -= 1
ans = max(list(accumulate(F)))
print(ans)


import sys
import numpy as np
readline = sys.stdin.readline
read = sys.stdin.read

def main():
	(n, c) = map(int, readline().split())
	m = 2 * 10 ** 5
	stc = [list(map(int, l.split())) for l in read().splitlines()]
	cht = np.zeros((c, m + 1), dtype='int64')
	for e in stc:
		cht[e[2] - 1, 2 * e[0] - 1:2 * e[1]] = np.ones(2 * e[1] - 2 * e[0] + 1)
	print(max(np.sum(cht, axis=0)))

def __starting_point():
	main()
__starting_point()


import itertools
(n, c) = map(int, input().split())
dp = [[0] * 100002 for i in range(c)]
for i in range(n):
	(s, t, x) = map(int, input().split())
	dp[x - 1][s - 1] += 1
	dp[x - 1][t] -= 1
for i in range(c):
	dp[i] = list(itertools.accumulate(dp[i]))
ans = 0
for i in range(100001):
	cnt = 0
	for j in range(c):
		if dp[j][i] != 0:
			cnt += 1
	ans = max(ans, cnt)
print(ans)


from itertools import accumulate
(N, C) = map(int, input().split())
R = [0] * (10 ** 5 + 1)
RC = [[] for _ in range(C)]
for _ in range(N):
	(s, t, c) = map(int, input().split())
	RC[c - 1].append((s, t))
for rc in RC:
	rc.sort()
	pt = 0
	for (s, t) in rc:
		if s == pt:
			R[pt] += 1
		else:
			R[s - 1] += 1
		R[t] -= 1
		pt = t
print(max(list(accumulate(R))))


(n, c) = map(int, input().split())
A = []
for i in range(n):
	(s, t, c) = map(int, input().split())
	A.append((s, t, c))
A.sort(key=lambda x: (x[2], x[0], x[1]))
B = []
(s, t, c) = A[0]
for i in range(1, n):
	(s2, t2, c2) = A[i]
	if c == c2 and t == s2:
		t = t2
	else:
		B.append((s - 1, t, c))
		(s, t, c) = (s2, t2, c2)
B.append((s - 1, t, c))
T = [0] * (10 ** 5 + 1)
for (s, t, c) in B:
	T[s] += 1
	T[t] -= 1
for i in range(10 ** 5):
	T[i + 1] += T[i]
print(max(T))


from itertools import accumulate
(n, c) = map(int, input().split())
stc = sorted([list(map(int, input().split())) for i in range(n)])
finish = [1] * (c + 1)
record = [0] * (10 ** 5 + 2)
ans = 1
for (s, t, c) in stc:
	if finish[c] != s:
		s -= 1
	finish[c] = t
	record[s] += 1
	record[t] -= 1
ans = max(list(accumulate(record)))
assert ans >= 1
assert ans <= n
print(ans)


from collections import defaultdict
import numpy as np
import sys
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7

def input():
	return sys.stdin.readline().strip()

def main():
	(N, C) = list(map(int, input().split()))
	MAX = 10 ** 5 + 2
	vals = [0] * MAX
	D = defaultdict(list)
	for _ in range(N):
		(s, t, c) = list(map(int, input().split()))
		D[c].append((s, t))
	for (k, v) in list(D.items()):
		prev = -1
		v.sort(key=lambda x: x[0])
		for (s, t) in v:
			if prev == s:
				vals[prev + 1] += 1
				vals[t + 1] -= 1
			else:
				vals[s] += 1
				vals[t + 1] -= 1
			prev = t
	cumsum = np.cumsum(vals)
	ans = max(cumsum)
	print(ans)

def __starting_point():
	main()
__starting_point()


(N, C) = map(int, input().split())
table = [[0] * (10 ** 5 + 1) for i in range(C)]
st = [[] for i in range(C)]
for i in range(N):
	(s, t, c) = map(int, input().split())
	st[c - 1].append([s, t])
st_new = [[] for i in range(C)]
for c in range(C):
	if st[c]:
		st[c].sort()
		st_new[c].append(st[c][0])
		n = len(st[c])
		for i in range(1, n):
			(si, ti) = st[c][i]
			(sii, tii) = st_new[c][-1]
			if si == tii:
				st_new[c][-1][1] = ti
			else:
				st_new[c].append([si, ti])
for c in range(C):
	for (s, t) in st_new[c]:
		table[c][s - 1] += 1
		table[c][t] -= 1
for c in range(C):
	for i in range(1, 10 ** 5 + 1):
		table[c][i] += table[c][i - 1]
ans = 0
for i in range(10 ** 5 + 1):
	num = 0
	for c in range(C):
		num += table[c][i]
	ans = max(ans, num)
print(ans)


(N, C) = map(int, input().split())
cha = [[0 for i in range(10 ** 5 + 1)] for j in range(C)]
for i in range(N):
	(s, t, c) = map(int, input().split())
	cha[c - 1][s - 1:t] = [1] * (t - s + 1)
channels = 0
for i in range(10 ** 5 + 1):
	chans = 0
	for c in range(C):
		chans += cha[c - 1][i]
	channels = max(channels, chans)
print(channels)


(N, C) = map(int, input().split())
STC = [list(map(int, input().split())) for _ in range(N)]
M = 10 ** 5 + 1
merge = [[0] * (M + 1) for _ in range(31)]
for i in range(N):
	(s, t, c) = STC[i]
	merge[c][s:t + 1] = [1] * (t - s + 1)
print(max(map(sum, zip(*merge))))


import math, itertools, fractions, heapq, collections, bisect, sys, queue, copy
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def LS():
	return sys.stdin.readline().split()

def S():
	return input()

def main():
	(N, C) = LI()
	l = [[0] * 100100 for _ in range(C)]
	for _ in range(N):
		(s, t, c) = LI()
		l[c - 1][s] += 1
		l[c - 1][t + 1] -= 1
	for i in range(C):
		for j in range(100000):
			l[i][j + 1] += l[i][j]
	for i in range(C):
		for j in range(100000):
			if l[i][j] == 2:
				l[i][j] = 1
	mx = 0
	for i in range(100000):
		sm = 0
		for j in range(C):
			sm += l[j][i]
		mx = max(mx, sm)
	return mx
print(main())


(n, c, *stc) = list(map(int, open(0).read().split()))
stc = list(zip(stc[::3], stc[1::3], stc[2::3]))
stc.sort()
record = []
for (s, t, c) in stc:
	for (i, (rt, rc)) in enumerate(record):
		if s - 0.5 >= rt:
			record[i] = (t, c)
			break
		elif c == rc and s >= rt:
			record[i] = (t, c)
			break
	else:
		record.append((t, c))
	record.sort(reverse=True)
print(len(record))


(N, C) = map(int, input().split())
T = [[0 for _ in range(C)] for j in range(100001)]
for i in range(N):
	(s, t, c) = map(int, input().split())
	for j in range(s - 1, t):
		T[j][c - 1] = 1
ans = 0
for i in range(100001):
	sumT = sum(T[i])
	if ans < sumT:
		ans = sumT
print(ans)


(N, C) = map(int, input().split())
STC = [[int(i) for i in input().split()] for i in range(N)]
STC.sort()
R = [[STC[0][1], STC[0][2]]]
for (s, t, c) in STC[1:]:
	for i in range(len(R)):
		(t_r, c_r) = (R[i][0], R[i][1])
		if c == c_r and t_r <= s:
			R[i] = [t, c]
			break
		if c != c_r and t_r < s:
			R[i] = [t, c]
			break
	else:
		R.append([t, c])
print(len(R))


(N, C) = map(int, input().split())
rec = [[0] * C for _ in range(10 ** 5)]
for _ in range(N):
	(s, t, c) = map(int, input().split())
	for i in range(s - 1, t):
		rec[i][c - 1] = 1
print(max([sum(rec[i]) for i in range(10 ** 5)]))


(N, C) = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
LEN = 10 ** 5 + 7
d = [[0] * LEN for _ in range(C + 1)]
for (s, t, c) in X:
	d[c][s] += 1
	d[c][t + 1] -= 1
for i in range(C + 1):
	for j in range(LEN - 1):
		d[i][j + 1] += d[i][j]
x = [0] * LEN
for i in range(C + 1):
	for j in range(LEN):
		x[j] += int(d[i][j] > 0)
print(max(x))


from collections import defaultdict
(n, c) = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(n)]
dd = defaultdict(lambda : [0] * (10 ** 5 + 1))
for (s, t, ch) in s:
	for i in range(s, t + 1):
		dd[ch][i] = 1
ans = 0
for i in range(10 ** 5 + 1):
	cnt = 0
	for ch in range(c + 1):
		if dd[ch][i] == 1:
			cnt += 1
	ans = max(ans, cnt)
print(ans)


import sys
readline = sys.stdin.readline
read = sys.stdin.read
(n, c) = list(map(int, readline().split()))
m = 2 * 10 ** 5
stc = [list(map(int, l.split())) for l in read().splitlines()]
cht = [[0] * (m + 1) for _ in range(c)]
for e in stc:
	cht[e[2] - 1][2 * e[0] - 1:2 * e[1]] = [1 for _ in range(2 * e[1] - 2 * e[0] + 1)]
mnr = 0
for i in range(1, m + 1):
	mnr = max(mnr, sum((cht[ch][i] for ch in range(c))))
print(mnr)


(n, c) = list(map(int, input().split()))
l = [[] for i in range(c)]
for i in range(n):
	(s, t, x) = list(map(int, input().split()))
	l[x - 1].append([s, t])
al = []
for i in range(c):
	if len(l[i]) > 1:
		l[i].sort()
		now2 = l[i][0][1]
		now1 = l[i][0][0]
		check = False
		for j in range(1, len(l[i])):
			if l[i][j][0] == now2:
				now2 = l[i][j][1]
			else:
				al.append([[now1, now2], i])
				check = True
				now1 = l[i][j][0]
				now2 = l[i][j][1]
		if not check:
			al.append([[now1, now2], i])
	elif l[i]:
		al.append([l[i][0], i])
al.sort()
count = [[-1, -1]]
for i in range(len(al)):
	(a, b, c) = (al[i][0][0], al[i][0][1], al[i][1])
	check = False
	for j in range(len(count)):
		if count[j][0] < a:
			count[j] = [b, c]
			check = True
			break
	if not check:
		count.append([b, c])
print(len(count))


maxlen = 10 ** 5 + 1
(n, channel) = [int(v) for v in input().split()]
use_list = [[0 for i in range(maxlen)] for i in range(channel)]
for i in range(n):
	(a, b, c) = [int(v) for v in input().split()]
	for j in range(a, b + 1):
		use_list[c - 1][j] = 1
ans = 0
for i in range(maxlen):
	max_at_i = sum([use_list[j][i] for j in range(channel)])
	ans = max(max_at_i, ans)
print(ans)


import sys
input = sys.stdin.readline
(N, C) = (int(i) for i in input().split())
pp = [[0] * 100001 for i in range(C)]
for i in range(N):
	(s, t, c) = (int(i) for i in input().split())
	for j in range(s, t + 1):
		pp[c - 1][j] = 1
res = 0
for i in range(100001):
	cc = 0
	for j in range(C):
		if pp[j][i]:
			cc += 1
	res = max(res, cc)
print(res)


(N, C) = list(map(int, input().split()))
stc = [list(map(int, input().split())) for _ in range(N)]
E = max(stc, key=lambda x: x[1])[1]
R = {}
stc.sort()
L = [0] * (E + 1)
for (s, t, c) in stc:
	if c not in R:
		R[c] = t
	else:
		if R[c] == s:
			s += 1
		R[c] = t
	L[s - 1] += 1
	L[t] -= 1
ans = L[0]
for i in range(E):
	L[i + 1] += L[i]
	ans = max(ans, L[i + 1])
print(ans)


from itertools import *
(n, c, *L) = map(int, open(0).read().split())
a = [0] * (max(L[1::3]) + 1)
bef = (0, 0)
for (c, s, t) in sorted(((c, s, t) for (s, t, c) in zip(*[iter(L)] * 3))):
	a[s - 1 + (bef == (c, s))] += 1
	a[t] -= 1
	bef = (c, t)
print(max(accumulate(a)))


from operator import itemgetter
(N, C) = map(int, input().split())
stc = [list(map(int, input().split())) for _ in range(N)]
stc.sort(key=itemgetter(2, 0))
cs = [0] * (10 ** 5 + 1)
(pt, pc) = (-1, -1)
for (s, t, c) in stc:
	if pt == s and pc == c:
		cs[s] += 1
	else:
		cs[s - 1] += 1
	cs[t] -= 1
	(pt, pc) = (t, c)
for i in range(1, 10 ** 5 + 1):
	cs[i] += cs[i - 1]
print(max(cs))


from collections import defaultdict
(N, C) = map(int, input().split())
event_list = []
for i in range(N):
	(s, t, c) = map(int, input().split())
	event_list.append((s - 0.5, c))
	event_list.append((t, -c))
event_list.sort()
answer = 0
cdic = defaultdict(int)
for (t, c) in event_list:
	if c > 0:
		cdic[c] += 1
		answer = max(answer, len(cdic))
	else:
		cdic[-c] -= 1
		if cdic[-c] == 0:
			cdic.pop(-c)
print(answer)


(N, C) = map(int, input().split())
tt = [[0] * (10 ** 5 + 1) for _ in range(C)]
for _ in range(N):
	(s, t, c) = map(int, input().split())
	ttc = tt[c - 1]
	for i in range(s - 1, t):
		ttc[i] = 1
ct = [0] * (10 ** 5 + 1)
for i in range(C):
	tti = tt[i]
	for j in range(10 ** 5 + 1):
		ct[j] += tti[j]
print(max(ct))


(N, C) = map(int, input().split())
prog = [list(map(int, input().split())) for _ in range(N)]
tv = [[-1, 0] for i in range(C)]
prog.sort()
for p in prog:
	(s, t, c) = p
	for i in range(C):
		if tv[i][0] < s - 0.5 or tv[i][1] == c or tv[i][1] == 0:
			tv[i][0] = t
			tv[i][1] = c
			break
ans = 0
for i in range(C):
	if tv[i][0] > 0:
		ans += 1
	else:
		break
print(ans)


(N, C) = list(map(int, input().split()))
tv = [[0] * C for _ in range(100000)]
for _ in range(N):
	(s, t, c) = list(map(int, input().split()))
	for i in range(s - 1, t):
		tv[i][c - 1] = 1
print(max([sum(tv[i]) for i in range(100000)]))


(N, C) = map(int, input().split())
r = [[0] * 10 ** 5 for c in range(C)]
for i in range(N):
	(s, t, c) = map(int, input().split())
	r[c - 1][s - 1:t] = [1] * (t - s + 1)
print(max(map(sum, zip(*r))))


(n, c) = map(int, input().split())
MAX_COLS = 10 ** 5
table = [[0 for _ in range(MAX_COLS)] for _ in range(c)]
for _ in range(n):
	(s, t, i) = list(map(int, input().split()))
	for j in range(max(0, s - 2), t - 1):
		table[i - 1][j] = 1
res = 0
for j in range(MAX_COLS):
	count = 0
	for i in range(c):
		count += table[i][j]
	res = max(res, count)
print(res)


from collections import defaultdict

def main():
	(N, C) = list(map(int, input().split(' ')))
	s = []
	t = []
	c = []
	channels = defaultdict(lambda : set())
	for i in range(N):
		(si, ti, ci) = list(map(int, input().split(' ')))
		for t in range(si - 1, ti):
			channels[t].add(ci)
	n_recorders = 0
	for t in channels:
		n_recorders = max(n_recorders, len(channels[t]))
	print(n_recorders)
main()


import io
import sys
import math
from itertools import accumulate as acc
data = sys.stdin.readline
(N, C) = map(int, data().split())
array = [[0 for i in range(10 ** 5 + 1)] for i in range(C + 1)]
rec = [0 for i in range(10 ** 5 + 1)]
for i in range(N):
	(s, t, c) = map(int, data().split())
	(recs, rect) = (array[c][s], array[c][t])
	if recs == 0 and rect == 0:
		rec[s - 1] += 1
		rec[t] -= 1
	elif recs == 0 and rect == 1:
		rec[s - 1] += 1
		rec[t - 1] -= 1
	elif recs == 1 and rect == 0:
		rec[s] += 1
		rec[t] -= 1
	elif recs == 1 and rect == 1:
		rec[s] += 1
		rec[t - 1] -= 1
	(array[c][s], array[c][t]) = (1, 1)
tmp = 0
ans = 0
for i in range(10 ** 5):
	tmp += rec[i]
	ans = max(tmp, ans)
print(ans)


(n, c) = map(int, input().split())
imos = [[0 for i in range(c)] for j in range(10 ** 5 + 1)]
for i in range(n):
	(s, t, _c) = map(int, input().split())
	imos[s - 1][_c - 1] += 1
	imos[t][_c - 1] -= 1
for i in range(1, 10 ** 5 + 1):
	for j in range(c):
		imos[i][j] += imos[i - 1][j]
imosans = [0] * (10 ** 5 + 1)
for i in range(10 ** 5 + 1):
	for j in range(c):
		imosans[i] += imos[i][j] >= 1
print(max(imosans))


(n, C) = map(int, input().split())
pro = [list(map(int, input().split())) for i in range(n)]
time = [0 for _ in range(2 * 10 ** 5 + 2)]
for i in range(C):
	w = [0 for _ in range(2 * 10 ** 5 + 2)]
	for (s, t, c) in pro:
		if c == i + 1:
			w[2 * s - 1] += 1
			w[2 * t] -= 1
	for j in range(2 * 10 ** 5 + 1):
		w[j + 1] += w[j]
		if w[j + 1]:
			time[j + 1] += 1
print(max(time))


(n, c) = [int(i) for i in input().split()]
A = [[0 for i in range(c)] for j in range(100000)]
for i in range(n):
	(s, t, c) = [int(i) for i in input().split()]
	for i in range(s - 1, t):
		A[i][c - 1] = 1
ans = 0
for i in range(100000):
	val = sum(A[i])
	if val > ans:
		ans = val
print(ans)


(N, C) = map(int, input().split())
from collections import defaultdict
Cbef = defaultdict(int)
time = defaultdict(int)
TV = [tuple(map(int, input().split())) for i in range(N)]
TV.sort(key=lambda x: x[0])
for (s, t, c) in TV:
	if Cbef[c] == s:
		time[s] += 1
		time[t] -= 1
		Cbef[c] = t
	else:
		time[s - 1] += 1
		time[t] -= 1
		Cbef[c] = t
ans = 0
now = time[0]
ans = now
for i in range(1, 10 ** 5 + 1):
	now += time[i]
	ans = max(ans, now)
print(ans)


def main():
	(N, C, *STC) = map(int, open(0).read().split())
	T = [[0] * 10 ** 5 for _ in range(C + 1)]
	for (s, t, c) in zip(*[iter(STC)] * 3):
		T[c][s - 1:t] = [1] * (t - s + 1)
	print(max(map(sum, zip(*T))))
main()


import sys
input = sys.stdin.readline
(N, C) = map(int, input().split())
T = 10 ** 5 + 1
A = [[0] * T for _ in range(C)]
for _ in range(N):
	(s, t, c) = map(int, input().split())
	A[c - 1][s - 1:t] = [1] * (t - s + 1)
ans = 0
for j in range(1, T):
	cnt = 0
	for i in range(C):
		cnt += A[i][j]
	ans = max(ans, cnt)
print(ans)


(N, C) = map(int, input().split())
stc = [list(map(int, input().split())) for _ in range(N)]
record = [[0] * 10 ** 5 for _ in range(C)]
for (s, t, c) in stc:
	for i in range(s, t + 1):
		record[c - 1][i - 1] = 1
ans = 0
for i in range(10 ** 5):
	cnt = 0
	for j in range(C):
		cnt += record[j][i]
	ans = max(ans, cnt)
print(ans)


import heapq
(N, C) = map(int, input().split())
inl = [tuple(map(int, input().split())) for i in range(N)]
inl.sort()
heap = []
res = 0
st = set()
for (s, t, c) in inl:
	nx = set()
	for (t1, c1) in st:
		if t1 == s and c == c1:
			nx.add((t, c))
		elif t1 >= s:
			nx.add((t1, c1))
	nx.add((t, c))
	st = nx
	res = max(len(nx), res)
print(res)


(N, C) = map(int, input().split())
inl = [tuple(map(int, input().split())) for i in range(N)]
inl.sort()
res = 0
st = [(0, 0)] * 30
for (s, t, c) in inl:
	nx = (t, c)
	cnt = 0
	for (i, (t1, c1)) in enumerate(st):
		if not (t1 == s and c == c1) and t1 >= s:
			st[i] = (t1, c1)
		else:
			st[i] = nx
			nx = (0, 0)
		if st[i][0] != 0:
			cnt += 1
	res = max(cnt, res)
print(res)


(n, c) = map(int, input().split())
t = [[0 for i in range(100001)] for j in range(c)]
for i in range(n):
	(si, ti, ci) = map(int, input().split())
	for j in range(si, ti + 1):
		t[ci - 1][j] = 1
print(max((sum((t[j][i] for j in range(c))) for i in range(100001))))


import sys
sdin = sys.stdin.readline
(n, c) = map(int, sdin().split())
stc = []
for _ in range(n):
	stc.append(tuple(map(int, sdin().split())))
table = [[0] * 10 ** 5 for _ in range(c)]
for (s, t, c) in stc:
	table[c - 1][s - 1:t] = [1] * (t - s + 1)
ans = max(map(sum, zip(*table)))
print(ans)


(N, C) = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(N)]
L.sort(key=lambda x: x[0])
R = [(L[0][1], L[0][2])]
for (s, t, c) in L[1:]:
	for (i, (t_r, c_r)) in enumerate(R):
		if c == c_r and t_r <= s:
			R[i] = (t, c)
			break
		if c != c_r and t_r < s:
			R[i] = (t, c)
			break
	else:
		R.append((t, c))
print(len(R))


import sys
from itertools import accumulate
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007

def main():
	(N, C, *STC) = list(map(int, read().split()))
	P = [[] for _ in range(C)]
	for (s, t, c) in zip(*[iter(STC)] * 3):
		P[c - 1].append((s, t))
	M = 10 ** 5
	vec = [0] * (M + 2)
	for i in range(C):
		P[i].sort()
		for (j, (s, t)) in enumerate(P[i]):
			if j > 0 and s == P[i][j - 1][1]:
				vec[s] += 1
				vec[t] += -1
			else:
				vec[s - 1] += 1
				vec[t] += -1
	vec = list(accumulate(vec))
	print(max(vec))
	return

def __starting_point():
	main()
__starting_point()


import sys
(N, C) = map(int, sys.stdin.readline().split())
times = [[set() for _ in range(10 ** 5 + 5)], [set() for _ in range(10 ** 5 + 5)]]
max_t = 0
for _ in range(N):
	(s, t, c) = map(int, sys.stdin.readline().split())
	times[0][s - 1].add(c)
	times[0][s].add(c)
	times[1][t].add(c)
	max_t = max(max_t, t)
ans = 0
recording = set()
for i in range(max_t + 5):
	recording -= times[1][i]
	recording |= times[0][i]
	ans = max(ans, len(recording))
print(ans)


(n, C) = [int(i) for i in input().split()]
stc = [[int(i) for i in input().split()] for _ in range(n)]
time = [0] * (2 * (10 ** 5 + 1))
end = [[0] * (10 ** 5 + 1) for _ in range(C)]
for (s, t, c) in stc:
	end[c - 1][t] += 1
for (s, t, c) in stc:
	if end[c - 1][s] == 0:
		time[2 * s - 1] += 1
	else:
		time[2 * s] += 1
	time[2 * t] -= 1
for i in range(1, 2 * 10 ** 5 + 2):
	time[i] += time[i - 1]
print(max(time))


(N, C) = map(int, input().split())
stc = [[int(x) for x in input().split()] for _ in range(N)]
im = [[0] * (10 ** 5 + 1) for _ in range(C + 1)]
for x in stc:
	(s, t, c) = x
	im[c][s] += 1
	im[c][t] -= 1
for c in range(1, C + 1):
	v = 0
	for i in range(1, 10 ** 5 + 1):
		n = im[c][i]
		v += n
		if n > 0:
			im[c][i - 1] += 1
		im[c][i] = v
print(max([sum(x) for x in zip(*im[1:])]))


(n, C) = map(int, input().split())
import collections
d = collections.defaultdict(list)
for i in range(n):
	(s, t, c) = map(int, input().split())
	d[c].append((s, t))
T = [0 for i in range(2 * 10 ** 5 + 3)]
for i in d.values():
	i.sort()
	T[i[0][0] * 2 - 1] += 1
	T[i[-1][1] * 2 + 1] -= 1
	for (x, y) in zip(i, i[1:]):
		(s1, t1) = x
		(s2, t2) = y
		if t1 != s2:
			T[s2 * 2 - 1] += 1
			T[t1 * 2 + 1] -= 1
from itertools import accumulate
T = list(accumulate(T))
print(max(T))


(N, C) = map(int, input().split())
STC = [list(map(int, input().split())) for _ in [0] * N]
STC.sort()
R = []
for (s, t, c) in STC:
	i = -1
	tm = 0
	for (j, r) in enumerate(R):
		(tr, cr) = r
		if c == cr and tm <= tr <= s or (c != cr and tm < tr <= s - 0.5):
			i = j
			tm = tr
	if i == -1:
		R.append((t, c))
	else:
		R[i] = (t, c)
print(len(R))


(n, c) = map(int, input().split())
l = [[0] * (10 ** 5 + 1) for _ in range(c + 1)]
for _ in range(n):
	(s, t, c) = map(int, input().split())
	for i in range(s, t + 1):
		l[c - 1][i] = 1
ans = [0] * (10 ** 5 + 1)
for i in range(len(l)):
	for j in range(len(l[i])):
		ans[j] += l[i][j]
print(max(ans))


(N, C) = map(int, input().split())
data = [[0] * (10 ** 5 + 1) for i in range(C)]
for i in range(N):
	(s, t, c) = map(int, input().split())
	c -= 1
	for i in range(s, t + 1):
		data[c][i] = 1
ans = 0
for i in range(1, 10 ** 5 + 1):
	count = 0
	for j in range(C):
		count += data[j][i]
	ans = max(ans, count)
print(ans)


(n, c) = map(int, input().split())
a = [[0 for _ in range(c)] for _ in range(10 ** 5 + 1)]
for _ in range(n):
	(s, t, u) = map(int, input().split())
	a[s][u - 1] += 1
	a[t][u - 1] -= 1
m = 0
x = 0
for b in a:
	x += b.count(1)
	if x > m:
		m = x
	x -= b.count(-1)
print(m)


def inpl():
	return list(map(int, input().split()))
(N, C) = inpl()
stc = [inpl() for _ in range(N)]
stc.sort()
num = [(-1, -1)]
for (s, t, c) in stc:
	for (i, Tuple) in enumerate(num):
		ch = Tuple[0]
		ti = Tuple[1]
		if ch != c and s - 0.5 >= ti:
			num[i] = (c, t)
			break
		elif ch == c and s >= ti:
			num[i] = (c, t)
			break
	else:
		num.append((c, t))
print(len(num))


import sys
import math
import collections
import bisect
import itertools
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 16
MOD = 10 ** 9 + 7
ni = lambda : int(sys.stdin.readline().rstrip())
ns = lambda : list(map(int, sys.stdin.readline().rstrip().split()))
na = lambda : list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda : list([int(x) - 1 for x in sys.stdin.readline().rstrip().split()])

def main():
	(n, c) = ns()
	l = 10 ** 5
	table = [[0 for _ in range(l + 1)] for __ in range(c)]
	for _ in range(n):
		(s, t, ci) = ns()
		ci -= 1
		table[ci][s] += 1
		table[ci][t] -= 1
	ans = 0
	tmp = 0
	for i in range(l + 1):
		fin = 0
		for j in range(c):
			if table[j][i] > 0:
				tmp += table[j][i]
			else:
				fin += table[j][i]
		ans = max(ans, tmp)
		tmp += fin
	print(ans)

def __starting_point():
	main()
__starting_point()


(N, C) = map(int, input().split())
T = [[0 for i in range(10 ** 5 + 1)] for j in range(C)]
for i in range(N):
	(s, t, c) = map(int, input().split())
	T[c - 1][s] += 1
	T[c - 1][t] -= 1
for i in range(C):
	for j in range(10 ** 5):
		T[i][j + 1] += T[i][j]
ans = 0
for i in range(1, 10 ** 5 + 1):
	a = 0
	for j in range(C):
		if T[j][i] or T[j][i - 1]:
			a += 1
	ans = max(ans, a)
print(ans)


(N, C) = map(int, input().split())
import heapq
endq = [[] for i in range(C)]
for i in range(C):
	heapq.heapify(endq[i])
progs = [None] * N
for i in range(N):
	(s, t, c) = map(int, input().split())
	progs[i] = [s, t, c - 1]
progs = sorted(progs, key=lambda x: x[0])
ans = 0
cur = 0
for i in range(N):
	(s, t, c) = progs[i]
	while endq[c]:
		endt = heapq.heappop(endq[c])
		if endt <= s:
			cur -= 1
		else:
			heapq.heappush(endq[c], endt)
			break
	for endc in range(C):
		if endc == c:
			continue
		while endq[endc]:
			endt = heapq.heappop(endq[endc])
			if endt < s:
				cur -= 1
			else:
				heapq.heappush(endq[endc], endt)
				break
	cur += 1
	heapq.heappush(endq[c], t)
	if cur > ans:
		ans = cur
print(ans)


import sys
sys.setrecursionlimit(10 ** 6)
(N, C) = list(map(int, input().split()))
C = 30
st = [[] for i in range(C)]
for i in range(N):
	(s, t, c) = list(map(int, input().split()))
	st[c - 1].append((s - 1, t - 1))
data = [0] * (10 ** 5 * 2)
for i in range(C):
	data_tmp = [0] * (10 ** 5 * 2)
	for j in range(len(st[i])):
		(s, t) = st[i][j]
		start = max(s * 2, 0)
		end = min((t - 1) * 2 + 1, 10 ** 5 * 2 - 1)
		data_tmp[start] += 1
		data_tmp[end + 1] -= 1
	for j in range(1, len(data_tmp) - 1):
		if data_tmp[j] > 0:
			data_tmp[j - 1] += data_tmp[j]
			data_tmp[j] = 0
	for j in range(0, len(data_tmp)):
		data[j] += data_tmp[j]
ans = [data[0]]
for i in range(1, len(data)):
	ans.append(ans[-1] + data[i])
print(max(ans))


def main():
	(N, C) = list(map(int, input().split(' ')))
	progams = [list(map(int, input().split(' '))) for _ in range(N)]
	progams.sort(key=lambda p: p[0])
	recorders = [[0, 0] for _ in range(C)]
	for prog in progams:
		(s, t, c) = prog
		for i in range(C):
			can_record = c == recorders[i][1] and recorders[i][0] <= s or (c != recorders[i][1] and recorders[i][0] < s)
			if can_record:
				recorders[i][0] = t
				recorders[i][1] = c
				break
	ans = 0
	for i in range(C):
		if recorders[i][0] > 0:
			ans += 1
	print(ans)

def __starting_point():
	main()
__starting_point()


(N, C) = map(int, input().split())
STC = [tuple(map(int, input().split())) for i in range(N)]
STC.sort()
rec = []
for i in range(N):
	isFree = False
	for j in range(len(rec)):
		if rec[j][0] < STC[i][0] and rec[j][1] != STC[i][2] or (rec[j][0] <= STC[i][0] and rec[j][1] == STC[i][2]):
			(isFree, rec[j]) = (True, (STC[i][1], STC[i][2]))
			break
	if not isFree:
		rec.append((STC[i][1], STC[i][2]))
print(len(rec))


(n, c) = map(int, input().split())
stc = [list(map(int, input().split())) for _ in range(n)]
stc.sort(key=lambda x: (x[2], x[0]))
imos = [0] * (10 ** 5 + 1)
curr_c = 0
curr_t = 0
for (s, t, c) in stc:
	if curr_c == c and curr_t == s:
		imos[s] += 1
	else:
		imos[s - 1] += 1
	imos[t] -= 1
	curr_t = t
	curr_c = c
rui = [0] * (10 ** 5 + 1)
for i in range(10 ** 5):
	rui[i + 1] = rui[i] + imos[i]
print(max(rui))


import operator
(N, C) = map(int, input().split())
stc = [[int(x) for x in input().split()] for _ in range(N)]
united = []
(pc, ps, pt) = (0, 0, 0)
for x in sorted(stc, key=operator.itemgetter(2, 0, 1)):
	(s, t, c) = x
	if c == pc and s == pt:
		united[-1][1] = t
	else:
		united.append([s, t, c])
	(ps, pt, pc) = x
cnt = [0] * (10 ** 5 + 1)
for x in united:
	(s, t, c) = x
	for i in range(s - 1, t):
		cnt[i] += 1
print(max(cnt))


import numpy as np
(N, C) = map(int, input().split())
s = np.empty(N)
t = np.empty(N)
c = np.empty(N)
for i in range(N):
	(s[i], t[i], c[i]) = map(int, input().split())
TimeTable = np.zeros((C, 100001))
maxTime = 0
for i in range(N):
	channle = int(c[i] - 1)
	for j in range(int(s[i]), int(t[i]) + 1):
		TimeTable[channle, j] = 1
	if maxTime < t[i]:
		maxTime = t[i]
MaxRecode = 0
for i in range(int(maxTime)):
	Recode = np.sum(TimeTable[:, i])
	if Recode > MaxRecode:
		MaxRecode = Recode
print(int(MaxRecode))


(N, C) = list(map(int, input().split()))
s = [0] * N
t = [0] * N
c = [0] * N
f = [False] * C
yoyaku = [False] * C
L = []
for i in range(N):
	(s[i], t[i], c[i]) = list(map(int, input().split()))
	L.append([s[i] - 0.5, c[i] - 1, 1])
	L.append([t[i], c[i] - 1, 0])
L.sort()
ans = 0
tmp = 0
for (i, (time, ch, sw)) in enumerate(L):
	if sw == 1:
		if f[ch] == False:
			tmp += 1
			f[ch] = True
			ans = max(ans, tmp)
		else:
			yoyaku[ch] = True
	elif yoyaku[ch]:
		yoyaku[ch] = False
	else:
		tmp -= 1
		f[ch] = False
print(ans)


(n, c) = map(int, input().split())
bangumi = [tuple(map(int, input().split())) for i in range(n)]
jikan = [0] * (10 ** 5 + 1)
from operator import itemgetter
bangumi = sorted(bangumi, key=itemgetter(2, 0))
nowch = 0
syuryo = 0
for (s, t, c) in bangumi:
	if c == nowch and s == syuryo:
		for i in range(s + 1, t + 1):
			jikan[i] += 1
	else:
		for i in range(s, t + 1):
			jikan[i] += 1
	nowch = c
	syuryo = t
print(max(jikan))


(n, C) = map(int, input().split())
L = [tuple(map(int, input().split())) for _ in range(n)]
m = 10 ** 5
S = [0] * m
for i in range(1, C + 1):
	T = [0] * (m + 1)
	for (s, t, c) in L:
		if c == i:
			T[s - 1] += 1
			T[t] -= 1
	for i in range(m):
		T[i + 1] += T[i]
	for i in range(m):
		S[i] += T[i] > 0
print(max(S))


(N, C) = map(int, input().split())
stc = [None] * N
for i in range(N):
	stc[i] = list(map(int, input().split()))
stc.sort()
recorders = []
for (s, t, c) in stc:
	ok = False
	for (i, rec) in enumerate(recorders):
		(t2, c2) = rec
		if c == c2 and t2 <= s or (c != c2 and t2 < s):
			recorders[i] = [t, c]
			ok = True
			break
	if not ok:
		recorders.append([t, c])
print(len(recorders))


class Imos:

	def __init__(self, n):
		self.B = [0] * n
		self.n = n
		from itertools import accumulate
		self.ac = accumulate

	def __call__(self, l, r):
		(l, r) = (max(l, 0), min(r, self.n - 1))
		self.B[l] += 1
		if r + 1 != self.n:
			self.B[r + 1] -= 1

	def out(self):
		(*res,) = self.ac(self.B)
		return res
from collections import defaultdict
d = defaultdict(list)
imos = Imos(10 ** 5 + 1)
((N, C), *D) = [[*map(int, o.split())] for o in open(0)]
for (s, t, c) in D:
	d[c] += ((s, t),)
for p in d.values():
	p.sort()
	(ps, pt) = p[0]
	for (s, t) in p[1:] + [[0, 0]]:
		if pt == s:
			pt = t
		else:
			imos(ps - 1, pt - 1)
			(ps, pt) = (s, t)
print(max(imos.out()))


(N, C) = map(int, input().split())
TV = [list(map(int, input().split())) for _ in range(N)]
TV = sorted(TV, key=lambda x: x[1])
rec = [0] * (10 ** 5 + 1)
cs = [set() for _ in range(10 ** 5 + 1)]
for (s, t, c) in TV:
	rec[t] -= 1
	if c not in cs[s]:
		rec[s - 1] += 1
	else:
		rec[s] += 1
	cs[t].add(c)
rec_s = [rec[0]]
for r in rec[1:]:
	rec_s.append(rec_s[-1] + r)
print(max(rec_s))


from operator import itemgetter

def resolve():
	(N, C) = list(map(int, input().split()))
	STC = sorted([list(map(int, input().split())) for _ in range(N)], key=itemgetter(2, 0))
	counts = [0] * (10 ** 5 + 1)
	(prevt, prevc) = (-1, -1)
	for stc in STC:
		(s, t, c) = stc
		if prevt == s and prevc == c:
			counts[s] += 1
		else:
			counts[s - 1] += 1
		counts[t] -= 1
		(prevt, prevc) = (t, c)
	for i in range(1, 10 ** 5 + 1):
		counts[i] += counts[i - 1]
	print(max(counts))
if '__main__' == __name__:
	resolve()


import sys

def main():
	(N, C) = map(int, input().split(' '))
	table = [[0] * 100000 for _ in range(C)]
	for _ in range(N):
		(s, t, c) = map(int, input().split(' '))
		table[c - 1][s - 1:t] = [1] * (t - s + 1)
	print(max(map(sum, zip(*table))))
sys.exit(main())


(n, c) = map(int, input().split())
r = [[0, 0] for _ in range(c)]
for (s, t, c) in sorted((list(map(int, input().split())) for _ in range(n))):
	for m in r:
		if m[0] < s - 0.5 or (m[1] == c and m[0] <= s):
			(m[0], m[1]) = (t, c)
			break
print(len(list(filter(lambda x: x != [0, 0], r))))


(N, C) = map(int, input().split())
stcs = []
for i in range(N):
	(s, t, c) = map(int, input().split())
	stcs.append((s, t, c))
stcs.sort()
rs = []
for (s, t, c) in stcs:
	ok = False
	for l in rs:
		(s0, t0, c0) = l[-1]
		if t0 < s or (t0 == s and c0 == c):
			l.append((s, t, c))
			ok = True
			break
	if not ok:
		l = [(s, t, c)]
		rs.append(l)
r = len(rs)
print(r)


(N, C) = map(int, input().split())
X = [[] for _ in range(C)]
A = []
for _ in range(N):
	(s, t, c) = map(int, input().split())
	A.append((s, t, c - 1))
A = sorted(A)
for (s, t, c) in A:
	if X[c] and X[c][-1][1] == s:
		X[c][-1][1] = t
	else:
		X[c].append([s - 1, t])
Y = []
for x in X:
	Y += x
Z = [0] * 101010
for (s, t) in Y:
	Z[s + 1] += 1
	Z[t + 1] -= 1
for i in range(1, 101010):
	Z[i] += Z[i - 1]
print(max(Z))


(n, c) = map(int, input().split())
stc = [list(map(int, input().split())) for i in range(n)]
stc.sort()
R = [[stc[0][1], stc[0][2]]]
for (s, t, c) in stc[1:]:
	for i in range(len(R)):
		(tr, cr) = (R[i][0], R[i][1])
		if c == cr and tr <= s:
			R[i] = [t, c]
			break
		if c != cr and tr < s:
			R[i] = [t, c]
			break
	else:
		R.append([t, c])
print(len(R))


(N, C) = list(map(int, input().split()))
tel = [[0, -1] for i in range(C)]
pro = [list(map(int, input().split())) for i in range(N)]
pro.sort()
for (s, t, c) in pro:
	for i in range(C):
		if tel[i][0] < s - 0.5 or tel[i][1] == c or tel[i][1] == -1:
			tel[i][0] = t
			tel[i][1] = c
			break
for i in range(C):
	if tel[i][1] == -1:
		print(i)
		return
print(C)


import numpy as np
import sys
input = sys.stdin.readline

def main(args):
	(N, C) = map(int, input().split())
	time = [[0] * (10 ** 5 + 1) for _ in range(C)]
	for _ in range(N):
		(s, t, c) = map(lambda x: int(x) - 1, input().split())
		time[c - 1][s] += 1
		time[c - 1][t + 1] -= 1
	recorder = np.where(np.cumsum(time[0]) > 0, 1, 0)
	for i in range(1, C):
		recorder += np.where(np.cumsum(time[i]) > 0, 1, 0)
	print(max(recorder))

def __starting_point():
	main(sys.argv[1:])
__starting_point()


from itertools import accumulate
(N, C) = map(int, input().split())
X = [[0] * (10 ** 5 + 1) for i in range(C)]
for i in range(N):
	(s, t, c) = map(int, input().split())
	c -= 1
	X[c][s - 1] += 1
	X[c][t] -= 1
for c in range(C):
	X[c] = list(accumulate(list(X[c])))
ans = 0
for i in range(10 ** 5 + 1):
	tmp = 0
	for c in range(C):
		tmp += min(1, X[c][i])
	ans = max(ans, tmp)
print(ans)


(N, C) = map(int, input().split())
tv = [list(map(int, input().split())) for _ in range(N)]
max_t = max(tv, key=lambda x: x[1])[1]
channels = [[0 for _ in range(max_t)] for _ in range(C)]
for (s, t, c) in tv:
	channels[c - 1][s - 1:t] = [1] * (t - s + 1)
ans = 0
for T in list(zip(*channels)):
	ans = max(ans, sum(T))
print(ans)


import sys
input = sys.stdin.readline
(n, C) = map(int, input().split())
ch = [[] for _ in range(C)]
tmax = 0
for _ in range(n):
	(s, t, c) = map(int, input().split())
	ch[c - 1].append((s, t))
	tmax = max(tmax, t)
ch = [sorted(i, key=lambda x: x[0]) for i in ch]
imos = [0] * (tmax + 2)
for i in ch:
	now = -1
	for (ds, dt) in i:
		if ds == now:
			imos[ds] += 1
		else:
			imos[ds - 1] += 1
		imos[dt] -= 1
		now = dt
for i in range(tmax + 1):
	imos[i + 1] += imos[i]
print(max(imos))


(N, C) = map(int, input().split())
STC = [[*map(int, input().split())] for _ in range(N)]
mx_t = 200002
R = [0] * mx_t
for cc in range(1, C + 1):
	TZ = [0] * mx_t
	for (s, t, c) in STC:
		if c == cc:
			TZ[2 * s - 1] += 1
			TZ[2 * t] -= 1
	for i in range(mx_t - 1):
		TZ[i + 1] += TZ[i]
		if TZ[i + 1] > 0:
			R[i + 1] += 1
print(max(R))


import sys
input = sys.stdin.readline
(n, c) = map(int, input().split())
TABLE = [[0] * 10 ** 5 for _ in range(c)]
for _ in range(n):
	(s, t, i) = [int(x) - 1 for x in input().split()]
	for j in range(s, t + 1):
		TABLE[i][j] = 1
answer = 0
for j in range(10 ** 5):
	temporary = sum((TABLE[i][j] for i in range(c)))
	answer = max(answer, temporary)
print(answer)


(n, C) = map(int, input().split())
time = 0
stc = []
for i in range(n):
	temp = list(map(int, input().split()))
	time = max(time, temp[1])
	stc.append(temp)
tv = [[0 for i in range(C)] for i in range(time + 1)]
for i in stc:
	(s, t, c) = (i[0], i[1], i[2])
	for j in range(s, t + 1):
		tv[j][c - 1] = 1
ans = 0
for i in tv:
	ans = max(ans, sum(i))
print(ans)


import functools
(N, C) = map(int, input().split())
T = [[0 for i in range(10 ** 5 + 1)] for j in range(C)]
for i in range(N):
	(s, t, c) = map(int, input().split())
	for j in range(s - 1, t):
		T[c - 1][j] = 1
ans = 0
for j in range(10 ** 5 + 1):
	r = 0
	for i in range(C):
		r += T[i][j]
	ans = max(ans, r)
print(ans)


from heapq import heappush, heappop
(N, C) = map(int, input().split())
(s, t, c) = zip(*(map(int, input().split()) for _ in range(N)))
Q = []
p = [0 for _ in range(C + 1)]
ans = 0
for (x, y, z) in sorted(zip(s, t, c)):
	while Q and (Q[0] < x or Q[0] == x == p[z]):
		p[z] = 0
		heappop(Q)
	p[z] = y
	heappush(Q, y)
	ans = max(ans, len(Q))
print(ans)


T_MAX = 10 ** 5
(n, nc) = list(map(int, input().split()))
stc = [list(map(int, input().split())) for _ in range(n)]
recs = [[0] * (T_MAX + 1) for c in range(nc + 1)]
for (s, t, c) in stc:
	recs[c][s - 1:t] = [1] * (t - s + 1)
ans = max(map(sum, zip(*recs)))
print(ans)


from itertools import accumulate as ac
from operator import add
(n, C) = map(int, input().split())
d = [[0 for _ in range(200002)] for _ in range(C)]
for _ in range(n):
	(s, t, c) = map(int, input().split())
	d[c - 1][s * 2 - 1] += 1
	d[c - 1][t * 2 + 1] -= 1
o = [[1 if i else 0 for i in ac(i)] for i in d]
(*v,) = map(lambda *x: sum(x), *o)
print(max(v))


(N, C) = map(int, input().split())
dic = []
for i in range(N):
	(s, t, c) = map(int, input().split())
	dic += [(c - 1, s, t)]
L = 2 * 100000 + 1
sm = [0] * L
for c in range(C):
	tt = [0] * L
	for i in range(N):
		if dic[i][0] == c:
			tt[dic[i][1] * 2 - 1] += 1
			tt[dic[i][2] * 2] -= 1
	for i in range(1, L):
		tt[i] += tt[i - 1]
	for i in range(L):
		if tt[i] > 0:
			sm[i] += 1
print(max(sm))


(N, C) = map(int, input().split())
stc = sorted([list(map(int, input().split())) for i in range(N)], key=lambda x: (x[2], x[0]))
cnow = 0
tnow = 0
end = max((i[1] for i in stc))
imos = [0 for i in range(end + 2)]
for (s, t, c) in stc:
	if cnow == c and tnow == s:
		imos[s] += 1
	else:
		imos[s - 1] += 1
	imos[t] -= 1
	cnow = c
	tnow = t
for i in range(end):
	imos[i + 1] += imos[i]
print(max(imos))


(N, C) = [int(_) for _ in input().split()]
MT = 10 ** 5 + 10
memo = [[0] * C for _ in range(MT)]
stc = sorted([[int(_) for _ in input().split()] for _ in range(N)])
for (s, t, c) in stc:
	if memo[s][c - 1] < 0:
		memo[s][c - 1] = 0
	else:
		memo[s - 1][c - 1] += 1
	memo[t][c - 1] -= 1
ans = 0
cnt = 0
for i in range(MT):
	cnt += sum(memo[i])
	ans = max(ans, cnt)
print(ans)


from sys import stdin
import numpy as np
(N, C) = [int(x) for x in stdin.readline().rstrip().split()]
imos = np.array([[0] * (10 ** 5 + 1) for i in range(C + 1)])
for i in range(N):
	(s, t, c) = [int(x) for x in stdin.readline().rstrip().split()]
	imos[c, s - 1:t] = 1
imos = np.array(imos)
ans = max(imos.sum(axis=0))
print(ans)


import itertools
(N, C) = list(map(int, input().split()))
MAX = 10 ** 5 + 1
table = [[0] * MAX for _ in range(C)]
for _ in range(N):
	(s, t, c) = list(map(int, input().split()))
	c -= 1
	table[c][s] += 1
	table[c][t] -= 1
for c in range(C):
	for x in range(MAX - 1):
		if table[c][x + 1] == 1:
			table[c][x + 1] = 0
			table[c][x] += 1
table_sum = [sum((table[c][i] for c in range(C))) for i in range(MAX)]
print(max(itertools.accumulate(table_sum)))


(N, C) = map(int, input().split())
G = {i: [0 for _ in range(10 ** 5 + 1)] for i in range(1, C + 1)}
for i in range(N):
	(s, t, c) = map(int, input().split())
	G[c][s] += 1
	G[c][t] -= 1
F = [0 for _ in range(2 * 10 ** 5 + 1)]
for c in range(1, C + 1):
	for i in range(10 ** 5 + 1):
		if G[c][i] == 1:
			F[2 * i - 1] += 1
		elif G[c][i] == -1:
			F[2 * i] -= 1
H = [0 for _ in range(2 * 10 ** 5 + 1)]
for i in range(1, 2 * 10 ** 5 + 1):
	H[i] = H[i - 1] + F[i]
print(max(H))


def IL():
	return list(map(int, input().split()))

def SL():
	return input().split()

def I():
	return int(input())

def S():
	return list(input())
(n, c) = IL()
imos = [[0] * 30 for i in range(pow(10, 5))]
for i in range(n):
	(s, t, c) = IL()
	for j in range(s - 1, t):
		imos[j][c - 1] = 1
ans = 0
for i in range(pow(10, 5)):
	ans = max(ans, sum(imos[i]))
print(ans)


from collections import defaultdict as dd
(N, C) = tuple(map(int, input().split()))
events = []
tmax = 0
dic = dd(list)
for i in range(N):
	(s, t, c) = map(int, input().split())
	dic[c].append((s, t))
eps = 0.5
for (k, v) in dic.items():
	v1 = sorted(v)
	lev = len(v1)
	prev = [-1, -1]
	for (i, val) in enumerate(v1):
		if tmax < val[1]:
			tmax = val[1]
		if prev == [-1, -1]:
			prev[0] = val[0]
			prev[1] = val[1]
			if lev != 1:
				continue
			else:
				events.append((prev[0] - eps, 1))
				events.append((prev[1], 0))
				break
		if prev[1] == val[0]:
			prev[1] = val[1]
			if i == lev - 1:
				events.append((prev[0] - eps, 1))
				events.append((prev[1], 0))
				break
		else:
			events.append((prev[0] - eps, 1))
			events.append((prev[1], 0))
			prev[0] = val[0]
			prev[1] = val[1]
			if i == lev - 1:
				events.append((val[0] - eps, 1))
				events.append((val[1], 0))
				break
events.sort()
idx = 0
cnt = 0
res = 0
events.append((0, -1))
for t in range(tmax + 1):
	while events[idx][0] <= t:
		event = events[idx]
		if event[1] == 1:
			cnt += 1
			if res < cnt:
				res = cnt
		elif event[1] == 0:
			cnt -= 1
		else:
			break
		idx += 1
print(res)


import sys
from itertools import accumulate
(N, C) = [int(i) for i in sys.stdin.readline().split()]
ls = {j: [0 for i in range(2 * 10 ** 5)] for j in range(1, C + 1)}
for i in range(N):
	(s, t, c) = [int(i) for i in sys.stdin.readline().split()]
	ls[c][s] += 1
	ls[c][t + 1] -= 1
res = [0 for i in range(2 * 10 ** 5)]
for _c in range(1, C + 1):
	for (i, j) in enumerate(accumulate(ls[_c])):
		res[i] += min(1, j)
print(max(res))


(N, C) = map(int, input().split())
STC = [list(map(int, input().split())) for _ in range(N)]
S = [[] for _ in range(10 ** 5 + 1)]
T = [[] for _ in range(10 ** 5 + 1)]
for (s, t, c) in STC:
	S[s].append(c)
	T[t].append(c)
used = set()
ans = 0
for i in range(10 ** 5 + 1):
	start = set()
	finish = set()
	for s in S[i]:
		start.add(s)
	for t in T[i]:
		finish.add(t)
	ans = max(ans, len(used) + len(start - finish))
	used = used - finish | start
print(ans)


import numpy as np
(N, C) = map(int, input().split())
T1 = [[] for _ in range(C)]
for _ in range(N):
	(s, t, c) = map(int, input().split())
	T1[c - 1].append([s, t])
for i in range(C):
	T1[i].sort()
T2 = [[] for _ in range(C)]
for i in range(C):
	for (s, t) in T1[i]:
		if len(T2[i]) != 0 and T2[i][-1][1] == s:
			T2[i][-1][1] = t
		else:
			T2[i].append([s, t])
L = np.zeros(10 ** 5 + 2, int)
for i in range(C):
	for time in T2[i]:
		L[time[0]] += 1
		L[time[1] + 1] -= 1
ans = L.cumsum().max()
print(ans)


(n, c) = map(int, input().split())
chan = [[] for _ in range(c)]
for _ in range(n):
	(s, t, sc) = map(int, input().split())
	sc -= 1
	chan[sc].append((s, t))
for i in range(c):
	chan[i].sort()
for i in range(c):
	lis = []
	if len(chan[i]) == 1:
		lis.append(chan[i][0][0])
		lis.append(chan[i][0][1])
	elif len(chan[i]) >= 2:
		lis.append(chan[i][0][0])
		for j in range(len(chan[i]) - 1):
			if chan[i][j][1] != chan[i][j + 1][0]:
				lis.append(chan[i][j][1])
				lis.append(chan[i][j + 1][0])
		lis.append(chan[i][j + 1][1])
	chan[i] = lis
accum = [0] * (10 ** 5 + 2)
for i in range(c):
	for j in range(0, len(chan[i]) - 1, 2):
		accum[chan[i][j]] += 1
		accum[chan[i][j + 1] + 1] -= 1
for i in range(10 ** 5 + 1):
	accum[i + 1] += accum[i]
print(max(accum))


L = 100005
(n, c) = map(int, input().split())
arr = [[0] * L for j in range(c)]
for _ in range(n):
	(s, t, col) = map(lambda x: int(x) - 1, input().split())
	arr[col][s] += 1
	arr[col][t] -= 1
imos = [0] * L
for i in range(c):
	for p in range(L):
		if arr[i][p] == 1:
			imos[p] += 1
		if arr[i][p] == -1:
			imos[p + 1] -= 1
ans = 0
for i in range(1, L):
	imos[i] += imos[i - 1]
	ans = max(ans, imos[i])
print(ans)


(n, c) = map(int, input().split())
cnt = [[0 for _ in range(10 ** 5 + 1)] for _ in range(c)]
for _ in range(n):
	(s, t, _c) = map(int, input().split())
	for j in range(s, t + 1):
		cnt[_c - 1][j] = 1
ans = 0
for i in range(10 ** 5 + 1):
	ans = max(ans, sum((cnt[j][i] for j in range(c))))
print(ans)


def main():
	from itertools import accumulate
	(n, c, *stc) = list(map(int, open(0).read().split()))
	table = [0] * 2 * (10 ** 5 + 1)
	m = list(zip(stc[::3], stc[1::3], stc[2::3]))
	m.sort(key=lambda a: (a[2], a[0], a[1]))
	ch_ = 0
	t_ = 0
	for (s, t, ch) in m:
		if ch != ch_:
			ch_ = ch
			t_ = 0
		if t_ == 2 * s:
			table[t_ + 1] += 1
		else:
			table[2 * s - 1] += 1
		table[2 * t + 1] -= 1
		t_ = 2 * t
	(*x,) = accumulate(table)
	ans = max(x)
	print(ans)

def __starting_point():
	main()
__starting_point()


import sys
input = sys.stdin.readline

def main():
	(N, C) = [int(x) for x in input().split()]
	STC = [[int(x) for x in input().split()] for _ in range(N)]
	S = [[] for _ in range(10 ** 5 + 1)]
	T = [[] for _ in range(10 ** 5 + 1)]
	for (s, t, c) in STC:
		S[s].append(c)
		T[t].append(c)
	used = set()
	ans = 0
	for i in range(10 ** 5 + 1):
		sused = set()
		tused = set()
		for s in S[i]:
			sused.add(s)
		for t in T[i]:
			tused.add(t)
		ans = max(ans, len(used) + len(sused - tused))
		used = used - tused | sused
	print(ans)

def __starting_point():
	main()
__starting_point()


import itertools
(N, C) = list(map(int, input().split()))
ch = [[] for _ in range(C + 1)]
time = [0] * (10 ** 5 + 1)
for _ in range(N):
	(s, t, c) = list(map(int, input().split()))
	ch[c].append(s)
	ch[c].append(t)
for i in range(1, C + 1):
	ch[i].sort()
for i in range(1, C + 1):
	for chi in range(len(ch[i])):
		if chi % 2 == 0:
			if chi == 0:
				time[ch[i][chi] - 1] += 1
			elif chi > 1 and ch[i][chi - 1] != ch[i][chi]:
				time[ch[i][chi] - 1] += 1
		elif chi % 2 == 1:
			if chi == len(ch[i]) - 1:
				time[ch[i][chi]] -= 1
			elif ch[i][chi + 1] != ch[i][chi]:
				time[ch[i][chi]] -= 1
integ_time = itertools.accumulate(time)
print(max(integ_time))


(n, c) = map(int, input().split())
T = 10 ** 5 + 1
l = [[0] * c for _ in range(T)]
for _ in range(n):
	(s, t, c_) = map(int, input().split())
	c_ -= 1
	for i in range(s - 1, t):
		l[i][c_] = 1
ans = 0
for i in range(T):
	ans = max(ans, sum(l[i]))
print(ans)


(n, c) = map(int, input().split())
l = sorted([list(map(int, input().split())) for _ in [0] * n], key=lambda x: [x[2], x[0]])
m = [l[0]]
for i in range(1, n):
	if l[i][2] == m[-1][2] and l[i][0] == m[-1][1]:
		m.append([m.pop()[0], l[i][1], l[i][2]])
	else:
		m.append(l[i])
for x in m:
	x[0] -= 1
ans = [0] * max((x[1] for x in m))
for x in m:
	for i in range(x[0], x[1]):
		ans[i] += 1
print(max(ans))


(N, C) = map(int, input().split())
log = [[0] * C for i in range(10 ** 5)]
for _ in range(N):
	(s, t, c) = map(int, input().split())
	log[s - 1][c - 1] += 1
	log[t - 1][c - 1] -= 1
ans = 0
temp = 0
for i in range(10 ** 5):
	plus = log[i].count(1)
	temp += plus
	ans = max(ans, temp)
	minus = log[i].count(-1)
	temp -= minus
print(ans)


(N, C) = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(N)]
D = [[] for i in range(C)]
DD = [[] for i in range(C)]
for (s, t, c) in A:
	D[c - 1].append([s, t])
for i in range(C):
	E = sorted(D[i])
	e = len(E)
	for j in range(e):
		if j == 0:
			DD[i].append([E[j][0], E[j][1]])
		elif j != 0 and E[j][0] == E[j - 1][1]:
			DD[i][-1][-1] = E[j][1]
		else:
			DD[i].append([E[j][0], E[j][1]])
ANS = [0] * (10 ** 5 + 3)
for i in range(C):
	F = DD[i]
	for (i, j) in F:
		ANS[i] += 1
		ANS[j + 1] -= 1
ans = 0
d = 0
for i in ANS:
	d += i
	ans = max(d, ans)
print(ans)


(N, C) = map(int, input().split())
M = 200005
rec = [[0] * M for i in range(C)]
for i in range(N):
	(s, t, c) = map(int, input().split())
	rec[c - 1][2 * s - 1] += 1
	rec[c - 1][2 * t] -= 1
for j in range(C):
	for i in range(1, M):
		rec[j][i] += rec[j][i - 1]
num = 0
for j in range(M):
	tmp = 0
	for i in range(C):
		if rec[i][j] >= 1:
			tmp += 1
	num = max(tmp, num)
print(num)


(N, C) = map(int, input().split())
r = [[0 for i in range(C)] for j in range(100000)]
for _ in range(N):
	(s, t, c) = map(int, input().split())
	for i in range(s - 1, t):
		r[i][c - 1] = 1
ans = 0
for i in range(100000):
	val = sum(r[i])
	if val > ans:
		ans = val
print(ans)


(n, c) = list(map(int, input().split()))
table = [0] * 220000
chanels = [[] for i in range(c)]
for i in range(n):
	(a, s, ch) = list(map(int, input().split()))
	chanels[ch - 1].append((a, s))
for i in range(c):
	if chanels[i]:
		chanels[i].sort()
		(x, y) = chanels[i][0]
		for (p, q) in chanels[i][1:] + [(0, 0)]:
			if y == p:
				y = q
			else:
				table[2 * x - 1] += 1
				table[2 * y] -= 1
				(x, y) = (p, q)
from itertools import accumulate
print(max(list(accumulate(table))))


(N, C) = map(int, input().split())
ch = {}
for _ in range(N):
	(s, t, c) = map(int, input().split())
	if c not in ch:
		ch[c] = [0 for _ in range(2 * 10 ** 5 + 2)]
	for i in range(2 * s - 1, 2 * t):
		ch[c][i] = 1
cmax = 0
for i in range(2 * 10 ** 5 + 2):
	cnt = 0
	for c in ch:
		if ch[c][i] == 1:
			cnt += 1
	cmax = max(cmax, cnt)
print(cmax)


(n, c) = (int(i) for i in input().split())
(x, y) = ([0 for i in range(100002)], [])
for _ in range(n):
	(i, j, k) = (int(l) for l in input().split())
	y.append([k, i, j])
y = sorted(y)
x[y[0][1] - 1] += 1
x[y[0][2]] -= 1
for i in range(1, n):
	if y[i][0] == y[i - 1][0] and y[i][1] == y[i - 1][2]:
		x[y[i][1]] += 1
		x[y[i][2]] -= 1
	else:
		x[y[i][1] - 1] += 1
		x[y[i][2]] -= 1
for i in range(1, len(x)):
	x[i] += x[i - 1]
print(max(x))


(N, C) = map(int, input().split())
A = [[0 for _ in range(C)] for j in range(100001)]
for i in range(N):
	(s, t, c) = map(int, input().split())
	for j in range(s - 1, t):
		A[j][c - 1] = 1
R = 0
for i in range(100001):
	sumA = sum(A[i])
	if R < sumA:
		R = sumA
print(R)


(N, C) = map(int, input().split())
T = [[0 for k in range(100001)] for l in range(C)]
for k in range(N):
	(s, t, c) = map(int, input().split())
	T[c - 1][s - 1] += 1
	T[c - 1][t] -= 1
for l in range(C):
	for k in range(1, 100001):
		T[l][k] += T[l][k - 1]
ans = 0
for k in range(100001):
	t = 0
	for l in range(C):
		if T[l][k] >= 1:
			t += 1
	ans = max(ans, t)
print(ans)


(N, C) = map(int, input().split())
accu = [[0] * (10 ** 5 + 10) for _ in range(C)]
for _ in range(N):
	(s, t, c) = map(int, input().split())
	accu[c - 1][s] += 1
	accu[c - 1][t + 1] -= 1
for i in range(C):
	for j in range(1, 10 ** 5 + 10):
		accu[i][j] += accu[i][j - 1]
ans = 0
for i in range(10 ** 5 + 10):
	tmp = 0
	for j in range(C):
		tmp += accu[j][i] > 0
	ans = max(ans, tmp)
print(ans)


import numpy as np
(N, C) = list(map(int, input().split()))
L = np.zeros((C, 10 ** 5 + 1))
for i in range(N):
	(s, t, c) = list(map(int, input().split()))
	L[c - 1, s - 1] += 1
	L[c - 1, t] -= 1
L = np.cumsum(L, axis=1)
print(int((L > 0).sum(axis=0).max()))


from itertools import accumulate as acc

def main():
	(N, C, *STC) = map(int, open(0).read().split())
	recorders = [[0] * (10 ** 5 + 1) for _ in range(C + 1)]
	for (s, t, c) in zip(*[iter(STC)] * 3):
		recorders[c][s - 1:t] = [1] * (t - s + 1)
	ans = max(map(sum, zip(*recorders)))
	print(ans)
main()


from itertools import accumulate

def main():
	(n, c) = list(map(int, input().split()))
	p = [[] for _ in range(c + 1)]
	for _ in range(n):
		(*st, cc) = list(map(int, input().split()))
		p[cc].append(st)
	all_p = [0] * (10 ** 5 + 10)
	for pp in p:
		if len(pp) == 0:
			continue
		pp.sort()
		(last_start, last_end) = pp[0]
		for (start, end) in pp[1:]:
			if start == last_end:
				last_end = end
			else:
				all_p[last_start - 1] += 1
				all_p[last_end] -= 1
				(last_start, last_end) = (start, end)
		all_p[last_start - 1] += 1
		all_p[last_end] -= 1
	print(max(accumulate(all_p)))

def __starting_point():
	main()
__starting_point()


(n, c) = map(int, input().split())
g = [[0] * 3 for i in range(n)]
for i in range(n):
	g[i] = list(map(int, input().split()))
g.sort(key=lambda x: x[0])
g.sort(key=lambda x: x[2])
T = [0] * (10 ** 5 + 3)
i = 0
while i < n:
	if i != n - 1 and g[i][2] == g[i + 1][2] and (g[i][1] == g[i + 1][0]):
		T[g[i][0]] += 1
		i = i + 1
		T[g[i][1]] -= 1
		i = i + 1
	else:
		T[g[i][0]] += 1
		T[g[i][1] + 1] -= 1
		i = i + 1
ans = 0
a = 0
for i in range(len(T)):
	a = a + T[i]
	if a > ans:
		ans = a
print(ans)


ma = lambda : map(int, input().split())
lma = lambda : list(map(int, input().split()))
ni = lambda : int(input())
yn = lambda fl: print('Yes') if fl else print('No')
import collections
import math
import itertools
import heapq as hq
(N, C) = ma()
nn = 10 ** 5 + 4
times = [[0 for i in range(nn)] for j in range(C + 1)]
for i in range(N):
	(s, t, c) = ma()
	times[c][s] += 1
	times[c][t] -= 1
for c in range(1, C + 1):
	for i in range(nn - 1):
		times[c][i + 1] += times[c][i]
tot = [0 for i in range(nn)]
for c in range(C + 1):
	for i in range(nn - 1):
		tot[i] += times[c][i]
		if times[c][i] == 0 and times[c][i + 1] == 1:
			tot[i] += 1
print(max(tot))


(N, C) = map(int, input().split())
channel = [tuple(map(int, input().split())) for i in range(N)]
channel = sorted(channel, key=lambda cha: cha[0])
n = 0
while channel != []:
	c = []
	n += 1
	pro = channel[0]
	channel.remove(pro)
	for i in channel:
		if i[0] > pro[1]:
			pro = i
		elif i[0] == pro[1] and i[2] == pro[2]:
			pro = i
		else:
			c.append(i)
	channel = c
print(n)


(n, c) = [int(i) for i in input().split()]
s0 = []
t0 = []
for _ in range(n):
	a = [int(i) for i in input().split()]
	s0.append((a[0], a[2]))
	t0.append((a[1], a[2]))
s1 = set(s0)
t1 = set(t0)
s2 = list(s1.difference(t0))
t2 = list(t1.difference(s0))
s = [i[0] - 0.5 for i in s2]
t = [i[0] for i in t2]
s.sort()
t.sort()
x = 0
m = 0
si = 0
ti = 0
while si != len(s):
	if s[si] < t[ti]:
		x += 1
		si += 1
	else:
		x -= 1
		ti += 1
	m = max(m, x)
print(m)


(N, C) = map(int, input().split())
STC = [tuple(map(int, input().split())) for i in range(N)]
cs = [[] for _ in range(30)]
for (s, t, c) in STC:
	cs[c - 1].append((s, t))
imos = [0] * 100005
for c in cs:
	c.sort(key=lambda x: x[0])
	pt = -1
	for (s, t) in c:
		if s == pt:
			imos[s] += 1
		else:
			imos[s - 1] += 1
		imos[t] -= 1
		pt = t
for i in range(len(imos) - 1):
	imos[i + 1] += imos[i]
print(max(imos))


(n, c) = map(int, input().split())
nca = sorted([tuple(map(int, input().split())) for _ in range(n)])
cnf = [True] * n
line = 0
while any(cnf):
	lst = ()
	for i in range(n):
		if cnf[i] == True:
			temp = nca[i]
			if lst == () or temp[2] == lst[2] or lst[1] < temp[0]:
				lst = temp
				cnf[i] = False
	line += 1
print(line)


from itertools import accumulate
(n, C) = list(map(int, input().split()))
U = 10 ** 5
channels = [[0] * (U + 1) for _ in range(C)]
for _ in range(n):
	(s, t, c) = [int(x) - 1 for x in input().split()]
	channels[c][s] += 1
	channels[c][t] -= 1
for i in range(C):
	for j in range(U):
		channels[i][j + 1] += channels[i][j]
schedules = [0] * (U + 1)
for i in range(C):
	L = None
	for j in range(U + 1):
		if channels[i][j] and L is None:
			L = j - 1
			continue
		if not channels[i][j] and L is not None:
			schedules[max(L, 0)] += 1
			schedules[j] -= 1
			L = None
print(max(accumulate(schedules)))


imos = [0] * (10 ** 5 + 2)
(N, C) = map(int, input().split())
C = 30
mitai = [[] for i in range(C + 1)]
for i in range(N):
	(s, t, c) = map(int, input().split())
	mitai[c].append([s, t])
for i in range(C + 1):
	mitai[i].sort()
for i in range(C + 1):
	preT = -1
	for j in mitai[i]:
		(s, t) = (j[0], j[1])
		if preT == s:
			imos[s + 1] += 1
			imos[t + 1] -= 1
		else:
			imos[s] += 1
			imos[t + 1] -= 1
		preT = t
for i in range(1, len(imos)):
	imos[i] = imos[i - 1] + imos[i]
print(max(imos))


from itertools import accumulate
MAX_T = 10 ** 5 + 100
MAX_C = 30
(n, c) = list(map(int, input().split()))
time = {c: [] for c in range(1, MAX_C + 1)}
for _ in range(n):
	(s, t, c) = list(map(int, input().split()))
	time[c].append((s, t))
n_program = [0 for _ in range(MAX_T + 1)]
for c in range(1, MAX_C + 1):
	recording = [0 for _ in range(MAX_T + 1)]
	for (s, t) in time[c]:
		recording[s] += 1
		recording[t + 1] -= 1
	recording = accumulate(recording)
	for (i, r) in enumerate(recording):
		if r:
			n_program[i] += 1
answer = max(n_program)
print(answer)


(N, C) = map(int, input().split())
channel_list = [[0 for _ in range(10 ** 5 + 1)] for _ in range(C)]
count_list = [0 for _ in range(10 ** 5 + 1)]
for i in range(N):
	(s, t, c) = map(int, input().split())
	channel_list[c - 1][s - 1] += 1
	channel_list[c - 1][t] -= 1
for i in range(C):
	for t in range(1, 10 ** 5 + 1):
		channel_list[i][t] += channel_list[i][t - 1]
		if channel_list[i][t] >= 1:
			count_list[t] += 1
print(max(count_list))


import sys
from collections import *
import heapq
import math
import bisect
import copy
from itertools import permutations, accumulate, combinations, product

def input():
	return sys.stdin.readline()[:-1]

def ruiseki(lst):
	return [0] + list(accumulate(lst))
mod = pow(10, 9) + 7
al = [chr(ord('a') + i) for i in range(26)]
direction = [[1, 0], [0, 1], [-1, 0], [0, -1]]
(n, c) = map(int, input().split())
stc = [list(map(int, input().split())) for i in range(n)]
stc.sort()
lst = [0] * c
for i in range(n):
	(s, t, ctmp) = stc[i]
	for j in range(c):
		if lst[j] == 0:
			lst[j] = stc[i]
			break
		elif lst[j][2] == ctmp:
			lst[j] = stc[i]
			break
		elif lst[j][1] < s:
			lst[j] = stc[i]
			break
ans = 0
for i in range(c):
	if lst[i] != 0:
		ans += 1
print(ans)


(n, c) = map(int, input().split())
program = [list(map(int, input().split())) for _ in range(n)]
table = [[0 for _ in range(c)] for _ in range(10 ** 5)]
for p in program:
	for i in range(p[0] - 1, p[1]):
		table[i][p[2] - 1] = 1
ans = 1
for i in range(10 ** 5):
	s = sum(table[i])
	if ans < s:
		ans = s
print(ans)


(N, C) = map(int, input().split())
t_max = 2 * 10 ** 5
c_imos = [[0] * t_max for t in range(C)]
c_imos = [[0] * t_max for t in range(C)]
for i in range(N):
	(s, t, c) = map(int, input().split())
	c -= 1
	s -= 1
	c_imos[c][s] += 1
	c_imos[c][t] -= 1
ans = [0] * t_max
from itertools import accumulate
for c_ in c_imos:
	acc = list(accumulate(c_))
	ans = [a + min(1, b) for (a, b) in zip(ans, acc)]
print(max(ans))


import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10 ** 9))
write = lambda x: sys.stdout.write(x + '\n')
(n, C) = list(map(int, input().split()))
stc = [tuple(map(int, input().split())) for _ in range(n)]
T = max((item[1] for item in stc))
l = [[False] * (T + 1) for _ in range(C)]
for (s, t, c) in stc:
	for i in range(s - 1, t):
		l[c - 1][i] = True
ans = max((sum((l[c][i] for c in range(C))) for i in range(T + 1)))
print(ans)


(N, C) = map(int, input().split())
R = 10 ** 5
T = [[0] * (R + 1) for _ in range(C)]
for _ in range(N):
	(s, t, c) = map(int, input().split())
	T[c - 1][s] += 1
	T[c - 1][t] -= 1
A = [0] * (R + 1)
ans = 0
for i in range(R):
	for c in range(C):
		A[i] += T[c][i + 1] if T[c][i + 1] > 0 else 0
		A[i] += T[c][i] if T[c][i] < 0 else 0
	A[i + 1] += A[i]
	ans = max(ans, A[i + 1])
print(ans)


(N, C) = map(int, input().split())
sch = sorted([list(map(int, input().split())) for _ in range(N)], key=lambda x: x[0])
rec = [[0, 0] for _ in range(C + 1)]
num_rec = 1
for i in range(N):
	(s, t, c) = sch[i]
	start = False
	for j in range(1, num_rec + 1):
		if rec[j][0] - int(rec[j][1] == c) < s:
			rec[j] = [t, c]
			start = True
			break
	if not start:
		num_rec += 1
		rec[num_rec] = [t, c]
print(num_rec)


(n, C) = list(map(int, input().split()))
part = [[0] * (3 * 10 ** 5) for _ in range(31)]
part2 = [0] * (3 * 10 ** 5)
for _ in range(n):
	(s, t, c) = list(map(int, input().split()))
	part[c][s] += 1
	part[c][t] -= 1
for i in range(1, C + 1):
	for j in range(1, 10 ** 5 + 1):
		if part[i][j] == 1:
			part2[2 * j - 1] += 1
		elif part[i][j] == -1:
			part2[2 * j] -= 1
ans = 0
for i in range(1, 2 * 10 ** 5 + 1):
	part2[i] += part2[i - 1]
	ans = max(ans, part2[i])
print(ans)


(n, c) = map(int, input().split())
ls = [[set(), set()] for i in range(30)]
l = [0] * (10 ** 5 + 1)
for i in range(n):
	(s, t, c) = map(int, input().split())
	if s in ls[c - 1][1]:
		ls[c - 1][1].remove(s)
	else:
		ls[c - 1][0].add(s - 1)
	if t - 1 in ls[c - 1][0]:
		ls[c - 1][0].remove(t - 1)
	else:
		ls[c - 1][1].add(t)
for i in ls:
	for j in i[0]:
		l[j] += 1
	for j in i[1]:
		l[j] -= 1
for i in range(10 ** 5):
	l[i + 1] += l[i]
print(max(l))


MAX = 114514
(N, C) = map(int, input().split())
Z = [[] for _ in range(C + 1)]
for _ in range(N):
	(s, t, c) = map(int, input().split())
	Z[c].append([s, t])
Y = []
for z in [sorted(z) for z in Z if len(z) > 0]:
	for i in range(len(z) - 1):
		if z[i][1] == z[i + 1][0]:
			z[i + 1][0] = z[i][0]
		else:
			Y.append(z[i])
	Y.append(z.pop())
X = [0 for _ in range(MAX)]
for (s, t) in Y:
	X[s] += 1
	X[t + 1] -= 1
for i in range(1, MAX):
	X[i] += X[i - 1]
print(max(X))


(N, C) = map(int, input().split())
f = [[0] * 100001 for _ in range(C)]
for i in range(N):
	(s, t, c) = map(int, input().split())
	f[c - 1][s - 1:t] = [1] * (t - s + 1)
print(max(map(sum, zip(*f))))


(N, C) = map(int, input().split())
max_size = 10 ** 5
record_list = [[int(i) - 1 for i in input().split()] for _ in range(N)]
ans_list = [0 for _ in range(max_size)]
for c in range(C):
	T = [0 for _ in range(max_size + 1)]
	for (s, t, i) in record_list:
		if i == c:
			T[s] += 1
			T[t + 1] -= 1
	for i in range(max_size):
		T[i + 1] += T[i]
	for i in range(max_size):
		ans_list[i] += T[i] > 0
print(max(ans_list))


(n, c) = map(int, input().split())
stc = [list(map(int, input().split())) for _ in range(n)]
stc.sort(key=lambda x: (x[2], x[0]))
imo = [0 for _ in range(10 ** 5 + 2)]
for i in range(n):
	if i < n - 1:
		if stc[i][2] == stc[i + 1][2] and stc[i][1] == stc[i + 1][0]:
			stc[i + 1][0] = stc[i][0]
			continue
	(s, t, c) = stc[i]
	imo[s] += 1
	imo[t + 1] -= 1
for i in range(10 ** 5 + 1):
	imo[i + 1] += imo[i]
print(max(imo))


(n, c) = map(int, input().split())
imos = [0 for _ in range(10 ** 5 + 1)]
ans = 0
channel = [[] for _ in range(30)]
for _ in range(n):
	(s, t, c) = map(int, input().split())
	channel[c - 1].append([s, t])
for lst in channel:
	lst.sort()
	before = 0
	for (s, t) in lst:
		start = max(before, s - 1)
		imos[start] += 1
		end = min(t, 10 ** 5 + 1)
		imos[end] -= 1
		before = end
tmp = 0
for num in imos:
	tmp += num
	ans = max(ans, tmp)
print(ans)


(n, c) = map(int, input().split())
l = [list(map(int, input().split())) for i in range(n)]
L = [[0 for i in range(10 ** 5 + 1)] for i in range(c)]
for i in range(n):
	for j in range(l[i][0], l[i][1] + 1):
		L[l[i][2] - 1][j] = 1
ans = []
for i in range(10 ** 5 + 1):
	ct = 0
	for j in range(c):
		ct += L[j][i]
		ans.append(ct)
print(max(ans))


(N, C) = map(int, input().split())
DP = [[0] * C for i in range(10 ** 5 + 1)]
for i in range(N):
	(s, t, c) = map(int, input().split())
	DP[s][c - 1] = t - s + 1
ans = 0
for i in range(10 ** 5):
	hoge = 0
	for j in range(C):
		DP[i + 1][j] = max(DP[i][j] - 1, DP[i + 1][j])
		if DP[i][j]:
			hoge += 1
	ans = max(ans, hoge)
print(ans)


def main():
	(N, C) = map(int, input().split())
	stc = [[0] * 10 ** 5 for _ in range(C)]
	for _ in range(N):
		(s, t, c) = map(int, input().split())
		stc[c - 1][s - 1:t] = [1] * (t - s + 1)
	print(max(map(sum, zip(*stc))))
main()


(N, C) = map(int, input().split())
s = [0] * N
t = [0] * N
c = [0] * N
for i in range(N):
	(s[i], t[i], c[i]) = map(int, input().split())
imos = [[0] * int(100000.0 + 20) for _ in range(31)]
for i in range(N):
	imos[c[i]][s[i]] += 1
	imos[c[i]][t[i] + 1] -= 1
ans = 0
for i in range(1, int(100000.0 + 10)):
	sm = 0
	for j in range(31):
		imos[j][i] = imos[j][i - 1] + imos[j][i]
		if imos[j][i] >= 1:
			sm += 1
	ans = max(ans, sm)
print(ans)


(n, c) = map(int, input().split())
a = []
tf = 0
for _ in range(n):
	(s, t, ch) = map(int, input().split())
	a += [(ch, s, t)]
a = sorted(a)
flag = a[0][0]
ans = [0] * (10 ** 5 + 1)
tf = 0
for (ch, s, t) in a:
	if ch == flag and tf == s:
		ans[s] += 1
	else:
		ans[s - 1] += 1
	ans[t] -= 1
	tf = t
	flag = ch
for i in range(10 ** 5):
	ans[i + 1] += ans[i]
print(max(ans))


def main():
	(N, C) = list(map(int, input().split()))
	l = []
	for _ in range(N):
		(s, t, c) = list(map(int, input().split()))
		l.append((s, t, c))
	l.sort(key=lambda x: x[0])
	r = []
	for i in l:
		if not r:
			r.append((i[1], i[2]))
			continue
		for (j, v) in enumerate(r):
			if v[0] < i[0] or (v[1] == i[2] and v[0] == i[0]):
				r[j] = (i[1], i[2])
				break
		else:
			r.append((i[1], i[2]))
		r.sort(key=lambda x: x[0])
	print(len(r))
main()


(N, C) = map(int, input().split())
ch = [[0] * (10 ** 5 + 1) for _ in range(C)]
for _ in range(N):
	(s, t, c) = map(int, input().split())
	ch[c - 1][s] += 1
	ch[c - 1][t] -= 1
for c in range(C):
	for i in range(10 ** 5):
		if ch[c][i + 1] == 1:
			ch[c][i + 1] = ch[c][i + 1] + ch[c][i]
			ch[c][i] = 1
		else:
			ch[c][i + 1] = ch[c][i + 1] + ch[c][i]
ans = 0
for i in range(10 ** 5):
	temp = 0
	for c in range(C):
		temp += ch[c][i + 1]
	ans = max(ans, temp)
print(ans)


from itertools import accumulate
(N, C) = map(int, input().split())
TimeTable = [[0] * (10 ** 5 + 2) for i in range(C + 1)]
for i in range(N):
	(s, t, c) = map(int, input().split())
	TimeTable[c][s] += 1
	TimeTable[c][t + 1] -= 1
for c in range(C + 1):
	TimeTable[c] = list(accumulate(TimeTable[c]))
ans = 0
for i in range(10 ** 5 + 2):
	cnt = 0
	for c in range(C + 1):
		cnt += min(TimeTable[c][i], 1)
	ans = max(ans, cnt)
print(ans)


(n, C) = map(int, input().split())
stc = [[int(i) for i in input().split()] for _ in range(n)]
dp = [0] * (2 * 10 ** 5 + 2)
for j in range(1, C + 1):
	tmp = [0] * (2 * 10 ** 5 + 2)
	for (s, t, c) in stc:
		if j == c:
			tmp[2 * s - 1] += 1
			tmp[2 * t] -= 1
	for i in range(2 * 10 ** 5 + 1):
		tmp[i + 1] += tmp[i]
		dp[i + 1] += tmp[i + 1] > 0
print(max(dp))


from heapq import heappop, heappush

def main():
	(n, c) = list(map(int, input().split()))
	program = [[] for _ in range(c)]
	for _ in range(n):
		(s, t, cc) = list(map(int, input().split()))
		cc -= 1
		s *= 2
		t *= 2
		program[cc].append([s - 1, t])
	all_p = []
	for i in range(c):
		if len(program[i]) == 0:
			continue
		now = program[i]
		now.sort(key=lambda x: x[1])
		(last_begin, last_end) = now[0]
		for (begin, end) in now[1:]:
			if begin + 1 == last_end:
				last_end = end
			else:
				all_p.append([last_begin, last_end, i])
				last_begin = begin
				last_end = end
		all_p.append([last_begin, last_end, i])
	all_p.sort()
	q = [(-1, -1)]
	for (begin, end, now_channel) in all_p:
		(last_end, last_channel) = q[0]
		if last_end < begin or now_channel == last_channel:
			heappop(q)
		heappush(q, (end, now_channel))
	print(len(q))

def __starting_point():
	main()
__starting_point()


(n, C) = map(int, input().split())
chs = [[] for i in range(31)]
for i in range(n):
	(s, t, c) = map(int, input().split())
	chs[c].append((s, t))
for q in range(len(chs)):
	ch = chs[q][:]
	ch.sort()
	new = []
	if len(ch) <= 1:
		continue
	else:
		now = ch[0]
		for i in range(1, len(ch)):
			if now[1] == ch[i][0]:
				now = (now[0], ch[i][1])
			else:
				new.append(now)
				now = ch[i]
		new.append(now)
		chs[q] = new[:]
tim = [0 for i in range(200002)]
for ch in chs:
	for pro in ch:
		tim[pro[0] * 2 - 1] += 1
		tim[pro[1] * 2] -= 1
cnt = 0
ans = 0
for i in range(len(tim)):
	cnt += tim[i]
	ans = max(ans, cnt)
print(ans)


import itertools
(n, c) = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
a.sort(key=lambda x: x[0])
a.sort(key=lambda x: x[2])
for i in range(n - 1):
	if a[i][1] == a[i + 1][0] and a[i][2] == a[i + 1][2]:
		a[i][1] -= 1
x = [0] * (10 ** 5 + 5)
for i in range(n):
	x[a[i][0]] += 1
	x[a[i][1] + 1] -= 1
x = itertools.accumulate(x)
print(max(x))


import heapq

def main():
	(N, C) = list(map(int, input().split()))
	STC = [tuple(map(int, input().split())) for _ in range(N)]
	STC.sort()
	CC = [(0, 0)] * C
	T = []
	for (s, t, c) in STC:
		(ps, pt) = CC[c - 1]
		if ps == 0:
			CC[c - 1] = (s, t)
		elif s == pt:
			CC[c - 1] = (ps, t)
		else:
			T.append((ps, pt, c))
			CC[c - 1] = (s, t)
	for (c, (s, t)) in enumerate(CC):
		if s != 0:
			T.append((s, t, c + 1))
	T.sort()
	STC = T
	h = []
	e = []
	r = 0
	for (s, t, c) in STC:
		while h and h[0][0] <= s:
			e.append(heapq.heappop(h)[1])
		if not e:
			e.append(r)
			r += 1
		heapq.heappush(h, (t + 1, e.pop()))
	return r
print(main())


import heapq
(N, C, *STC) = [int(_) for _ in open(0).read().split()]
STC = [(s, t, c) for (s, t, c) in zip(STC[::3], STC[1::3], STC[2::3])]
STC.sort()

class SegmentTree:

	def __init__(self, array, f, ti):
		self.f = f
		self.ti = ti
		self.n = n = 2 ** len(array).bit_length()
		self.dat = dat = [ti] * n + array + [ti] * (n - len(array))
		for i in range(n - 1, 0, -1):
			dat[i] = f(dat[i << 1], dat[i << 1 | 1])

	def update(self, p, v):
		(f, n, dat) = (self.f, self.n, self.dat)
		p += n
		dat[p] = v
		while p > 1:
			p >>= 1
			dat[p] = f(dat[p << 1], dat[p << 1 | 1])

	def operate_right(self, p, v):
		(f, n, dat) = (self.f, self.n, self.dat)
		p += n
		dat[p] = f(dat[p], v)
		while p > 1:
			p >>= 1
			dat[p] = f(dat[p << 1], dat[p << 1 | 1])

	def operate_left(self, p, v):
		(f, n, dat) = (self.f, self.n, self.dat)
		p += n
		dat[p] = f(v, dat[p])
		while p > 1:
			p >>= 1
			dat[p] = f(dat[p << 1], dat[p << 1 | 1])

	def query(self, l, r):
		(f, ti, n, dat) = (self.f, self.ti, self.n, self.dat)
		vl = vr = ti
		l += n
		r += n
		while l < r:
			if l & 1:
				vl = f(vl, dat[l])
				l += 1
			if r & 1:
				r -= 1
				vr = f(dat[r], vr)
			l >>= 1
			r >>= 1
		return f(vl, vr)
ti = (10 ** 10, -10 ** 10)
st = SegmentTree([(10 ** 10, i) for i in range(C + 1)], min, ti)
ans = 0
for (s, t, c) in STC:
	if st.query(c, c + 1)[0] == 10 ** 10:
		(t2, c2) = st.query(1, C + 1)
		if t2 < s:
			st.update(c2, (10 ** 10, c2))
		else:
			ans += 1
	st.update(c, (t, c))
print(ans)


(n, C) = map(int, input().split())
imos = [0] * (10 ** 5 + 2)
ch = [set() for _ in range(C)]
for i in range(n):
	(s, t, c) = map(int, input().split())
	c -= 1
	if s in ch[c]:
		ch[c].remove(s)
		imos[s + 1] += 1
	else:
		ch[c].add(s)
		imos[s] += 1
	if t in ch[c]:
		ch[c].remove(t)
		imos[t] -= 1
	else:
		ch[c].add(t)
		imos[t + 1] -= 1
ans = 0
cnt = 0
for i in imos:
	cnt += i
	ans = max(ans, cnt)
print(ans)


from heapq import *
from itertools import accumulate as ac
(n, c) = map(int, input().split())
a = sorted([list(map(int, input().split())) for i in range(n)])
b = [[] for i in range(c + 1)]
for (i, j, h) in a:
	if len(b[h]) > 0:
		if b[h][-1][1] == i:
			b[h][-1][1] = j
		else:
			b[h].append([i, j])
	else:
		b[h].append([i, j])
s = [0] * (2 * 10 ** 5 + 2)
for i in b:
	for (h, w) in i:
		s[2 * h - 1] += 1
		s[2 * w + 1] -= 1
print(max(list(ac(s))))


(N, C) = map(int, input().split())
STC = [[] for _ in range(C)]
for i in range(N):
	(s, t, c) = map(int, input().split())
	STC[c - 1].append((s, t))
lenA = 200001
A = [[0] * lenA for _ in range(C)]
for i in range(C):
	for (s, t) in STC[i]:
		A[i][s * 2 - 1:t * 2] = [1] * (t * 2 - s * 2 + 1)
Ans = [0] * lenA
for i in range(C):
	for j in range(lenA):
		if A[i][j] > 0:
			Ans[j] += 1
print(max(Ans))


(n, c) = map(int, input().split())
r = [[0 for i in range(c)] for j in range(100000)]
for dummy in range(n):
	(s, t, c) = map(int, input().split())
	for j in range(s - 1, t):
		r[j][c - 1] = 1
ans = 0
for i in range(100000):
	if sum(r[i]) > ans:
		ans = sum(r[i])
print(ans)


(n, c) = map(int, input().split())
stc = [list(map(int, input().split())) for _ in range(n)]
cs_dc = {}
dc = {}
for (s, t, c) in stc:
	if c in dc:
		dc[c][s] += 1
		dc[c][t] -= 1
	else:
		dc[c] = [0] * (10 ** 5 + 2)
		dc[c][s] += 1
		dc[c][t] -= 1
		cs_dc[c] = [0] * (10 ** 5 + 2)
for i in range(10 ** 5 + 1):
	for ci in dc:
		cs_dc[ci][i + 1] = cs_dc[ci][i] + dc[ci][i + 1]
ans = 0
for i in range(10 ** 5 + 1):
	tmp = 0
	for ci in dc:
		tmp += max(cs_dc[ci][i:i + 2])
	ans = max(ans, tmp)
print(ans)


(n, c) = map(int, input().split())
list_rec = [[0] * 10 ** 5 for _ in range(c)]
list_tv = [tuple(map(int, input().split())) for _ in range(n)]
for (start, end, ch) in list_tv:
	list_rec[ch - 1][start - 1:end] = [1] * (end - (start - 1))
count = max(map(sum, zip(*list_rec)))
print(count)


(n, c) = list(map(int, input().split()))
program = [[] for _ in range(c)]
for i in range(n):
	(s, t, cc) = list(map(int, input().split()))
	program[cc - 1].append((s, t))
count = [0] * (10 ** 5 + 1)
for i in range(c):
	program[i].sort()
	l = len(program[i])
	judge = True
	for j in range(l - 1):
		if judge:
			count[program[i][j][0] - 1] += 1
		if program[i][j][1] == program[i][j + 1][0]:
			judge = False
		else:
			judge = True
		if judge:
			count[program[i][j][1]] -= 1
	if l == 0:
		continue
	if judge:
		count[program[i][l - 1][0] - 1] += 1
	count[program[i][l - 1][1]] -= 1
ans = 0
for i in range(10 ** 5 + 1):
	if i != 0:
		count[i] += count[i - 1]
	if ans < count[i]:
		ans = count[i]
print(ans)


(n, c) = map(int, input().split())
table = [[0] * 10 ** 5 for i in range(c)]
for i in range(n):
	(s, t, c) = map(int, input().split())
	table[c - 1][s - 1:t] = [1] * (t - s + 1)
print(max(map(sum, zip(*table))))


(n, _) = map(int, input().split())
a = sorted((tuple(map(int, input().split())) for _ in range(n)))
r = [(0, 0)]
for (s, t, c) in a:
	(u, i) = min(((u + 0.5 * (c != d), i) for (i, (u, d)) in enumerate(r)))
	if s < u:
		r.append((t, c))
	else:
		r[i] = (t, c)
print(len(r))


from collections import deque
(N, C) = list(map(int, input().split()))
que = []
Que = []
channel = [[] for i in range(C + 1)]
for i in range(N):
	(s, t, c) = list(map(int, input().split()))
	channel[c].append((s, t))
for i in range(C + 1):
	channel[i].sort()
	tmp_que = deque(channel[i])
	left_que = deque([])
	if tmp_que:
		(x, y) = tmp_que.popleft()
		left_que.append((x, y))
		while tmp_que:
			(lx, ly) = left_que.pop()
			(rx, ry) = tmp_que.popleft()
			if ly == rx:
				left_que.append((lx, ry))
			elif ly < rx:
				left_que.append((lx, ly))
				left_que.append((rx, ry))
	for (x, y) in left_que:
		Que.append((2 * x - 1, 1))
		Que.append((2 * y, -1))
ans = 0
value = 0
Que.sort(reverse=True)
while Que:
	(v, command) = Que.pop()
	value += command
	ans = max(ans, value)
print(ans)


(N, C) = map(int, input().split())
query = [list(map(int, input().split())) for _ in range(N)]
timeTable = [[False for _ in range(10 ** 5)] for _ in range(C)]
time = [0 for _ in range(10 ** 6)]
for q in query:
	(s, t, c) = q
	for i in range(s - 1, t):
		timeTable[c - 1][i] = True
for channel in timeTable:
	for i in range(10 ** 5):
		if channel[i]:
			time[2 * i - 1] += 1
			time[2 * i] += 1
print(max(time))


import sys
import numpy as np
readline = sys.stdin.readline
read = sys.stdin.read
(n, c, *stc) = list(map(int, read().split()))
m = 2 * 10 ** 5
cht = np.zeros((c, m + 1), dtype='int64')
for (s, t, ch) in zip(*[iter(stc)] * 3):
	cht[ch - 1, 2 * s - 1:2 * t] = np.ones(2 * t - 2 * s + 1)
print(max(np.sum(cht, axis=0)))


(N, C) = map(int, input().split())
r = [[0] * C for _ in range(10 ** 5)]
for _ in range(N):
	(s, t, c) = map(int, input().split())
	for i in range(s - 1, t):
		r[i][c - 1] = 1
ans = 0
for t in r:
	sum_t = sum(t)
	if sum_t > ans:
		ans = sum_t
print(ans)


import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7

def resolve():
	(n, c) = list(map(int, input().split()))
	STC = sorted([list(map(int, input().split())) for _ in range(n)], key=lambda x: [x[2], x[0]])
	STC2 = []
	tmp = STC[0]
	for i in range(1, n):
		(pre_s, pre_t, pre_c) = tmp
		(now_s, now_t, now_c) = STC[i]
		if pre_c == now_c:
			if pre_t == now_s:
				tmp = [pre_s, now_t, now_c]
			else:
				STC2.append(tmp)
				tmp = STC[i]
		else:
			STC2.append(tmp)
			tmp = STC[i]
	if len(tmp):
		STC2.append(tmp)
	imos = [[0] * (10 ** 5 + 1) for _ in range(c)]
	for i in range(len(STC2)):
		(s, t, c) = STC2[i]
		imos[c - 1][s - 1] += 1
		imos[c - 1][t] -= 1
	for i in range(c):
		for j in range(1, 10 ** 5 + 1):
			imos[i][j] += imos[i][j - 1]
	res = [0] * (10 ** 5 + 1)
	for i in range(c):
		for j in range(10 ** 5 + 1):
			res[j] += imos[i][j]
	print(max(res))

def __starting_point():
	resolve()
__starting_point()


(N, C) = map(int, input().split())
db = [0 for i in range(100001)]
mem = [set() for i in range(C + 1)]
for i in range(N):
	(s, t, c) = map(int, input().split())
	if s not in mem[c]:
		db[s - 1] += 1
		mem[c].add(s)
	else:
		db[s] += 1
	if t not in mem[c]:
		db[t] -= 1
		mem[c].add(t)
	else:
		db[t - 1] -= 1
ans = 1
cnt = 0
for d in db:
	cnt += d
	ans = max(ans, cnt)
print(ans)


def main():
	from collections import namedtuple
	from heapq import heappop, heappush
	import sys
	input = sys.stdin.readline
	Prog = namedtuple('Prog', 'L R')
	Prog.__eq__ = lambda self, other: self.R == other.R
	Prog.__lt__ = lambda self, other: self.R < other.R
	(N, C) = list(map(int, input().split()))
	ps = tuple(([] for _ in range(30)))
	for _ in range(N):
		(l, r, ch) = list(map(int, input().split()))
		heappush(ps[ch - 1], Prog(l, r))
	imos = [0] * (10 ** 5 + 1)
	for ps_ch in ps:
		while ps_ch:
			(l, r) = heappop(ps_ch)
			while ps_ch and ps_ch[0].L == r:
				r = ps_ch[0].R
				heappop(ps_ch)
			else:
				imos[l - 1] += 1
				imos[r] -= 1
	for i in range(10 ** 5):
		imos[i + 1] += imos[i]
	print(max(imos))

def __starting_point():
	main()
__starting_point()


import numpy as np
(N, C) = (int(x) for x in input().split())
R = [[0] * 100000 for _ in range(C)]
R = np.array(R)
for _ in range(N):
	(s, t, c) = map(int, input().split())
	R[c - 1, s - 1:t] = 1
ans = max(sum(R))
print(ans)


(A, B) = list(map(int, input().split()))
l = [[] for i in range(100001)]
for i in range(A):
	(X, Y, Z) = list(map(int, input().split()))
	for j in range(X - 1, Y):
		l[j].append(Z)
ans = 0
for i in l:
	ans = max(ans, len(set(i)))
print(ans)


import itertools
(N, C) = map(int, input().split())
imos = [0] * 10 ** 6
info = [list(map(int, input().split())) for i in range(N)]
info = sorted(info, key=lambda x: (x[2], x[0]))
note = -1
before_t = -1
for i in range(N):
	(s, t, c) = info[i]
	s -= 1
	if c == note and s < before_t:
		s = before_t
	imos[s] += 1
	imos[t] -= 1
	note = c
	before_t = t
acc_sum = list(itertools.accumulate(imos))
ans = max(acc_sum)
print(ans)


(n, c) = map(int, input().split())
t = [[0] * 10 ** 5 for i in range(c)]
for i in range(n):
	(a, b, c) = map(int, input().split())
	t[c - 1][a - 1:b] = [1] * (b - a + 1)
print(max(map(sum, zip(*t))))


(n, _) = map(int, input().split())
CST = {}
for i in range(n):
	(s, t, c) = map(int, input().split())
	if c in CST:
		CST[c] += [[s, t]]
	else:
		CST[c] = [[s, t]]
mx_t = 200002
R = [0] * mx_t
for (c, ST) in CST.items():
	TZ = [0] * mx_t
	for (s, t) in ST:
		TZ[2 * s - 1] += 1
		TZ[2 * t] -= 1
	for i in range(mx_t - 1):
		TZ[i + 1] += TZ[i]
		if TZ[i + 1] > 0:
			R[i + 1] += 1
print(max(R))


import numpy as np
(n, c) = map(int, input().split())
li = np.zeros(10 ** 5 + 1, int)
ch = [[] for _ in range(10 ** 5 + 1)]
lin = []
for _ in range(n):
	(s, t, c) = map(int, input().split())
	lin.append((s, t, c))
lin.sort()
for (i, j, k) in lin:
	if k in ch[i - 1]:
		li[i:j] += 1
		ch[j - 1].append(k)
	else:
		li[i - 1:j] += 1
		ch[j - 1].append(k)
print(np.max(li))


import heapq
(N, C) = list(map(int, input().split()))
ans = C
d = [list() for _ in range(C + 1)]
for _ in range(N):
	(s, t, c) = list(map(int, input().split()))
	d[c].append([s, t])
S = [0] * (10 ** 5 + 1)
T = [0] * (10 ** 5 + 1)
for i in range(C + 1):
	if not d[i]:
		continue
	d[i].sort()
	(s, t) = d[i][0]
	for j in range(1, len(d[i])):
		if t == d[i][j][0]:
			t = d[i][j][1]
		else:
			S[s] += 1
			T[t] += 1
			(s, t) = d[i][j]
	S[s] += 1
	T[t] += 1
temp = 0
ans = 0
for i in range(1, 10 ** 5 + 1):
	temp += S[i] - T[i - 1]
	ans = max(ans, temp)
print(ans)


(n, c) = map(int, input().split())
stc = []
for _ in range(n):
	stc.append(tuple(map(int, input().split())))
sm = [0 for _ in range(2 * (pow(10, 5) + 1))]
for _c in range(c):
	tt = [0 for _ in range(2 * (pow(10, 5) + 1))]
	for (s, t, c) in stc:
		if c == _c + 1:
			tt[s * 2 - 1] += 1
			tt[t * 2] -= 1
	for i in range(1, len(tt)):
		tt[i] += tt[i - 1]
	for i in range(len(sm)):
		if tt[i] > 0:
			sm[i] += 1
print(max(sm))


from collections import deque
(N, C) = list(map(int, input().split()))
Mx = 10 ** 5 + 1
sch = [[0] * Mx for _ in range(C)]
scht = [0] * Mx
plist = [[] for _ in range(C)]
for _ in range(N):
	(s, t, c) = list(map(int, input().split()))
	plist[c - 1].append((s, t))
for (c, p) in enumerate(plist):
	p.sort()
	prevt = 0
	for (s, t) in p:
		if prevt == s:
			sch[c][prevt] = 0
		else:
			sch[c][s] = 1
		sch[c][t] = -1
		prevt = t
	for i in range(1, Mx):
		if sch[c][i] == 1:
			scht[i - 1] += 1
		if sch[c][i] == -1:
			scht[i] -= 1
for i in range(1, Mx):
	scht[i] += scht[i - 1]
print(max(scht))


from collections import defaultdict
from itertools import accumulate
(N, K) = map(int, input().split())
timetables = defaultdict(list)
for i in range(N):
	(s, t, c) = map(int, input().split())
	timetables[c].append([s, t])
for (name, times) in timetables.items():
	times.sort()
	new = []
	for (i, time) in enumerate(times):
		(s, t) = time
		if i == 0:
			new.append([s, t])
			continue
		if s == new[-1][1]:
			new[-1][1] = t
		else:
			new.append([s, t])
	timetables[name] = new
time_count = [0] * 100010
for (name, times) in timetables.items():
	for (s, t) in times:
		time_count[s] += 1
		time_count[t + 1] -= 1
acc = accumulate(time_count)
print(max(acc))


import heapq
(N, C) = map(int, input().split())
stc = [list(map(int, input().split())) for _ in range(N)]
stc.sort()
lst = []
hq = [[-1, -1]]
heapq.heapify(hq)
ans = 1
for i in range(N):
	p = stc[i]
	q = heapq.heappop(hq)
	if p[0] < q[0]:
		heapq.heappush(hq, q)
		ans += 1
	elif p[0] == q[0]:
		lst = []
		jdg2 = True
		while p[0] == q[0] and p[2] >= q[1]:
			if p[2] == q[1]:
				jdg2 = False
			else:
				lst.append(q)
			if hq:
				q = heapq.heappop(hq)
			else:
				break
		if jdg2:
			ans += 1
		if p[0] != q[0] or p[2] < q[1]:
			heapq.heappush(hq, q)
		for k in lst:
			heapq.heappush(hq, k)
	heapq.heappush(hq, [p[1], p[2]])
print(ans)


import sys
sys.setrecursionlimit(10 ** 6)
buff_readline = sys.stdin.readline
readline = sys.stdin.readline
INF = 2 ** 62 - 1

def read_int():
	return int(buff_readline())

def read_int_n():
	return list(map(int, buff_readline().split()))

def read_float():
	return float(buff_readline())

def read_float_n():
	return list(map(float, buff_readline().split()))

def read_str():
	return readline().strip()

def read_str_n():
	return readline().strip().split()

def error_print(*args):
	print(*args, file=sys.stderr)

def mt(f):
	import time

	def wrap(*args, **kwargs):
		s = time.time()
		ret = f(*args, **kwargs)
		e = time.time()
		error_print(e - s, 'sec')
		return ret
	return wrap

@mt
def slv(N, C, STC):
	from collections import Counter
	se = [(2 * s, 0, c) for (s, t, c) in STC]
	te = [(2 * t + 1, 1, c) for (s, t, c) in STC]
	e = se + te
	e.sort(reverse=True)
	r = Counter()
	ans = 0
	while e:
		(_, k, c) = e.pop()
		if k == 0:
			r[c] += 1
		else:
			r[c] -= 1
			if r[c] == 0:
				r.pop(c)
		ans = max(ans, len(r))
	return ans

def main():
	(N, C) = read_int_n()
	STC = [read_int_n() for _ in range(N)]
	print(slv(N, C, STC))

def __starting_point():
	main()
__starting_point()


(n, c) = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
import numpy as np
a = np.zeros((c + 1, 10 ** 5))
for i in range(n):
	a[ab[i][2]][ab[i][0] - 1:ab[i][1]] = [1] * (ab[i][1] - ab[i][0] + 1)
b = a.sum(axis=0)
print(int(max(b)))


import sys
import numpy as np
input = sys.stdin.readline
(n, C) = map(int, input().split())
a = np.zeros((C, 10 ** 5), dtype='int')
for _ in range(n):
	(s, t, c) = map(int, input().split())
	a[c - 1, s - 1:t] = 1
print(max(np.sum(a, axis=0)))


f = lambda : map(int, input().split())
(n, c) = f()
d = [list(f()) for _ in range(n)]
d.sort(key=lambda x: (x[2], x[0]))
p = []
for i in range(n):
	if len(p) > 0 and p[-1][2] == d[i][2] and (p[-1][1] == d[i][0]):
		p[-1][1] = d[i][1]
	else:
		p.append(d[i])
ans = [0] * 200100
for i in range(len(p)):
	ans[p[i][0] - 1] += 1
	ans[p[i][1]] -= 1
from itertools import accumulate as acc
print(max(acc(ans)))


(N, C) = map(int, input().split())
old = [[] for i in range(C)]
for i in range(N):
	(s, t, c) = map(int, input().split())
	old[c - 1].append((s, t))
ch = []
for li in old:
	li.sort()
	j = 0
	while j < len(li):
		start = li[j][0]
		while j < len(li) - 1 and li[j][1] == li[j + 1][0]:
			j += 1
		end = li[j][1]
		ch.append(((start - 1) * 2 + 1, end * 2))
		j += 1
imos = [0] * (2 * 10 ** 5 + 10)
for (s, t) in ch:
	imos[s] += 1
	imos[t] -= 1
for i in range(1, 2 * 10 ** 5 + 10):
	imos[i] = imos[i - 1] + imos[i]
print(max(imos))


from numpy import *
(N, C) = map(int, input().split())
A = zeros((C, 10 ** 5), int32)
for n in range(N):
	(s, t, c) = map(int, input().split())
	A[c - 1, s - 1:t] = 1
print(max(sum(A, axis=0)))


import math
import numpy as np
import queue
from collections import deque, defaultdict
import heapq as hpq
from sys import stdin, setrecursionlimit
ipt = stdin.readline
setrecursionlimit(10 ** 7)

def main():
	(n, c) = list(map(int, ipt().split()))
	cc = [[] for _ in [0] * c]
	tma = 0
	for i in range(n):
		(s, t, c) = list(map(int, ipt().split()))
		hpq.heappush(cc[c - 1], (s, t))
		if t > tma:
			tma = t
	cnt = np.zeros(tma + 1, dtype=int)
	for i in cc:
		ps = -1
		pt = -1
		while len(i) > 0:
			(ns, nt) = hpq.heappop(i)
			if pt == ns:
				pt = nt
				continue
			elif not pt == -1:
				cnt[ps:pt + 1] += np.ones(pt - ps + 1, dtype=int)
			ps = ns
			pt = nt
		if not pt == -1:
			cnt[ps:pt + 1] += np.ones(pt - ps + 1, dtype=int)
	print(max(cnt))
	return

def __starting_point():
	main()
__starting_point()


(N, C) = map(int, input().split())
S = []
for i in range(N):
	S.append(list(map(int, input().split())))
S.sort()
R = [[] for i in range(C)]
for i in range(N):
	c = S[i][2] - 1
	if R[c]:
		if R[c][-1][1] == S[i][0]:
			R[c][-1][1] = S[i][1]
			continue
	R[c].append(S[i][:])
D = [0] * 100001
for r in R:
	for s in r:
		for i in range(s[0], s[1] + 1):
			D[i] += 1
print(max(D))


(n, C) = map(int, input().split())
d = [[0] * C for i in range(10 ** 5)]
for i in range(n):
	(s, t, c) = map(int, input().split())
	for j in range(s - 1, t):
		d[j][c - 1] = 1
a = 1
for i in range(10 ** 5):
	s = sum(d[i])
	if s > a:
		a = s
print(a)


(N, C) = map(int, input().split())
ch = [[False for i in range(100001)] for j in range(C + 1)]
for i in range(N):
	(s, t, c) = map(int, input().split())
	for j in range(s, t + 1):
		ch[c][j] = True
ans = 0
for i in range(100001):
	count = 0
	for j in range(1, C + 1):
		if ch[j][i]:
			count += 1
	ans = max(count, ans)
print(ans)


def Recording():
	(n, c) = list(map(int, input().split()))
	num = 2 * 10 ** 5 + 1
	imos = [[0] * num for _ in range(c)]
	for _ in range(n):
		(s, t, c0) = list(map(int, input().split()))
		if imos[c0 - 1][s * 2] < 0 and imos[c0 - 1][t * 2 - 1] > 0:
			imos[c0 - 1][s * 2] = 0
			imos[c0 - 1][t * 2 - 1] = 0
		elif imos[c0 - 1][s * 2] < 0:
			imos[c0 - 1][s * 2] = 0
			imos[c0 - 1][t * 2] -= 1
		elif imos[c0 - 1][t * 2 - 1] > 0:
			imos[c0 - 1][s * 2 - 1] += 1
			imos[c0 - 1][t * 2 - 1] = 0
		else:
			imos[c0 - 1][s * 2 - 1] += 1
			imos[c0 - 1][t * 2] -= 1
	ans = [0 for _ in range(num)]
	for i in range(c):
		for j in range(1, num):
			imos[i][j] += imos[i][j - 1]
			ans[j] += imos[i][j]
	print(max(ans))

def __starting_point():
	Recording()
__starting_point()


(N, C) = map(int, input().split())
table = [[0] * 100000 for i in range(C)]
for i in range(N):
	(s, t, c) = map(int, input().split())
	table[c - 1][s - 1:t] = [1] * (t - s + 1)
print(max(map(sum, zip(*table))))


(n, c) = list(map(int, input().split()))
r = [[0 for i in range(c)] for j in range(100000)]
for _ in range(n):
	(s, t, c) = list(map(int, input().split()))
	for j in range(s - 1, t):
		r[j][c - 1] = 1
ans = 0
for i in range(len(r)):
	ans = max(ans, sum(r[i]))
print(ans)


(n, C) = map(int, input().split())
stc = [list(map(int, input().split())) for i in range(n)]
m = 0
for i in stc:
	m = max(m, i[1])
lis = [[0] * C for i in range(m + 1)]
for i in stc:
	for j in range(i[0], i[1] + 1):
		lis[j][i[2] - 1] = 1
ans = 0
for i in lis:
	ans = max(ans, sum(i))
print(ans)


import sys

def MI():
	return map(int, sys.stdin.readline().rstrip().split())
(N, C) = MI()
A = [[0] * (10 ** 5 + 2) for i in range(C + 1)]
for i in range(N):
	(s, t, c) = MI()
	A[c][s] += 1
	A[c][t + 1] -= 1
from itertools import accumulate
for i in range(1, C + 1):
	A[i] = list(accumulate(A[i]))
ans = 0
for j in range(10 ** 5 + 2):
	ans = max(ans, sum((A[i][j] > 0 for i in range(1, C + 1))))
print(ans)


import itertools
(n, C) = map(int, input().split())
lst = [[0] * 100002 for _ in range(C)]
end = []
for _ in range(n):
	(s, t, c) = map(int, input().split())
	c -= 1
	lst[c][s] += 1
	lst[c][t + 1] -= 1
for c in range(C):
	lst[c] = list(itertools.accumulate(lst[c]))
	for i in range(100002):
		if lst[c][i] >= 2:
			lst[c][i] = 1
ans = 0
for i in range(100002):
	tmp = 0
	for c in range(C):
		tmp += lst[c][i]
	ans = max(ans, tmp)
print(ans)


(N, C) = map(int, input().split())
cusum = [[0 for j in range(10 ** 5 + 1)] for i in range(C + 1)]
for i in range(N):
	(s, t, c) = map(int, input().split())
	cusum[c][s] += 1
	cusum[c][t] += -1
ans = 0
s = 0
for j in range(10 ** 5 + 1):
	cp = 0
	cm = 0
	for i in range(C + 1):
		if cusum[i][j] == 1:
			cp += 1
		elif cusum[i][j] == -1:
			cm += 1
	s += cp
	ans = max(s, ans)
	s -= cm
print(ans)


import numpy as np
(n, c) = list(map(int, input().split()))
stc = [[] for i in range(c + 1)]
for i in range(n):
	(s_, t_, c_) = list(map(int, input().split()))
	stc[c_].append([s_, t_])
stc_ = []
for i in range(1, c + 1):
	stc[i] = sorted(stc[i], key=lambda x: (x[0], x[1]))
	j = 0
	l = len(stc[i])
	flg = False
	while j < l:
		if not flg:
			(cs, ct) = (stc[i][j][0], stc[i][j][1])
		if j == l - 1:
			stc_.append([cs, ct])
			break
		(ns, nt) = (stc[i][j + 1][0], stc[i][j + 1][1])
		if ct != ns:
			flg = False
			stc_.append([cs, ct])
		else:
			flg = True
			ct = nt
			if j == l - 2:
				stc_.append([cs, ct])
				break
		j += 1
stc_ = sorted(stc_, key=lambda x: (x[0], x[1]))
m = len(stc_)
cnt = np.zeros(10 ** 5 + 5, dtype=int)
for i in range(m):
	(s, t) = (stc_[i][0] - 1, stc_[i][1])
	cnt[s:t] += 1
print(cnt.max())


import sys
input = sys.stdin.readline
(N, C) = map(int, input().split())
c = [list(map(int, input().split())) for _ in range(N)]
t = [[0] * (10 ** 5 + 1) for _ in range(C + 1)]
for i in range(N):
	for j in range(c[i][0], c[i][1] + 1):
		t[c[i][2]][j] = 1
res = 0
for i in range(10 ** 5 + 1):
	p = 0
	for j in range(C + 1):
		p += t[j][i]
	res = max(p, res)
print(res)


(N, C) = map(int, input().split())
timetable = [[0] * 10 ** 5 for _ in range(C)]
for _ in range(N):
	(s, t, c) = map(int, input().split())
	timetable[c - 1][s - 1:t] = [1] * (t - s + 1)
ans = 0
for i in range(10 ** 5):
	now = 0
	for c in range(C):
		now += timetable[c][i]
	if ans < now:
		ans = now
print(ans)


(n, c) = map(int, input().split())
d = [[0] * c for _ in [0] * int(100000.0)]
for _ in range(n):
	(s, t, c) = map(int, input().split())
	for j in range(s - 1, t):
		d[j][c - 1] = 1
ans = 1
for i in range(int(100000.0)):
	s = sum(d[i])
	if s > ans:
		ans = s
print(ans)


def Csum(a):
	(b, c) = ([0], 0)
	for i in range(len(a)):
		c += a[i]
		b.append(c)
	return b
(n, c) = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
b = [[0] * (10 ** 5 + 10) for i in range(c)]
for i in a:
	b[i[2] - 1][i[0] - 1] += 1
	b[i[2] - 1][i[1]] -= 1
b = [Csum(i) for i in b]
ans = []
for i in range(10 ** 5 + 10):
	d = 0
	for j in range(c):
		if b[j][i] > 0:
			d += 1
	ans.append(d)
print(max(ans))


(N, C) = map(int, input().split())
(S, T) = (set(), set())
for _ in range(N):
	(s, t, c) = map(int, input().split())
	S.add((s, c))
	T.add((t, c))
ST = S & T
S -= ST
T -= ST
S = sorted(S)
T = sorted(T)
ans = 0
cnt = 0
(si, ti) = (0, 0)
while si < len(S):
	if S[si][0] <= T[ti][0]:
		cnt += 1
		ans = max(ans, cnt)
		si += 1
	else:
		cnt -= 1
		ti += 1
print(ans)