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 collections
N, C = map(int, input().split())
stc = [list(map(int, input().split())) for i in range(N)]

stc.sort(key=lambda x: x[0])
table = collections.defaultdict(list)
for s, t, c in stc:
    table[c].append((s, t))
maxtime = 0
for x in table:
    for i in range(len(table[x]) - 1):
        if table[x][i][1] == table[x][i+1][0]:
            table[x][i+1] = (table[x][i][0], table[x][i+1][1])
            table[x][i] = (-1, -1)
    maxtime = max(maxtime, table[x][-1][1])

im = [0]*(maxtime+2)

for x in table:

    for s, t in table[x]:
        if s == -1:
            continue
        im[s] += 1
        im[t+1] -= 1

s = [0]*(maxtime+3)
for i in range(1, maxtime+2):
    s[i+1] = s[i]+im[i]

print(max(s))

Solution (Python):
maxlen = 10**5+1
n, channel = [ int(v) for v in input().split() ]
use_list = [ [ 0 for i in range(maxlen) ] for i in range(channel) ]

for i in range(n):
    a, b, c = [ int(v) for v in input().split() ]
    for j in range(a,b+1):
        use_list[c-1][j] = 1


ans = 0
for i in range(maxlen):
    max_at_i = sum([ use_list[j][i] for j in range(channel) ])
    ans = max(max_at_i,ans)
print(ans)

Solution (Python):
from itertools import *

def main():
	n, c, *L = map(int, open(0).read().split())
	a = [0] * (10 ** 5 + 1)
	bef = (0, 0)
	for c, s, t in sorted((c, s, t) for s, t, c in zip(*[iter(L)] * 3)):
		a[s - 1 + (bef==(c, s))] += 1
		a[t] -= 1
		bef = (c, t)
	print(max(accumulate(a)))

if __name__=="__main__":
	main()

Solution (Python):
from itertools import*
n,c,*L=map(int,open(0).read().split())
a=[0]*(max(L[1::3])+1)
bef=(0,0)
for c,s,t in sorted((c,s,t) for s,t,c in zip(*[iter(L)]*3)):
	a[s-1+(bef==(c,s))]+=1
	a[t]-=1
	bef=(c,t)
print(max(accumulate(a)))

Solution (Python):

N, C = map(int, input().split(' '))
lim = (10 ** 5 + 2) * 2
buf = [0 for _ in range(lim)]

import collections

c_durations_dict = collections.defaultdict(list)
for _ in range(N):
    s, t, c = map(int, input().split(' '))
    c_durations_dict[c].append((s, t))

for durations in c_durations_dict.values():
    durations.sort(key=lambda x: x[0])
    i = 0
    while i < len(durations):
        s1, t1 = durations[i]
        while i + 1 < len(durations) and t1 == durations[i + 1][0]:
            t1 = durations[i + 1][1]
            i += 1

        buf[s1 * 2 - 1] += 1
        buf[t1 * 2] -= 1
        i += 1

ans = 0
for i in range(1, lim):
    buf[i] += buf[i - 1]
    ans = max(ans, buf[i])

print(ans)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    pn, cn = map(int, input().split())
    st = [[set(), set()] for _ in range(cn)]
    
    for _ in range(pn):
        s, t, c = map(int, input().split())
        c -= 1
        if s in st[c][1]:
            st[c][1].remove(s)
            if t in st[c][0]:
                st[c][0].remove(t)
            else:
                st[c][1].add(t)
        elif t in st[c][0]:
            st[c][0].remove(t)
            st[c][0].add(s)
        else:
            st[c][0].add(s)
            st[c][1].add(t)
    
    
    tt = set()
    for c_st in st:
        for s in c_st[0]:
            tt.add(s)
        for t in c_st[1]:
            tt.add(t)
    tn = len(tt)
    ttoi = {}
    for i, t in enumerate(sorted(tt)):
        ttoi[t] = i
    
    
    cnt = [0] * (tn + 1)
    for c_st in st:
        for s in c_st[0]:
            i = ttoi[s]
            cnt[i] += 1
        for t in c_st[1]:
            i = ttoi[t]
            cnt[i + 1] -= 1
    
    
    ans = 0
    for i in range(tn):
        cnt[i + 1] += cnt[i]
        ans = max(ans, cnt[i + 1])
    
    print(ans)

main()

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,c=map(int,input().split())
    STC=[tuple(map(int,input().split())) for _ in range(n)]
    STC.sort(lambda x:(x[2],x[0],x[1]))

    
    for i in range(n-1):
        s0,t0,c0=STC[i]
        s1,t1,c1=STC[i+1]
        if(c0!=c1): continue
        if(t0==s1):
            STC[i]=(None,None,None)
            STC[i+1]=(s0,t1,c0)
    
    M=100000
    imos=[0]*(M+1)
    for s,t,c in STC:
        if(s is None): continue
        imos[s-1]+=1
        imos[t]-=1
    for i in range(M):
        imos[i+1]+=imos[i]
    print(max(imos))
resolve()

Solution (Python):
import sys

input = sys.stdin.readline

def main():
    N, C = map(int, input().split())
    
    event = []
    
    for i in range(N):
        s, t, c = map(int, input().split())
        event.extend([[s, c-1, 1], [t+0.5, c-1, 0]])
        
    event.sort()
    
    nums = [0] * C
    ans = cur = 0
    
    for e, c, m in event:
        if m:
            if not nums[c]: 
                cur += 1
                ans = max(ans, cur)
            nums[c] += 1
        else:
            nums[c] -= 1
            if not nums[c]: cur -= 1
            
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
N, C = map(int, input().split())
X = [[] for _ in range(C)]
A = []
for _ in range(N):
    s, t, c = map(int, input().split())
    A.append((s, t, c-1))

A = sorted(A)
for s, t, c in A:
    if X[c] and X[c][-1][1] == s:
        X[c][-1][1] = t
    else:
        X[c].append([s-1, t])
Y = []
for x in X:
    Y += x
Z = [0] * 101010
for s, t in Y:
    Z[s+1] += 1
    Z[t+1] -= 1

for i in range(1, 101010):
    Z[i] += Z[i-1]

print(max(Z))

Solution (Python):
def examD():
    N, C = LI()
    S = [0] * N; T = [0] * N; c = [0] * N
    
    maxt = int(0)
    for i in range(N):
        s, t, a = LI()
        S[i], T[i] = s, t
        c[i] = a
        if maxt < t:
            maxt = t
    pairs = zip(S, T,c)
    sortedpairs = sorted(pairs, key=lambda x: x[1])
    sortedpairs = sorted(sortedpairs, key=lambda x: x[0])
    for i in range(N):
        S[i] = sortedpairs[i][0]
        T[i] = sortedpairs[i][1]
        c[i] = sortedpairs[i][2]



    ans = int(0)
    time = [0] * (maxt + 2)
    timeC = [[] for _ in range(maxt + 2)]
    for i in range(N):
        
        timeC[T[i]].append(c[i])
        if not c[i] in timeC[S[i]]:
            time[S[i]] += 1
            time[T[i] + 1] -= 1
        else:
            time[S[i] + 1] += 1
            time[T[i] + 1] -= 1

    ansC = int(0)
    for i in range(maxt + 1):
        ansC += time[i]
        ans = max(ansC, ans)
    
    print(ans)
    

import sys,copy,bisect,itertools
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examD()

Solution (Python):
import sys
import numpy as np
read = sys.stdin.read

N, C, *stc = map(int, read().split())
recoder = np.zeros((C + 1, 10 ** 5 + 1), np.int64)

for s, t, c in zip(*[iter(stc)] * 3):
    recoder[c, s - 1:t] = 1

answer = np.cumsum(recoder, axis=0).max()

print(answer)

Solution (Python):
N,C=map(int,input().split())
L=[list(map(int,input().split())) for _ in range(N)]
L.sort()
stc=[[] for _ in range(C)]
for i in range(N):
  s,t,c=L[i]
  if stc[c-1] and s-stc[c-1][-1][1]<=1:
    stc[c-1][-1]=[stc[c-1][-1][0],t]
  else:
    stc[c-1].append([s-1,t])

STC=[j for i in stc for j in i]
STC.sort()

RCM=[[0,0] for _ in range(C)]
for S,T in STC:
  for i in range(C):
    if RCM[i][1]<=S:
      RCM[i][1]=T
      break

for i in range(C):
  if RCM[i]==[0,0]:
    print(i)
    exit()
print(C)

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

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

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

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

for i in range(N):
    s, t, c = pgs[i]
    if i >= 1 and pgs[i-1][2] == pgs[i][2] and pgs[i-1][1] == pgs[i][0]:
        imos[s] += 1
        imos[t] -= 1
    else:
        imos[s-1] += 1
        imos[t] -= 1

ans = 0
a = 0
for i in imos:
    a += i
    ans = max(ans, a)

print(ans)

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

ans = [0]*C
chan = [0]*C
L.sort()
for i in range(N):
    for j in range(C):
        if ans[j] == L[i][0] and chan[j] == L[i][2]:
            ans[j] = L[i][1]
            break
        elif ans[j] < L[i][0]:
            ans[j] = L[i][1]
            chan[j] = L[i][2]
            break
    ans.sort(reverse=True)
    
num = 0
for i in range(C):
    if ans[i] > 0:
        num += 1
        
print(num)

Solution (Python):
import sys

N,C = map(int,input().split())
STC = []
for _ in range(N):
  s,t,c = map(int,sys.stdin.readline().split())
  STC.append([s,t,c])
STC.sort()

rs = [[STC[0][1],STC[0][2]]]
for i in range(1,N):
  len_rs = len(rs)
  
  min_idx = None
  for j in range(len_rs):
    if rs[j][1] != STC[i][2]: tmp_stc_r = STC[i][0] - 0.5
    else: tmp_stc_r = STC[i][0]
 
    if rs[j][0] <= tmp_stc_r:
      if min_idx is None: min_idx = j
      else:
        if rs[j][0] < rs[min_idx][0]: min_idx = j

  if min_idx is None: rs.append([STC[i][1], STC[i][2]])
  else: rs[min_idx] = [STC[i][1], STC[i][2]]
  
print(len(rs))

Solution (Python):

from operator import itemgetter

N, C = map(int, input().split())
stc = [list(map(int, input().split())) for _ in range(N)]
stc.sort(key=itemgetter(2, 0))

cs = [0] * (10 ** 5 + 1)
pt, pc = -1, -1
for s, t, c in stc:
    if pt == s and pc == c:
        cs[s] += 1
    else:
        cs[s - 1] += 1
    cs[t] -= 1
    pt, pc = t, c

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

print(max(cs))

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

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

ct = [0] * (10 ** 5 + 1)
for i in range(C):
    for j in range(10 ** 5 + 1):
        ct[j] += tt[i][j]

print(max(ct))

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

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

ct = [0] * (10 ** 5 + 1)
for i in range(C):
    tti = tt[i]
    for j in range(10 ** 5 + 1):
        ct[j] += tti[j]

print(max(ct))

Solution (Python):

from operator import itemgetter

N, C = map(int, input().split())
stc = [list(map(int, input().split())) for _ in range(N)]
stc.sort(key=itemgetter(2, 0))

cs = [0] * (10 ** 5 + 1)
pc = -1
for s, t, c in stc:
    if pc != c:
        pt = -1
        pc = c
    if pt == s:
        cs[s] += 1
    else:
        cs[s - 1] += 1
    cs[t] -= 1
    pt = t

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

print(max(cs))

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

tt = [[0] * (10 ** 5 + 1) for _ in range(30)]
for _ in range(N):
    s, t, c = map(int, input().split())
    ttc = tt[c - 1]
    for i in range(s - 1, t):
        ttc[i] = 1

ct = [0] * (10 ** 5 + 1)
for i in range(30):
    tti = tt[i]
    for j in range(10 ** 5 + 1):
        ct[j] += tti[j]

print(max(ct))

Solution (Python):
from operator import itemgetter

N, C = map(int, input().split())
stc = [list(map(int, input().split())) for _ in range(N)]
stc.sort(key=itemgetter(2, 0))

cs = [0] * (10 ** 5 * 2 + 1)
pc = -1
for s, t, c in stc:
    if pc != c:
        pt = -1
        pc = c
    if pt == s:
        cs[s * 2] += 1
    else:
        cs[s * 2 - 1] += 1
    cs[t * 2] -= 1
    pt = t

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

print(max(cs))

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

tt = [[0] * (2 * 10 ** 5 + 1) for _ in range(30)]
for _ in range(N):
    s, t, c = map(int, input().split())
    ttc = tt[c - 1]
    for i in range(s * 2 - 1, t * 2):
        ttc[i] = 1

ct = [0] * (2 * 10 ** 5 + 1)
for i in range(30):
    tti = tt[i]
    for j in range(2 * 10 ** 5 + 1):
        ct[j] += tti[j]

print(max(ct))

Solution (Python):

import sys
from collections import deque

N,C=map(int, sys.stdin.readline().split()) 
stc=[ map(int, sys.stdin.readline().split()) for _ in range(N)]
stc.sort(key=lambda x:(x[0]) )
max_t=max(stc, key=(lambda x: x[1]))[1]

channel=[ deque() for _ in range(C+1) ]

for s,t,c in stc:
    try:
        prev_s,prev_t=channel[c].pop()
        if prev_t==s:
            channel[c].append((prev_s,t))
        else:
            channel[c].append((prev_s,prev_t))
            channel[c].append((s,t))
    except:
        channel[c].append((s,t))


T=[ 0 for _ in range(max_t+1) ] 

c=1
for c in range(1,C+1):  
    while channel[c]:
        s,t=channel[c].pop()
        for i in range(s,t+1):
            T[i]+=1

print max(T)

Solution (Python):
import sys
input = sys.stdin.readline
N, C = map(int, input().split())
c = [list(map(int, input().split())) for _ in range(N)]
t = [[0] * (10 ** 5 + 1) for _ in range(C + 1)]
for i in range(N):
  for j in range(c[i][0], c[i][1] + 1):
    t[c[i][2]][j] = 1
res = 0
for i in range(10 ** 5 + 1):
  p = 0
  for j in range(C + 1):
    p += t[j][i]
  res = max(p, res)
print(res)

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

list_tv = [tuple(map(int, input().split())) for _ in range(n)]
for start, end, ch in list_tv:
  list_rec[ch-1][(start-1):end] = [1] * (end - (start - 1))

count = max(map(sum, zip(*list_rec)))
print(count)

Solution (Python):
n,C=map(int,input().split())
stc=[list(map(int,input().split())) for i in range(n)]
d=[[0]*(10**5+1) for i in range(C+1)]
for u in stc:
    s,t,c=u
    if d[c][s]==-1:
        d[c][s]=0
        if d[c][t]==1:
            d[c][t]=0
        else:
            d[c][t]=-1
    else:
        d[c][s]=1
        if d[c][t]==1:
            d[c][t]=0
        else:
            d[c][t]=-1
for i in range(1,C+1):
    for j in range(10**5):
        if d[i][j+1]==1:
            d[i][j]+=1
            d[i][j+1]=0
data=[0]*(10**5+1)
for j in range(1,C+1):
    data[0]+=d[j][0]
for i in range(1,10**5+1):
    for j in range(1,C+1):
        data[i]+=d[j][i]
    data[i]+=data[i-1]
print(max(data))

Solution (Python):

def main():
    N, C, *STC = map(int, open(0).read().split())
    recorders = [[0] * (10 ** 5 + 1) for _ in range(C + 1)]
    for s, t, c in zip(*[iter(STC)] * 3):
        recorders[c][s - 1 : t] = [1] * (t - s + 1)
    ans = max(sum(sliced) for sliced in zip(*recorders))
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):

def main():
    N, C, *STC = map(int, open(0).read().split())
    recorders = [[0] * (10 ** 5 + 1) for _ in range(C + 1)]
    for s, t, c in zip(*[iter(STC)] * 3):
        recorders[c][s - 1 : t] = [1] * (t - s + 1)
    ans = max(map(sum, zip(*recorders)))
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):

from itertools import accumulate as acc


def main():
    N, C, *STC = map(int, open(0).read().split())
    recorders = [[0] * (10 ** 5 + 1) for _ in range(C + 1)]
    for s, t, c in zip(*[iter(STC)] * 3):
        recorders[c][s - 1 : t] = [1] * (t - s + 1)
    ans = max(map(sum, zip(*recorders)))
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):

def main():
        
    N,C = map(int, input().split())

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

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

    ans = max(map(sum, zip(*R)))
    """
    ans = 0
    for t in range(10**5):
        cnt = 0
        
        for ch in range(C):
            if R[ch][t] == 1: cnt += 1

        ans = max(ans, cnt)
    """
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):

def main():
        
    N,C = map(int, input().split())

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

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

    ans = 0
    for t in range(10**5):
        cnt = 0
        
        for ch in range(C):
            if R[ch][t] == 1: cnt += 1

        ans = max(ans, cnt)

    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):

def main():
        
    N,C = map(int, input().split())

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

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

    ans = 0
    for t in range(10**5):
        cnt = 0
        for ch in range(C):
            if R[ch][t] == 1: cnt += 1

        ans = max(ans, cnt)

    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
import numpy as np

LIM = int(10e5)
time = [0] * (LIM + 1)
N, C = list(map(int, input().split(" ")))
schs = []
for _ in range(N):
    s, t, c = list(map(int, input().split(" ")))
    schs.append((s,t,c))
schs.sort(key = lambda x:x[0])

schs.sort(key = lambda x:x[2])


for i,temp in enumerate(schs):
    s,t,c = temp

    s_p,t_p,c_p = schs[i-1]
    if i != 0 and c_p == c and t_p == s:
        time[t_p + 1] += 1
        time[t + 1] -= 1

    else:
        time[s] += 1
        time[t + 1] -= 1

ruiseki = np.cumsum(time)


print(np.max(ruiseki[1:]))

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

print(ans)

Solution (Python):
import sys
from itertools import accumulate
input = sys.stdin.readline
def inputs():return [int(x) for x in input().split()]
N,C = inputs()
stc = [inputs() for i in range(N)]
stc = sorted(stc,key=lambda x:x[1])
stc = sorted(stc,key=lambda x:x[2])
ans = [0]*(10**5+2)
for i in range(N):
    s,t,c, = stc[i]
    if i>0 and c==stc[i-1][2] and s==stc[i-1][1]:
      ans[s+1]+=1
      ans[t+1]-=1
      continue
    ans[s]+=1
    ans[t+1]-=1
ans = list(accumulate(ans))
print(max(ans))

Solution (Python):
import bisect

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


P = {}
for p in STC:
  if p[2] not in P:
    P[p[2]] = [p[:2]]
  else:
    pe = P[p[2]][-1]
    if pe[1] == p[0]:
      P[p[2]][-1][1] = p[1]
    else:
      P[p[2]].append(p[:2])


P2 = []
maxt = 0
for val in P.values():
  for v in val:
    P2.append([v[0]-1,v[1]])
    maxt = max(maxt,v[1])


T = [0 for _ in range(maxt+2)]
for p in P2:
  T[p[0]] += 1
  T[p[1]] -= 1

for i in range(1,maxt+2):
  T[i] += T[i-1]

print(max(T))

Solution (Python):
N,C = map(int,input().split())
num = 100009*2
channel = [[0]*num for _ in range(C)]
time = [0]*num

max_num = 0
for i in range(N):
  s,t,c = map(int,input().split())
  s,t,c = 2*s-1,2*t,c-1
  if(channel[c][s-1] == 1): channel[c][s-1] = 0
  else: channel[c][s] = 1 
  channel[c][t] = 1
  max_num = max(max_num,t)

tmp = 0
for i in range(C):
 for j in range(max_num+15):
  if((tmp == 0)and(channel[i][j] == 1)):
    tmp = 1
    a = j
  elif((tmp == 1)and(channel[i][j] == 1)):
    tmp = 0
    b = j
    time[a] += 1
    time[b+1] -= 1

ans = 0    
for i in range(max_num+15):
  if(i != 0): time[i] += time[i-1]
  ans = max(ans,time[i])
print(ans)

Solution (Python):
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools


import queue
from collections import deque




def main():
    num_bangumi, num_channel = map(int, input().split())
    data = [list(map(int, input().split())) for i in range(num_bangumi)]
    max_len = 10 ** 5 + 10

    ans_list = [[0 for i in range(max_len)] for j in range(num_channel)]

    for i in range(num_bangumi):
        s, t, c = data[i]
        ans_list[c - 1][s] += 1
        ans_list[c - 1][t] -= 1
    
    
    
    

    for i in range(num_channel):
        for j in range(1, max_len):
            if ans_list[i][j] == 1:
                ans_list[i][j - 1] += ans_list[i][j]
                ans_list[i][j] = 0

    
    
    
    
    
    
    
    
    



    ans = 0
    now_bangumi = 0

    for j in range(max_len):
        for i in range(num_channel):
            now_bangumi += ans_list[i][j]
        ans = max(ans, now_bangumi)

    print(ans)















if __name__ == '__main__':
    main()

Solution (Python):
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N,C = map(int,input().split())
time = [0]*(100009*2)
channel = [[0]*(100009*2) for _ in range(C)]









max_num = 0
for i in range(N):
 s,t,c = map(int,input().split())
 s,t = 2*s-1,2*t 
 if(channel[c-1][s-1] == 1): channel[c-1][s-1] = 0
 else: channel[c-1][s] = 1
 channel[c-1][t] = 1
 max_num = max(max_num,t)







tmp = 0
for i in range(C):
 for j in range(max_num+10):
  if((tmp == 0)and(channel[i][j] == 1)):
    tmp = 1
    a = j
  elif((tmp == 1)and(channel[i][j] == 1)):
    tmp = 0
    b = j
    
    time[a] += 1
    time[b+1] -= 1

    
ans = 0
for i in range(max_num+10):
  if(i != 0): time[i] += time[i-1]
  ans = max(ans,time[i])
print(ans)

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
from bisect import bisect_left
import random
from itertools import permutations, accumulate, combinations
import sys
import string


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 10 ** 9 + 7


n, c = LI()
L = [0] * (10 ** 5 + 2)
each_channel = [[] for _ in range(c)]
for s, t, k in LIR(n):
    each_channel[k - 1] += [(s, t)]



for i in each_channel:
    i.sort()


for i in range(c):
    pre_t = -1
    for j in range(len(each_channel[i])):
        s, t = each_channel[i][j]
        if j >= 1 and pre_t == s:
            L[pre_t + 1] += 1
            L[t + 1] -= 1
        else:
            L[s] += 1
            L[t + 1] -= 1
        pre_t = t


print(max(accumulate(L)))

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):
N,C=map(int,input().split())
f=[[0]*int(1e5) for _ in range(C)]

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

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

Solution (Python):
n,c=map(int,input().split())
t=[[0]*10**5 for i in range(c)]
for i in range(n):
	a,b,c=map(int,input().split())
	t[c-1][a-1:b]=[1]*(b-a+1)
print(max(map(sum,zip(*t))))

Solution (Python):
N,C = map(int,input().split())
ST = []
for _ in range(N):
  s,t,c = map(int,input().split())
  ST.append([s,0,c])
  ST.append([t,1,c])
ST.sort(key=lambda x:x[0])
ST.sort(key=lambda x:x[2])
for i in range(len(ST)-1):
  if ST[i][2]==ST[i+1][2] and ST[i][0]==ST[i+1][0]:
    ST[i][1]=2
    ST[i+1][1]=2

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

ans =[0]
for st in ST:
  if st[1]==0:
    ans.append(ans[-1]+1)
  elif st[1]==1:
    ans.append(ans[-1]-1)
print(max(ans))

Solution (Python):
from itertools import accumulate

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

channels = [[0]*(10**5+1) for _ in range(C)]
for s, t, c in STC:
    
    s, t, c = s-1, t-1, c-1
    channels[c][s] += 1
    channels[c][t] -= 1
all_channels = [0]*(10**5+1)
for channel in channels:
    
    for j, x in enumerate(channel):
        if x == 1:
            all_channels[j] += 1
        if x == -1:
            all_channels[j+1] -= 1 


a = list(accumulate(all_channels))


print(max(a))

Solution (Python):
from operator import itemgetter
N,C = [int(x) for x in input().split()]

actions = []
for _ in range(N):
    s,t,c = [int(x) for x in input().split()]
    actions.append((s-0.5, 1, c))
    actions.append((t, 0, c))
actions.sort(key=itemgetter(0))

cnt_now_rec = 0

channel_now_rec = [-1] * (C+1)
ans = 0
for time,action,channel in actions:
    if(action == 1):
        if(channel_now_rec[channel]==-1):
            cnt_now_rec += 1
        channel_now_rec[channel] = time
    elif(action == 0):
        if(time == channel_now_rec[channel]+0.5):
            pass
        else:
            cnt_now_rec -= 1
            channel_now_rec[channel] = -1
    ans = max(ans,cnt_now_rec)
print(ans)

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

def main():
    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])) + [[1, 1, 31]]
    
    imos = [0] * (int(1e5) + 10)
    s, t, c = stc[0]
    pre_s, pre_t, pre_c = s, t, c
    for i in range(1, N+1):
        s, t, c = stc[i]
        if c == pre_c and pre_t == s:
            pre_t = t
        else:
            imos[pre_s] += 1
            imos[pre_t + 1] -= 1
            pre_s, pre_t, pre_c = s, t, c
    

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

if __name__ == "__main__":
    main()

Solution (Python):
T_max = 10**5
N, C = map(int, input().split())
channel = [[] for _ in range(C)]
time = [0]*(T_max+2)
for i in range(N):
    s, t, c = map(int, input().split())
    channel[c-1].append((s, t))
for c in channel:
    c.sort()
    if len(c)==0:
        continue
    time[c[0][0]]+=1
    for i in range(1, len(c)):
        if c[i-1] [1] != c[i][0]:
            time[c[i-1][1]+1] -= 1
            time[c[i][0]]+=1
    time[c[-1][1]+1]-=1
for i in range(1, T_max+1):
    time[i] = time[i-1]+time[i]
print(max(time))

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

def getlist():
	return list(map(int, input().split()))


N, C = getlist()
Lis = [[0 for i in range(10 ** 5 + 3)] for j in range(C)]
for i in range(N):
	s, t, c = getlist()
	Lis[c - 1][s] += 1
	Lis[c - 1][t] -= 1


for j in range(C):
	v = "x"
	for i in range(10 ** 5 + 1):
		if Lis[j][i] == 1:
			v = "o"
			Lis[j][i] = "o"
		elif Lis[j][i] == 0:
			Lis[j][i] = v
		elif Lis[j][i] == -1:
			Lis[j][i] = "o"
			v = "x"

ans = 0
for i in range(10 ** 5 + 1):
	val = 0
	for j in range(C):
		if Lis[j][i] == "o":
			val += 1
	ans = max(ans, val)

print(ans)

Solution (Python):


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

record = [[0] * 10 ** 5 for _ in range(C)]
for s, t, c in stc:
    for i in range(s, t + 1):
        record[c-1][i-1] = 1

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

print(ans)

Solution (Python):
n,c=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
L=[[0 for i in range(10**5+1)] for i in range(c)]
for i in range(n):
  for j in range(l[i][0],l[i][1]+1):
    L[l[i][2]-1][j]=1
ans=[]
for i in range(10**5+1):
  ct=0
  for j in range(c):
    ct+=L[j][i]
    ans.append(ct)
print(max(ans))

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

for _ in range(n):
    s, t, i = list(map(int, input().split()))
    for j in range(max(0, s - 2), t - 1):
        table[i - 1][j] = 1

res = 0
for j in range(MAX_COLS):
    count = 0
    for i in range(c):
        count += table[i][j]
    res = max(res, count)
print(res)

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

for _ in range(n):
    s, t, i = list(map(int, input().split()))
    for j in range(s - 1, t - 1):
        table[i - 1][j] = 1

for i in range(c):
    for j in range(MAX_COLS - 1):
        if table[i][j] == 0 and table[i][j + 1] == 1:
            table[i][j] = 1

res = 0
for j in range(MAX_COLS):
    count = 0
    for i in range(c):
        count += table[i][j]
    res = max(res, count)
print(res)

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    
    N,C = map(int,input().split())
    STC = []
    B = [[0]*(10**5+1) for _ in range(C)]
    for i in range(N):
        s,t,c = map(int,input().split())
        for j in range(s,t+1):
            B[c-1][j] = 1
    
    x = 0
    flag = 1
    nowc = -1
    while flag == 1:
        flag = 0
        x += 1
        nowc = -1
        for i in range(1,10**5+1):
            if nowc != -1:
                if B[nowc][i] == 1:
                    B[nowc][i] = 0
                else:
                    nowc = -1
                    for j in range(C):
                        if B[j][i] == 1:
                            nowc = j
                            B[j][i] = 0
                            break
            else:
                for j in range(C):
                    if B[j][i] == 1:
                        flag = 1
                        nowc = j
                        B[j][i] = 0
                        break
    print(x-1)

main()