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):
T_MAX = 10 ** 5
N, C = map(int, input().split())
programs = []
for _ in range(N):
    s, t, c = map(int, input().split())
    programs.append((c - 1, s - 1, t))

programs.sort()
for i in range(N - 2, -1, -1):
    c0, s0, t0 = programs[i]
    c1, s1, t1 = programs[i + 1]
    if c0 == c1 and t0 == s1 + 1:
        programs[i] = (c0, s0, t1) 
        programs[i + 1] = (-1, 0, 0) 

acc = [0] * (T_MAX + 1)
for i in range(N):
    _c, s, t = programs[i]
    acc[s] += 1
    acc[t] -= 1
for i in range(T_MAX):
    acc[i + 1] += acc[i]

result = max(acc)
print(result)

Solution (Python):
import sys
from itertools import accumulate


r = lambda: sys.stdin.readline().strip() 
R = lambda: list(map(int, r().split())) 
Rmap = lambda: map(int, r().split())

N, C = R()
STC = [R() for _ in range(N)]

tbl = [[0]*(2*(10**5)+5) for _ in range(C)]

for s, t, c in STC:
    c -= 1
    
    if tbl[c][2*s] != 0 and tbl[c][2*t-1] != 0:
        tbl[c][2*s] = 0
        tbl[c][2*t-1] = 0
    
    elif tbl[c][2*s] != 0:
        tbl[c][2*s] += 1
        tbl[c][2*t] -= 1
    
    elif tbl[c][2*t-1] != 0:
        tbl[c][2*t-1] -= 1
        tbl[c][2*s-1] += 1
    
    else:
        tbl[c][2*s-1] = 1
        tbl[c][2*t] = -1

tbl2 = [list(accumulate(a)) for a in tbl]

ans = max([sum(x) for x in zip(*tbl2)])
print(ans)

Solution (Python):
import sys
from itertools import accumulate


r = lambda: sys.stdin.readline().strip() 
R = lambda: list(map(int, r().split())) 
Rmap = lambda: map(int, r().split())

N, C = R()
STC = [R() for _ in range(N)]

tbl = [[0]*(2*(10**5)+5) for _ in range(C)]

for s, t, c in STC:
    c -= 1
    tbl[c][2*s-1] += 1
    tbl[c][2*t] -= 1


tbl2 = [list(accumulate(a)) for a in tbl]
for i in range(200002):
     for j in range(C):
         if tbl2[j][i]>1:
          	tbl2[j][i]=1

ans = max([sum(x) for x in zip(*tbl2)])
print(ans)

Solution (Python):
import sys
from itertools import accumulate


r = lambda: sys.stdin.readline().strip() 
R = lambda: list(map(int, r().split())) 
Rmap = lambda: map(int, r().split())

N, C = R()
STC = [R() for _ in range(N)]

tbl = [[0]*(2*(10**5)+5) for _ in range(C)]

for s, t, c in STC:
    c -= 1
    
    if tbl[c][2*s] == -1:
        tbl[c][2*s] = 0
        tbl[c][2*t] = -1
    
    elif tbl[c][2*t-1] == 1:
        tbl[c][2*t-1] = 0
        tbl[c][2*s-1] = 1
    
    else:
        tbl[c][2*s-1] = 1
        tbl[c][2*t] = -1

tbl2 = [list(accumulate(a)) for a in tbl]
for i in range(200002):
     for j in range(C):
         if tbl2[j][i]>1:
          	tbl2[j][i]=1

ans = max([sum(x) for x in zip(*tbl2)])
print(ans)

Solution (Python):
import sys
from itertools import accumulate


r = lambda: sys.stdin.readline().strip() 
R = lambda: list(map(int, r().split())) 
Rmap = lambda: map(int, r().split())

N, C = R()
STC = [R() for _ in range(N)]

tbl = [[0]*(2*(10**5)+5) for _ in range(C)]

for s, t, c in STC:
    c -= 1
    
    if tbl[c][2*s] != 0:
        tbl[c][2*s] += 1
        tbl[c][2*t] -= 1
    
    elif tbl[c][2*t-1] != 0:
        tbl[c][2*t-1] -= 1
        tbl[c][2*s-1] += 1
    
    else:
        tbl[c][2*s-1] = 1
        tbl[c][2*t] = -1

tbl2 = [list(accumulate(a)) for a in tbl]
for i in range(200002):
     for j in range(C):
         if tbl2[j][i]==2:
          	tbl2[j][i]=1

ans = max([sum(x) for x in zip(*tbl2)])
print(ans)

Solution (Python):
import sys
from itertools import accumulate


r = lambda: sys.stdin.readline().strip() 
R = lambda: list(map(int, r().split())) 
Rmap = lambda: map(int, r().split())

N, C = R()
STC = [R() for _ in range(N)]

tbl = [[0]*(2*(10**5)+5) for _ in range(C)]

for s, t, c in STC:
    c -= 1
    
    if tbl[c][2*s] != 0:
        tbl[c][2*s] += 1
        tbl[c][2*t] -= 1
    
    elif tbl[c][2*t-1] != 0:
        tbl[c][2*t-1] -= 1
        tbl[c][2*s-1] += 1
    
    else:
        tbl[c][2*s-1] = 1
        tbl[c][2*t] = -1

tbl2 = [list(accumulate(a)) for a in tbl]
for i in range(200002):
     for j in range(C):
         if tbl2[j][i]>1:
          	tbl2[j][i]=1

ans = max([sum(x) for x in zip(*tbl2)])
print(ans)

Solution (Python):
import sys
from itertools import accumulate


r = lambda: sys.stdin.readline().strip() 
R = lambda: list(map(int, r().split())) 
Rmap = lambda: map(int, r().split())

N, C = R()
STC = [R() for _ in range(N)]

tbl = [[0]*(2*(10**5)+5) for _ in range(C)]

for s, t, c in STC:
    c -= 1
    
    if tbl[c][2*s] != 0:
        tbl[c][2*s] += 1
        tbl[c][2*t] -= 1
    
    elif tbl[c][2*t-1] != 0:
        tbl[c][2*t-1] -= 1
        tbl[c][2*s-1] += 1
    
    else:
        tbl[c][2*s-1] = 1
        tbl[c][2*t] = -1

tbl2 = [list(accumulate(a)) for a in tbl]




res = 0
for i in range(200002):
    cc = 0
    for j in range(C):
        if tbl2[j][i] == 1:
            cc += 1
    res = max(res, cc)
print(res)

Solution (Python):
import sys
from itertools import accumulate


r = lambda: sys.stdin.readline().strip() 
R = lambda: list(map(int, r().split())) 
Rmap = lambda: map(int, r().split())

N, C = R()
STC = [R() for _ in range(N)]

tbl = [[0]*(2*(10**5)+5) for _ in range(C)]

for s, t, c in STC:
    c -= 1
    
    if tbl[c][2*s] != 0:
        tbl[c][2*s] += 1
        tbl[c][2*t] -= 1
    
    elif tbl[c][2*t-1] != 0:
        tbl[c][2*t-1] -= 1
        tbl[c][2*s-1] += 1
    
    else:
        tbl[c][2*s-1] = 1
        tbl[c][2*t] = -1

tbl2 = [list(accumulate(a)) for a in tbl]




res = 0
for i in range(200002):
    cc = 0
    for j in range(C):
        if tbl2[j][i]:
            cc += 1
    res = max(res, cc)
print(res)

Solution (Python):
N,C = map(int,input().split())
cum = [0]*(10**5+1)
st = [[] for _ in range(C)]
for _ in range(N):
    s,t,c = map(int,input().split())
    st[c-1].append([s,t])
for c in range(C):
    st[c].sort()

st_concat = [[] for _ in range(C)]
for c in range(C):
    if len(st[c]) != 0:
        s0,t0 = st[c].pop()
        while st[c]:
            s,t = st[c].pop()
            if t != s0:
                st_concat[c].append([s0,t0])
                s0,t0 = s,t
            else:
                s0 = s
        st_concat[c].append([s0,t0])

for c in range(C):
    for s,t in st_concat[c]:
        cum[s-1] += 1
        cum[t] -= 1

for i in range(10**5):
    cum[i+1] += cum[i]
print(max(cum))

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

Solution (Python):







import sys
sys.setrecursionlimit(10**7)
from itertools import accumulate, combinations, permutations 
from math import factorial
def combinations_count(n, r):
    
    
    
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n
    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]
    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot
    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])
    return result
def combination_with_repetition_count(n, r):
    return combinations_count(n + r - 1, r)
from collections import deque, Counter 
from heapq import heapify, heappop, heappush, heappushpop, heapreplace,nlargest,nsmallest 
from copy import deepcopy, copy 
from operator import itemgetter 


from functools import reduce
from fractions import gcd 
def gcds(numbers):
    return reduce(gcd, numbers)
def lcm(x, y):
    return (x * y) // gcd(x, y)
def lcms(numbers):
    return reduce(lcm, numbers, 1)



INF = 10 ** 18
MOD = 10 ** 6 + 3
modpow = lambda a, n, p = MOD: pow(a, n, p) 
def modinv(a, p = MOD):
    
    
    return modpow(a, p-2, p)
def modinv_list(n, p = MOD):
    if n <= 1:
        return [0,1][:n+1]
    else:
        inv_t = [0,1]
        for i in range(2, n+1):
            inv_t += [inv_t[p % i] * (p - int(p / i)) % p]
        return inv_t
def modfactorial_list(n, p = MOD):
    if n == 0:
        return [1]
    else:
        l = [0] * (n+1)
        tmp = 1
        for i in range(1, n+1):
            tmp = tmp * i % p
            l[i] = tmp
        return l
def modcomb(n, k, fac_list = [], p = MOD):
    
    
    from math import factorial
    if n < 0 or k < 0 or n < k: return 0
    if n == 0 or k == 0: return 1
    if len(fac_list) <= n:
        a = factorial(n) % p
        b = factorial(k) % p
        c = factorial(n-k) % p
    else:
        a = fac_list[n]
        b = fac_list[k]
        c = fac_list[n-k]
    return (a * modpow(b, p-2, p) * modpow(c, p-2, p)) % p
def modadd(a, b, p = MOD):
    return (a + b) % MOD
def modsub(a, b, p = MOD):
    return (a - b) % p
def modmul(a, b, p = MOD):
    return ((a % p) * (b % p)) % p
def moddiv(a, b, p = MOD):
    return modmul(a, modpow(b, p-2, p))




    
    

    
    
    
    
    

    
    





r = lambda: sys.stdin.readline().strip() 
R = lambda: list(map(int, r().split())) 
Rmap = lambda: map(int, r().split())

N, C = R()
STC = [R() for _ in range(N)]
tbl = [[0]*(2*(10**5)+5) for _ in range(C)]


for s, t, c in STC:
    c -= 1
    if tbl[c][2*s] != 0:
        tbl[c][2*s] += 1
        tbl[c][2*t] -= 1
    elif tbl[c][2*t-1] != 0:
        tbl[c][2*t-1] -= 1
        tbl[c][2*s-1] += 1
    else:
        tbl[c][2*s-1] = 1
        tbl[c][2*t] = -1












tbl2 = [list(accumulate(a)) for a in tbl]



res = 0
for i in range(200002):
    cc = 0
    for j in range(C):
        if tbl2[j][i]:
            cc += 1
    res = max(res, cc)
 
print(res)

Solution (Python):
from functools import reduce
import math
import collections

def main():
    
    
    
    

    
    
    
    
    
    

    
    

    
    
    
    
    
    
    
    
    
    INF = float("inf")

    
    MOD = 10**9+7
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

    
    
    
    
    N_max = 100005
    N, C = (int(_) for _ in input().split())
    s = []
    t = []
    c = []
    for i in range(N):
        s1, s2,s3 = (int(_) for _ in input().split())
        s.append(s1)
        t.append(s2)
        c.append(s3)
        
    d = [[0 for j in range(C)] for i in range(N_max)]
    for i in range(N):
        for j in range(s[i]-1,t[i]):
            d[j][c[i]-1] = 1
    ans = 0
    for i in range(N_max):
        ans = max(sum(d[i]),ans)
    print(ans)
    
    
    
    
    
    
    
    
    
    
    
    
    
                
    
    
    
    
    
    
    
    
    
    
    
    
if __name__ == '__main__':
    main()

Solution (Python):
import sys
import math
from itertools import accumulate as acc

input=sys.stdin.readline

N,C=map(int,input().split())


a=[[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,input().split())
    recs,rect=a[c][s],a[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

    a[c][s],a[c][t]=1,1

print(max(list(acc(rec))))

Solution (Python):
import sys
import math
from itertools import accumulate as acc

input=sys.stdin.readline

N,C=map(int,input().split())


a=[[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,input().split())
    recs,rect=a[c][s],a[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

    a[c][s],a[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):
import sys
import math
from itertools import accumulate as acc

N,C=map(int,input().split())


a=[[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,input().split())
    recs,rect=a[c][s],a[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

    a[c][s],a[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 = list(map(int, input().split()))
stc = [list(map(int, input().split())) for _ in range(N)]

E = max(stc, key = lambda x: x[1])[1]

R = {}
stc.sort()
L = [0] * (E + 1)
for s, t, c in stc:
  if c not in R:
    R[c] = t
  else:
    if R[c] == s:
      s += 1
    R[c] = t
  L[s - 1] += 1
  L[t] -= 1

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

print(ans)

Solution (Python):
N,C=map(int, input().split())
inl = [tuple(map(int, input().split())) for i in range(N)]
inl.sort()

res = 0
st = [(0,0)]*30
for s,t,c in inl:
    nx = (t,c)
    cnt = 0
    for i, (t1, c1) in enumerate(st):
        if not (t1 == s and c == c1) and t1 >= s:
            st[i] = (t1,c1)
        else:
            st[i] = nx
            nx = (0, 0)

        if st[i][0] != 0:
            cnt += 1
    res = max(cnt, res)

print(res)

Solution (Python):
N,C=map(int, input().split())
inl = [tuple(map(int, input().split())) for i in range(N)]
inl.sort()

res = 0
st = set()
for s,t,c in inl:
    nx = set()
    for t1, c1 in st:
        if not (t1 == s and c == c1) and t1 >= s:
            nx.add((t1,c1))
    nx.add((t,c))
    st = nx
    res = max(len(nx), res)

print(res)

Solution (Python):
N,C=map(int, input().split())
inl = [tuple(map(int, input().split())) for i in range(N)]
inl.sort()

res = 0
st = set()
for s,t,c in inl:
    nx = set()
    for t1, c1 in st:
        if not (t1 == s and c == c1) and t1 >= s:
            nx.add((t1,c1))
    nx.add((t,c))
    st = nx
    res = max(len(nx), res)

print(res)

Solution (Python):
import heapq

N,C=map(int, input().split())

inl = [tuple(map(int, input().split())) for i in range(N)]
inl.sort()

heap = []
res = 0

st = set()
for s,t,c in inl:
    nx = set()
    for t1, c1 in st:
        if t1 == s and c == c1:
            
            nx.add((t,c))
        elif t1 >= s:
            nx.add((t1,c1))
    nx.add((t,c))
    st = nx
    res = max(len(nx), res)

print(res)

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

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


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

print(ans)

Solution (Python):
N,C = list(map(int,input().split()))

P = [[] for i in range(C)]

for i in range(N):
    s,t,c = list(map(int,input().split()))
    P[c-1].append([s,"S"])
    P[c-1].append([t,"T"])

P = [sorted(sorted(P[i],key=lambda x:x[1]),key=lambda x: x[0]) for i in range(C)]

P2 = []

for i in range(C):
    for j in range(len(P[i])):
        if P[i][j][1]=="T":
            if j!=0:
                if P[i][j][0]!=P[i][j-1][0]:
                    P2.append(P[i][j])
            else:
                P2.append(P[i][j])
        else:
            if j!=len(P[i])-1:
                if P[i][j][0]!=P[i][j+1][0]:
                    P2.append([P[i][j][0]-0.5,P[i][j][1]])
            else:
                P2.append([P[i][j][0]-0.5,P[i][j][1]])

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

count=0
max_count=0
s_buf = 0
t_buf = 0

prev = -1
for i in range(len(P)):
    if prev!=P[i][0]:
        prev=P[i][0]
        count+=s_buf-t_buf
        s_buf=0
        t_buf=0
        max_count=max(count,max_count)
    if P[i][1]=="S":
        s_buf+=1
    else:
        t_buf+=1

count+=s_buf-t_buf
max_count=max(count,max_count)

print(max_count)

Solution (Python):

import sys
from itertools import accumulate
INF = float("inf")


def solve(N: int, C: int, s: "List[int]", t: "List[int]", c: "List[int]"):
    seq = [0]*(3*10**5)
    
    
    c, s, t = zip(*sorted(sorted(zip(c, s, t), key=lambda x: x[1])))
    
    
    pre_s, pre_t, pre_c = -1, -1, -1
    for sv, tv, cv in zip(s, t, c):
        if pre_c == cv and pre_t == sv:
            seq[2*pre_t] += 1
            seq[2*tv] -= 1
        else:
            seq[2*sv-1] += 1
            seq[2*tv] -= 1
        pre_s, pre_t, pre_c = sv, tv, cv
    acc = list(accumulate(seq))
    
    
    print(max(acc))
    return


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

from collections import defaultdict
N,C=map(int,raw_input().split())
S=[];T=[];C=[]
for i in range(N):
    s,t,c=map(int,raw_input().split())
    S.append(s);T.append(t);C.append(c)
beg=defaultdict(int)
end=defaultdict(int)
F=defaultdict(list)
for s,t,c in zip(S,T,C):
    F[c].append((s,t))
for k,v in F.iteritems():
    v.sort()
    buf=[]
    s,t=v[0]
    buf.append([s,t])
    for ss,tt in v[1:]:
        if t!=ss:
            buf.append([ss,tt])
        else:
            buf[-1][1]=tt
        s,t=ss,tt
    for s,t in buf:
        beg[2*s-1]+=1
        end[2*t]+=1
ans=-1; cur=0
for i in range(0,max(end)+100):
    cur+=beg[i]
    cur-=end[i]
    ans=max(ans,cur)
print(ans)

Solution (Python):



import sys
input = sys.stdin.readline

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

  
def simplify(times):
  result = []
  times.sort()
  for s,t in times:
    if result and result[-1][1] == s:
      result[-1] = (result[-1][0],t)
    else:
      result.append((s,t))
  return result

T = [simplify(x) for x in T]





import numpy as np
A = np.zeros(10**5+10,dtype=np.int32)
for times in T:
  for s,t in times:
    A[s] += 1
    A[t+1] -= 1

    
answer = A.cumsum().max()
print(answer)

Solution (Python):
n,c=map(int,input().split())
d=[[] for i in range(c)]
w=[0]*100002
for i in range(n):
    s,t,x=map(int,input().split())
    d[x-1].append((s,t))
for i in range(c):
    d[i].sort()
    e=0
    for j in range(len(d[i])):
        if len(d[i])==1:
            w[d[i][0][0]]+=1
            w[d[i][0][1]+1]-=1
        elif j==0:
            w[d[i][0][0]]+=1
            e=d[i][0][1]
        elif j+1==len(d[i]):
            if e!=d[i][j][0]:
                w[e+1]-=1
                w[d[i][j][0]]+=1
            w[d[i][j][1]+1]-=1
        else:
            if e!=d[i][j][0]:
                w[e+1]-=1
                w[d[i][j][0]]+=1
            e=d[i][j][1]
ans=chk=0
for i in w:
    chk+=i
    ans=max(ans,chk)
print(ans)

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


main()

Solution (Python):
N,C = [ int(it) for it in input().split() ]
li = [ [ int(it) for it in input().split() ] for i in range(N) ]

li.sort( key = lambda x:x[0] )

vi_li = [ [-1,-1] for i in range(C) ] 


for s,t,c in li:
  vi_li.sort( key= lambda x:x[0] + (1000000000 if x[0]==-1 else 0) )
  for vi in vi_li:
    if ( vi[1] == c ):
      if (vi[0]<=s):
        vi[0] = t
        vi[1] = c
        break
    else:
      if (vi[0]<s):
        vi[0] = t
        vi[1] = c
        break
        
print ( len( [1 for it in vi_li if it[0]!=-1 ] ) )

Solution (Python):


N, C = map(int, input().split())
ps = [[] for _ in range(C)]

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

N_max = 10 ** 5
imos = [0] * (N_max + 1)

for c in range(C):
    ps[c].sort()
    cont = False
    for i, (s, t) in enumerate(ps[c]):
        if not cont:
            imos[s - 1] += 1
        if i + 1 < len(ps[c]) and t == ps[c][i + 1][0]:
            cont = True
        else:
            imos[t] -= 1
            cont = False

ans = t = 0
for imo in imos:
    t += imo  
    ans = max(ans, t)
print(ans)

Solution (Python):


N, C = map(int, input().split())
ps = [[] for _ in range(C)]

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

N_max = 10 ** 5
imos = [0] * (N_max + 1)

for c in range(C):
    ps[c].sort()
    cont = False
    for i, (s, t) in enumerate(ps[c]):
        if not cont:
            imos[s - 1] += 1
        if i + 1 < len(ps[c]) and t == ps[c][i + 1][0]:
            cont = True
        else:
            imos[t] -= 1
            cont = False

ans = t = 0
for imo in imos:
    t += imo  
    ans = max(ans, t)
print(ans)

Solution (Python):
t_max = 10 ** 5

N, C = map(int, input().split())
imos = [[0] * (t_max + 1) for _ in range(C + 1)]




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

for c in range(1, C + 1):
    for i in range(1, t_max + 1):
        imos[c][i] += imos[c][i - 1]
        if imos[c][i] > 0 and imos[c][i - 1] == 0:
            imos[c][i - 1] = imos[c][i]

ans = 0
for i in range(1, t_max + 1):
    ans = max(ans, sum(imos[c][i] for c in range(1, C + 1)))
print(ans)

Solution (Python):
N,C=map(int, input().split())
stc=[list(map(int,input().split())) for i in range(N)]
line=[[0]*(10**5+1) for c in range(C+1)]
for s,t,c in stc:
    line[c][s]+=1
    line[c][t]-=1
for c in range(1,C+1):
    for s in range(1,10**5+1):
        if line[c][s]==1:
            line[0][s-1]+=1
        elif line[c][s]==-1:
            line[0][s]-=1
        line[c][s]+=line[c][s-1]
ans=0
for s in range(1,10**5+1):
    line[0][s]+=line[0][s-1]
    ans=max(ans,line[0][s])
print(ans)

Solution (Python):
import sys

import numpy as np

sys.setrecursionlimit(10000)
INF = float('inf')

N, Cn = list(map(int, input().split()))
S, T, C = zip(*[list(map(int, input().split())) for _ in range(N)])

channels = np.zeros((Cn + 1, 10 ** 5 + 1), dtype=int)
for s, t, c in zip(S, T, C):
    channels[c][s - 1] += 1
    channels[c][t] -= 1

counts = np.minimum(1, channels.cumsum(axis=1)).sum(axis=0)
print(counts.max())

Solution (Python):
from collections import defaultdict

d = defaultdict(lambda:defaultdict(lambda:0))

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

using = [0]*C
ma = 0

for i in sorted(d.keys()):
    e = d[i]
    
    ekeys = e.keys()
    for j in ekeys:
        if e[j] == 1:
            using[j-1] = 1
    ma = max(ma,sum(using))
    
    for j in ekeys:
        if e[j] == -1:
            using[j-1] = 0

print(ma)

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

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

sm = [0 for _ in range(2 * (pow(10, 5) + 1))]
for _c in range(c):
  tt = [0 for _ in range(2 * (pow(10, 5) + 1))]
  for s, t, c in stc:
    if c == _c + 1:
      tt[s * 2 - 1] += 1
      tt[t * 2] -= 1
  for i in range(1, len(tt)):
    tt[i] += tt[i-1]
  for i in range(len(sm)):
    if tt[i] > 0:
      sm[i] += 1

print(max(sm))

Solution (Python):
MAX = 114514

N,C=map(int, input().split())

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

Y=[]
for z in [sorted(z) for z in Z if len(z) > 0]:
	for i in range(len(z)-1):
		if z[i][1] == z[i+1][0]:
			z[i+1][0] = z[i][0]
		else:
			Y.append(z[i])
	Y.append(z.pop())

X=[0 for _ in range(MAX)]
for s,t in Y:
	X[s] += 1
	X[t+1] -= 1

for i in range(1, MAX):
	X[i] += X[i-1]

print(max(X))

Solution (Python):
N,C=map(int,input().split())

l=[[]for i in range(C)]
for i in range(N):
    s,t,c=map(int,input().split())
    l[c-1].append([s,t])
    
for i in range(C):
    if len(l[i])>=2:
        l[i].sort()
    
        X=[]
        Y=l[i][0]
        for j in range(1,len(l[i])):
            
            
                
            if j!=len(l[i])-1:
                
                    
                if Y[1]==l[i][j][0]:
                    Y[1]=l[i][j][1]
                else:
                    X.append(Y)
                    Y=l[i][j]
                    
            else:
                if Y[1]==l[i][j][0]:
                    Y[1]=l[i][j][1]
                    X.append(Y)
                else:
                    X.append(Y)
                    X.append(l[i][j])
        l[i]=X

TV=[0 for i in range(2*10**5+5)]

for i in range(C):
    for j in range(len(l[i])):
        TV[l[i][j][0]*2-1]+=1
        TV[l[i][j][1]*2]-=1

ANS=[TV[0]]
for i in range(1,len(TV)):
    ANS.append(ANS[i-1]+TV[i])
print(max(ANS))

Solution (Python):


import sys
import math



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

  Cn[c-1][s] += 1
  Cn[c-1][t] -= 1

for i in range(1,10**5+1):
  An[i] += An[i-1]

print(max(An))

Solution (Python):

import sys
import numpy as np

def solve(N: int, C: int, s: "List[int]", t: "List[int]", c: "List[int]"):
    torec = np.zeros((C, max(t)+1), int)
    for i in range(N):
        torec[c[i]-1][s[i]:t[i]+1] = 1
    print(np.max(np.sum(torec, axis=0)))
    return



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())
tv_times = [[int(j) for j in input().split()] for i in range(N)]

channells = {}
for i in range(C+1):
    channells[i] = []
max_end = -1

for i in range(N):
    s,g,c = tv_times[i]
    max_end = max(max_end,g)
    channells[c] += [s,g]

tv_times = []
f = [0 for i in range(max_end+1)]
for cha in channells.keys():
    remove_list = []
    time = channells[cha]
    time.sort()
    for i in range(1,len(time)-1):
        if time[i] == time[i+1]:
            remove_list.append(time[i])
    time = list(set(time)-set(remove_list))
    time.sort()
    for i in range(len(time)//2):
        f[max(time[2*i]-1,0)] += 1
        f[time[2*i+1]] -= 1
ans = -1
for i in range(1,max_end+1):
    f[i] += f[i-1]
    if ans < f[i]:
        ans = f[i]

print(ans)

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

nofc=np.zeros((C,10**5),dtype=int)

for i in range(N):
  s,t,c=map(int,input().split())
  vec=np.ones(t-s+1,dtype=int)
  nofc[c-1][s-1:t]=vec
print(int(max(np.sum(nofc,axis=0))))

Solution (Python):
from collections import defaultdict
from copy import deepcopy
from math import log
from itertools import accumulate

N,C=map(int,input().split())
T=10**5+1
programs=defaultdict(list)
for i in range(N):
    s,t,c=map(int,input().split())
    programs[c].append((s,t))
imos=[0]*(T)
for c,p in programs.items():
    p.sort()
    ps,pt=p[0]
    for s,t in p[1:]:
        if pt==s:
            pt=t
            continue
        imos[ps-1]+=1
        imos[pt]-=1
        ps,pt=s,t
    imos[ps-1]+=1
    imos[pt]-=1
print(max(accumulate(imos)))

Solution (Python):
N, C = map(int, input().split())
ch = [[False for i in range(100001)] for j in range(C+1)]

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

    ans = max(count, ans)
print(ans)

Solution (Python):
import sys
import numpy as np
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())



N, C = mi()
time = [0 for i in range(10 ** 5 + 10)]
use = [[] for i in range(10 ** 5 + 10)]
F = []
for i in range(N):
    F.append(lmi())
F.sort(key=lambda x: x[0])

for s, t, c in F:
    use[t].append(c)
    if c in use[s]:
        time[s] += 1
    else:
        time[s-1] += 1
    time[t] -= 1

timesum = np.cumsum(np.array(time))

print(max(timesum))