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

Solution (Python):
import sys
input = sys.stdin.readline
n,c = map(int, input().split())
channels = {i:[] for i in range(1,c+1)}
table = [0 for _ in range(200004)]
for _ in range(n):
    s,t,c = map(int, input().split())
    channels[c].append([s,t])

for ch, time in channels.items():
    sub = [0 for _ in range(200004)]
    for s,t in time:
        if sub[s*2]:
            sub[s*2] = 0
        else:
            sub[s*2-1] = 1
        if sub[t*2-1]:
            sub[t*2-1] = 0
        else:
            sub[t*2] = -1
    for i in range(1,200002):
        sub[i] += sub[i-1]
        table[i] += max(0, sub[i])
ans = 0
for i in range(1,200002):
    ans = max(ans, table[i])
print(ans)

Solution (Python):
import numpy as np

n,c = map(int,input().split())
table = np.zeros(10**5+2, dtype=np.int32)
chs = [[] for _ in range(c+1)]

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


times = []
for ch in chs:
    if not ch: continue
    ch.sort()
    for i in range(len(ch)):
        if i == 0: continue
        if ch[i-1][1] == ch[i][0]:
            ch[i] = [ch[i-1][0], ch[i][1]]
            ch[i-1] = []
    for arr in ch:
        if not arr: continue
        times.append(arr)


for arr in times:
    table[arr[0]] += 1
    table[arr[1]+1] -= 1


ans = table.cumsum().max()

print(ans)

Solution (Python):
n,c=map(int,input().split())
A=[]
for i in range(n):
  s,t,c=map(int,input().split())
  A.append((s,t,c))
A.sort(key=lambda x:(x[2],x[0],x[1]))
B=[]
s,t,c=A[0]

for i in range(1,n):
  s2,t2,c2=A[i]
  if c==c2 and t==s2:
    t=t2
  else:
    B.append((s-1,t,c))
    s,t,c=s2,t2,c2
B.append((s-1,t,c))

T=[0]*(10**5+1)
for s,t,c, in B:
  T[s]+=1
  T[t]-=1
for i in range(10**5):
  T[i+1]+=T[i]
print(max(T))

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

def inc(n):
  return n+1
def dec(n):
  return n-1

history = {}
for i in range(N):
  s,t,c = map(int,input().split())
  s *= 2
  t *= 2
  
  if (t-1) in history and c in history[t-1]:
    history[t-1].pop(c)
  else:
    if t in history:
      history[t][c] = dec
    else:history[t] = {c:dec}
  if (s) in history and c in history[s]:
    history[s].pop(c)
  else:
    
    if s-1 in history:
      history[s-1][c] = inc
    else:
      history[s-1] = {c:inc}
maximum = 0
counter = 0
for i in range(100000*2):
  if i in history:
    for func in history[i].values():
      counter = func(counter)
    if counter > maximum:
      maximum = counter

print(maximum)

Solution (Python):
from collections import defaultdict
from itertools import accumulate

def main():
    N, C = 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] * (10**5 + 1)
    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)))

main()

Solution (Python):
n,c = map(int,input().split())
l = [list() for _ in range(c+1)]
for _ in range(n):
  s,t,ch = map(int,input().split())
  l[ch].append((s,t))
al = list()
for x in l:
  x.sort()
for i in range(c+1):
  if l[i] == []:
    continue
  t = list()
  for j in range(len(l[i])-1):
    if l[i][j][1] == l[i][j+1][0]:
      l[i][j+1] = (l[i][j][0],l[i][j+1][1])
    else:
      t.append(l[i][j])
  t.append(l[i][-1])
  al += t
tl = [0]*(10**5+10)
for s,t in al:
  tl[s] += 1
  tl[t+1] -= 1
for i in range(10**5+9):
  tl[i+1] += tl[i]
print(max(tl))

Solution (Python):
N, C = map(int, input().split())
stc = [[int(i) for i in input().split()] for _ in range(N)]
stc.append([float('inf')] * 3)

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

imos = [0] * (10 ** 5 + 2)
ps, pt, pc = stc[0]
for i in range(1, N + 1) :
    if stc[i][0] == pt and stc[i][2] == pc :
        pt = stc[i][1]
    else :
        imos[ps] += 1
        imos[pt+1] -= 1
        ps, pt, pc = stc[i]
    
for i in range(1, 10 ** 5 + 2) :
    imos[i] += imos[i-1]

print(max(imos))

Solution (Python):

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

slis = [0] * (10 ** 5 + 1)
tlis = [0] * (10 ** 5 + 1)

ans = 0

cs = []
ct = []
for i in range(31):
    cs.append([0] * (10 ** 5 + 1))
    ct.append([0] * (10 ** 5 + 1))

for i in range(N):

    s,t,c = map(int,input().split())

    if ct[c][s] > 0:
        ct[c][s] -= 1
    else:
        cs[c][s] += 1

    if cs[c][t] > 0:
        cs[c][t] -= 1
    else:
        ct[c][t] += 1

for i in range(31):

    for j in range(10 ** 5 + 1):

        slis[j] += cs[i][j]
        tlis[j] += ct[i][j]

now = 0
for i in range(10 ** 5):

    i += 1
    now += slis[i]
    now -= tlis[i-1]
    ans = max(ans,now)

print (ans)

Solution (Python):
N, C = map(int, input().split())
MAX = 10**5
s_list = [[] for _ in range(MAX+1)]
t_list = [[] for _ in range(MAX+1)]
for _ in range(N):
  s, t, c = map(int, input().split())
  s_list[s].append(c)
  t_list[t].append(c)
cnt = 0
ans = 0
before = 0
for i in range(MAX+1):
  if before != 0:
    cnt -= before
    before = 0
  for s in s_list[i]:
    cnt += 1
  for t in t_list[i]:
    if not t in s_list[i]:
      before +=1
    cnt -= 1
  cnt += before
  ans = max(ans, cnt)
print(ans)

Solution (Python):
from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

n,c = inpl()
s = [inpl() for i in range(n)]
s.sort()
rec = [[0,0]]
for i in range(n):
    flag = False
    for j in range(len(rec)):
        if s[i][0] > rec[j][0] or s[i][2] == rec[j][1]:
            rec[j] = [s[i][1],s[i][2]]
            flag = True
            break
    if flag == False:
        rec.append([s[i][1],s[i][2]])
print(len(rec))

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

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

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



import heapq
h = []
for s, t, c in STC:
    heapq.heappush(h, (s-0.5, 0, c))
    heapq.heappush(h, (t, 1, c))

ans = 0
cnt = 0
rec = [0] * (C+1)
while h:
    t, flag, c = heapq.heappop(h)
    if flag == 0:
        if rec[c] == 0:
            rec[c] += 1
            cnt += 1
        else:
            rec[c] += 1
    else:
        rec[c] -= 1
        if rec[c] == 0:
            cnt -= 1
        else:
            pass
        
    ans = max(ans, cnt)
print(ans)

Solution (Python):
from collections import defaultdict
n, c = map(int, input().split())
org = defaultdict(list)
for _ in range(n):
    s, t, ch = map(int, input().split())
    org[ch].append((s, t))


all = []
for ch in range(1, c+1):
    org[ch].sort()
    m = len(org[ch])
    for i in range(m):
        s, t = org[ch][i]
        
        if i == 0:
            pre_s, pre_t = s, t
        else:
            if pre_t == s:
                pre_t = t
            else:
                all.append((2*pre_s-1, 2*pre_t))
                pre_s, pre_t = s, t
            
        if i == m-1:
            all.append((2*pre_s-1, 2*pre_t))


time = [0]*(2*10**5+2)
for l, r in all:
    time[l] += 1
    time[r+1] -= 1
for i in range(2*10**5+1):
    time[i+1] += time[i]

print(max(time))

Solution (Python):
from collections import defaultdict
n, c = map(int, input().split())
org = defaultdict(list)
for _ in range(n):
    s, t, ch = map(int, input().split())
    org[ch].append((s, t))


all = []
for ch in range(1, c+1):
    org[ch].sort()
    m = len(org[ch])
    for i in range(m):
        s, t = org[ch][i]
        if i == 0:
            pre_s, pre_t = s, t
            if i == m-1:
                all.append((2*pre_s-1, 2*pre_t))
        else:
            if pre_t == s:
                pre_t = t
            else:
                all.append((2*pre_s-1, 2*pre_t))
                pre_s, pre_t = s, t
            
            if i == m-1:
                all.append((2*pre_s-1, 2*pre_t))


time = [0]*(2*10**5+2)
for l, r in all:
    time[l] += 1
    time[r+1] -= 1
for i in range(2*10**5+1):
    time[i+1] += time[i]

print(max(time))

Solution (Python):



import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,C = LI()
cha = [[] for _ in range(C)]
ans = 0
lst = [0]*(10**5+2)
for _ in range(n):
    s,t,c = LI()
    cha[c-1].append([s,t])
for i in range(C):
    if len(cha[i]) == 0:
        continue
    cha[i].sort(key = itemgetter(0))
    s,t = cha[i][0]
    tmp = []
    for j in range(1,len(cha[i])):
        if t == cha[i][j][0]:
            t = cha[i][j][1]
        else:
            tmp.append([s,t])
            s,t = cha[i][j]
    tmp.append([s,t])
    for i,j in tmp:
        lst[i] += 1
        lst[j+1] -= 1
lst = list(accumulate(lst))
print(max(lst))

Solution (Python):
from heapq import heappop, heappush, heapify
from collections import defaultdict

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

d = defaultdict(list)
for _ in range(N):
    s, t, c = tuple(map(int, input().split()))
    d[c].append((s, t))
stc = list()
for c, lst in d.items():
    if len(lst) == 1:
        s, t = lst[0]
        stc.append((s, t, c))
        continue
    lst.sort()
    s0, t0 = lst[0]
    i = 1
    while i < len(lst):
        s1, t1 = lst[i]
        if t0 == s1:
            t0 = t1
            if i == len(lst) - 1:
                stc.append((s0, t0, c))
        else:
            stc.append((s0, t0, c))
            s0 = s1
            t0 = t1
        i += 1

heapify(stc)
end = []
ans = 0
while len(stc) > 0:
    s, t, c = heappop(stc)
    if len(end) > 0:
        endtime = heappop(end)
        if endtime >= s:
            heappush(end, endtime)
    heappush(end, t)
    ans = max(ans, len(end))
print(ans)

Solution (Python):
N, C = map(int, input().split())
stcs = []
for i in range(N):
  s, t, c = map(int, input().split())
  stcs.append((s, t, c))
stcs.sort()
rs = []
for s, t, c in stcs:
  ok = False
  for l in rs:
    s0, t0, c0 = l[-1]
    if t0 < s or (t0 == s and c0 == c):
      l.append((s, t, c))
      ok = True
      break
  if not(ok):
    l = [(s, t, c)]
    rs.append(l)

r = len(rs)
print(r)

Solution (Python):
from heapq import *
from itertools import accumulate as ac
n,c=map(int,input().split())
a=sorted([list(map(int,input().split()))for i in range(n)])
b=[[]for i in range(c+1)]
for i,j,h in a:
    if len(b[h])>0:
        if b[h][-1][1]==i:
            b[h][-1][1]=j
        else:
            b[h].append([i,j])
    else:
        b[h].append([i,j])
s=[0]*(2*10**5+2)
for i in b:
    for h,w in i:
        s[2*h-1]+=1
        s[2*w+1]-=1
print(max(list(ac(s))))

Solution (Python):
n,c=map(int,input().split())
l=sorted([list(map(int,input().split())) for _ in [0]*n],key=lambda x:[x[2],x[0]])
m=[l[0]]
for i in range(1,n):
    if l[i][2]==m[-1][2] and l[i][0]==m[-1][1]:
        m.append([m.pop()[0],l[i][1],l[i][2]])
    else:m.append(l[i])
for x in m:
    x[0]-=1
ans=[0]*max(x[1] for x in m)
for x in m:
    for i in range(x[0],x[1]):
        ans[i]+=1
print(max(ans))

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

stc = [list(map(int, input().split())) for i in range(n)]

stc2 = sorted(stc)

ans = []

for i in range(n):
    ans2 = [list(ans[i]) for i in range(len(ans))]
    time = [stc2[i][0],0,0]
    for j in range(len(ans2)):
        if stc2[i][2] != ans2[j][1]:
            ans2[j][0]+=1
        if ans2[j][0]<time[0]:
            time[0] = ans2[j][0]
            time[1] = ans2[j][1]
            time[2] = j
        elif ans2[j][0]==time[0] and time[1]!=stc2[i][2]:
            time[0] = ans2[j][0]
            time[1] = ans2[j][1]
            time[2] = j
    if time[1] == 0:
        ans.append([0,0])
        time[2]=-1
    ans[time[2]][0]=stc2[i][1]
    ans[time[2]][1]=stc2[i][2]

print(len(ans))

Solution (Python):


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

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

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

merged_channels = [[]for i in range(C)]
for i in range(len(channels)):
    channels[i].sort()
    if len(channels[i])>0:
        merged_channels[i].append(channels[i][0])
        for j in range(1,len(channels[i])):
            if merged_channels[i][-1][1]==channels[i][j][0]:
                merged_channels[i][-1][1] = channels[i][j][1]
            else:
                merged_channels[i].append(channels[i][j])

tv = [0]*(10**5+1)
for i in range(len(merged_channels)):
    for s,t in merged_channels[i]:
        for k in range(s,t+1):
            tv[k]+=1

print(max(tv))

Solution (Python):
N,C  = map(int, input().split())
t_max = 2*10**5
c_imos = [[0]*t_max for t in range(C)]

c_imos = [[0]*t_max for t in range(C)]

for i in range(N):
    s,t,c = map(int, input().split())
    c -= 1
    s -= 1
    
    c_imos[c][s] += 1
    c_imos[c][t] -= 1
    
ans = [0] * t_max
from itertools import accumulate
for c_ in c_imos:
    acc = list(accumulate(c_))
    ans = [a+min(1,b) for a,b in zip(ans,acc)]
print(max(ans))

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
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))


n,C = LI()
stc = [LI() for _ in range(n)]
L = []
for i in range(C):
    lst = []
    for j in range(n):
        s,t,c = stc[j]
        if i+1 == c:
            lst.append([s,t])
    lst.sort(key = itemgetter(0))
    lst2 = []
    j = 0
    while j < len(lst):
        if j < len(lst)-1:
            if lst[j][1] == lst[j+1][0]:
                lst2.append((lst[j][0],lst[j+1][1]))
                j += 2
                continue

        lst2.append(tuple(lst[j]))
        j += 1
    L.append(lst2)
x = [[0]*100002 for _ in range(C)]
for i in range(C):
    for j,k in L[i]:
        x[i][j] += 1
        x[i][k+1] -= 1
    x[i] = list(accumulate(x[i]))
ans = 0
for i in range(1,10**5+1):
    s = 0
    for j in range(C):
        if x[j][i] == 1:
            s += 1
    ans = max(ans,s)
print(ans)

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

from heapq import heappop, heappush

def main():
  n, c = map(int, input().split())
  stc = []
  for _ in range(n):
    stc.append(tuple(map(int, input().split())))
  stc = list(sorted(stc, key=lambda x: (x[2], x[0])))
  restc = []
  prev = stc[0]
  for _stc in stc[1:]:
    if prev[2] == _stc[2] and prev[1] == _stc[0]:
      prev = (prev[0], _stc[1], prev[2])
    else:
      restc.append(prev)
      prev = _stc
  restc.append(prev)

  ans = 0
  th = []
  for _stc in sorted(restc):
    if not th:
      heappush(th, _stc[1])
      if ans == 0:
        ans = 1
    else:
      _th = heappop(th)
      if _th < _stc[0]:
        heappush(th, _stc[1])
      else:
        heappush(th, _th)
        heappush(th, _stc[1])
        ans = max(ans, len(th))
  print(ans)


if __name__ == '__main__':
  main()

Solution (Python):
from itertools import accumulate

N, C = map(int, input().split())
E = [[0] * 100010 for _ in range(C)]
for _ in range(N):
    s, t, c = map(int, input().split())
    E[c-1][s-1] += 1
    E[c-1][t-1] -= 1
F = [0] * 100010
for e in E:
    for i, v in enumerate(e):
        if v == 1:
            F[i] += 1
        if v == -1:
            F[i+1] -= 1
ans = max(list(accumulate(F)))
print(ans)

Solution (Python):
n,c=map(int,input().split())
ls=[[set(),set()] for i in range(30)]
l=[0]*(10**5+1)
for i in range(n):
    s,t,c=map(int,input().split())
    if s in ls[c-1][1]:ls[c-1][1].remove(s)
    else:ls[c-1][0].add(s-1)
    if t-1 in ls[c-1][0]:ls[c-1][0].remove(t-1)
    else:ls[c-1][1].add(t)
for i in ls:
    for j in i[0]:
        l[j]+=1
    for j in i[1]:
        l[j]-=1
for i in range(10**5):
    l[i+1]+=l[i]
print(max(l))

Solution (Python):

import sys
input = sys.stdin.readline
import numpy as np

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


lst = [[0] * (10 ** 5 + 10) for _ in range(C + 1)]





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

lst = np.array(lst)
np.cumsum(lst, axis = 1, out = lst)
np.minimum(lst, 1, out = lst)
np.cumsum(lst, axis = 0, out = lst)

print (np.max(lst[-1]))

Solution (Python):

import sys
input = sys.stdin.readline
import numpy as np

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


lst = [[0] * (10 ** 5 + 10) for _ in range(C + 1)]
lst_max = [[1] * (10 ** 5 + 10) for _ in range(C + 1)]




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

lst = np.array(lst)
np.cumsum(lst, axis = 1, out = lst)
np.minimum(lst, lst_max, out = lst)
np.cumsum(lst, axis = 0, out = lst)

print (np.max(lst[-1]))

Solution (Python):
from operator import itemgetter

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

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

Q = []
for ps in P:
    ps.sort(key=itemgetter(0))
    if not ps:
        continue
    for i, (s, t) in enumerate(ps):
        if i == 0:
            pres = s
            pret = t
            continue
        if s == pret:
            pret = t
            continue
        Q.append((pres-1, pret))
        pres = s
        pret = t
    Q.append((pres-1, pret))

imos = [0 for _ in range(100003)]
for qx, qy in Q:
    imos[qx] += 1
    imos[qy] -= 1

for i in range(100002):
    imos[i] += imos[i-1]
print(max(imos))

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

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

STC.sort()

rec = []
for i in range(N):
    found = False
    for j in range(len(rec)):
        if (rec[j][0] < STC[i][0] and rec[j][1] != STC[i][2]) or (rec[j][0] <= STC[i][0] and rec[j][1] == STC[i][2]):
            found, rec[j] = True, (STC[i][1], STC[i][2])
            break
    if not found:
        rec.append((STC[i][1], STC[i][2]))

print(len(rec))

Solution (Python):

import sys
input = sys.stdin.readline

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


lst = [[0] * (10 ** 5 + 10) for _ in range(C + 1)]

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


for i in range(1, C + 1):
    for j in range(1, 10 ** 5 + 10): 
        lst[i][j] += lst[i][j - 1]
    for j in range(1, 10 ** 5 + 10): 
        lst[i][j] = min(1, lst[i][j])

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

print (max(lst[-1]))

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

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

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

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

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

rec = [0] * (10 ** 5 + 1)
cs =  [set() for _ in range(10 ** 5 + 1)]

for s, t, c in TV:
    rec[t] -= 1
    if c not in cs[s]:
        rec[s - 1] += 1
    else:
        rec[s] += 1
    cs[t].add(c)

rec_s = [rec[0]]
for r in rec[1:]:
    rec_s.append(rec_s[-1] + r)

print(max(rec_s))

Solution (Python):
n,c = map(int,input().split())
arr = [0 for i in range(10**5+1)]
tv = [[0,0,0] for i in range(n)]
for i in range(n):
    s,t,c = map(int,input().split())
    tv[i][0] = s
    tv[i][1] = t
    tv[i][2] = c

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


channel = tv[0][2]
bef = -1
for i in range(n):
    if channel != tv[i][2]:
        channel = tv[i][2]
        bef = -1
        s = tv[i][0]
        e = tv[i][1]
        if bef != s:
            arr[s]+=1
        bef = e
        for j in range(s+1,e+1):
            arr[j] += 1
    else:
        s = tv[i][0]
        e = tv[i][1]
        if bef != s:
            arr[s]+=1
        bef = e
        for j in range(s+1,e+1):
            arr[j] += 1

print(max(arr))

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

channels = [[] for _ in range(C)]
maxT = 0

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

maxT = maxT * 2 + 10
tvSum = [0 for _ in range(maxT)]

for tv in channels :
    imos = [0 for _ in range(maxT)]
    for (s, t) in tv :
        imos[s * 2 - 1] += 1
        imos[t * 2] -= 1
    for i in range(1, maxT) :
        imos[i] += imos[i - 1]
    for i in range(maxT) :
        if imos[i] > 0 :
            tvSum[i] += 1

print(max(tvSum))

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

R = []
for s,t,c in STC:
    i = -1
    tm = 0
    for j,r in enumerate(R):
        tr,cr = r
        if (c==cr and tm<=tr<=s) or (c!=cr and tm<tr<=s-0.5):
            i = j
            tm = tr
    if i==-1:R.append((t,c))
    else:R[i] = (t,c)
print(len(R))

Solution (Python):
import numpy as np

import numpy as np

N, C = map(int, input().split(' '))
s = []
t = []
c = []
for i in range(N):
    s_i, t_i, c_i = map(int, input().split(' '))
    s.append(s_i)
    t.append(t_i)
    c.append(c_i - 1)
T = 2*max(t)


table = np.zeros(T)
for i in range(C):
    table_i = np.zeros(T)
    for j in range(N):
        if c[j] == i:
            table_i[2*s[j]-1: 2*t[j]] = 1
    table += table_i
print(int(np.max(table)))

Solution (Python):
import numpy as np

import numpy as np

N, C = map(int, input().split(' '))
s = []
t = []
c = []
for i in range(N):
    s_i, t_i, c_i = map(int, input().split(' '))
    s.append(s_i)
    t.append(t_i)
    c.append(c_i - 1)
T = 2*max(t)


table = np.zeros(T)
for i in range(C):
    table_i = np.zeros(T)
    for j in range(N):
        if c[j] == i:
            table_i[2*s[j]-1: 2*t[j]] = 1
    table += table_i
print(int(np.max(table)))

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

tp = defaultdict(list)
i_max = 0
for _ in range(n):
    s, t, c = map(int, input().split())
    tp[c].append([s, t])
    i_max = max(i_max, t+1)

for c in tp:
    tp[c].sort()
    x = [tp[c][0]]
    for i in range(1, len(tp[c])):
        if x[-1][1] == tp[c][i][0]:
            x[-1][1] = tp[c][i][1]
        else:
            x.append(tp[c][i])
    tp[c] = x

r = [0] * (i_max + 5)

for c in tp:
    for s, t in tp[c]:
        r[s] += 1
        r[t+1] -= 1

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

print(ans)

Solution (Python):
n,c=map(int,input().split())
stc=[[] for i in range(c+1)]
a=[]
t=0
for i in range(n):
    p=[int(j) for j in input().split()]
    stc[p[2]].append([p[0],p[1]])
    t=max(t,p[1])
ans=10**100
for i in range(c+1):
    p=10**10
    stc[i].sort()
    for j in range(len(stc[i])):
        if j+1<len(stc[i]):
            if stc[i][j][1]==stc[i][j+1][0]:
                if p==10**10:
                    p=stc[i][j][0]
            else:
                if p!=10**10:
                    a.append([p,stc[i][j][1]])
                else:
                    a.append([stc[i][j][0],stc[i][j][1]])
                p=10**10
        else:
            if p!=10**10:
                a.append([p,stc[i][j][1]])
            else:
                a.append([stc[i][j][0],stc[i][j][1]])

table=[0]*(t+1)
for i in range(len(a)):
    table[a[i][0]-1]+=1
    table[a[i][1]]-=1
for i in range(1,t+1):
    table[i]+=table[i-1]

print(max(table))

Solution (Python):
n,c=map(int,input().split())
stc=[[] for i in range(c+1)]
a=[]
t=0
for i in range(n):
    p=[int(j) for j in input().split()]
    stc[p[2]].append([p[0],p[1]])
    t=max(t,p[1])
ans=10**100
for i in range(c+1):
    p=10**10
    stc[i].sort()
    for j in range(len(stc[i])):
        if j+1<len(stc[i]):
            if stc[i][j][1]==stc[i][j+1][0]:
                if p==10**10:
                    p=stc[i][j][0]
            else:
                if p!=10**10:
                    a.append([p,stc[i][j][1]])
                else:
                    a.append([stc[i][j][0],stc[i][j][1]])
                p=10**10
        else:
            if p!=10**10:
                a.append([p,stc[i][j][1]])
            else:
                a.append([stc[i][j][0],stc[i][j][1]])

table=[0]*(t+1)
for i in range(len(a)):
    table[a[i][0]-1]+=1
    table[a[i][1]]-=1
for i in range(1,t+1):
    table[i]+=table[i-1]

print(max(table))

Solution (Python):
N,C=map(int,input().split())
stc=sorted([list(map(int,input().split())) for _ in [0]*N],key=lambda x:x[0])
rokuga=[]
for i in range(N):
    for j,r in enumerate(rokuga):
        if r[0]==stc[i][2]:
            if r[1]<=stc[i][0]:
                rokuga[j][1]=stc[i][1]
                break
    else:
        for j,r in enumerate(rokuga):
            if r[1]<stc[i][0]:
                rokuga[j]=[stc[i][2],stc[i][1]]
                break
        else:
            rokuga.append([stc[i][2],stc[i][1]])
print(len(rokuga))

Solution (Python):
n,c=map(int,input().split())
pro=[]
for i in range(c):
    pro.append([])
for i in range(n):
    s,t,c_0=map(int,input().split())
    pro[c_0-1].append((s,t))
Pro=[]
for i in range(c):
    pro[i].sort(reverse=True)
    if pro[i]==[]:
        continue
    pre=pro[i].pop()
    while pro[i]!=[]:
        now=pro[i].pop()
        if pre[1]==now[0]:
            pre=(pre[0],now[1])
        else:
            Pro.append(pre)
            pre=now
    Pro.append(pre)
import heapq
heapq.heapify(Pro)
Used=[]
heapq.heapify(Used)
now=heapq.heappop(Pro)
heapq.heappush(Used,now[1])
ans=1
while len(Pro)!=0:
    now=heapq.heappop(Pro)
    near=heapq.heappop(Used)
    if near<now[0]:
        heapq.heappush(Used,now[1])
    else:
        ans+=1
        heapq.heappush(Used,now[1])
        heapq.heappush(Used,near)
print(ans)

Solution (Python):
n,C=[int(i) for i in input().split()]
stc=[[int(i) for i in input().split()] for _ in range(n)]
time=[0]*(2*(10**5+1))
end=[[0]*(10**5+1) for _ in range(C)]   

for s,t,c in stc:
    end[c-1][t]+=1

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

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

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

program_list = []

for i in range(N):
    s,t,c = list(map(int,input().split()))
    program_list.append((s-0.5,"s",c-1))
    program_list.append((t,"t",c-1))

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

c_list=[0 for i in range(C)]
count_list=[0 for i in range(C)]

max_num=0
for i in range(2*N):
    if program_list[i][1]=="s":
        c = program_list[i][2]
        count_list[c]+=1
        c_list[c] = min(1,count_list[c])
        max_num=max(sum(c_list),max_num)
    else:
        c = program_list[i][2]
        count_list[c]-=1
        c_list[c] = min(1,count_list[c])

print(max_num)

Solution (Python):
N, C = map(int, input().split())
channels = [[] for _ in range(C)]
for _ in range(N):
    a, b, c = map(int, input().split())
    channels[c-1].append((a, b))
for c in range(C):
    channels[c].sort()
recorders = [0]*(10**5+2)
for c in channels:
    if c:
        recorders[c[0][0]] += 1; recorders[c[0][1] + 1] -= 1;
        for i in range(1, len(c)):
            if c[i][0] == c[i-1][1]:
                recorders[c[i][0] + 1] += 1; recorders[c[i][1] + 1] -= 1;
            else:
                recorders[c[i][0]] += 1; recorders[c[i][1] + 1] -= 1;
for i in range(1, len(recorders)):
    recorders[i] += recorders[i-1]
print(max(recorders))

Solution (Python):
from itertools import accumulate


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

N, C = map(int, input().split())
TV = dict()
programs = [list(map(int, input().split())) for _ in range(N)]
last_time = max([p[1] for p in programs])
for i in range(1, C+1):
    TV[i] = [0]*(last_time*2+2)

for s, t, c in programs:
    s *= 2
    t *= 2
    TV[c][s] += 1
    TV[c][t+1] -= 1

for c in range(1, C+1):
    TV[c] = list(accumulate(TV[c]))

ans = 0
for i in range(last_time*2+1):
    tmp = 0
    for c in range(1, C+1):
        if TV[c][i] > 0:
            tmp += 1
    ans = max(ans, tmp)
print(ans)

Solution (Python):
n,m=map(int,input().split())
arr=[list(map(int,input().split())) for _ in range(n)]
arr.append([10**10,10**10,100])
arr=sorted(arr,key=lambda x:x[0])
arr=sorted(arr,key=lambda x:x[2])
job=[[] for _ in range(m+1)]
c=arr[0][2]
ts=arr[0][0]
tt=arr[0][1]
for i in range(1,n+1):
  if c!=arr[i][2]:
    job[c].append([ts,tt])
    ts=arr[i][0]
    tt=arr[i][1]
    c=arr[i][2]
  else:
    if tt==arr[i][0]:
      tt=arr[i][1]
    else:
      job[c].append([ts,tt])
      ts=arr[i][0]
      tt=arr[i][1]
cnt=[0]*(10**5+2)
for tj in job:
  for ts,tt in tj:
    cnt[ts]+=1
    cnt[tt+1]-=1
for i in range(1,10**5+2):
  cnt[i]=cnt[i]+cnt[i-1]
print(max(cnt))