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):
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))

Solution (Python):
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.5or m[1]==c and m[0]<=s:
            m[0],m[1]=t,c
            break
print(len(list(filter(lambda x:x!=[0,0],r))))

Solution (Python):
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.5or m[1]==c and m[0]<=s:
            m[0],m[1]=t,c
            break
print(len(list(filter(lambda x:x!=[0,0],r))))

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

Solution (Python):
N, C = map(int, input().split())
stc = [list(map(int, input().split())) for _ in range(N)]

stc.sort()
counter = 0
array = []

for i in stc:
    s, t, c =  i
    flag = True
    for j in range(len(array)):
        if array[j][0] == s and array[j][2] == c or array[j][0] < s:
            array[j] = [t, s, c]
            flag = False
            array.sort(reverse = True)
            break

    if flag:
        array.append([t, s, c])
        array.sort(reverse = True)
        counter += 1

print(counter)

Solution (Python):
def merge(s):
    correct_s = []
    s.sort(key = lambda x:(x[2],x[0]))
    min_max = [s[0][0],s[0][1]]
    for i in range(1,len(s)):
        if s[i][2] == s[i-1][2] and s[i][0] == min_max[1]:
            min_max[1] = s[i][1]   
        else:
            correct_s.append([min_max[0],min_max[1],s[i-1][2]])
            min_max[0],min_max[1] = s[i][0],s[i][1]
    else:
        correct_s.append([min_max[0],min_max[1],s[len(s)-1][2]])

    return correct_s
        
        
    
import heapq
N,C = list(map(int,input().split()))
data = []
av = []
for i in range(N):
    data.append(list(map(int,input().split())))
    


s = merge(data)
s.sort()


for i in range(len(s)):
    if i == 0:
        heapq.heappush(av,s[i][1])
    elif s[i][0] <= av[0]:
        heapq.heappush(av,s[i][1])
    else:
        heapq.heappop(av)
        heapq.heappush(av,s[i][1])

print(len(av))

Solution (Python):


import sys
import heapq


INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


n, c = LI()
tv = [tuple(LI()) for _ in range(n)]

used = [[0] * (10 ** 5 + 1) for _ in range(c)]
for s, t, channel in tv:
    used[channel - 1][s:t + 1] = [1] * (t - s + 1)

ans = 0
for col in zip(*used):
    ans = max(ans, sum(col))

print(ans)

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

Solution (Python):
from itertools import accumulate
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))))

Solution (Python):
from itertools import accumulate
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] += 1
    merge[c][t+1] -= 1
for c in range(31):
    merge[c] = list(map(lambda x: int(bool(x)), accumulate(merge[c])))

ans = []
for i in range(M+1):
    res = 0
    for j in range(31):
        res += merge[j][i]
    ans.append(res)
print(max(ans))

Solution (Python):
from itertools import accumulate
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] += 1
    merge[c][t+1] -= 1
for c in range(31):
    merge[c] = list(map(lambda x: int(bool(x)), accumulate(merge[c])))

ans = []
for i in range(M+1):
    res = 0
    for j in range(31):
        res += merge[j][i]
    ans.append(res)
print(max(ans))

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

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

Solution (Python):
def show(imos):
    print(imos[:20])
    print()
n, C = [int(i) for i in input().split()]
imos = [[0 for _ in range(C)] for _ in range(10**5+10)]
for i in range(n):
    s, t, c = [int(i) - 1 for i in input().split()]
    imos[s][c] += 1
    imos[t][c] -= 1

_max = 0
for i in range(1, len(imos)):
    _count = 0
    for j in range(C):
        if imos[i][j] < 0:
            _count += -imos[i][j]
        imos[i][j] += imos[i-1][j]
    _max = max(_max, sum(imos[i]) + _count)

print(_max)

Solution (Python):


N, C = map(int, input().split())
T = 10**5+2

c_ls = [[0] * T for _ in range(C)]

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

for i in range(C):
    for j in range(1, T):
        c_ls[i][j] += c_ls[i][j-1]

for i in range(C):
    for j in range(1, T):
        if c_ls[i][j] > c_ls[i][j-1]:
            c_ls[i][j-1] += 1

sm = [0] * T
for i in range(C):
    for j in range(T):
        sm[j] += c_ls[i][j]

print(max(sm))

Solution (Python):
N, C = [int(_) for _ in input().split()]
STC = [[int(_) for _ in input().split()] for _ in range(N)]
ST = [[set(), set()] for _ in range(C)]
for s, t, c in STC:
    c -= 1  
    ST[c][0].add(s)
    ST[c][1].add(t)
    if t in ST[c][0]:
        ST[c][0].discard(t)
        ST[c][1].discard(t)
    if s in ST[c][1]:
        ST[c][0].discard(s)
        ST[c][1].discard(s)
D = {}
for i in range(C):
    for s in ST[i][0]:
        D[s - 0.5] = D.get(s - 0.5, 0) + 1
    for t in ST[i][1]:
        D[t] = D.get(t, 0) - 1
times = sorted(D.keys())
count = 0
ans = 0
for time in times:
    count += D[time]
    ans = max(ans, count)
print(ans)

Solution (Python):
from itertools import accumulate
N, C = map(int, input().split())
V = [[0] * (10 ** 5 + 1) for i in range(C)]

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

for c in range(C):
    V[c] = list(accumulate(V[c]))

ans = 0
for i in range(10 ** 5 + 1):
    tmp = 0
    for c in range(C):
        tmp += min(1, V[c][i])
    ans = max(ans, tmp)

print(ans)

Solution (Python):


import sys
import math
import fractions
import heapq
import collections
import re
import array
import bisect

from collections import Counter, defaultdict


def array2d(dim1, dim2, init=None):
    return [[init for _ in range(dim2)] for _ in range(dim1)]

II = lambda: int(input())
MI = lambda: map(int, input().split())
DBGLOG = lambda s: sys.stderr.write(s + "\n")


def main():
    N, C = MI()
    STs_tmp = [[] for _ in range(C)]

    for i in range(N):
        s, t, c = MI()
        heapq.heappush(STs_tmp[c-1], (s, t))

    s_cnt = defaultdict(int)
    t_cnt = defaultdict(int)
    times = set()
    for c in range(C):
        ls, lt = None, None
        while STs_tmp[c]:
            s, t = heapq.heappop(STs_tmp[c])
            if ls is None:
                ls, lt = s, t
                continue
            if lt == s:
                lt = t
                continue
            else:
                s_cnt[ls-0.5] += 1
                times.add(ls-0.5)
                t_cnt[lt] += 1
                times.add(lt)
                
                ls, lt = s, t
        if ls is not None:
            s_cnt[ls-0.5] += 1
            times.add(ls-0.5)
            t_cnt[lt] += 1
            times.add(lt)
            

    ans, cnt = 0, 0
    for t in sorted(times):
        cnt += s_cnt[t] - t_cnt[t]
        ans = max(ans, cnt)
        
    return ans


if __name__ == "__main__":
    print(main())

Solution (Python):
N, C = map(int, input().split())
time = 10**5+1
channel_list = [[0 for _ in range(time)]for _ in range(C)]
count_list = [0 for _ in range(time)]
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, time):
        channel_list[i][t] += channel_list[i][t-1]
        if channel_list[i][t] >= 1:
            count_list[t] += 1

print(max(count_list))

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

Solution (Python):
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):
        if t == 10 ** 5:
            continue
        channel_list[i][t] += channel_list[i][t-1]
        if channel_list[i][t] >= 1:
            count_list[t] += 1
x = 0
for t in range(1, 10**5+1):
    count = count_list[t]
    if count > x:
        x = count
print(x)

Solution (Python):

from operator import itemgetter

N,C = map(int, input().split())
T = 0
record = []
for _ in range(N):
    s,t,c = map(int, input().split())
    T = max(T, t)
    record.append((s,t,c))
record.sort(key=itemgetter(2,0,1))

tl = [0]*(T+1)
curr_channel = None
for r in record:
    s,t,c = r
    if curr_channel==c:
        if curr_time==s:
            tl[s] += 1
            tl[t] -= 1
        else:
            tl[s-1] += 1
            tl[t] -= 1
        curr_time = t
    else:
        tl[s-1] += 1
        tl[t] -= 1
        curr_channel = c
        curr_time = t

s = 0
res = 0
for t in tl:
    s += t
    res = max(res, s)
print(res)

Solution (Python):

from operator import itemgetter

N,C = map(int, input().split())
record = []
for _ in range(N):
    s,t,c = map(int, input().split())
    record.append((s,t,c))
record.sort(key=itemgetter(1,0,2))

def can_record(k):
    slots = [(-1,-1)]*k  

    for r in record:
        idx = -1
        t = -1
        for i in range(k):
            end_time, channel = slots[i]
            if channel==r[2]:
                if end_time<=r[0]:
                    if t<=end_time:
                        t = end_time
                        idx = i
            else:
                if end_time<r[0]:
                    if t<=end_time:
                        t = end_time
                        idx = i
        if idx==-1:
            return False
        else:
            slots[idx] = (r[1],r[2])
    return True

for k in range(1,C+1):
    if can_record(k):
        print(k)
        break

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

Solution (Python):

from pprint import pprint
N, C = map(int, input().split())
stc = [list(map(int, input().split())) for _ in range(N)]

X = 10**5+2

c_s = [[0 for _ in range(X)] for _ in range(C)]
c_t = [[0 for _ in range(X)] for _ in range(C)]


for s,t,c in stc:
    c_s[c-1][s] += 1
    c_t[c-1][t] -= 1







c_rec = [[0 for _ in range(X)] for _ in range(C)]
for c in range(C):
    c_rec[c][0] = c_s[c][0] + c_t[c][0]
    for i in range(1,X):
        c_rec[c][i] = c_rec[c][i-1] + c_s[c][i] + c_t[c][i]






for c in range(C):
    for i in range(X-1):
        diff = c_rec[c][i+1] - c_rec[c][i]
        if diff > 0: 
            c_rec[c][i] += diff






sumlist = [0 for _ in range(X)]
for c in range(C):
    for i in range(X):
        sumlist[i] += c_rec[c][i]



print(max(sumlist))

Solution (Python):
from heapq import heappush, heappop
N,C=list(map(int,input().split()))

arr=[]
for _ in range(N):
    arr.append(list(map(int,input().split())))

arr=sorted(arr, key=lambda x:x[0])

ans=0
cnt=0
tmp=0
recorder = [(10**10,31)]

for x in arr:
    s, t, c= x
    while recorder[0][0]<s:
        heappop(recorder)
        cnt-=1
        cnt+=tmp
        tmp=0
    
    for i in range(len(recorder)):
        if recorder[i][0] == s and recorder[i][1] ==c:
            cnt-=1
            tmp+=1
            break
    heappush(recorder,(t,c))
    cnt+=1
    if ans < cnt:
        ans=cnt            
print(ans)

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

Solution (Python):
INF = 10**5
N,C = map(int,input().split())
table = [0]*(INF+1)
prog = [list(map(int,input().split())) for i in range(N)]
prog.sort(key=lambda x:x[0])
cs = [set() for i in range(INF+1)]
for s,t,c in prog:
    cs[s].add(c)
for i in range(N):
    table[prog[i][0]-1] += 1
    if prog[i][2] in cs[prog[i][1]]:
        table[prog[i][1]-1] -= 1
    else:
        table[prog[i][1]] -= 1
ans,tmp = 0,0
for i in range(INF+1):
    tmp += table[i]
    ans = max(tmp,ans)
print(ans)

Solution (Python):
N, C = map(int, input().split())
latest = 0
P = [[] for i in range(C)]
for i in range(N):
    s, t, c = map(int, input().split())
    P[c-1].append((s, t))
    latest = max(latest, t)

Dup = [0 for i in range(latest + 2)]
for i in range(C):
    P[i].sort()
    for j in range(len(P[i])):
        Dup[P[i][j][0]] += 1
        Dup[P[i][j][1] + 1] -= 1
        if j >= 1:
            if P[i][j][0] == P[i][j-1][1]:
                Dup[P[i][j][0]] -= 1
                Dup[P[i][j][0] + 1] += 1
for i in range(1, latest + 2):
    Dup[i] += Dup[i-1]
print(max(Dup))

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

Solution (Python):
n, c = map(int, input().split())
r = []
for i in range(n):
    r.append([int(m) for m in input().split()])

r.sort(key=lambda x:(x[0], x[1],x[2]))

xli = []
p = 0
for i in range(n):
    if i == 0:
        xli.append(r[i])
    else:
        xli.sort(key=lambda x: (x[1]), reverse=True)
        for jnum, j in enumerate(xli, 0):
            if (j[1] < r[i][0]) or (j[1] <= r[i][0] and j[2] == r[i][2]):
                p = 1
                xli[jnum] = r[i]
                break
        if p == 0:
            xli.append(r[i])
        p = 0

print(len(xli))

Solution (Python):
n, c = map(int, input().split())
r = []
for i in range(n):
    r.append([int(m) for m in input().split()])

r.sort(key=lambda x:(x[0], x[1],x[2]))

xli = []
p = 0
for i in range(n):
    if i == 0:
        xli.append(r[i])
    else:
        for jnum, j in enumerate(xli, 0):
            if (j[1] < r[i][0]) or (j[1] <= r[i][0] and j[2] == r[i][2]):
                p = 1
                xli[jnum] = r[i]
                break
        if p == 0:
            xli.append(r[i])
        p = 0

print(len(xli))

Solution (Python):
import numpy as np
n,c=map(int, input().split())
a=[list(map(int, input().split())) for  i in range(n)]
a.sort(key=lambda x: (x[2],x[0]))
ans=np.array([0]*3*10**5)
channel,last=0,0
for i,j,k in a:
    if channel==k and last==i:
        ans[i*2+1:j*2+1]+=1
        last=j
    else:
        ans[i*2-1:j*2+1]+=1
        last=j
        channel=k
print(ans.max())

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

Solution (Python):
def inpl(): return [int(i) for i in input().split()]
N, C = inpl()
channel = [[] for _ in range(C)]
for i in range(N):
    s, t, c = inpl()
    channel[c-1].append([s,t])
H = [0 for i in range(10**5+3)]
for i in range(C):
    channel[i].sort(key = lambda x: x[0])
    for j in range(len(channel[i])-1):
        if channel[i][j][1] == channel[i][j+1][0]:
            channel[i][j+1] = [channel[i][j][0],channel[i][j+1][1]]
            channel[i][j] = []
    channel[i] = [k for k in channel[i] if k != []]

for i in range(C):
    for st, en in channel[i]:
        H[st] += 1
        H[en+1] -= 1
ans = H[0]
for i in range(10**5+1):
    H[i+1] += H[i]
    ans = max(ans,H[i+1])
        
print(ans)

Solution (Python):
from itertools import accumulate
N, C = map(int, input().split())
G = [[0] * (10 ** 5 + 1) for i in range(C)]
for i in range(N):
    s, t, c = map(int, input().split())
    c = c - 1
    G[c][s - 1] += 1
    G[c][t] -= 1

for i in range(C):
    G[i] = list(accumulate(G[i]))

ans = 0
for i in range(10 ** 5 + 1):
    tmp = 0
    for c in range(C):
        tmp += min(1, G[c][i])
    ans = max(ans, tmp)

print(ans)

Solution (Python):
from operator import attrgetter


class Data:
    def __init__(self, s, t, c):
        self.s = s
        self.t = t
        self.c = c


N, C = map(int, input().split())
data_list = []
for _ in range(N):
    s, t, c = map(int, input().split())
    data_list.append(Data(s, t, c))

ch_map = {}
for data in data_list:
    if data.c in ch_map:
        ch_map[data.c].append(data)
    else:
        ch_map[data.c] = [data]
data_list = []

m = {}
for key, val in ch_map.items():
    ch_list = sorted(val, key=attrgetter("s"))
    
    ch_m = {}
    end = 0
    for ch in ch_list:
        if end <= ch.s:
            for i in range(ch.s-1, ch.t):
                if i in m:
                    if i not in ch_m:
                        m[i] += 1
                else:
                    m[i] = 1
                ch_m[i] = 1
                
            end = ch.t
        elif end > ch.t:
            for i in range((end+1, ch.t)):
                if i in m:
                    if i not in ch_m:
                        m[i] += 1
                else:
                    m[i] = 1
                ch_m[i] = 1
                
            end = ch.t
    


max = 0
for key, val in m.items():
    if max < val:
        max = val


'''
for i in range(100001):
    cnt = 0
    for key, val in ch_map.items():
        if i in val:
            cnt += 1
    if cnt > max:
        max = cnt
    cnt = 0
'''
print(max)

Solution (Python):
N,C = map(int,input().split())
cum = [0]*(10**5+1)
tail = {}
head = {}
for i in range(10**5+1):
    tail[i] = []
    head[i] = []
for i in range(N):
    s,t,c = map(int,input().split())
    if c not in tail[s] and c not in head[t-1]:
        cum[s-1] += 1
        cum[t] -= 1
    elif c not in head[t-1]:
        cum[s] += 1
        cum[t] -= 1
    elif c not in tail[s]:
        cum[s-1] += 1
        cum[t-1] -= 1
    else:
        cum[s] += 1
        cum[t-1] -= 1
    tail[t].append(c)
    head[s-1].append(c)
    
import numpy as np
print(np.cumsum(cum).max())

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

Solution (Python):
N, C = map(int, input().split())
M = 10 ** 5 * 2 + 5
T = [[0] * M for i in range(C)]
for i in range(N):
    s, t, c = map(int, input().split())
    s = 2 * s - 1
    t = 2 * t
    c -= 1
    T[c][s] += 1
    T[c][t] -= 1

TT = [[0] * (2 * N) for i in range(C)]
for i in range(C):
    for j in range(1, M):
        T[i][j] += T[i][j - 1]

num = 0
for j in range(M):
    tmp = 0
    for i in range(C):
        if T[i][j] >= 1:
            tmp += 1

    num = max(tmp, num)
print(num)

Solution (Python):
n,c=map(int,input().split())
stc=[list(map(int,input().split())) for _ in range(n)]
ts=[t[1] for t in stc]
mst=max(ts)
xstc=[[] for _ in range(c)]
for i in range(n):
    xstc[stc[i][2]-1].append([stc[i][0],stc[i][1]])
for i in range(c):
    xstc[i]=sorted(xstc[i],key=lambda x:x[0])
    for j in range(1,len(xstc[i])):
        if xstc[i][j-1][1]==xstc[i][j][0]:
            xstc[i][j][0]=xstc[i][j-1][0]
            xstc[i][j-1]=[]
z=[]
for i in range(c):
    for j in range(len(xstc[i])):
        if len(xstc[i][j])>0:
            z.append(xstc[i][j])
x=[0 for _ in range(mst+2)]
for i in range(len(z)):
    x[z[i][0]-1]+=1
    x[z[i][1]]-=1
for i in range(1,mst+2):
    x[i]+=x[i-1]
print(max(x))

Solution (Python):
import numpy as np


N, C_num = map(int, input().split(" "))
S, T, C = [], [], []
for _ in range(N):
    s, t, c = map(int, input().split(" "))
    S.append(s * 2 - 1)
    T.append(t * 2)
    C.append(c - 1)

table = np.zeros((C_num, 10 ** 5 * 3), "int32")
for s, t, c in zip(S, T, C):
    table[c, s:t] = 1

print(table.sum(0).max())

Solution (Python):
n, c = map(int, input().split())
tv = [list(map(int, input().split())) for i in range(n)]

tv.sort(key=lambda x: x[1])
imos = [0 for i in range(10**5+2)]
mark = [[] for i in range(10**5+2)]
for i in range(n):
    flag = 0
    for j in mark[tv[i][0]]:
        if j == tv[i][2]:
            flag = 1
    if flag:
        imos[tv[i][0]+1] += 1
    else:
        imos[tv[i][0]] += 1
    imos[tv[i][1]+1] -= 1
    mark[tv[i][1]].append(tv[i][2])

for i in range(10**5+1):
    imos[i+1] += imos[i]

print(max(imos[:-1]))

Solution (Python):
N,C = map(int,input().split())
src = [list(map(int,input().split())) for i in range(N)]
MAX = 10**5
bucket = [[] for i in range(MAX+2)]
bucket2 = [set() for i in range(MAX+2)]
for s,t,c in src:
    bucket[s].append((t,c))
    bucket2[s].add(c)

imos = [0]*(MAX+2)

for s in range(MAX):
    for t,c in bucket[s]:
        imos[s-1] += 1
        if c in bucket2[t]:
            imos[t-1] -= 1
        else:
            imos[t] -= 1

ans = tmp = 0
for im in imos:
    tmp += im
    ans = max(ans, tmp)
print(ans)

Solution (Python):
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from itertools import accumulate

N,C = li()
MAX = 10**5

stc = []
for _ in range(N):
    stc.append(list(li()))
    
rec = [[0 for _ in range(MAX+1)] for _ in range(C)]
for s,t,c in stc:
    rec[c-1][s-1] += 1
    rec[c-1][t] -= 1
    
for i in range(C):
    rec[i] = list(accumulate(rec[i]))
    rec[i] = [min(1,reci) for reci in rec[i]]
    
rec_total = rec[0]
    
for i in range(1,C):
    for j in range(MAX+1):
        rec_total[j] = rec_total[j] + rec[i][j]

print(max(rec_total))

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

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

Solution (Python):
N, c = map(int, input().split())
time = [0 for i in range(100001)]
time_c = [[0 for i in range(100001)] for j in range(c)]
          
for i in range(N):
    S, T, C = map(int, input().split())
    time_c[C - 1][S] += 1
    time_c[C - 1][T] -= 1
    
for i in range(100001):
    for j in range(c):
        if time_c[j][i] > 0:
            time[i - 1] += time_c[j][i]
        if time_c[j][i] < 0:
            time[i] += time_c[j][i]

for i in range(1, 100001):
    time[i] += time[i - 1]

print(max(time))

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

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

Solution (Python):
from itertools import accumulate

def unite_intervals(lst: list) -> list:

    
    n = len(lst)
    mx = max([lst[i][1] for i in range(n)])
    imos = [0] * (2*(mx+1) + 2)
    
    
    for st, ed in lst:
        imos[2*st + 1] += 1
        imos[2*ed] -= 1
        
    imos_cum = list(accumulate(imos))

    
    ans = []
    start = -1
    last = -1
    for i in range(mx+2):
        if imos_cum[2*i] == 0 and imos_cum[2*i+1] > 0:
            start = i
            
        elif imos_cum[2*i+1] > 0 and imos_cum[2*i+2] == 0:
            last = i+1
            
            ans.append((start, last))
            start = -1
            last = -1
        
    return ans

import sys
sdin = sys.stdin.readline

n,c = map(int, sdin().split())

dic = {}  
for i in range(c):
    dic.update({i+1: []})
    

ch_st = []
max_t = 0
for _ in range(n):
    s,t,ch = map(int, sdin().split())
    max_t = max(max_t, t)
    dic[ch].append((max(0,s-1),t))
    

for ch in range(c):
    ch += 1
    if len(dic[ch]) > 0:
        dic[ch] = unite_intervals(dic[ch])
    

imos = [0]*(max_t+1)
for ch in range(1,c+1):
    for s, t in dic[ch]:
        imos[s] += 1
        imos[t] -= 1
        
imos = list(accumulate(imos))
print(max(imos))

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

Solution (Python):
def d_recording(N, C, R):
    
    
    
    from itertools import accumulate

    
    
    l = 10**5 * 2 + 2
    running_recorder = [0] * l  

    for channel in range(1, C + 1):
        rec = [0] * l  
        
        for s, t, c in R:
            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))