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

Solution (Python):
def examA():
    C1 = SI()
    C2 = SI()
    ans = "YES"
    if C1[0]!=C2[2] or C1[1]!=C2[1] or C1[2]!=C2[0]:
        ans = "NO"
    print(ans)
    return

def examB():
    A, B, C, X, Y = LI()
    loop = max(X,Y)
    ans = inf
    for i in range(loop+1):
        cost = i*2*C
        if X>i:
            cost += A*(X-i)
        if Y>i:
            cost += B*(Y-i)
        ans = min(ans,cost)
    print(ans)
    return

def examC():
    def gcd(x, y):
        if y == 0:
            return x
        while (y != 0):
            x, y = y, x % y
        return x
    N, x = LI()
    X = LI()
    if N==1:
        print(abs(X[0]-x))
        return
    for i in range(N):
        X[i] = abs(X[i]-x)
    now = gcd(X[0],X[1])
    for i in range(2,N):
        now = gcd(now,X[i])
    ans = now
    print(ans)
    return

def examD():
    N = I()
    C = [LI()for _ in range(N-1)]
    ans = [inf]*N
    for i in range(N):
        cur = 0
        for j in range(i,N-1):
            c, s, f = C[j]
            next = 0
            if cur<=s:
                cur = s+c
            else:
                cur = (1+(cur-1)//f)*f + c
        ans[i] = cur
    for v in ans:
        print(v)
    return

def examE():
    class segment_():
        def __init__(self, A, n, segfunc, ide_ele=0):
            
            self.ide_ele = ide_ele
            
            self.num = 1 << (n - 1).bit_length()
            self.seg = [self.ide_ele] * 2 * self.num
            self.segfunc = segfunc
            
            for i in range(n):
                self.seg[i + self.num] = A[i]
                
            for i in range(self.num - 1, 0, -1):
                self.seg[i] = self.segfunc(self.seg[2 * i], self.seg[2 * i + 1])

        def update(self, k, r):
            k += self.num
            self.seg[k] = r
            while k:
                k >>= 1
                self.seg[k] = self.segfunc(self.seg[k * 2], self.seg[k * 2 + 1])

        
        def add(self, k, x=1):
            k += self.num
            self.seg[k] += x
            while k:
                k >>= 1
                self.seg[k] = self.segfunc(self.seg[k * 2], self.seg[k * 2 + 1])

        def query(self, p, q):
            
            if q < p:
                return self.ide_ele
            p += self.num;
            q += self.num
            res = self.ide_ele
            while p < q:
                if p & 1 == 1:
                    res = self.segfunc(res, self.seg[p])
                    p += 1
                if q & 1 == 1:
                    q -= 1
                    res = self.segfunc(res, self.seg[q])
                p >>= 1;
                q >>= 1
            return res
    N, C = LI()
    S = defaultdict(list)
    T = 0
    for _ in range(N):
        s,t,c = LI()
        c -= 1
        T = max(t,T)
        S[c].append([s,t])
    Seg = segment_([0]*(T+1), (T+1), lambda a, b: a + b)
    for i in range(C):
        if not S[i]:
            continue
        S[i].sort()
        
        Seg.add(S[i][0][0])
        Seg.add(S[i][0][1] + 1, -1)
        for j in range(1,len(S[i])):
            s,t = S[i][j]
            if S[i][j-1][1]==s:
                Seg.add(s + 1)
                Seg.add(t + 1, -1)
            else:
                Seg.add(s)
                Seg.add(t + 1, -1)
    ans = 0
    for j in range(T):
        cur = Seg.query(0,j+1)
        ans = max(ans,cur)
    print(ans)
    return

def examF():
    class combination():
        
        def __init__(self, n, mod):
            self.n = n
            self.mod = mod
            self.fac = [1] * (n + 1)
            self.inv = [1] * (n + 1)
            for j in range(1, n + 1):
                self.fac[j] = self.fac[j - 1] * j % mod

            self.inv[n] = pow(self.fac[n], mod - 2, mod)
            for j in range(n - 1, -1, -1):
                self.inv[j] = self.inv[j + 1] * (j + 1) % mod

        def comb(self, n, r):
            if r > n or n < 0 or r < 0:
                return 0
            return self.fac[n] * self.inv[n - r] * self.inv[r] % self.mod
    N, M, K = LI()
    B = N*M
    C = combination(B,mod)
    ans = 0
    for i in range(N):
        for j in range(M):
            if i>0 and j>0:
                ans += (i+j)*(N - i) * (M - j) * C.comb(B - 2, K-2) *2
            else:
                ans += (i+j)*(N - i) * (M - j) * C.comb(B - 2, K-2)
            ans %= mod
            
    print(ans)
    return

from decimal import Decimal as dec
import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def DI(): return dec(input())
def LDI(): return list(map(dec,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examE()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Solution (Python):
n, cc = [int(i) for i in input().split()]
up = [[0] * (2 * 10 ** 5) for _ in range(cc)]
ch = [[0] * (2 * 10 ** 5) for _ in range(cc)]

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

for j in range(cc):
    k = 0
    for i in range(2 * 10 ** 5):
        if up[j][i] == 1:
            k = 1
        ch[j][i] = k
        if up[j][i] == -1:
            k = 0
ans = 0
for i in range(2 * 10 ** 5):
    k = 0
    for j in range(cc):
        k += ch[j][i]
    ans = max(ans, k)
print(ans)

Solution (Python):
import math
import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit


ipt = stdin.readline
setrecursionlimit(10**7)

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

if __name__ == '__main__':
    main()

Solution (Python):

import sys
sys.setrecursionlimit(10**6)

buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


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


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


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


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


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


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


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


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap



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


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


if __name__ == '__main__':
    main()

Solution (Python):

import sys
sys.setrecursionlimit(10**6)

buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


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


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


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


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


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


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


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


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap



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


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


if __name__ == '__main__':
    main()

Solution (Python):
n,C = map(int,input().split())
ch = [[0]*(200001) for _ in range(C)]
m = 0
for _ in range(n):
    s,t,c = map(int,input().split())
    s = s*2-1
    t *= 2
    c -= 1
    ch[c][s] += 1
    ch[c][t] -= 1
    m = max(m,t)

cnt = [0]*(m+1)
for c in range(C):
    for i in range(1,m+1):
        ch[c][i] += ch[c][i-1]
        if ch[c][i-1] == 0 and ch[c][i] > 0: cnt[i] += 1
        if ch[c][i-1] > 0 and ch[c][i] == 0: cnt[i] -= 1

for i in range(1,m+1): cnt[i] += cnt[i-1]
print(max(cnt))

Solution (Python):
n,C = map(int,input().split())
INF = float("INF")
ch = [[0]*(200001) for _ in range(C)]
m = 0
for _ in range(n):
    s,t,c = map(int,input().split())
    s = s*2-1
    t *= 2
    c -= 1
    ch[c][s] += 1
    ch[c][t] -= 1
    m = max(m,t)

cnt = [0]*(m+1)
for c in range(C):
    for i in range(1,m+1):
        ch[c][i] += ch[c][i-1]
        if ch[c][i-1] == 0 and ch[c][i] > 0: cnt[i] += 1
        if ch[c][i-1] > 0 and ch[c][i] == 0: cnt[i] -= 1

for i in range(1,m+1): cnt[i] += cnt[i-1]
print(max(cnt))

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

from itertools import accumulate
print(max(list(accumulate(table))))

Solution (Python):
import numpy as np
N, C = map(int,input().split())
T1 = [[] for _ in range(C)]
for _ in range(N):
    s, t, c = map(int,input().split())
    T1[c-1].append([s,t])
for i in range(C):
    T1[i].sort()
T2 = [[] for _ in range(C)]
for i in range(C):
    for s, t in T1[i]:
        if len(T2[i]) != 0 and T2[i][-1][1] == s:
            T2[i][-1][1] = t
        else:
            T2[i].append([s,t])

L = np.zeros(10 ** 5 + 2, int)
for i in range(C):
    for time in T2[i]:
        L[time[0]] += 1
        L[time[1]+1] -= 1

ans = L.cumsum().max()

print(ans)

Solution (Python):


import sys

















from heapq import heapify, heappush, heappop 







from operator import itemgetter              


def channel_seamless_join(channel):
    """
    >>> channel_seamless_join([(1, 2), (2, 3), (7, 10), (5, 6), (10, 11)])
    [(1, 3), (5, 6), (7, 11)]
    """
    size = len(channel)
    concatnated = []
    channel.sort(key=itemgetter(0))
    s_memo = -1
    for i in range(size):
        if s_memo < 0:
            s_memo = channel[i][0]
        if i != size - 1:
            if channel[i][1] != channel[i+1][0]:
                concatnated.append((s_memo, channel[i][1]))
                s_memo = -1
        else:
            concatnated.append((s_memo, channel[i][1]))
    return concatnated


def calc_min_machine(seq):
    h = []
    cnt = 0
    for s, t in seq:
        if len(h) == 0 or h[0] > s:
            cnt += 1
        else:
            heappop(h)
        heappush(h, t+1)
    return cnt



def main():
    mod = 1000000007                
    inf = float('inf')              
    
    sys.setrecursionlimit(10**6)    
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())

    
    n, c = mi()
    channels_list = [[] for _ in range(c)]
    for _ in range(n):
        s, t, c = mi()
        c -= 1
        channels_list[c].append((s, t))

    seq = sum([channel_seamless_join(channel) for channel in channels_list], [])
    
    seq.sort(key=itemgetter(0))
    print(calc_min_machine(seq))


if __name__ == "__main__":
    
    
    main()

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

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

st_new = [[] for i in range(C)]
for c in range(C):
  if st[c]:
    st[c].sort()
    st_new[c].append(st[c][0])
    n = len(st[c])
    for i in range(1, n):
      si, ti = st[c][i]
      sii, tii = st_new[c][-1]
      if si == tii:
        st_new[c][-1][1] = ti
      else:
        st_new[c].append([si, ti])

for c in range(C):
  for s, t in st_new[c]:
    table[c][s-1] += 1
    table[c][t] -= 1
  
for c in range(C):
  for i in range(1, 10**5+1):
    table[c][i] += table[c][i-1]

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

print(ans)

Solution (Python):
n, c = map(int, input().split())
cnt = [[0 for _ in range(10 ** 5 + 1)] for _ in range(c)]

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

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


if __name__ == '__main__':
    main()

Solution (Python):
n, C = map(int, input().split())
T = 10**5
channel = []
recorder = [0 for _ in range(2*T+1)]
for loop in range(n):
    s, t, ch = map(int, input().split())
    channel.append([s, t, ch-1])

for c in range(C):
    time = [0 for _ in range(2*T+1)] 
    for i in range(n):
        s, t, ch = channel[i]
        if ch == c:
            time[2*s-1] += 1
            time[2*t] -= 1
    for t in range(1, 2*T+1):
        time[t] += time[t-1]
    for t in range(2*T+1):
        if time[t] > 0:
            recorder[t] += 1
ans = 0
for t in range(2*T+1):
    ans = max(ans, recorder[t])
print(ans)

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

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

Solution (Python):
n,C=map(int,input().split())
schedule=[]
time=[[0 for i in range(C)] for j in range(2*10**5+2)]

for i in range(n):
    s,t,c=map(int,input().split())
    schedule.append([s,t,c])

schedule.sort()

for s,t,c in schedule:
    if time[2*s][c-1]==-1:
        time[2*s][c-1]+=1
    else:
        time[2*s-1][c-1]+=1
    time[2*t][c-1]-=1

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

print(ans)

Solution (Python):
n,C = map(int,input().split())
st = [[] for _ in range(C)]
st2 = [[] for _ in range(C)]

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

for i in range(C):
    st[i].sort()

for i,e in enumerate(st):
    s1 = -1
    t1 = -1
    for j in e:
        if s1 == -1:
            s1 = j[0]
            t1 = j[1]
        else:
            if j[0] == t1:
                t1 = j[1]
            else:
                st2[i].append((s1-1,t1))
                s1 = j[0]
                t1 = j[1]
    if s1 != -1:
        st2[i].append((s1-1,t1))

imos = [0]*(2*10**5+10)

for i in st2:
    for j in i:
        imos[int(j[0]*2)] += 1
        imos[int(j[1]*2)] -= 1

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

print(max(imos))

Solution (Python):

import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N,C=map(int,input().split())
    l=[]
    for i in range(N):
        l.append(list(map(int,input().split())))
    l.sort(key=lambda t:(t[2],t[1]))
    a=[0]*(10**5+1)
    ss,tt,cc=-1,-1,-1
    for s,t,c in l:
        if s==tt and c==cc:
            a[tt]+=1
            a[t]-=1
        else:
            a[s-1]+=1
            a[t]-=1
        ss,tt,cc=s,t,c
    ans=0
    tmp=0
    for x in a:
        tmp+=x
        ans=max(ans,tmp)
    print(ans)
            

if __name__ == '__main__':
    main()

Solution (Python):
from itertools import accumulate

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

Solution (Python):
from itertools import accumulate

MAX_T = 10 ** 5 + 100
MAX_C = 30

n, c = map(int, input().split())
time = {c: [] for c in range(1, MAX_C + 1)}

for _ in range(n):
    s, t, c = map(int, input().split())
    time[c].append((s, t))

n_program = [0 for _ in range(MAX_T + 1)]

for c in range(1, MAX_C + 1):

    recording = [0 for _ in range(MAX_T + 1)]

    for s, t in time[c]:
        recording[s] += 1
        recording[t + 1] -= 1

    recording = accumulate(recording)

    for i, r in enumerate(recording):
        if r:
            n_program[i] += 1

answer = max(n_program)
print(answer)

Solution (Python):
import sys
from operator import itemgetter
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
n,c = map(int,readline().split())
ch = [[[0,0]] for _ in range(c)]
for i in range(n):
    s,t,c = map(int,readline().split())
    ch[c-1].append([s,t])
imos = [0]*(10**5+1)
for i in ch:
    i.sort()
    for j in range(1,len(i)):
        s,t = i[j]
        if i[j-1][1] < s:
            imos[s-1] += 1
        else:
            imos[s] += 1
        imos[t] -= 1

for i in range(1,len(imos)):
    imos[i] += imos[i-1]

print(max(imos))

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

S=[[] for _ in range(10**5+1)]
T=[[] for _ in range(10**5+1)]

for s,t,c in STC:
    S[s].append(c)
    T[t].append(c)

used=set()
ans=0
for i in range(10**5+1):
    start=set()
    finish=set()
    for s in S[i]:
        start.add(s)
    for t in T[i]:
        finish.add(t)
    ans=max(ans,len(used)+len(start-finish))
    used=used-finish|start
print(ans)

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

import heapq  
tv=[-1]
heapq.heapify(tv)  


ch=[0]*c

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

stc.sort()

for item in stc:
    s,t,c=item[0],item[1],item[2]
    temp=heapq.heappop(tv)
    if temp<s:
        heapq.heappush(tv,t)
    elif temp==s and ch[c-1]==temp:
        heapq.heappush(tv, t)
    else:
        heapq.heappush(tv,temp)
        heapq.heappush(tv,t)
    ch[c-1]=t
    
print(len(tv))

Solution (Python):
import sys

input = sys.stdin.readline


def main():
    N, C = [int(x) for x in input().split()]
    STC = [[int(x) for x in input().split()] for _ in range(N)]

    S = [[] for _ in range(10 ** 5 + 1)]
    T = [[] for _ in range(10 ** 5 + 1)]

    for s, t, c in STC:
        S[s].append(c)
        T[t].append(c)

    used = set()
    ans = 0
    for i in range(10 ** 5 + 1):
        sused = set()
        tused = set()

        for s in S[i]:
            sused.add(s)
        for t in T[i]:
            tused.add(t)

        ans = max(ans, len(used) + len(sused - tused))
        used = used - tused | sused

    print(ans)








if __name__ == '__main__':
    main()

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

l = [[] for i in range(c)]
for i in range(n):
    s,t,x = map(int,input().split())
    l[x-1].append([s,t])

al= []
for i in range(c):
    if len(l[i]) > 1:
        l[i].sort()
        now2 = l[i][0][1]
        now1 = l[i][0][0]
        check = False
        for j in range(1,len(l[i])):
            if l[i][j][0] == now2:
                now2 = l[i][j][1]
            else:
                al.append([[now1,now2],i])
                check = True
                now1 = l[i][j][0]
                now2 = l[i][j][1]
        if not check:
            al.append([[now1,now2],i])

    else: 
        if l[i]:
            al.append([l[i][0],i])
al.sort()

count = [[-1,-1]]
for i in range(len(al)):
    a,b,c = al[i][0][0], al[i][0][1],al[i][1]
    check = False
    for j in range(len(count)):
        if count[j][0] < a:
            count[j] = [b,c]
            check = True
            break
    if not check:
        count.append([b,c])

print(len(count))

Solution (Python):
from collections import defaultdict
import numpy as np
import sys


sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


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


def main():
    N, C = map(int, input().split())
    MAX = 10 ** 5 + 2
    vals = [0] * MAX
    D = defaultdict(list)
    for _ in range(N):
        s, t, c = map(int, input().split())
        D[c].append((s, t))

    for k, v in D.items():
        prev = -1
        v.sort(key=lambda x: x[0])
        for s, t in v:
            if prev == s:
                vals[prev + 1] += 1
                vals[t + 1] -= 1
            else:
                vals[s] += 1
                vals[t + 1] -= 1
            prev = t

    cumsum = np.cumsum(vals)
    ans = max(cumsum)
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import sys,queue,math,copy,itertools,bisect,collections,heapq
sys.setrecursionlimit(10**7)
INF = 10**18
MOD = 10**9 + 7
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())

N,C = LI()
p = [[(0,0)] for _ in range(C+1)]
for _ in range(N):
    s,t,c = LI()
    p[c].append((s,t))

im = [0 for _ in range(10**5+1)]
for x in p:
    x.sort()
    for i in range(1,len(x)):
        s,t = x[i]
        if x[i-1][1] < s: s -= 1
        im[s] += 1
        im[t] -= 1

ans = 0
tm = 0
for t in im:
    tm += t
    ans = max(ans,tm)
print(ans)

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

Solution (Python):








N,C = map(int,input().split())
import heapq
endq = [[] for i in range(C)]
for i in range(C):
  heapq.heapify(endq[i])
progs = [None] * N
for i in range(N):
  s,t,c = map(int,input().split())
  progs[i] = [s,t,c-1]

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

ans = 0
cur = 0

for i in range(N):
  s,t,c = progs[i]
  
  
  while endq[c]:
    endt = heapq.heappop(endq[c])
    if endt <= s:
      cur -= 1
    else:
      heapq.heappush(endq[c],endt)
      break
  
  
  for endc in range(C):
    if endc == c:
      continue 
    while endq[endc]:
      endt = heapq.heappop(endq[endc]) 
      if endt < s:
        cur -= 1
      else:
        heapq.heappush(endq[endc],endt)
        break
  
  cur += 1
  heapq.heappush(endq[c],t)
  if cur > ans:
    ans = cur

print(ans)

Solution (Python):








N,C = map(int,input().split())
import heapq
endq = [[] for i in range(C)]
for i in range(C):
  heapq.heapify(endq[i])
progs = [None] * N
for i in range(N):
  s,t,c = map(int,input().split())
  progs[i] = [s,t,c-1]

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

ans = 0
cur = 0

for i in range(N):
  s,t,c = progs[i]
  
  
  while endq[c]:
    endt = heapq.heappop(endq[c])
    if endt <= s:
      cur -= 1
    else:
      heapq.heappush(endq[c],endt)
      break
  
  
  for endc in range(C):
    if endc == c:
      continue 
    while endq[endc]:
      endt = heapq.heappop(endq[endc]) 
      if endt < s:
        cur -= 1
      else:
        heapq.heappush(endq[endc],endt)
        break
  
  cur += 1
  heapq.heappush(endq[c],t)
  if cur > ans:
    ans = cur

print(ans)

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

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

LEN = 10 ** 5 + 7
d = [[0] * LEN for _ in range(C + 1)]
for s, t, c in X:
    d[c][s] += 1
    d[c][t + 1] -= 1

for i in range(C + 1):
    for j in range(LEN - 1):
        d[i][j + 1] += d[i][j]

x = [0] * LEN
for i in range(C + 1):
    for j in range(LEN):
        x[j] += int(d[i][j] > 0)
        
print(max(x))

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

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

Solution (Python):
from collections import defaultdict
N,C=map(int,input().split())

event_list=[]
for i in range(N):
  s,t,c=map(int,input().split())
  event_list.append((s-0.5,c))
  event_list.append((t,-c))
event_list.sort()


answer=0
cdic=defaultdict(int)
for t,c in event_list:
  if c>0:
    cdic[c]+=1
    answer=max(answer,len(cdic))
  else:
    cdic[-c]-=1
    if cdic[-c]==0:
      cdic.pop(-c)
  

print(answer)