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):
import sys
input = sys.stdin.readline

N, C = [int(x) for x in input().split()]
imos = [0]*(10**6 + 2)
stc = [[] for _ in range(31)]
for _ in range(N):
    tmp = [int(x) for x in input().split()]
    stc[tmp[2]].append([tmp[0], tmp[1]])

for i in range(C + 1):
    if len(stc[i]) == 0:
        continue
    stc[i].sort()
    s, t = stc[i][0][0], stc[i][0][1]
    new_stc_i = []
    flag = 1
    for j in range(1, len(stc[i])):
        flag = 0
        if t == stc[i][j][0]:
            t = stc[i][j][1]
            flag = 1
        else:
            new_stc_i.append([s, t])
            s = stc[i][j][0]
            t = stc[i][j][1]
    if flag:
        new_stc_i.append([s, t])
    stc[i] = new_stc_i

for i in range(C + 1):
    stc_i = stc[i]
    for j in stc_i:
        s, t = j 
        s *= 10
        t *= 10
        imos[max(0, s - 5)] += 1
        imos[t] -= 1

from itertools import accumulate

csum = list(accumulate(imos))

print(max(csum))

Solution (Python):
def main():
    N,C = [int(_n) for _n in input().split()]
    L = 100010
    table = [[0]*L for _ in range(C)]
    for i in range(N):
        s,t,c = [int(_n) for _n in input().split()]
        c -= 1
        s -= 1
        t -= 1
        table[c][s] += 1
        table[c][t+1] -= 1 
    for c in range(C):
        for j in range(L-1):
            table[c][j+1] += table[c][j]
    for i in range(C):
        for j in range(L):
            table[i][j] = min(1, table[i][j])
    for j in range(L):
        for c in range(C-1):
            table[c+1][j] += table[c][j]
    print(max(table[C-1]))
    
    
    
    



main()

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


if __name__ == '__main__':
    main()

Solution (Python):
n,c,*stc = 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))

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

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

Solution (Python):


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)

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

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

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

ans = 0

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

time = 10**5+1

c_imos = [[0 for i in range(time)] for j in range(c)]

for i in range(n):
    for j in range(stc[i][1]-stc[i][0]+1):
        c_imos[stc[i][2]-1][stc[i][0]-1+j] = 1


"""
for i in range(n):
    c_imos[stc[i][2]-1][stc[i][0]-1] += 1
    c_imos[stc[i][2]-1][stc[i][1]] -= 1
"""

"""
for i in range(c):
    for j in range(time):
        if j == 0:
            if c_imos[i][j] == 1:
                nd_v[i][j] = 1
        else:
            nd_v[i][j] = nd_v[i][j-1] + c_imos[i][j]
"""
"""
for i in range(c):
    for j in range(time):
        if nd_v[i][j] >= 2:
            nd_v[i][j] = 1
"""
ans = 1



for i in range(time):
    tmp = 0
    for j in range(c):
        tmp += c_imos[j][i]
    
    ans = max(tmp,ans)

print(ans)

exit()
    
c_num = stc[0][2]
t_num = stc[0][1]
idx = 0
print(stc)
for i in range(1,n):
    print(t_num,i)
    if stc[idx+i][2] == c_num:
        if stc[idx+i][0] == t_num:
            stc[idx+i-1][1] = stc[idx+i][1]
            t_num = stc[idx+i][1]
            del stc[idx+i]
            idx -= 1
        else:
            print(t_num,t_num,t_num)
            c_num = stc[idx+i][2]
            t_num = stc[idx+i][1]

stc.sort(key=lambda x:x[1])
print(stc)
exit()
tmp = stc[0][1]

ans = 1
ans_tmp = 1

for i in range(1,len(stc)):
    for j in range(i+1,len(stc)):
        if tmp >= stc[j][0]:
            ans_tmp += 1
        else:
            tmp = stc[j][0]
            ans = max(ans_tmp,ans)

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

ans = 0

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

time = 10**5+3

c_imos = [[0 for i in range(time)] for j in range(c)]

for i in range(n):
    c_imos[stc[i][2]-1][stc[i][0]-1] += 1
    c_imos[stc[i][2]-1][stc[i][1]] -= 1

nd_v = [[0 for i in range(time)] for j in range(c)]

for i in range(c):
    for j in range(time):
        if j == 0:
            if c_imos[i][j] == 1:
                nd_v[i][j] = 1
        else:
            nd_v[i][j] = nd_v[i][j-1] + c_imos[i][j]

for i in range(c):
    for j in range(time):
        if nd_v[i][j] >= 2:
            nd_v[i][j] = 1
ans = 1

for i in range(time-1):
    tmp = 0
    for j in range(c):
        tmp += nd_v[j][i]
    ans = max(tmp,ans)

print(ans)

exit()
    
c_num = stc[0][2]
t_num = stc[0][1]
idx = 0
print(stc)
for i in range(1,n):
    print(t_num,i)
    if stc[idx+i][2] == c_num:
        if stc[idx+i][0] == t_num:
            stc[idx+i-1][1] = stc[idx+i][1]
            t_num = stc[idx+i][1]
            del stc[idx+i]
            idx -= 1
        else:
            print(t_num,t_num,t_num)
            c_num = stc[idx+i][2]
            t_num = stc[idx+i][1]

stc.sort(key=lambda x:x[1])
print(stc)
exit()
tmp = stc[0][1]

ans = 1
ans_tmp = 1

for i in range(1,len(stc)):
    for j in range(i+1,len(stc)):
        if tmp >= stc[j][0]:
            ans_tmp += 1
        else:
            tmp = stc[j][0]
            ans = max(ans_tmp,ans)

Solution (Python):


def submit():
    n, c = map(int, input().split())
    table_max = 10 ** 5
    table = [0 for _ in range(table_max + 1)]

    programs = []
    for _ in range(n):
        s, t, c = map(int, input().split())
        programs.append((s, t, c))
    programs.sort(key=lambda x: (x[2], x[0]))

    program_merge = [programs[0]]
    last = programs[0]
    for p in programs[1:]:
        if last[2] == p[2] and last[1] == p[0]:
            program_merge.pop()
            program_merge.append((last[0], p[1], p[2]))
        else:
            program_merge.append(p)
        last = program_merge[-1]
            

    for s, t, _ in program_merge:
        table[s - 1] += 1
        table[t] -= 1

    curr_max = 0
    for i in range(1, table_max + 1):
        table[i] += table[i - 1]
        if table[i] > curr_max:
            curr_max = table[i]

    print(curr_max)


submit()

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

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

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

Solution (Python):
import heapq

def main():
    N, C = 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())

Solution (Python):
def main():
    N, C = map(int, input().split())
    l = []
    for _ in range(N):
        s, t, c = 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()

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

Solution (Python):
import sys
input = sys.stdin.buffer.readline

n, C = map(int, input().split())
stc = []
max_t = 0
for i in range(n):
    s, t, c = map(int, input().split())
    max_t = max(max_t, t)
    stc.append([s, t, c])

len_imos = max_t+1
imos = [[0 for _ in range(len_imos)] for _ in range(C)]
for i in range(n):
    s, t, c = stc[i]
    imos[c-1][s-1] += 1
    imos[c-1][t] -= 1

for j in range(C):
    v = 0
    for i in range(len_imos):
        v += imos[j][i]
        imos[j][i] = v

ans = 0
v = 0
for i in range(len_imos):
    v = 0
    for c in range(C):
        v += 1 if imos[c][i] > 0 else 0
    ans = max(ans, v)

print(ans)

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

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

ans = 0
for i in range(10**5):
    a = 0
    for j in range(C):
        if T[i][j] or T[i+1][j]:
            a += 1
    ans = max(ans,a)
print(ans)

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

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

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

Solution (Python):
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
ans = 0
for i in range(100001):
    ans = max(ans,sum(t[j][i] for j in range(c)))
print(ans)

Solution (Python):
N,C = map(int,input().split())
T = [[0 for i in range(10**5+1)] for j in range(30)]

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]

for i in range(C):
    for j in range(10**5):
        if T[i][-j-1] == 0 and T[i][-j-2] == 1:
            T[i][-j-1] = 1
ans = 0
for i in range(10**5+1):
    ans = max(ans,sum(T[j][i] for j in range(C)))
print(ans)

Solution (Python):
N,C = map(int,input().split())
imos = [[0]*100005 for i in range(30)]
for i in range(N):
    s,t,c = map(int,input().split())
    s -= 1
    c -= 1
    imos[c][s] += 1
    imos[c][t] -= 1
for c in range(C):
    for i in range(1,100005):
        imos[c][i] += imos[c][i-1]
for c in range(C):
    for i in range(1, 100005):
        if imos[c][i]:
            imos[c][i] = 1

ans = 0
for i in range(100005):
    cnt = 0
    for c in range(C):
        cnt += imos[c][i]
    ans = max(ans,cnt)
print(ans)

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    
    from itertools import combinations, permutations, accumulate, groupby
    
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    

    
    

    n,c = map(int, input().split())
    stc = [list(map(int, input().split())) for _ in range(n)]
    rokuga = [[0]*c for _ in range(2*10**5+10)]

    for s,t,ch in stc:
        for i in range(int((s-0.5)*2), 2*t):
            rokuga[i][ch-1] = 1
    
    res = 0
    for i in range(1, 2*10**5+10):
        res = max(res, sum(rokuga[i]))
    print(res)

if __name__ == '__main__':
    main()

Solution (Python):
import itertools

N, C = map(int, input().split())
MAX = 10 ** 5 + 1
table = [[0] * MAX for _ in range(C)]

for _ in range(N):
    s, t, c = 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)))

Solution (Python):






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

imos = [[0 for _ in range(x)] for _ in range(C)]
for _ in range(N):
    s, t, c = map(int, input().split())
    s, t, c = s * 2 - 1, t * 2 - 1, c - 1
    imos[c][s - 1] += 1
    imos[c][t] -= 1
    

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

ans = 0
for j in range(x):
    tmp = 0
    for i in range(C):
        tmp += min(1, imos[i][j])
    ans = max(ans, tmp)



print(ans)

Solution (Python):
import sys
input=sys.stdin.buffer.readline
n,c=map(int,input().split())
a=[ [0 for _ in range(10**5+2)] for _ in range(c)]
for _ in range(n):
    s,t,cc=map(int,input().split())
    cc-=1

    
    
    for i in range(s-1,t):
        a[cc][i]=1
'''for i in range(c):
    for j in range(1,10**5+1):
        a[i][j]+=a[i][j-1]
'''
ans=1
for j in range(0,10**5):
    su=0

    for i in range(c):


        su+=a[i][j]
    ans=max(ans,su)
print(ans)

Solution (Python):
import sys
input=sys.stdin.buffer.readline
n,c=map(int,input().split())
a=[ [0 for _ in range(10**5+2)] for _ in range(c)]
for _ in range(n):
    s,t,cc=map(int,input().split())
    cc-=1

    
    
    for i in range(s-1,t):
        a[cc][i]=1
'''for i in range(c):
    for j in range(1,10**5+1):
        a[i][j]+=a[i][j-1]
'''
ans=1
for j in range(0,10**5+1):
    su=0

    for i in range(c):


        su+=a[i][j]
    ans=max(ans,su)
print(ans)

Solution (Python):
import numpy as np
n, C = map(int,input().split())
cha = [[0] for _ in range(C+1)]
stc = [list(map(int, input().split())) for _ in range(n)]
stc.sort()
result = np.zeros(2*10**5)
for s, t, c in stc:
    if cha[c] == s:
        result[2*s+1:2*t] += 1
    else:
        result[2*s-1:2*t] += 1
    cha[c] = t
print(int(max(result)))

Solution (Python):
import numpy as np
n, C = map(int,input().split())
cha = [[[0,0]] for _ in range(C+1)]
stc = [list(map(int, input().split())) for _ in range(n)]
stc.sort()
for s, t, c in stc:
    if cha[c][-1][1]==s:
        cha[c][-1][1] = t
    else:
        cha[c].append([s, t])
result = np.zeros(2*10**5)
for i in range(1, C+1):
    for s, t in cha[i]:
        result[s*2-1:t*2] += 1
print(int(max(result)))

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

Solution (Python):
from itertools import accumulate

N,C=map(int,input().split())
imos=[0 for i in range(0,10**5+2)]
bangumi={i:[] for i in range(1,C+1)}
for i in range(0,N):
    s,t,c=map(int,input().split())
    imos[s]+=1
    imos[t+1]+=-1
    bangumi[c].append((s,t))

ans=list(accumulate(imos))
for i in range(1,C+1):
    bangumi[i].sort()

for i in range(1,C+1):
    if len(bangumi[i])>1:
        for j in range(0,len(bangumi[i])-1):
            s,t=bangumi[i][j]
            u,v=bangumi[i][j+1]
            if t==u:
                ans[t]-=1

print(max(ans))

Solution (Python):
N, C = map(int, input().split())
MAX_N = (10 ** 5 + 5)
X = [[0] * MAX_N for _ in range(C)]

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

res = [[0] * MAX_N for _ in range(C)]
for c in range(C):
    for i in range(MAX_N - 1):
        res[c][i + 1] = res[c][i] + X[c][i]

ans = 0
for i in range(MAX_N - 1):
    count = 0
    for c in range(C):
        if 0 < res[c][i]:
            count += 1
    ans = max(ans, count)
print(ans)

Solution (Python):
N, C = map(int, input().split())
MAX_N = (10 ** 5 + 5)
X = [[0] * MAX_N for _ in range(C)]

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

res = [[0] * MAX_N for _ in range(C)]
for c in range(C):
    for i in range(MAX_N - 1):
        res[c][i + 1] = res[c][i] + X[c][i]

ans = 0
for i in range(MAX_N - 1):
    count = 0
    for c in range(C):
        if 0 < res[c][i]:
            count += 1
    ans = max(ans, count)
print(ans)

Solution (Python):
N,C=map(int,input().split())
ch=[[] for i in range(31)]
for i in range(N):
  s,t,c=map(int,input().split())
  ch[c].append([s,t])
arr=[[] for i in range(31)]
start=[]
end=[]
for i in range(31):
  score=[0]*(10**5+1)
  for j in range(len(ch[i])):
    score[ch[i][j][0]]+=1
    score[ch[i][j][1]]-=1
  for j in range(10**5+1):
    if score[j]==1:
      start.append(j)
    if score[j]==-1:
      end.append(j)
ans=[0]*(10**5+3)
for i in start:
  ans[i]+=1
for j in end:
  ans[j+1]-=1
for i in range(10**5):
  ans[i+1]+=ans[i]
print(max(ans))

Solution (Python):

import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, C: int, s: "List[int]", t: "List[int]", c: "List[int]"):
    progs = [[] for _ in range(C)]
    for si, ti, ci in zip(s, t, c):
        progs[ci - 1].append((si, ti))
    ds = []
    for prog in progs:
        if not prog:
            continue
        prog.sort()
        ds.append((prog[0][0] - 1, 1))
        ds.append((prog[-1][1], -1))
        for i in range(len(prog) - 1):
            if prog[i][1] != prog[i + 1][0]:
                ds.append((prog[i][1], -1))
                ds.append((prog[i + 1][0] - 1, 1))
    ds.sort()
    ans = 0
    m = 0
    for _, d in ds:
        m += d
        ans = max(ans, m)
    print(ans)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    C = int(next(tokens))  
    s = [int()] * (N)  
    t = [int()] * (N)  
    c = [int()] * (N)  
    for i in range(N):
        s[i] = int(next(tokens))
        t[i] = int(next(tokens))
        c[i] = int(next(tokens))
    solve(N, C, s, t, c)


if __name__ == '__main__':
    main()

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

Solution (Python):

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

Solution (Python):
import numpy as np
n,C = map(int,input().split())
ch = [[] for _ in range(30)]
for _ in range(n):
    s,t,c = map(int,input().split())
    if s>t:
        s,t = t,s
    ch[c-1].append((s,t))

lst = []
for i in range(30):
    if len(ch[i])!=0:    
        for i, (ns,nt) in enumerate(ch[i]):
            if i==0:
                s,t = ns, nt
            else:
                if ns == t:
                    t = nt
                else:
                    lst.append((s,t))
                    s,t = ns, nt
        else:
            lst.append((s,t))
    
d = [0]*(10**6)
for s,t in lst:
    d[s-1] += 1
    d[t] -= 1
d = np.cumsum(d)
print(min(max(d), C))

Solution (Python):



import numpy

def main():
  n, c = map(int, input().split())
  recoders = numpy.zeros((c, 2*(10**5+1)), dtype=numpy.int)
  for _ in range(n):
    s, t, c = map(int, input().split())
    s = 2*s - 1
    t = 2*t
    c -= 1
    recoders[c][s:t] = 1
  
  print(max(numpy.sum(recoders, axis=0)))
    

if __name__=='__main__':
  main()

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

P.sort()

rec = []
rec_cha = [None] * C
for s, t, c in P:
    c -= 1
    if rec_cha[c] is None:
        for i, (pt, pc) in enumerate(rec):
            if pt < s:
                rec[i] = (t, c)
                rec_cha[pc] = None
                rec_cha[c] = i
                break
        else:
            rec.append((t, c))
            rec_cha[c] = len(rec) - 1
    else:
        rec[rec_cha[c]] = (t, c)

print(len(rec))

Solution (Python):




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

Solution (Python):
n,c = map(int,input().split())
L = [[] for i in range(c)]
for i in range(n):
    s,t,k = map(int,input().split())
    L[k-1].append([s,t])
for i in range(c):
    L[i].sort()
for i in range(c):
    d = [0]*(10**5+1)
    T = []
    for j in range(len(L[i])):
        d[L[i][j][0]] += 1
        d[L[i][j][1]] -= 1
    for j in range(10**5):
        d[j+1] += d[j]
    cur = 0
    start = 0
    end = 0
    for j in range(10**5+1):
        if d[j] == 1 and cur == 0:
            start = j
            cur = 1
        elif d[j] == 0 and cur == 1:
            end = j
            cur = 0
            T.append([start*2-1, end*2])
    L[i] = T
dp = [0]*(10**5)*3
ans = 0
for i in range(c):
    for j in range(len(L[i])):
        dp[L[i][j][0]] += 1
        dp[L[i][j][1]] -= 1
for j in range(1,(10**5)*2+3):
    dp[j] = dp[j-1]+dp[j]
    ans = max(ans, dp[j])
print(ans)

Solution (Python):
n,c = map(int,input().split())
L = [[] for i in range(c)]
for i in range(n):
    s,t,k = map(int,input().split())
    L[k-1].append([s,t])
for i in range(c):
    L[i].sort()
for i in range(c):
    d = [0]*(10**5+1)
    T = []
    for j in range(len(L[i])):
        d[L[i][j][0]] += 1
        d[L[i][j][1]] -= 1
    for j in range(10**5):
        d[j+1] += d[j]
    cur = 0
    start = 0
    end = 0
    for j in range(10**5+1):
        if d[j] == 1 and cur == 0:
            start = j
            cur = 1
        elif d[j] == 0 and cur == 1:
            end = j
            cur = 0
            T.append([start*2-1, end*2])
    L[i] = T
dp = [0]*(10**5)*3
ans = 0
for i in range(c):
    for j in range(len(L[i])):
        dp[L[i][j][0]] += 1
        dp[L[i][j][1]] -= 1
for j in range(1,(10**5)*3):
    dp[j] = dp[j-1]+dp[j]
    ans = max(ans, dp[j])
print(ans)

Solution (Python):
n,c = map(int,input().split())
L = [[] for i in range(c)]
for i in range(n):
    s,t,k = map(int,input().split())
    L[k-1].append([s,t])
for i in range(c):
    L[i].sort()
for i in range(c):
    d = [0]*(10**5+1)
    T = []
    for j in range(len(L[i])):
        d[L[i][j][0]] += 1
        d[L[i][j][1]] -= 1
    for j in range(10**5):
        d[j+1] += d[j]
    cur = 0
    start = 0
    end = 0
    for j in range(10**5+1):
        if d[j] == 1 and cur == 0:
            start = j
            cur = 1
        elif d[j] == 0 and cur == 1:
            end = j
            cur = 0
            T.append([start*2-1, end*2])
    L[i] = T
dp = [0]*(10**5)*3
ans = 0
for i in range(c):
    for j in range(len(L[i])):
        dp[L[i][j][0]] += 1
        dp[L[i][j][1]] -= 1
for j in range(1,(10**5)*3):
    dp[j] = dp[j-1]+dp[j]
    ans = max(ans, dp[j])
print(ans)