Problem:
 Score : 400 points    Problem Statement Joisino is planning to record N TV programs with recorders.  The TV can receive C channels numbered 1 through C .  The i -th program that she wants to record will be broadcast from time s_i to time t_i (including time s_i but not t_i ) on Channel c_i .  Here, there will never be more than one program that are broadcast on the same channel at the same time.  When the recorder is recording a channel from time S to time T (including time S but not T ), it cannot record other channels from time S-0.5 to time T (including time S-0.5 but not T ).  Find the minimum number of recorders required to record the channels so that all the N programs are completely recorded.      Constraints  1≤N≤10^5  1≤C≤30  1≤s_i<t_i≤10^5  1≤c_i≤C  If c_i=c_j and i≠j , either t_i≤s_j or s_i≥t_j .  All input values are integers.         Input Input is given from Standard Input in the following format:  N  C  s_1  t_1  c_1  :  s_N  t_N  c_N       Output When the minimum required number of recorders is x , print the value of x .        Sample Input 1 3 2
1 7 2
7 8 1
8 12 1      Sample Output 1 2  Two recorders can record all the programs, for example, as follows:   With the first recorder, record Channel 2 from time 1 to time 7 . The first program will be recorded. Note that this recorder will be unable to record other channels from time 0.5 to time 7 .  With the second recorder, record Channel 1 from time 7 to time 12 . The second and third programs will be recorded. Note that this recorder will be unable to record other channels from time 6.5 to time 12 .        Sample Input 2 3 4
1 3 2
3 4 4
1 4 3      Sample Output 2 3  There may be a channel where there is no program to record.       Sample Input 3 9 4
56 60 4
33 37 2
89 90 3
32 43 1
67 68 3
49 51 3
31 32 3
70 71 1
11 12 3      Sample Output 3 2

Solution (Python):
def d_recording(N, C, R):
    
    
    
    from itertools import accumulate
    start = [row[0] for row in R]
    end = [row[1] for row in R]
    channel_num = [row[2] for row in R]

    
    
    l = max(end) * 2 + 2
    running_recorder = [0 for _ in range(l)]  

    for channel in range(1, C + 1):
        rec = [0 for _ in range(l)]  
        
        for s, t, c in zip(start, end, channel_num):
            if c == channel:
                
                
                rec[s * 2 - 1] += 1
                rec[t * 2] -= 1
        rec = accumulate(rec)
        
        for j, running in enumerate(rec):
            if running > 0:
                running_recorder[j] += 1
    ans = max(running_recorder)
    return ans

N, C = [int(i) for i in input().split()]
R = [[int(i) for i in input().split()] for j in range(N)]
print(d_recording(N, C, R))

Solution (Python):
import sys
import math
import collections
import itertools
import array
import inspect


sys.setrecursionlimit(10000)



def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))



def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]




dp = None


def main():
    N, C = li_input()

    A = [[0] * 100001 for _ in range(C)]
    S = [0] * 100001

    for i in range(N):
        s, t, c = li_input()

        for j in range(s - 1, t):
            A[c - 1][j] += 1

    for a in A:
        for i in range(1, len(a)):
            if a[i]:
                S[i] += 1

    print(max(S))


main()

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

Solution (Python):
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)

Solution (Python):
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
    A[c - 1][t] -= 1

for i in range(C):
    for j in range(1, T):
        A[i][j] += A[i][j - 1]
        if A[i][j] == 1 and A[i][j - 1] == 0:
            A[i][j - 1] = 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)

Solution (Python):
import sys
import math
import collections
import itertools
import array
import inspect


sys.setrecursionlimit(10000)



def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))



def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]




dp = None


def main():
    N, C = li_input()

    A = [[0] * 100001 for _ in range(C)]
    S = [0] * 100001

    for i in range(N):
        s, t, c = li_input()

        for j in range(s, t):
            A[c - 1][j] += 1

    for a in A:
        for i in range(1, len(a)):
            if a[i] == 1 or (i != len(a) - 1 and a[i + 1]) == 1:
                S[i] += 1

    print(max(S))


main()

Solution (Python):
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)

Solution (Python):
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

N,C = inpl()
datas = [[] for i in range(C)]
Times = set()
for _ in range(N):
	s,t,n = inpl()
	datas[n-1].append([s,t])
	Times.add(s-0.5)
	Times.add(t)

dataset = []
for c in range(C):
	data = sorted(datas[c])
	if len(data) == 0: continue
	bs,bt = data[0]
	for i in range(1,len(data)):
		s,t = data[i]
		if bt == s:
			
			s = bs
		else:
			dataset.append([bs-0.5,bt])
		bs,bt = s,t
	dataset.append([bs-0.5,bt])

ddT = defaultdict(int)
for i,t in enumerate(sorted(list(Times))):
	ddT[t] = i
	
L = len(Times)
imos = [0]*L
for s,t in dataset:
	s,t = ddT[s],ddT[t]
	imos[s] += 1
	imos[t] -= 1

tmp = 0
ans = 0
for i in range(L):
	tmp += imos[i]
	ans = max(tmp,ans)

print(ans)

Solution (Python):
n, c = map(int,raw_input().split())

arr = [[0 for i in range(c)] for j in range(10**5+1)]

for i in range(n):
	s,t,ch = map(int,raw_input().split())
	s -= 1
	ch -= 1
	for i in range(s,t):
		arr[i][ch] = 1

ans = 0

for i in range(10**5+1):
	ans = max(ans,sum(arr[i]))

print ans

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
N,C=map(int,input().split())
s=[0 for i in range(N)];t=[0 for i in range(N)];c=[0 for i in range(N)]
MT=0
for i in range(N):
    s[i],t[i],c[i]=map(int,input().split())
    s[i]-=1
    t[i]-=1
    c[i]-=1
for i in range(N):
    if t[i]>MT:
        MT=t[i]
CBC=[[0 for i in range(MT+1)] for i in range(C)]
for i in range(N):
    for j in range(s[i]-1,t[i]):
        CBC[c[i]][j]=1
MaxC=0
for i in range(MT+1):
    NowC=0
    for j in range(C):
        if CBC[j][i]==1:
            NowC+=1
    if NowC>MaxC:
        MaxC=NowC
print(MaxC)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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))

Solution (Python):
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:])]))

Solution (Python):

import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


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


def read_float():
    return float(input())


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


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().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):
    tbl = [0] * (2*int(1e+5) + 2)
    ST = defaultdict(list)
    for s, t, c in STC:
        ST[c].append((s, t))
    for st in ST.values():
        st.sort()
        for i, (s, t) in enumerate(st):
            if i > 0 and st[i-1][1] == st[i][0]:
                tbl[2*(st[i][0])] += 1
                tbl[2*(st[i][1])] -= 1
            else:
                tbl[2*st[i][0]-1] += 1
                tbl[2*st[i][1]] -= 1

    for i in range(1, len(tbl)):
        tbl[i] += tbl[i-1]
    ans = max(tbl)
    return ans


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


if __name__ == '__main__':
    main()

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

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
N,C = map(int,input().split())
tvs = [list(map(int,input().split())) for _ in range(N)]
chans = [[] for _ in range(C+1)]
tvs.sort(key=lambda x:x[0])
targets = []
times = [0]*(pow(10,5)+2)

for tv in tvs:
  chans[tv[2]].append([tv[0],tv[1]])

for chan in chans:
  tmp = []
  if len(chan) == 1:
    targets.append(chan[0])
    continue
  for x in range(len(chan)):
    if len(tmp) == 0:
      tmp = chan[x]
      continue
    if chan[x][0] <= tmp[1] + 1:
      tmp[1] = chan[x][1]
      if x == len(chan)-1:
        targets.append(tmp)
    else:
      targets.append(tmp)
      tmp = chan[x]

for target in targets:
  times[target[0]] += 1
  times[target[1]+1] += -1

for j in range(1,pow(10,5)+2):
  times[j] += times[j-1]

print(max(times))

Solution (Python):
MAX_T = 2 * 10 ** 5


def main():
    n, c = map(int, input().split())

    ch = [[] for i in range(c)]
    for i in range(n):
        si, ti, ci = map(int, input().split())
        ch[ci-1].append([si, ti])

    for i in range(c):
        if len(ch[i]) != 0:
            ch[i].sort(key=lambda lst: lst[0])
            pro_lst = [ch[i][0]]
            for j in range(1, len(ch[i])):
                if ch[i][j][0] == pro_lst[-1][1]:
                    pro_lst[-1][1] = ch[i][j][1]
                else:
                    pro_lst.append(ch[i][j])
            ch[i] = pro_lst

    im = [0 for i in range(MAX_T+1)]
    for i in range(c):
        for j in range(len(ch[i])):
            im[2*ch[i][j][0]-1] += 1
            im[2*ch[i][j][1]] -= 1

    im_s = [0 for i in range(MAX_T+1)]
    for i in range(1, len(im)):
        im_s[i] = im_s[i-1] + im[i]

    print(max(im_s))


if __name__ == '__main__':
    main()

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
from collections import defaultdict
N,C=map(int,input().split())
stc=[]
c_st=defaultdict(list)
for i in range(N):
    ss,tt,cc = map(int,input().split())
    stc.append((ss,tt,cc))
    c_st[cc].append((ss,tt))

S=[]
T=[]
for c,lst in c_st.items():
    ss=sorted(lst)
    s,t=ss[0]
    for i in range(1,len(lst)):
        if ss[i][0]==ss[i-1][1]:
            t=ss[i][1]
            continue
        else:
            S.append(s-0.5)
            T.append(t)
            s,t=ss[i]
    S.append(s-0.5)
    T.append(t)
S=sorted(S)
T=sorted(T)
count=0
maxc=0
si,ti=0,0
while si<len(S):
    s=S[si]
    t=T[ti]
    if s<t:
        count+=1
        si+=1
    else:
        count-=1
        ti+=1
    if count>maxc:
        maxc=count
print(maxc)

Solution (Python):
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)

Solution (Python):
N,C =map(int,input().split())
chan=[[] for i in range(C)]
for i in range(N):
    a,b,c=map(int,input().split())
    chan[c-1].append([a,b])
for i in range(C):
    chan[i].sort()
imos=[0]*(10**5+2)
for i in range(C):
    if len(chan[i])==0:
        continue
    imos[chan[i][0][0]]+=1
    imos[chan[i][0][1]+1]-=1
    for k in range(1,len(chan[i])):
        if chan[i][k][0]==chan[i][k-1][1]:
            imos[chan[i][k][0]+1]+=1
            imos[chan[i][k][1]+1]-=1
        else:
            imos[chan[i][k][0]]+=1
            imos[chan[i][k][1]+1]-=1

for i in range(1,10**5+2):
     imos[i] +=imos[i-1]  
print(max(imos))

Solution (Python):
N,C =map(int,input().split())
chan=[[] for i in range(C)]
for i in range(N):
    a,b,c=map(int,input().split())
    chan[c-1].append([a,b])
for i in range(C):
    chan[i].sort()
imos=[0]*(10**5+2)
for i in range(C):
    if len(chan[i])==0:
        continue
    imos[chan[i][0][0]]+=1
    imos[chan[i][0][1]+1]-=1
    for k in range(1,len(chan[i])):
        if chan[i][k][0]==chan[i][k-1][1]:
            imos[chan[i][k][0]+1]+=1
            imos[chan[i][k][1]+1]-=1
        else:
            imos[chan[i][k][0]]+=1
            imos[chan[i][k][1]+1]-=1

for i in range(1,10**5+2):
     imos[i] +=imos[i-1]  
print(max(imos))

Solution (Python):
N, Ch = map(int, input().split())
L = [list(map(int, input().split())) for i in range(N)]
L.sort(key=lambda x: x[0])
time = 0
T = [-1]
C = [-1]
ans = 1
for si, ti, ci in L:
    if time < si:
        time = si
        for xt, t in enumerate(T):
            if t == -1:
                continue
            elif t < si:
                T[xt] = -1
                C[xt] = -1
            elif t == si:
                T[xt] = -2

    if -2 in T:
        flg = False
        for index, t in enumerate(T):
            if t != -2:
                continue
            if C[index] == ci:
                T[index] = ti
                flg = True
                break
        if flg:
            continue

    if -1 in T:
        index = T.index(-1)
        T[index] = ti
        C[index] = ci
        continue
    else:
        ans += 1
        T.append(ti)
        C.append(ci)
print(ans)

Solution (Python):
import numpy as np
from collections import Counter
N,C = map(int,input().split())
link =[[] for _ in range(C+1)]
for i in range(N):
    x,y,c=[int(i) for i in input().split()]
    link[c].append((x,y))
siyou = np.array([0] * (C) * 100000).reshape(C,100000)
for i in range(1,C+1):
  for x,y in link[i]:
    siyou[i-1][x-1:y] = 1
print(np.max((np.sum(siyou, axis=0))))

Solution (Python):
N, C = map(int, input().split())
program = []
program_list = [False for _ in range((((10 ** 5) * 2) + 10))]
for _ in range(C + 1):
    program.append(program_list.copy())

for _ in range(N):
    s, t, c = map(int, input().split())
    s2 = (t * 2) - ((s * 2) - 1)
    program[c][(s * 2) - 1:t * 2] = [True] * s2

max_c = 0
for i in range(len(program_list)):
    c = 0
    for j in range(1, C + 1):
        if program[j][i]:
            c += 1
        if c > max_c:
            max_c = c
print(max_c)

Solution (Python):
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))

Solution (Python):
import numpy as np
N,C = map(int,input().split())

f=[[0]*100000 for _ in range(C)]

for n in range(N):
    s, t, c = map(int, input().split())
    f[c-1][s-1:t] = [1] * (t-s + 1)

arr = np.array(f)
print(np.max((np.sum(arr, axis=0))))

Solution (Python):
N, C = map(int, input().split())
TV = [[0]*(2*10**5) for i in range(C)]

for i in range(N):
    s, t, c = map(int, input().split())
    TV[c-1][2*s-2] += 1
    TV[c-1][2*t-1] -= 1

for i in range(C):
    for j in range(1, 2*10**5):
        TV[i][j] = TV[i][j]+TV[i][j-1]

for i in range(C):
    for j in range(1, 2*10**5):
        TV[i][j] = min(1, TV[i][j])

ans = 0
for i in range(2*10**5):
    tmp = 0
    for j in range(C):
        tmp += TV[j][i]
    ans = max(ans, tmp)
print(ans)

Solution (Python):
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)

Solution (Python):


N,C=map(int,raw_input().split())
l=[[0 for i in xrange(C)] for j in xrange(10**5)]
for i in xrange(N):
 s,t,c=map(int,raw_input().split())
 s-=1
 for j in xrange(s,t):
  l[j][c-1]=1

res=0
for i in xrange(10**5):
 if sum(l[i])>res:
  res=sum(l[i])
print res

Solution (Python):


N,C=map(int,raw_input().split())
l=[[0 for i in xrange(C)] for j in xrange(10**5)]
for i in xrange(N):
 s,t,c=map(int,raw_input().split())
 s-=1
 for j in xrange(s,t):
  l[j][c-1]=1

res=0
for i in xrange(10**5):
 if sum(l[i])>res:
  res=sum(l[i])
print res

Solution (Python):
def m():
    N, C = map(int, input().split())
    s = []
    t = []
    c = []
    for i in range(N):
        x, y, z = map(int, input().split())
        s.append(x)
        t.append(y)
        c.append(z)

    TIME = 100002
    recod = [[0 for _ in range(1, TIME+1)] for _ in range(1, C+2)]
    for n in range(N):
        for k in range(s[n], t[n]+1):
            recod[c[n]][k] = 1

    recodcnt = 1
    for n in range(TIME):
        tmp = 0
        for g in range(1, C+1):
            if recod[g][n] == 1:
               tmp += 1
        recodcnt = max(tmp, recodcnt)
    return recodcnt


print(m())

Solution (Python):
N, C = map(int, input().split())
imos = [0] * 100002
channel = [[0] * 100002 for i in range(C)]

for i in range(N):
    s, t, c = map(int, input().split())
    channel[c - 1][s] += 1
    channel[c - 1][t] -= 1

for i in range(C):
    for j in range(100001):
        channel[i][j + 1] += channel[i][j]

for i in range(C):
    for j in range(100001):
        if channel[i][j] == 0 and channel[i][j + 1] == 1:
            imos[j] += 1
        elif channel[i][j] == 1 and channel[i][j + 1] == 0:
            imos[j + 1] -= 1

for j in range(100001):
    imos[j + 1] += imos[j]

print(max(imos))

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
N,C=map(int,input().split())
ans=[[] for i in range(10**5*2+2)]
for i in range(N):
  s,t,c=map(int,input().split())
  if -c in ans[2*s]:
    d=ans[2*s].index(-c)
    ans[2*s].pop(d)
  else:
    ans[2*s-1].append(c)
  if c in ans[2*t-1]:
    d=ans[2*t-1].index(c)
    ans[2*t-1].pop(d)
  else:
    ans[2*t].append(-c)
timetable=[0 for j in range(200002)]
for i in range(10**5*2+2):
  for j in range(len(ans[i])):
    if ans[i][j]>0:
      timetable[i]+=1
    else:
      timetable[i]-=1
res=0
for i in range(1,200002):
  timetable[i]+=timetable[i-1]
  res=max(res,timetable[i])
print(res)

Solution (Python):
N, C = list(map(int, input().split()))
tmax = 0
s = [0 for _ in range(N)]
t = [0 for _ in range(N)]
c = [0 for _ in range(N)]
for i in range(N):
    s[i], t[i], c[i] = list(map(int, input().split()))

tmax = max(t)
c_timeline = [[0]*C for _ in range(2 * tmax + 1)]
for i in range(N):
    S = s[i]
    T = t[i]
    channel = c[i] - 1
    for j in range(2 * S - 1, 2 * T + 1):
        c_timeline[j][channel] = 1

time = [0 for _ in range(2*tmax+1)]
for timeline in c_timeline:
    time.append(sum(timeline))

print(max(time))

Solution (Python):
N, C = list(map(int, input().split()))
tmax = 0
s = [0 for _ in range(N)]
t = [0 for _ in range(N)]
c = [0 for _ in range(N)]
for i in range(N):
    s[i], t[i], c[i] = list(map(int, input().split()))

tmax = max(t)
c_timeline = [[0]*C for _ in range(2 * tmax + 1)]
for i in range(N):
    S = s[i]
    T = t[i]
    channel = c[i] - 1
    for j in range(2 * S - 1, 2 * T + 1):
        c_timeline[j][channel] = 1

rokuga = 0
for timeline in c_timeline:
    time = sum(timeline)
    if rokuga < time:
        rokuga = time

print(rokuga)

Solution (Python):
import numpy

N, C = map(int, input().split())
STC = [list(map(int, input().split())) for i in range(N)]
Channel = numpy.array([[0]*(2*10**5+1) for i in range(C+1)])

for s, t, c in STC:
    Channel[c][2*s-1] += 1
    Channel[c][2*t] -= 1
    
for i in range(len(Channel)):
    Channel[i] = numpy.cumsum(Channel[i])
bool_Channel = Channel.astype(numpy.bool_)

needs = numpy.sum(bool_Channel, axis=0)
print(needs.max())

Solution (Python):

"""
https://beta.atcoder.jp/contests/abc080/tasks/abc080_d

"""
import sys
from sys import stdin
from heapq import heappop, heappush, heappushpop
input = stdin.readline


def prep_programs(programs, C):
    
    channels = [[] for _ in range(C+1)]
    res = []

    programs.sort()
    for s, t, c in programs:    
        channels[c].append([s, t])

    for i in range(1, C+1):      
        channels[i].append([-1, -1])

    
    for i in range(1, C+1):
        prev_start = channels[i][0][0]
        for a, b in zip(channels[i], channels[i][1:]):
            if a[1] == b[0]:
                pass
            else:
                res.append([prev_start, a[1], i])
                prev_start = b[0]
    res.sort()
    return res                  


def solve(programs, N, C):
    P = prep_programs(programs, C)

    max_used = 1                
    R = []

    heappush(R, 0)
    for s, t, c in P:
        end_time = heappushpop(R, t)
        if end_time >= s:       
            heappush(R, end_time)
            max_used = len(R)
    return max_used


def main(args):
    programs = []
    N, C = map(int, input().split())
    for _ in range(N):
        s, t, c = map(int, input().split())
        programs.append([s, t, c])
    ans = solve(programs, N, C)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Solution (Python):

"""
https://beta.atcoder.jp/contests/abc080/tasks/abc080_d

"""
import sys
from sys import stdin
from heapq import heappop, heappush, heappushpop
input = stdin.readline


def prep_programs(programs):
    
    channels = [[] for _ in range(31)]
    res = []

    for s, t, c in programs:
        channels[c].append([s, t])

    for i in range(1, 31):
        channels[i].append([-1, -1])

    for i in range(1, 31):
        prev_start = channels[i][0][0]
        for a, b in zip(channels[i], channels[i][1:]):
            if a[1] == b[0]:
                pass
            else:
                res.append([prev_start, a[1], i])
                prev_start = b[0]
    return res


def solve(programs, N, C):
    programs.sort()
    programs = prep_programs(programs)
    programs.sort()

    max_used = 1
    R = []

    heappush(R, 0)
    for s, t, c in programs:
        end_time = heappushpop(R, t)
        if end_time >= s:
            heappush(R, end_time)
            max_used = len(R)
    return max_used


def main(args):
    programs = []
    N, C = map(int, input().split())
    for _ in range(N):
        s, t, c = map(int, input().split())
        programs.append([s, t, c])
    ans = solve(programs, N, C)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Solution (Python):

from itertools import accumulate
def inpl(): return tuple(map(int, input().split()))

N, C = inpl()
P = [[] for _ in range(C)]

for _ in range(N):
    s, t, c = inpl()
    P[c-1].append((2*s, 2*t))

S = [0 for _ in range(2*10**5 + 3)]
for p in P:
    if len(p) == 0:
        continue
    p2 = []
    p = sorted(p)
    s, t = p[0]
    for i in range(1, len(p)):
        if t == p[i][0]:
            t = p[i][1]
        else:
            S[s-1] += 1
            S[t+1] -= 1
            s, t = p[i]
    S[s-1] += 1
    S[t+1] -= 1

print(max(accumulate(S)))

Solution (Python):
def getter(starts, ends):
    while starts:
        if starts[-1][0] < ends[-1][1]:
            yield (starts.pop(), True)
        else:
            yield (ends.pop(), False)


def foo(C, targets):
    starts = sorted(targets, key=lambda x:x[0], reverse=True)
    ends = sorted(targets, key=lambda x: x[1], reverse=True)

    result = 0
    active = [0]*(C+1)
    for x, p in getter(starts, ends):
        if p:
            active[x[2]] += 1
        else:
            active[x[2]] -= 1
        result = max(result, sum(map(lambda x: 1 if x > 0 else 0 ,active)))
    return result


if __name__ == "__main__":
    n, C  = map(int, input().split())

    targets = []
    for i in range(n):
        s, t, c = list(map(int, input().split()))
        targets.append((s-1, t, c))
    print(foo(C, targets))

Solution (Python):
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)

Solution (Python):
MAX_T = int(1e5)
N, C = map(int, input().split())
s, t, c = [], [], []
for i in range(N):
    _s, _t, _c = map(int, input().split())
    s.append(_s)
    t.append(_t)
    c.append(_c-1)

chs = [[0] * (MAX_T + 1) for i in range(C)]
for i in range(N):
    chs[c[i]][s[i]] += 1
    chs[c[i]][t[i]] -= 1

ups = [0] * (MAX_T + 1)
downs = [0] * (MAX_T + 1)
for i in range(MAX_T):
    ups[i] = sum([chs[j][i] for j in range(C) if chs[j][i] > 0])
    downs[i] = sum([-chs[j][i] for j in range(C) if chs[j][i] < 0])

ans = 0
cur = 0
for i in range(MAX_T+1):
    cur += ups[i]
    ans = max((ans, cur))
    cur -= downs[i]

print(ans)

Solution (Python):
N,C = map(int,input().split())
stc = [[int(x) for x in input().split()] for _ in [0]*N]
st = []
for c in range(1,C+1):
    stlist = sorted([x for x in stc if x[2]==c])
    prevs = prevt = 0
    for s,t,c in stlist:
        if s != prevt:
            st.append((prevs,prevt))
            prevs = s
        prevt = t
    st.append((prevs,prevt))
st = sorted([x for x in st if x!=(0,0)])
rec = [0]
for _st in st:
    m= min(rec)
    if m<_st[0]:
        rec.remove(m)
    rec.append(_st[1])
print(len(rec))