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
import itertools
input = sys.stdin.readline
sys.setrecursionlimit(100000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


class v:
    def __init__(self, f):
        self.f = f
        self.v = None
 
    def __str__(self):
        return str(self.v)
 
    def ud(self, n):
        if self.v is None:
            self.v = n
        else:
            self.v = self.f(self.v, n) 


def main():
    import bisect
    N, C = read_values()
    W = read_lists(N)
    W.sort(key=lambda x: x[1], reverse=True)

    R = []
    for s, t, c in W:
        i = bisect.bisect_left(R, (t, -1))

        while i < len(R):
            if R[i][0] != t:
                break
            if R[i][1] == c:
                break
            i += 1

        if i < len(R):
            del R[i]

        bisect.insort(R, (s, c))
    print(len(R))


if __name__ == "__main__":
    main()

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

data = [[0]*(10**5+1) for i in range(C)]

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

ans = 0

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

print(ans)

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


def solve():
    N, C = map(int, rline().split())
    schedule = [[0] * 100001 for _ in range(C)]
    for _ in range(N):
        s, t, c = map(lambda x: int(x) - 1, rline().split())
        schedule[c][s] += 1
        schedule[c][t] -= 1
    
    imos = [0] * 100001
    for ch_i in schedule:
        for i in range(100001):
            if ch_i[i] == 1:
                imos[i] += 1
            elif ch_i[i] == -1:
                imos[i + 1] -= 1
    for i in range(1, 100001):
        imos[i] += imos[i - 1]
    print(max(imos))


if __name__ == '__main__':
    solve()

Solution (Python):
import sys
INF = 10 ** 9
MOD = 10 ** 9 + 7
from collections import deque
sys.setrecursionlimit(100000000)

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

    for _ in range(n):
        s,t,c1 = map(int,input().split())
        c1 -= 1
        time[s][c1] += 1
        time[t][c1] -= 1
    
    for i in range(10 ** 5):
        for j in range(c):
            if time[i][j] == 0 and time[i + 1][j] == 1:
                time[i][j] = 1
                time[i + 1][j] = 0

    ans = sum(time[0])
    tmp = ans
    for i in range(1,10 ** 5 + 1):
        tmp += sum(time[i])
        ans = max(ans, tmp)
    
    print(ans)
if __name__=='__main__':
    main()

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):
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):
n, c = map(int, input().split())
a = [[0 for _ in range(c)] for _ in range(10 ** 5 + 1)]
for _ in range(n):
    s, t, u = map(int, input().split())
    a[s][u - 1] += 1
    a[t][u - 1] -= 1
m = 0
x = 0
for b in a:
    x += b.count(1)
    if x > m:
        m = x
    x -= b.count(-1)
print(m)

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

program.sort()
program.sort(key = lambda x: x[2])
 
for i in range(1,n):
    if program[i][2]==program[i-1][2] and program[i][0]==program[i-1][1]:
        program[i][0] = program[i-1][0]
        program[i-1][0] = None

 
for i in range(n):
    if program[i][0] == None:
        continue
    time[program[i][0]-1] += 1
    time[program[i][1]] -= 1
 
count = 0
max_count = 0
 
for i in range(10**5+1):
    count += time[i]
    max_count = max(max_count,count)
 
print(max_count)

Solution (Python):
class Solution:
    def solve(self, N: int, C: int, stc) -> int:

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

        for s, t, c in stc:
            for i in range(2*s-1, 2*t):
                p[c-1][i] = 1

        ans = 0
        for i in range(2*10**5):
            q = 0
            for c in range(C):
                q += p[c][i]
            ans = max(ans, q)

        return ans


if __name__ == '__main__':

    
    N, C = map(int, input().split())
    stc = []
    for _ in range(N):
        stc.append(tuple(map(int, input().split())))

    
    solution = Solution()
    print(solution.solve(N, C, stc))

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, C = MAP()
stc = [LIST() for _ in range(N)]
stc.sort(key=lambda x:(x[2], x[0]))

tmp_s = stc[0][0]
tmp_t = stc[0][1]
tmp_c = stc[0][2]

stc = stc[1:]
stc_new = []
for s, t, c in stc:
	if tmp_c != c:
		stc_new.append((tmp_s, tmp_t))
		tmp_s = s
		tmp_t = t
		tmp_c = c
		
	elif tmp_t != s:
		stc_new.append((tmp_s, tmp_t))
		tmp_s = s
	
	tmp_t = t
stc_new.append((tmp_s, tmp_t))

now = [0]*(10**5+2)
for s, t in stc_new:
	now[s] += 1
	now[t+1] -= 1

now_acc = accumulate(now)
print(max(now_acc))

Solution (Python):
import sys
def input():
    return sys.stdin.readline()[:-1]
N,C=map(int,input().split())
l=[[0]*10**5 for i in range(C)]
for i in range(N):
    s,t,c=map(lambda x: int(x)-1,input().split())
    for j in range(s,t+1):
        l[c][j]=1
a=0
for i in range(10**5):
    t=0
    for j in range(C):
        if l[j][i]:
            t+=1
    if t>a:
        a=t
print(a)

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

def main():
    N,C = map(int,input().split())
    ch = [[] for _ in range(C)]
    l = 0
    for _ in range(N):
        s,t,c = map(int,input().split())
        l = max(l,t)
        ch[c-1].append((s,t))
    
    for x in ch:
        x.sort(key=itemgetter(0))

    imos = [0 for _ in range(l+2)]
    for x in ch:
        now = -1
        for st,ft in x:
            if st == now:
                imos[st] += 1
            else:
                imos[st-1] += 1
            imos[ft] -= 1
            now = ft
                
    for i in range(l+1):
        imos[i+1] += imos[i]
    
    print(max(imos))
    
if __name__ == "__main__":
    main()

Solution (Python):







class Imos1d:
    def __init__(self, N: int):
        '''
        [0]*N の配列に対して、区間の加算を管理する。
        '''
        self.ls = [0] * (N + 1)  
        self.N = N

    def add(self, l, r, x):
        '''
        [l,r)の区間にxを足し込む O(1)
        '''
        self.ls[l] += x
        self.ls[min(r, self.N)] -= x  

    def get_result(self):
        '''
        O(N) かけて、区間の加算結果を取得する
        '''
        from itertools import accumulate
        return list(accumulate(self.ls[:-1]))


import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


N, C = read_ints()
from collections import defaultdict, Counter
STbyC = defaultdict(lambda: [])
for n in range(N):
    s, t, c = read_ints()
    STbyC[c].append(s)
    STbyC[c].append(t)

kukan = []
for c in STbyC:
    tmp = Counter(STbyC[c])
    tmp = [k for k, v in tmp.items() if v == 1]  
    kukan.extend(sorted(tmp))


imos = Imos1d(10 ** 5 + 1)
for i in range(0, len(kukan), 2):
    j = i + 1
    imos.add(kukan[i] - 1, kukan[j], 1)



print(max(imos.get_result()))

Solution (Python):
class SegmentTreeLazy():
    def __init__(self, arr, ti, ei, func, op, merge):
        self.h = len(arr).bit_length()
        self.n = 2**self.h
        self.func = func
        self.op = op
        self.merge = merge
        self.ti = ti
        self.ei = ei
        self.data = [ti for _ in range(2 * self.n)]
        for i in range(len(arr)):
            self.data[i + self.n] = arr[i]
        for i in range(1, self.n)[::-1]:
            self.data[i] = self.func(self.data[2 * i], self.data[2 * i + 1])
        self.lazy = [ei for _ in range(2 * self.n)]

    def reflect(self, k):
        if self.lazy[k] == self.ei:
            return self.data[k]
        return self.op(self.data[k], self.lazy[k])

    def propagate(self, k):
        if self.lazy[k] == self.ei:
            return
        self.lazy[2 * k] = self.merge(self.lazy[2 * k], self.lazy[k])
        self.lazy[2 * k + 1] = self.merge(self.lazy[2 * k + 1], self.lazy[k])
        self.data[k] = self.reflect(k)
        self.lazy[k] = self.ei

    def thrust(self, k):
        for i in range(1, self.h + 1)[::-1]:
            self.propagate(k >> i)

    def recalc(self, k):
        while k:
            k //= 2
            self.data[k] = self.func(
                self.reflect(2 * k), self.reflect(2 * k + 1))

    def update(self, left, right, x):
        l, r = left, right
        left += self.n
        right += self.n
        self.thrust(left)
        self.thrust(right - 1)
        while right - left > 0:
            if left & 1:
                self.lazy[left] = self.merge(self.lazy[left], x)
                left += 1
            if right & 1:
                right -= 1
                self.lazy[right] = self.merge(self.lazy[right], x)
            left //= 2
            right //= 2
        self.recalc(l + self.n)
        self.recalc(r + self.n - 1)

    def query(self, left, right):
        left += self.n
        right += self.n
        self.thrust(left)
        self.thrust(right - 1)
        tmp_l = tmp_r = self.ti
        while right - left > 0:
            if left & 1:
                tmp_l = self.func(tmp_l, self.reflect(left))
                left += 1
            if right & 1:
                right -= 1
                tmp_r = self.func(self.reflect(right), tmp_r)
            left //= 2
            right //= 2
        return self.func(tmp_l, tmp_r)


import sys
input = sys.stdin.readline
from operator import add

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

st = SegmentTreeLazy(A, 0, 0, max, add, add)

P = [list(map(int, input().split())) for _ in range(N)]
P.sort()
P.sort(key=lambda x:x[2])

Q = []
prev = P[0]
for i in range(1, N):
    if prev[2] != P[i][2] or prev[1] != P[i][0]:
        Q.append((prev[0], prev[1]))
        prev = P[i]
    else:
        prev = (prev[0], P[i][1], prev[2])
Q.append((prev[0], prev[1]))

for i in range(len(Q)):
    s, t = Q[i]
    st.update(s, t+1, 1)

print(st.query(0, 100010))

Solution (Python):
import numpy as np
N, C, *L = map(int, open(0).read().split())
program = np.zeros((10**5+2,C+1),np.int32)
for s,t,c in zip(*[iter(L)]*3):
  program[s][c] += 1
  program[t+1][c] += -1
program = np.cumsum(program, axis=0)
ans = max(np.count_nonzero(a) for a in program)
print(ans)

Solution (Python):
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): 
    return list(map(int,input().split()))
def m(): 
    return map(int,input().split())
def onem(): 
    return int(input())
def s(x): 
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): 
    return " ".join(map(str,x))
def max2(x): 
    return max(map(max,x))
def In(x,a): 
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n,c = m()

time = [[0 for i in range(31)] for j in range(10**5+2)]

popopo = [[] for i in range(30)]

for i in range(n):
    s,t,c = m()
    popopo[c-1].append([s,t])


for i in range(30):
    popopo[i].sort()
    
for i in range(30):
    for j in range(len(popopo[i])):
        s,t = popopo[i][j]
        if time[s][i+1] == 0:
            time[t][i+1] = 1
            time[s-1][0] += 1
            time[t][0] -= 1
        else:
            time[t][i+1] = 1
            time[s][0] += 1
            time[t][0] -= 1

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

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

A = [0] * (R+1)
ans = 0
for i in range(R):
    for c in range(C):
        A[i] += T[c][i+1] if T[c][i+1] > 0 else 0
        A[i] += T[c][i] if T[c][i] < 0 else 0
    A[i+1] += A[i]
    ans = max(ans, A[i+1])
print(ans)

Solution (Python):
n, c = map(int, input().split())
stc = [list(map(int, input().split())) for _ in range(n)]
T = 10**5+1
record = [[0]*(T+3) for _ in range(c+1)]
channel = [[] for _ in range(c+1)]
stc.sort()

for s, t, c in stc:
    if not channel[c]:
        channel[c].append([s - 1, t])
        continue
    if channel[c][-1][1] == s:
        channel[c][-1][1] = t
    else:
        channel[c].append([s-1, t])

for i, v in enumerate(channel):
    for s, t in v:
        record[i][s] += 1
        record[i][t] -= 1

for i in record:
    for j in range(T+2):
        i[j+1] += i[j]

ans = 0
for i in range(T+2):
    y = 0
    for r in record:
        y += r[i]
    ans = max(ans, y)
print(ans)

Solution (Python):
n, c = map(int, input().split())
stc = [list(map(int, input().split())) for _ in range(n)]
T = 10**5+1
record = [[0]*(T+3) for _ in range(c+1)]
channel = [[] for _ in range(c+1)]
stc.sort()

for s, t, c in stc:
    if not channel[c]:
        channel[c].append([s - 1, t])
        continue
    if channel[c][-1][1] == s:
        channel[c][-1][1] = t
    else:
        channel[c].append([s-1, t])

for i, v in enumerate(channel):
    for s, t in v:
        record[i][s] += 1
        record[i][t] -= 1

for i in record:
    for j in range(T+2):
        i[j+1] += i[j]

ans = 0
for i in range(T+2):
    y = 0
    for r in record:
        y += r[i]
    ans = max(ans, y)
print(ans)

Solution (Python):

import math
import heapq
import bisect
import numpy as np
from collections import Counter


N,C = map(int, input().split())
L = [list(map(int, input().split())) for i in range(N)]

T_MAX = 10**5
time = [[0]*C for i in range(T_MAX)]

for s,t,c in L:
    time[s-1][c-1] += 1
    time[t-1][c-1] -= 1
 
ans = 0
tmp = 0
for i in range(T_MAX):
    tmp += time[i].count(1)
    ans = max(ans,tmp)
    tmp -= time[i].count(-1)

print(ans)

Solution (Python):
N, C = map(int, input().split())
stc = [None] * N
for i in range(N):
    stc[i] = list(map(int, input().split()))
stc.sort()
recorders = []
for s, t, c in stc:
    ok = False
    for i, rec in enumerate(recorders):
        t2, c2 = rec
        if c == c2 and t2 <= s or c != c2 and t2 < s:
            recorders[i] = [t, c]
            ok = True
            break
    if not ok:
        recorders.append([t, c])
print(len(recorders))

Solution (Python):
n, channel = map(int, input().split())
STC = []
for _ in range(n):
    s, t, c = map(int, input().split())
    STC.append([2*s,2*t,c])

STC = sorted(STC, key=lambda x: (x[2], x[1]))


now_s = STC[0][0]
now_t = STC[0][1]
now_c = STC[0][2]

All_bangumi = []

for i in range(1,n):
    if now_c == STC[i][2]:
        if now_t == STC[i][0]:
            now_t = STC[i][1]
            if i == n-1:
                All_bangumi.append([now_s, now_t])
        else:
            All_bangumi.append([now_s, now_t])
            now_s = STC[i][0]
            now_t = STC[i][1]

    else:   
        All_bangumi.append([now_s, now_t])
        now_s = STC[i][0]
        now_t = STC[i][1]
        now_c = STC[i][2]
        if i == n-1:
            All_bangumi.append([now_s, now_t])

if n == 1:
    All_bangumi.append([STC[0][0], STC[0][1]])

for i in range(len(All_bangumi)):
    All_bangumi[i][0] = All_bangumi[i][0] -1


Imos = [0 for _ in range(2*(10**5)+1)]
for i in range(len(All_bangumi)):
    Imos[All_bangumi[i][0]] += 1
    Imos[All_bangumi[i][1]] -= 1

Imos_rui = [0]
for i in range(len(Imos)):
    Imos_rui.append(Imos_rui[-1]+Imos[i])

print(max(Imos_rui))

Solution (Python):


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

log=[[0]*C for i in range(10**5)]


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

ans=0
temp=0
for i in range(10**5):
    plus=log[i].count(1)
    temp+=plus
    ans=max(ans,temp)
    minus=log[i].count(-1)
    temp-=minus

print(ans)

Solution (Python):
from heapq import heappop, heappush

N, C, *STC = map(int, open(0).read().split())

A = [[] for _ in range(C + 1)]
for s, t, c in zip(*[iter(STC)] * 3):
    A[c].append((s, t))

ST = []
for a in A:
    if not a:
        continue
    a = sorted(a)
    B = [a[0]]
    for s2, t2 in a[1:]:
        s1, t1 = B[-1]
        if t1 == s2:
            B[-1] = (s1, t2)
        else:
            B.append((s2, t2))
    ST += B

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

ans = 0
Q = []
for s, t in ST:
    while Q and Q[0] < s:
        heappop(Q)
    heappush(Q, t)
    ans = max(ans, len(Q))

print(ans)

Solution (Python):
def main():
    N, C, *STC = map(int, open(0).read().split())

    T = [[0] * 10 ** 5 for _ in range(C + 1)]
    for s, t, c in zip(*[iter(STC)] * 3):
        T[c][s - 1:t] = [1] * (t - s + 1)

    print(max(map(sum, zip(*T))))

main()

Solution (Python):
N, C, *STC = map(int, open(0).read().split())

T = [[0] * 10 ** 5 for _ in range(C + 1)]
for s, t, c in zip(*[iter(STC)] * 3):
    T[c][s - 1:t] = [1] * (t - s + 1)

print(max(map(sum, zip(*T))))

Solution (Python):

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
mod=10**9+7

def main():
    N,C=MI()
    T=10**5
    
    tc=[[0]*(T+1) for _ in range(C)]
    
    
    for i in range(N):
        s,t,c=MI()
        tc[c-1][s-1]+=1
        tc[c-1][t]-=1
        
    for c in range(C):
        for i in range(T):
            tc[c][i+1] +=tc[c][i]
            
    ans=0
    
    for i in range(T+1):
        temp=0
        for c in range(C):
            if tc[c][i]>0:
                temp+=1
        ans=max(ans,temp)
        
    print(ans)        
                    
        



main()

Solution (Python):
N,C = map(int,input().split())
stc = sorted([list(map(int,input().split())) for i in range(N)], key = lambda x:(x[2],x[0]))
cnow = 0
tnow = 0
end = max(i[1] for i in stc)
imos = [0 for i in range(end+2)]
for s,t,c in stc:
    if cnow == c and tnow == s:
        imos[s]+=1
    else:
        imos[s-1] += 1
    imos[t] -=1
    cnow = c
    tnow = t
for i in range(end):
    imos[i+1] += imos[i]
print(max(imos))

Solution (Python):

n,cn = map(int,input().split())
event = []
for _ in range(n):
  s,t,c = map(int,input().split())
  event.append([s-1,1,c-1])
  event.append([t  ,0,c-1])
event.sort()
can = []
now = 0
chan = [0 for _ in range(cn)]
for x in event:
  u,i,c = x
  if chan[c] == 0 and i == 1:
    chan[c] += 1
    now += 1
    can.append(now)
  elif chan[c] == 1 and i == 1:
    chan[c] += 1
  elif chan[c] == 1 and i == 0:
    chan[c] -= 1
    now -= 1
  elif chan[c] == 2 and i == 0:
    chan[c] -= 1
  else:
    print(fuck)
  
print(max(can))

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]))
 
imos = [0] * (10**5 + 1)

curr_c = 0
curr_t = 0
for s, t, c in stc:
  if curr_c == c and curr_t == s:
    imos[s] += 1
  else:
    imos[s-1] += 1
  imos[t] -= 1
  curr_t = t
  curr_c = c
  
rui = [0] * (10**5 + 1)

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

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]))
 
imos = [0] * (10**5 + 1)

curr_c = 0
cuur_t = 0
for s, t, c in stc:
  if curr_c == c and curr_t == s:
    imos[s] += 1
  else:
    imos[s-1] += 1
  imos[t] -= 1
  curr_t = t
  curr_c = c
  
rui = [0] * (10**5 + 1)

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

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

rec = []

for i in range(n):
    s, t, c = map(int, input().split())
    c = c-1
    L[i][0] = s
    L[i][1] = t
    L[i][2] = c

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

for i in range(n):
    s = L[i][0]
    t = L[i][1]
    c = L[i][2]
    if i == 0:
        rec.append([c, t])
    else:
        for j in range(len(rec)):
            if rec[j][0] == c and rec[j][1] <= s:
                rec[j][1] = t
                break
        else:
            rec.sort(key=lambda x: x[1])
            for k in range(len(rec)):
                if rec[k][1]+1 <= s:
                    rec[k][0] = c
                    rec[k][1] = t
                    break
            else:
                rec.append([c, t])

print(len(rec))

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

rec = []

for i in range(n):
    s, t, c = map(int, input().split())
    c = c-1
    L[i][0] = s
    L[i][1] = t
    L[i][2] = c

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

for i in range(n):
    s = L[i][0]
    t = L[i][1]
    c = L[i][2]
    if i == 0:
        rec.append([c, t])
    else:
        for j in range(len(rec)):
            if rec[j][0] == c and rec[j][1] <= s:
                rec[j][1] = t
                break
        else:
            rec.sort(key=lambda x: x[1])
            for k in range(len(rec)):
                if rec[k][1]+1 <= s:
                    rec[k][0] = c
                    rec[k][1] = t
                    break
            else:
                rec.append([c, t])

print(len(rec))

Solution (Python):
def main():
    N,C=map(int,input().split())
    stc=[0]*N
    for i in range(N):
        abc=list(map(int,input().split()))
        stc[i]=abc

    a=[0]*(C+1)
    stc.sort(key=lambda x:(x[2],x[0]))
    c=1
    for i in range(N):
        while stc[i][2]!=c:
            c+=1
        if stc[i][2]==c:
            a[c]+=1
    for i in range(1,C+1):
        a[i]+=a[i-1]
    
    table=[0]*(2*10**5+2)
    for i in range(C):
        for j in range(a[i],a[i+1]):
            if j==a[i]:
                table[stc[j][0]*2-1]+=1
                table[stc[j][1]*2]-=1
            else:
                if stc[j-1][1]==stc[j][0]:
                    table[stc[j][0]*2]+=1
                    table[stc[j][1]*2]-=1
                else:
                    table[stc[j][0]*2-1]+=1
                    table[stc[j][1]*2]-=1                    
    M=0
    for i in range(len(table)):
        if 0<i:
            table[i]+=table[i-1]
    for i in range(len(table)):
        if M<table[i]:
            M=table[i]
    print(M)
if __name__=="__main__":
    main()

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

cs = [[] for _ in range(30)]
for s,t,c in STC:
    cs[c-1].append((s,t))

imos = [0]*(100005)
for c in cs:
    c.sort(key=lambda x:x[0])
    pt = -1
    for s,t in c:
        if s==pt:
            imos[s] += 1
        else:
            imos[s-1] += 1
        imos[t] -= 1
        pt = t
for i in range(len(imos)-1):
    imos[i+1] += imos[i]
print(max(imos))

Solution (Python):
from itertools import accumulate
n,c=map(int,input().split())
time=[0]*(10**5+2)
stc=[]
for i in range(n):
	s,t,c=map(int,input().split())
	stc.append([s,t,c])
stc.sort(key=lambda x:(x[2],x[0]))
for i in range(n-1):
	if stc[i][2]==stc[i+1][2]:
		if stc[i][1]==stc[i+1][0]:
			stc[i+1][0]=stc[i][0]
			stc[i]=[-1]
lis=[]
for i in range(n):
	if stc[i]!=[-1]:
		lis.append(stc[i])
for i in range(len(lis)):
	time[lis[i][0]-1]+=1
	time[lis[i][1]]-=1
print(max(accumulate(time)))

Solution (Python):
from operator import itemgetter
N, C = list(map(int, input().split()))

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

BA.sort(key=itemgetter(2,0,1))


IMO = [0] * (200010)
prev_c = -1
prev_t = -1
tmax = 0
for i in range(N):
  s, t, c = BA[i]
  if prev_c == c and prev_t == s:
    IMO[2*s+1] += 1
    IMO[2*t+1] -= 1
  else:
    IMO[2*s-1] += 1
    IMO[2*t+1] -= 1
    
  prev_t, prev_c = t,c
  tmax = max(tmax, t)
  
for i in range(2*tmax+5):
  IMO[i+1] += IMO[i]
  
print(max(IMO[:2*tmax+5]))

Solution (Python):
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
mod=10**9+7

n,c=map(int,input().split())
stc=[list(map(int,input().split())) for i in range(n)]
stc.sort(key=lambda x: x[2])

lst=[[0]*(10**5+5) for i in range(c)]
for i in range(len(stc)):
    s,t,c=stc[i]
    for j in range(s-1,t):
        lst[c-1][j]+=1
anslst=[0]*(10**5+5)
for i in range(c):
    for j in range(10**5+5):
        if lst[i][j]!=0:
            anslst[j]+=1
print(max(anslst))

Solution (Python):

from itertools import accumulate
from collections import defaultdict
N, V = map(int, input().split())  
programs = defaultdict(list)
for _ in range(N):
    s, t, c = map(int, input().split())
    programs[c].append((s, t))

imos = [0] * (100002)
for c, p in programs.items():  
    p.sort()  
    ps, pt = p[0]  
    for s, t in p[1:]:
        if pt == s:  
            pt = t
        else:
            
            imos[ps-1] += 1  
            imos[pt] -= 1  
            ps, pt = s, t

    
    imos[ps-1] += 1
    imos[pt] -= 1

print(max(accumulate(imos)))

Solution (Python):
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[] for _ in range(num)]
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))




import heapq
class Reverse:
    def __init__(self, val):
        self.val = val
        
    def __lt__(self, other):
        return self.val > other.val
        
    def __repr__(self):
        return repr(self.val)
    
class Heapq:
    def __init__(self, arr, desc = False):
        if desc:
            for i in range(len(arr)):
                arr[i] = Reverse(arr[i])
        self.desc = desc
        self.hq = arr
        heapq.heapify(self.hq)
 
    def pop(self):
        if self.desc: return heapq.heappop(self.hq).val
        else: return heapq.heappop(self.hq)
 
    def push(self, a):
        if self.desc: heapq.heappush(self.hq, Reverse(a))
        else: heapq.heappush(self.hq, a)
 
    def top(self):
        if self.desc: return self.hq[0].val
        else: return self.hq[0]


from operator import itemgetter
def index_sort(A):
    A_sort = sorted(enumerate(A),key=itemgetter(1))
    index = [a[0] for a in A_sort]
    sorted_A = [a[1] for a in A_sort]
    return index, sorted_A


N,C = II()
s,t,c = Line(N,3)


new_s = []
new_t = []
tl = [[] for _ in range(C)]
for i in range(N):
    tl[c[i]-1].append((s[i],t[i]))
for j in range(C):
    if not tl[j]:
        continue
    tl[j].sort(key=itemgetter(0))
    sj = []
    tj = []
    start,last = tl[j][0][0],tl[j][0][1]
    for i in range(1,len(tl[j])):
        if tl[j][i][0] != last:
            sj.append(start)
            tj.append(last)
            start = tl[j][i][0]
            last = tl[j][i][1]
        else:
            last = tl[j][i][1]
    sj.append(start)
    tj.append(last)
    new_s.extend(sj)
    new_t.extend(tj)

index, _ = index_sort(new_s)
s = [new_s[i] for i in index]
t = [new_t[i] for i in index]

h = Heapq([10**6])
ans = 0
for i in range(len(s)):
    if h.top() < s[i]:
        h.pop()
        h.push(t[i])
    else:
        h.push(t[i])
        ans += 1

print(ans)

Solution (Python):
n,c = map(int,input().split())
imos = [0 for i in range(10**5+1)]
stcl = []
for _ in range(n):
    s,t,c = map(int,input().split())
    stcl.append((s,t,c))
    imos[s-1] += 1
    imos[t] -= 1

stcl = sorted(stcl, key=lambda x: (x[2], x[1]))

new = []
s,t,c = stcl[0]
for i in range(1,n):
    if c == stcl[i][2] and t == stcl[i][0]:
        t = stcl[i][1]
    else:
        new.append((s, t, c))
        s, t ,c = stcl[i]
else:
    new.append((s, t, c))

imos = [0 for i in range(10**5+1)]
for s,t,c in new:
    imos[s-1] += 1
    imos[t] -= 1
import itertools
imos_ac = list(itertools.accumulate(imos))
print(max(imos_ac))