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 heapq
N, C = list(map(int, input().split()))

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

S = [0]*(10**5+1)
T = [0]*(10**5+1)

for i in range(C+1):
    if not d[i]:
        continue
    d[i].sort()
    s, t = d[i][0]
    for j in range(1, len(d[i])):
        if t == d[i][j][0]:
            t = d[i][j][1]
        else:
            S[s] += 1
            T[t] += 1
            s, t = d[i][j]
    S[s] += 1
    T[t] += 1

temp = 0
ans = 0
for i in range(1, 10**5+1):
    temp += S[i]-T[i-1]
    ans = max(ans, temp)
    
print(ans)

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

MT = (10 ** 5 + 10)

memo = [[0] * C for _ in range(MT)]

stc = sorted([[int(_) for _ in input().split()] for _ in range(N)])
for s, t, c in stc:
    if memo[s][c - 1] < 0:
        memo[s][c - 1] = 0
    else:
        memo[s - 1][c - 1] += 1
    memo[t][c - 1] -= 1
ans = 0
cnt = 0
for i in range(MT):
    cnt += sum(memo[i])
    ans = max(ans,cnt)
print(ans)

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7






N, C = getNM()
query = [getList() for i in range(N)]
dp = [[0] * (C + 1) for i in range(10 ** 5 + 2)]
for i in range(N):
    s, t, c = query[i]
    dp[s][c] += 1
    dp[t + 1][c] -= 1

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

ans = 0
for i in range(10 ** 5 + 2):
    cnt = 0
    for j in dp[i]:
        if j > 0:
            cnt += 1
    ans = max(ans, cnt)
print(ans)

Solution (Python):
def main():
    from itertools import accumulate
    n, c, *stc = map(int, open(0).read().split())
    table = [0] * (10 ** 5 + 2)
    m = sorted(list(zip(*[iter(stc)] * 3)), key=lambda a: (a[2], a[0]))

    ch_ = 0
    t_ = 0
    for s, t, ch in m:
        if ch != ch_:
            ch_ = ch
            t_ = 0
        if t_ == s:
            table[t_ + 1] += 1
        else:
            table[s] += 1

        table[t + 1] -= 1
        t_ = t

    *x, = accumulate(table)
    ans = max(x)

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    from itertools import accumulate
    n, c, *stc = map(int, open(0).read().split())
    table = [0] * (10 ** 5 + 2)
    m = sorted(list(zip(*[iter(stc)] * 3)), key=lambda a: (a[2], a[0], a[1]))

    ch_ = 0
    t_ = 0
    for s, t, ch in m:
        if ch != ch_:
            ch_ = ch
            t_ = 0
        if t_ == s:
            table[t_ + 1] += 1
        else:
            table[s] += 1

        table[t + 1] -= 1
        t_ = t

    *x, = accumulate(table)
    ans = max(x)

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    from itertools import accumulate
    n, c, *stc = map(int, open(0).read().split())
    table = [0] * (10 ** 5 + 2)
    m = sorted(list(zip(*[iter(stc)] * 3)), key=lambda a: (a[2], a[0], a[1]))

    ch_ = 0
    t_ = 0
    for s, t, ch in m:
        if ch != ch_:
            ch_ = ch
            t_ = 0
        if t_ == s:
            table[t_ + 1] += 1
        else:
            table[s] += 1

        table[t + 1] -= 1
        t_ = t

    *x, = accumulate(table)
    ans = max(x)

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    from itertools import accumulate
    n, c, *stc = map(int, open(0).read().split())
    table = [0] * (10 ** 5 + 2)
    m = list(zip(stc[::3], stc[1::3], stc[2::3]))
    m.sort(key=lambda a: (a[2], a[0], a[1]))

    ch_ = 0
    t_ = 0
    for s, t, ch in m:
        if ch != ch_:
            ch_ = ch
            t_ = 0
        if t_ == s:
            table[t_ + 1] += 1
        else:
            table[s] += 1

        table[t + 1] -= 1
        t_ = t

    *x, = accumulate(table)
    ans = max(x)

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    from itertools import accumulate
    n, c, *stc = map(int, open(0).read().split())
    table = [0] * 2 * (10 ** 5 + 1)
    m = list(zip(stc[::3], stc[1::3], stc[2::3]))
    m.sort(key=lambda a: (a[2], a[0], a[1]))

    ch_ = 0
    t_ = 0
    for s, t, ch in m:
        if ch != ch_:
            ch_ = ch
            t_ = 0
        if t_ == 2 * s:
            table[t_ + 1] += 1
        else:
            table[2 * s - 1] += 1

        table[2 * t + 1] -= 1
        t_ = 2 * t

    *x, = accumulate(table)
    ans = max(x)

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    from itertools import accumulate
    n, c, *stc = map(int, open(0).read().split())
    table = [0] * 2 * (10 ** 5 + 1)
    m = list(zip(stc[::3], stc[1::3], stc[2::3]))
    m.sort(key=lambda a: (a[2], a[0], a[1]))

    ch_ = 0
    t_ = 0
    for s, t, ch in m:
        if ch != ch_:
            ch_ = ch
            t_ = 0
        if t_ == 2 * s:
            table[t_ + 1] += 1
        else:
            table[2 * s - 1] += 1

        table[2 * t + 1] -= 1
        t_ = 2 * t

    *x, = accumulate(table)
    ans = max(x)

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):






import sys
input = sys.stdin.readline

import math

import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache





MOD = 10**9+7
INF = float('inf')
AZ = "abcdefghijklmnopqrstuvwxyz"






def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]


def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()


def DD(arg): return defaultdict(arg)


def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n): return kaijo_memo[n]
  if(len(kaijo_memo) == 0): kaijo_memo.append(1)
  while(len(kaijo_memo) <= n): kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n): return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0): gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n): gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if n == r: return 1
  if n < r or r < 0: return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1: arr.append([temp, 1])
  if arr==[]: arr.append([n, 1])
  return arr


def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors


def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum


def gcd(a, b):
    while b: a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd (a, b)


def count_bit(n):
  count = 0
  while n:
    n &= n-1
    count += 1
  return count


def base_10_to_n(X, n):
  if X//n: return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

def base_10_to_n_without_0(X, n):
  X -= 1
  if X//n: return base_10_to_n_without_0(X//n, n)+[X%n]
  return [X%n]


def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count





N,C = IL()
L = ILL(N)
L.sort()

count = 1
q = [(L[0][1],L[0][2])]
for s,t,c in L[1:]:
  if (s,c) in q:
    q.remove((s,c))
    heapq.heappush(q,(t,c))
  elif q[0][0] < s:
    heapq.heappop(q)
    heapq.heappush(q,(t,c))
  else:
    count += 1
    heapq.heappush(q,(t,c))

print(count)

Solution (Python):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, c = map(int, readline().split())
    l = 2 * (10 ** 5) + 1
    cum = [0] * l
    used = [[False] * l for _ in range(c + 1)]

    for i in range(n):
        s, t, c = map(int, readline().split())
        if used[c][2 * s]:
            cum[2 * s] += 1
        else:
            cum[2 * s - 1] += 1
            used[c][2 * s] = True

        if used[c][2 * t]:
            cum[2 * t - 1] -= 1
        else:
            cum[2 * t] -= 1
            used[c][2 * t] = True

    ans = 0
    cur = 0
    for x in cum:
        cur += x
        ans = max(ans, cur)

    print(ans)


if __name__ == '__main__':
    main()

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

tv = [[0]*C for _ in range(100000)]
for _ in range(N):
    s, t, c = map(int, input().split())
    for i in range(s-1, t): tv[i][c-1] = 1
    
print(max([sum(tv[i]) for i in range(100000)]))

Solution (Python):








import sys

N,C = map(int,sys.stdin.readline().split())
stc = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) 
M = 10**5
imos=[[0]*(M+1) for _ in range(C+1)]

for s,t,c in stc:
    imos[c][s] += 1
    if t+1 < M+1:
        imos[c][t+1] -= 1


s = set()
ret = 0
for i in range(M):
    for c in range(C+1):
        imos[c][i+1] += imos[c][i]
    ret = max(ret,sum(min(1,imos[c][i+1]) for c in range(C+1)))

print(ret)

Solution (Python):
n,c=map(int,input().split())
stc=[list(map(int,input().split())) for _ in range(n)]
cs_dc={}
dc={}
for s,t,c in stc:
  if c in dc:
    dc[c][s]+=1
    dc[c][t]-=1
  else:
    dc[c]=[0]*(10**5+2)
    dc[c][s]+=1
    dc[c][t]-=1
    cs_dc[c]=[0]*(10**5+2)

for i in range(10**5+1):
  for ci in dc:
    cs_dc[ci][i+1]=cs_dc[ci][i]+dc[ci][i+1]
ans=0
for i in range(10**5+1):
  tmp=0
  for ci in dc:
    tmp+=max(cs_dc[ci][i:i+2])
  ans=max(ans,tmp)
print(ans)

Solution (Python):
n,c=map(int,input().split())
chan=[[] for _ in range(c)]
for _ in range(n):
    s,t,sc=map(int,input().split())
    sc-=1
    chan[sc].append((s,t))
for i in range(c):
    chan[i].sort()

for i in range(c):
    lis=[]
    if len(chan[i])==1:
        lis.append(chan[i][0][0])
        lis.append(chan[i][0][1])
    elif len(chan[i])>=2:
        lis.append(chan[i][0][0])
        for j in range(len(chan[i])-1):
            if chan[i][j][1]!=chan[i][j+1][0]:
                lis.append(chan[i][j][1])
                lis.append(chan[i][j+1][0])
        lis.append(chan[i][j+1][1])
    chan[i]=lis

accum=[0]*(10**5+2)
for i in range(c):
    for j in range(0,len(chan[i])-1,2):
        accum[chan[i][j]]+=1
        accum[chan[i][j+1]+1]-=1
for i in range(10**5+1):
    accum[i+1]+=accum[i]

print(max(accum))

Solution (Python):
from operator import itemgetter
def resolve():
    N, C = list(map(int, input().split()))
    STC = sorted([list(map(int, input().split())) for _ in range(N)], key=itemgetter(2, 0))
    
    counts = [0]*(10**5+1)
    prevt, prevc = -1, -1
    for stc in STC:
        s, t, c = stc
        if prevt == s and prevc == c:
            counts[s] += 1
        else:
            counts[s - 1] += 1
        counts[t] -= 1
        prevt, prevc = t, c
    for i in range(1, 10**5+1):
        counts[i] += counts[i-1]
    
    print(max(counts))


if '__main__' == __name__:
    resolve()

Solution (Python):
N, C = map(int, input().split())
tv = [[0]*C for _ in range(100000)]
for _ in range(N):
    s, t, c = map(int, input().split())
    for i in range(s-1, t): tv[i][c-1] = 1
print(max([sum(tv[i]) for i in range(100000)]))

Solution (Python):
N, C = map(int, input().split())
tv = [[0]*C for _ in range(100000)]
for _ in range(N):
    s, t, c = map(int, input().split())
    for i in range(s-1, t): tv[i][c-1] = 1
print(max([sum(tv[i]) for i in range(100000)]))

Solution (Python):
n, _ = map(int, input().split())
CST = {} 
for i in range(n):
    s, t, c = map(int, input().split())
    if c in CST: CST[c] += [[s,t]]
    else: CST[c] = [t, [s,t]]
    CST[c][0] = max(CST[c][0], t)
R = [0]*200002
for c, ST in CST.items():
    mx_t = ST[0]*2+2
    TZ = [0]*mx_t
    for s,t in ST[1:]:
        TZ[2*s - 1] += 1
        TZ[2*t] -= 1
    for i in range(mx_t - 1):
        TZ[i+1] += TZ[i]
        if TZ[i+1] > 0: R[i+1] += 1
print(max(R))

Solution (Python):
n, _ = map(int, input().split())
CST = {} 
for i in range(n):
    s, t, c = map(int, input().split())
    if c in CST: CST[c] += [[s,t]]
    else: CST[c] = [[s,t]]
mx_t = 200002
R = [0]*mx_t
for c, ST in CST.items():
    TZ = [0]*mx_t
    for s,t in ST:
        TZ[2*s - 1] += 1
        TZ[2*t] -= 1
    for i in range(mx_t - 1):
        TZ[i+1] += TZ[i]
        if TZ[i+1] > 0: R[i+1] += 1
print(max(R))

Solution (Python):
N, C = map(int, input().split())
STC = [[*map(int, input().split())] for _ in range(N)]
mx_t = 200002
R = [0]*mx_t
for cc in range(1, C+1):
    TZ = [0]*mx_t
    for s,t,c in STC:
        if c == cc:
            TZ[2*s - 1] += 1
            TZ[2*t] -= 1
    for i in range(mx_t - 1):
        TZ[i+1] += TZ[i]
        if TZ[i+1] > 0: R[i+1] += 1
print(max(R))

Solution (Python):
n,C=map(int,input().split())
dp=[[0 for i in range(100002)] for j in range(31)]
for i in range(n):
  s,t,c=map(int,input().split())
  t+=1
  dp[c][s]+=1
  dp[c][t]-=1
nm=[0 for i in range(100002)]
for i in range(31):
  s=1
  for j in range(1,100002):
    dp[i][j]+=dp[i][j-1]
    if dp[i][j]==0 and dp[i][j-1]==1:
      nm[s]+=1
      nm[j]-=1
    elif dp[i][j]==1 and dp[i][j-1]==0:
      s=j
for i in range(1,100002):
  nm[i]+=nm[i-1]
print(max(nm))

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

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

for i in range(N):
    s,t,c=map(int,input().split())
    old[c-1].append((s,t))
ch=[]
for li in old:
    li.sort()
    j=0
    while(j<len(li)):
        start=li[j][0]
        while(j<len(li)-1 and li[j][1]==li[j+1][0]):
            j+=1
        end=li[j][1]
        ch.append((((start-1)*2)+1,end*2))
        j+=1
    
        
imos=[0]*(2*10**5+10)
for s,t in ch:
    imos[s]+=1
    imos[t]-=1
for i in range(1,2*10**5+10):
    imos[i]=imos[i-1]+imos[i]
print(max(imos))

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

def main(args):
    N,C = map(int,input().split())
    
    time = [[0]*(10**5+1) for _ in range(C)]
    
    for _ in range(N):
        s, t, c = map(lambda x:int(x)-1,input().split())
        time[c-1][s] += 1
        time[c-1][t+1] -= 1
        
    recorder = np.where(np.cumsum(time[0]) > 0, 1, 0)
    
    for i in range(1,C):
        recorder += np.where(np.cumsum(time[i]) > 0, 1, 0)
    
    print(max(recorder))
    
if __name__ == '__main__':
    main(sys.argv[1:])

Solution (Python):
n, c = map(int, input().split())
imos = [0 for _ in range(10 ** 5 + 1)]
ans = 0
channel = [[] for _ in range(30)]
for _ in range(n):
    s, t, c = map(int, input().split())
    channel[c - 1].append([s, t])
    
for lst in channel:
    lst.sort()
    before = 0
    for s, t in lst:
        start = max(before, s - 1)
        imos[start] += 1
        end = min(t, 10 ** 5 + 1)
        imos[end] -= 1
        before = end
tmp = 0
for num in imos:
    tmp += num
    ans = max(ans, tmp)
print(ans)

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




r = [[0 for i in range(c)] for j in range(100000)]
for _ in range(n):
    s,t,c = map(int, input().split())
    for j in range(s-1, t):
        r[j][c - 1] = 1


ans = 0
for i in range(len(r)):
    ans = max(ans, sum(r[i]))
print(ans)

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

for i in range(C):
    table[i].sort()
    for j in range(len(table[i])-1):
        if table[i][j][1] == table[i][j+1][0]:
            table[i][j+1][0] = table[i][j][0]
            table[i][j] = [-1, -1]

imos = [0] * (10 ** 5 + 1000)
for channel in table:
    for s, t in channel:
        if s + t < 0:
            continue
        imos[s] += 1
        imos[t+1] -= 1

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

print(max(imos))

Solution (Python):

from sys import stdin
import numpy as np
N, C = [int(x) for x in stdin.readline().rstrip().split()]
imos = np.array([[0]*(10**5+1) for i in range(C+1)])

for i in range(N):
    s, t, c = [int(x) for x in stdin.readline().rstrip().split()]
    imos[c, s - 1:t] = 1

imos = np.array(imos)

ans = max(imos.sum(axis=0))
print(ans)

Solution (Python):
import math



def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    
    return divisors

def ValueToBits(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

def BitsToValue(arr):
    n = len(arr)
    ans = 0
    for i in range(n):
        ans+= arr[i] * 2**i
    return ans

def ZipArray(a):
    aa = [[a[i],i]for i in range(n)]

    aa.sort(key = lambda x : x[0])
    for i in range(n):
        aa[i][0]=i+1
    aa.sort(key = lambda x : x[1])
    b=[aa[i][0] for i in range(len(a))]
    return b

def ValueToArray10(x, digit):
    ans = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        ans[digit-i-1] = now%10
        now = now //10
    return ans

def Zeros(a,b):
    if(b<=-1):
        return [0 for i in range(a)]
    else:
        return [[0 for i in range(b)] for i in range(a)]

def AddV2(v,w):
    return [v[0]+w[0],v[1]+w[1]]

dir4 = [[1,0],[0,1],[-1,0],[0,-1]]


def clamp(x,y,z):
    return max(y,min(z,x))

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
            

def Zaatsu(a):
    a.sort()
    now = a[0][0]
    od = 0
    for i in range(n):
        if(now==a[i][0]):
            a[i][0]=od
        else:
            now = a[i][0]
            od+=1
            a[i][0] = od
    
    a.sort(key = lambda x : x[1])
    return a

class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)

    
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    
    def same_check(self, x, y):
        return self.find(x) == self.find(y)


'''
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 2
N = 10 ** 6 + 2
fact = [1, 1]  
factinv = [1, 1]  
inv = [0, 1]  

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

'''

def rl(x):
    return range(len(x))












n,c = list(map(int, input().split()))

info2 = [[] for i in range(c)]
info=[]

for i in range(n):
    temp = list(map(int, input().split()))
    info2[temp[2]-1].append(temp)
    
for i in range(c):
    info2[i].sort()
for i in range(c):
    if(len(info2[i])==0):
        continue
    info.append(info2[i][0])
    for j in range(1,len(info2[i])):
        if(info2[i][j][0] == info[-1][1]):
            info[-1][1] = info2[i][j][1]
        else:
            info.append(info2[i][j])
        


tl = []

for i in info:
    tl.append([i[0]-0.5,1])
    tl.append([i[1],-1])


ans = 0
now = 0

tl.sort()


for i in tl:
    now += i[1]
    ans = max(ans,now)
        
print(ans)

Solution (Python):
N,C = map(int, input().split())
s =[0]*N
t =[0]*N
c =[0]*N
for i in range(N):
    s[i],t[i],c[i] = map(int, input().split())

imos = [[0]*int(1e5+20) for _ in range(31)]
for i in range(N):
    imos[c[i]][s[i]]+=1
    imos[c[i]][t[i]+1]-=1

ans = 0
for i in range(1,int(1e5+10)):
    sm = 0
    for j in range(C+1):
        imos[j][i]=imos[j][i-1]+ imos[j][i]
        if imos[j][i] >= 1:
            sm+=1
    ans = max(ans,sm)
print(ans)

Solution (Python):
N,C = map(int, input().split())
s =[0]*N
t =[0]*N
c =[0]*N
for i in range(N):
    s[i],t[i],c[i] = map(int, input().split())

imos = [[0]*int(1e5+20) for _ in range(31)]
for i in range(N):
    imos[c[i]][s[i]]+=1
    imos[c[i]][t[i]+1]-=1

ans = 0
for i in range(1,int(1e5+10)):
    sm = 0
    for j in range(31):
        imos[j][i]=imos[j][i-1]+ imos[j][i]
        if imos[j][i] >= 1:
            sm+=1
    ans = max(ans,sm)
print(ans)

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

import numpy as np
a = np.zeros((c+1, 10**5))

for i in range(n):
    a[ab[i][2]][(ab[i][0]-1):ab[i][1]] = [1]*(ab[i][1]-ab[i][0]+1)

b = a.sum(axis=0)

print(int(max(b)))

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, c = map(int, input().split())
    STC = sorted([list(map(int, input().split())) for _ in range(n)], key=lambda x:[x[2], x[0]])

    STC2 = []
    tmp = STC[0]
    for i in range(1, n):
        pre_s, pre_t, pre_c = tmp
        now_s, now_t, now_c = STC[i]
        if pre_c == now_c:
            if pre_t == now_s:
                tmp = [pre_s, now_t, now_c]
            else:
                STC2.append(tmp)
                tmp = STC[i]
        else:
            STC2.append(tmp)
            tmp = STC[i]
    if len(tmp):
        STC2.append(tmp)

    imos = [[0] * (10 ** 5 + 1) for _ in range(c)]
    for i in range(len(STC2)):
        s, t, c = STC2[i]
        imos[c - 1][s - 1] += 1
        imos[c - 1][t] -= 1

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

    res = [0] * (10 ** 5 + 1)
    for i in range(c):
        for j in range(10 ** 5 + 1):
            res[j] += imos[i][j]

    print(max(res))


if __name__ == '__main__':
    resolve()

Solution (Python):



def main():
    from collections import namedtuple
    from heapq import heappop, heappush
    import sys
    input = sys.stdin.readline

    Prog = namedtuple('Prog', 'L R')
    Prog.__eq__ = lambda self, other: self.R == other.R
    Prog.__lt__ = lambda self, other: self.R < other.R

    N, C = map(int, input().split())
    ps = tuple([] for _ in range(30))
    for _ in range(N):
        l, r, ch = map(int, input().split())
        heappush(ps[ch - 1], Prog(l, r))

    imos = [0] * (10 ** 5 + 1)
    for ps_ch in ps:
        while ps_ch:
            l, r = heappop(ps_ch)
            while ps_ch and ps_ch[0].L == r:
                r = ps_ch[0].R
                heappop(ps_ch)
            else:
                imos[l - 1] += 1
                imos[r] -= 1

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

    print(max(imos))


if __name__ == '__main__':
    main()

Solution (Python):



def main():
    from collections import namedtuple
    from heapq import heappop, heappush
    import sys
    input = sys.stdin.readline

    Prog = namedtuple('Prog', 'L R')
    Prog.__eq__ = lambda self, other: self.R == other.R
    Prog.__lt__ = lambda self, other: self.R < other.R

    N, C = map(int, input().split())
    ps = [[] for _ in range(30)]
    for _ in range(N):
        l, r, ch = map(int, input().split())
        heappush(ps[ch - 1], Prog(l, r))

    imos = [0] * (10 ** 5 + 1)
    for ps_ch in ps:
        while ps_ch:
            l, r = heappop(ps_ch)
            while ps_ch and ps_ch[0].L == r:
                r = ps_ch[0].R
                heappop(ps_ch)
            else:
                imos[l - 1] += 1
                imos[r] -= 1

    ans = imos[0]
    for i in range(10 ** 5):
        imos[i + 1] += imos[i]
        ans = max(ans, imos[i + 1])

    print(ans)


if __name__ == '__main__':
    main()

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


L=np.zeros((C, 10**5+1))

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

L=np.cumsum(L, axis=1)
print(int((L>0).sum(axis=0).max()))

Solution (Python):
import collections
def main():

    N, C = map(int, input().split())
    d = collections.defaultdict(list)

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

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

    
    index = dict()
    for c in d: index[c] = 0
    bound = max([d[c][-1][1] for c in d])
    ans = 0
    for i in range(1, bound + 1):
        cnt = 0
        for c in d:
            while index[c] < len(d[c]) and d[c][index[c]][1] < i:
                index[c] += 1
            if index[c] < len(d[c]) and d[c][index[c]][0] <= i <= d[c][index[c]][1]:
                cnt += 1
        
        ans = max(ans, cnt)
    return ans


if __name__ == '__main__':
    print(main())

Solution (Python):
from bisect import bisect_left
import sys
input = sys.stdin.readline
N, C = map(int, input().split())
stc = [[int(i) for i in input().split()] for _ in range(N)]
stc.sort()
stc.sort(key=lambda x: x[2])
a = []
S, T, C = stc[0]
for s, t, c in stc[1:]:
    if c == C and T == s:
        T = t
    else:
        a.append((S, T, C))
        S, T, C = s, t, c
a.append((S, T, C))

a.sort(key=lambda x: x[1])
l = [a[0][1]]
for s, t, c in a[1:]:
    i = bisect_left(l, s)
    if 0 < i and l[i - 1] < s:
        l.pop(i - 1)
    l.append(t)
print(len(l))

Solution (Python):
import numpy as np

n,c = map(int,input().split())

li = np.zeros(10**5+1,int)
ch = [[] for _ in range(10**5+1)]
lin = []

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

lin.sort()

for i,j,k in lin:
    if k in ch[i-1]:
        li[i:j] += 1
        ch[j-1].append(k)
    else:
        li[i-1:j] += 1
        ch[j-1].append(k)

print(np.max(li))

Solution (Python):
N,C = map(int,input().split())
G = {i:[0 for _ in range(10**5+1)] for i in range(1,C+1)}
for i in range(N):
    s,t,c = map(int,input().split())
    G[c][s] += 1
    G[c][t] -= 1
F = [0 for _ in range(2*(10**5)+1)]
for c in range(1,C+1):
    for i in range(10**5+1):
        if G[c][i]==1:
            F[2*i-1] += 1
        elif G[c][i]==-1:
            F[2*i] -= 1
H = [0 for _ in range(2*(10**5)+1)]
for i in range(1,2*(10**5)+1):
    H[i] = H[i-1]+F[i]
print(max(H))