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

Solution (Python):
def LI(): return list(map(int, input().split()))
def LS(): return input().split()
def I(): return int(input())
def S(): return input()

n, c = LI()
l = []
for i in range(n):
    l.append(LI())



la = [[[], []] for i in range(c)]
for i in l:
    la[i[2] - 1][0].append(i[0])
    la[i[2] - 1][1].append(i[1])

starts = []
ends = []
for s, e in la:
    wa = set(s).union(set(e))
    seki = set(s).intersection(set(e))
    a = list(wa.difference(seki))
    a.sort()
    for i, j in zip(a[0::2], a[1::2]):
        starts.append(i)
        ends.append(j)

s = min(starts)
e = max(ends)

imos = [0 for i in range(s,e + 2)]
for i, j in zip(starts, ends):
    imos[i - s] += 1
    imos[j - s + 1] -= 1
for i in range(len(imos) - 1):
    imos[i + 1] += imos[i]

print(max(imos))

Solution (Python):
N, C = map(int, input().split())
f = [[0] * 100001 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, raw_input().split())
time_table = [list(map(int, raw_input().split())) for _ in xrange(n)]
time_table.sort()

recoders = [[True for i in xrange(10**5+1)]]
for tt in time_table:
    for recoder in recoders:
        if recoder[0] == tt[2]:
            for i in xrange(tt[0], tt[1]+1):
                recoder[i] = False
            break
        else:
            if recoder[tt[0]]:
                for i in xrange(tt[0], tt[1]+1):
                    recoder[i] = False
                recoder[0] = tt[2]
                break
    else:
        recoders.append([True for i in xrange(10**5+1)])
        recoders[-1][0] = tt[2]
        for i in xrange(tt[0], tt[1]+1):
            recoders[-1][i] = False
print len(recoders)

Solution (Python):
import collections
N,C=map(int,raw_input().split())
a=collections.defaultdict(list)

max_t=0
for i in range(N):
	s,t,c=map(int,raw_input().split())
	a[c].append((s,t))
	max_t=max(max_t,t)

[a[i].sort() for i in a.keys()]



b=collections.defaultdict(list)


for i,j in a.items():
	start=0
	end=0
	for k in j:
		if start==0 and end==0:
			start=k[0]-1
			end=k[1]
			continue
		elif k[0]<=end:
			end=k[1]
		else:
			b[i].append((start,end))
			start=k[0]-1
			end=k[1]
	else:
		b[i].append((start,end))		




c=[0 for i in range(max_t+2)]

for i in b.values():
	for j,k in i:
		
		c[j]+=1
		c[k]-=1


ans=0
sum=0
for i in c:
	sum+=i
	ans=max(ans,sum)

print ans

Solution (Python):



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

sort_stc = sorted(stc)



counter = 0
rokuga_joutai = []
for bangumi in range(N):
    flag = -1
    for rokugaki in range(counter):
        if ((rokuga_joutai[rokugaki][2] == sort_stc[bangumi][2] and rokuga_joutai[rokugaki][1]-0.1 < sort_stc[bangumi][0]) or rokuga_joutai[rokugaki][1] + 0.5 < sort_stc[bangumi][0]):
            flag = rokugaki
    if flag != -1:

        rokuga_joutai[flag][0] = sort_stc[bangumi][0]
        rokuga_joutai[flag][1] = sort_stc[bangumi][1]
        rokuga_joutai[flag][2] = sort_stc[bangumi][2]
    else:
        rokuga_joutai.append([sort_stc[bangumi][0],sort_stc[bangumi][1],sort_stc[bangumi][2]])
        counter += 1

print(counter)

Solution (Python):
L = 100005
 
n,c = map(int, input().split())
 
arr = [[0]*L for j in range(c)]
for _ in range(n):
    s,t,col = map(lambda x:int(x)-1, input().split())
    arr[col][s] += 1
    arr[col][t] -= 1
 
imos = [0]*L
 
for i in range(c):
    for p in range(L):
        if arr[i][p] == 1: imos[p] += 1
        if arr[i][p] == -1: imos[p+1] -= 1
 
ans = 0
for i in range(1,L):
    imos[i] += imos[i-1]
    ans = max(ans, imos[i])
 
print(ans)

Solution (Python):
N, C = map(int, input().split())
 
f = [[0] * 100000 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):
import sys

def main():
    n, c = getLineInts()
    ss = [0 for i in range(n)]
    ts = [0 for i in range(n)]
    cs = [0 for i in range(n)]
    ics = [[] for c in range(31)]
    for i in range(n):
        ss[i], ts[i], cs[i] = getLineInts()
        ics[cs[i]].append(i)
        
    icms = []
    for c in range(31):
        prepS = None
        prepT = None
        for i in sorted(ics[c], key = lambda i: ss[i]):
            if prepS is not None and prepT == ss[i]:
                prepT = ts[i]
            else:
                if prepS is not None:
                    icms.append((prepS, 0))
                    icms.append((prepT, 1))
                prepS = ss[i]
                prepT = ts[i]
        if prepS is not None:
            icms.append((prepS, 0))
            icms.append((prepT, 1))
    
    vMax = 0
    cur = 0
    icms = sorted(icms, key = lambda e: e[1])
    icms = sorted(icms, key = lambda e: e[0])
    for (t, type) in icms:
        if type == 0:
            cur += 1
            if vMax < cur:
                vMax = cur
        else:
            cur -= 1
    print(vMax)


def getLineInts():
    return [int(x) for x in sys.stdin.readline().rstrip().split(' ')]


if __name__ == '__main__':
    main()

Solution (Python):
from collections import defaultdict as ddict
N, C = map(int, input().split())
imos = [0] * (10**5 + 2)
last_s_by_c = ddict(lambda: 1)
last_t_by_c = ddict(int)
stc = [list(map(int, input().split())) for i in range(N)]
for s, t, c in sorted(stc, key=lambda x: x[1]):
	if last_t_by_c[c] != s:
		imos[last_s_by_c[c] - 1] += 1
		imos[last_t_by_c[c]] -= 1
		last_s_by_c[c] = s
	last_t_by_c[c] = t
for c in last_s_by_c:
	imos[last_s_by_c[c] - 1] += 1
	imos[last_t_by_c[c]] -= 1
for i in range(10**5 + 1):
	imos[i + 1] += imos[i]
print(max(imos))

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

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())

f = [[0] * 100000 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):
import sys


def ReadLineInt():
    return [int(x) for x in sys.stdin.readline().split()]

n, c = ReadLineInt()


recorders = [-1] * (c+1)


programs = sorted([ReadLineInt() for _ in range(n)])


for start, end, channel in programs:
    for i in range(c):
        if recorders[i] < start:
            recorders[i] = end
            break

ans = 0


for i in range(c+1):
    if recorders[i] < 0:
        ans = i
        break

print(ans)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
 
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7
 
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
 
 
def main():
    n,c = LI()
    a = [-1] * (c+1)
    b = sorted([LI() for _ in range(n)])
    for s,t,d in b:
        for i in range(c):
            if a[i] < s:
                a[i] = t
                break
 
    for i in range(c+1):
        if a[i] < 0:
            return i
 
    return -1
 
 
 
print(main())

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n,c = LI()
    a = [-1] * (c+1)
    b = sorted([LI() for _ in range(n)])
    for s,t,d in b:
        for i in range(c):
            if a[i] < s:
                a[i] = t
                break

    for i in range(c+1):
        if a[i] < 0:
            return i

    return -1



print(main())

Solution (Python):
N,C = [int(val) for val in raw_input().split(" ")]

table = [[0]*(10**5) for i_c in range(C)]

for i_n in xrange(N):
    s_i, t_i, c_i = [int(val) for val in raw_input().split(" ")]
    for loc in xrange(s_i-1, t_i-1):
        table[c_i-1][loc] = 1
    if s_i>1:
        table[c_i-1][s_i-2] = 1

req = 0
for loc in xrange(10**5):
    tmp = sum([table[i_c][loc] for i_c in xrange(C)])
    if tmp > req:
        req = tmp

print req

Solution (Python):
N, C = map(int, input().split())
S = []
for i in range(N):
    S.append(list(map(int, input().split())))
S.sort()
R = [[] for i in range(C)]
for i in range(N):
    c = S[i][2] - 1
    if R[c]:
        if R[c][-1][1] == S[i][0]:
            R[c][-1][1] = S[i][1]
            continue
    R[c].append(S[i][:])
D = [0]*100001
for r in R:
    for s in r:
        for i in range(s[0], s[1]+1):
            D[i] += 1
print(max(D))

Solution (Python):
def func():
    tvs = []
    for i in range(num):
        tvs.append((-1, -1))
    for i in range(len(bans)):
        now = bans[i][0]
        can = bans[i][2]
        
        for j, tv in enumerate(tvs):
            if tv[1] == -1 or (tv[1] == can and tv[0] <= now) or tv[0] <= now - 1:
                del tvs[j]
                tvs.append((bans[i][1], can))
                break
        else:
            return False
    return True


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

bans = []
for i in range(n):
    bans.append(tuple(map(int, input().split())))
bans.sort(key=lambda x: x[0])

for num in range(1, 1024):
    if func():
        print(num)
        break

Solution (Python):
def func():
    tvs = []
    for i in range(num):
        tvs.append((-1, -1))
    for i in range(len(bans)):
        now = bans[i][0]
        can = bans[i][2]
        tvs = [tv for tv in tvs if tv[1] == can] + [tv for tv in tvs if tv[1] != can]
        for j, tv in enumerate(tvs):
            if tv[1] == -1 or (tv[1] == can and tv[0] <= now) or tv[0] <= now - 1:
                del tvs[j]
                tvs.append((bans[i][1], can))
                break
        else:
            return False
    return True


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

bans = []
for i in range(n):
    bans.append(tuple(map(int, input().split())))
bans.sort(key=lambda x: x[0])

for num in range(1, 1024):
    if func():
        print(num)
        break

Solution (Python):



"""abc080_d"""


import sys


def main():
    """Main function."""
    N, C = map(int, input().split(' '))
    table = [[0]*100000 for _ in range(C)]

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

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


if __name__ == '__main__':
    sys.exit(main())

Solution (Python):
def d_recording(N, C, R):
    """
    N:録画する番組の数
    C:テレビが受信できるチャンネルの数
    R:録画する番組の情報 [開始時刻s,終了時刻t,チャンネルc]
    """
    s = [row[0] for row in R]
    t = [row[1] for row in R]
    c = [row[2] for row in R]

    
    
    l = max(t) * 2 + 2
    sm = [0 for _ in range(l)]  

    for i in range(1, C + 1):
        tt = [0 for _ in range(l)]  
        
        for j in range(N):
            if c[j] == i:
                
                
                tt[s[j] * 2 - 1] += 1
                tt[t[j] * 2] -= 1
        for j in range(1, l):
            tt[j] += tt[j - 1]
        
        for j in range(l):
            if tt[j] > 0:
                sm[j] += 1
    ans = max(sm)
    return ans

N,C = [int(i) for i in input().split()]
R = [[int(i) for i in input().split()] for j in range(N)]
print(d_recording(N, C, R))

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

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

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

Solution (Python):
import heapq

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

pq = []
for ch, TVc in enumerate(TVs):
    if not TVc: continue
    TVc.sort()
    heapq.heappush(pq, (TVc[0][0] - 0.5, ch))

states = [0] * C
iTVs = [0] * C

prev = 0
ans = 0
while pq:
    tm, ch = heapq.heappop(pq)
    if tm != prev:
        ans = max(ans, sum(states))
        prev = tm

    if states[ch] == 0:
        
        states[ch] = 1
        heapq.heappush(pq, (TVs[ch][iTVs[ch]][1], ch)) 
    else:
        
        states[ch] = 0
        iTVs[ch] += 1
        if iTVs[ch] >= len(TVs[ch]): continue

        if tm == TVs[ch][iTVs[ch]][0]:
            
            states[ch] = 1
            heapq.heappush(pq, (TVs[ch][iTVs[ch]][1], ch)) 
        else:
            heapq.heappush(pq, (TVs[ch][iTVs[ch]][0] - 0.5, ch)) 

print(ans)

Solution (Python):
import sys
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
INF = float("inf")
sys.setrecursionlimit(10**7)


dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]


def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W


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

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

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

        for s, t, c in s_t_c:
            if c == i:
                dp[s * 2 - 1] += 1
                dp[t * 2] -= 1
        for j in range(1, len(dp)):
            dp[j] += dp[j - 1]

        for j in range(len(dp)):
            ans[j] += dp[j] > 0

    print(max(ans))


if __name__ == '__main__':
    main()

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




arr = [[0]*L for _ in range(c)]

for i in range(n):
    s,t,col = map(int,input().split(" "))
    arr[col-1][s-1] += 1
    arr[col-1][t-1] -= 1

imos = [0]*L


for i in range(c):
    for p in range(L):
        if arr[i][p] == 1: imos[p] += 1    
        if arr[i][p] == -1: imos[p+1] -= 1



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

print(ans)

Solution (Python):
n, _ = map(int, input().split())
a = sorted(tuple(map(int, input().split())) for _ in range(n))
r = [(0,0)]
for s, t, c in a:
    u, i = min((u+0.5*(c!=d), i) for i, (u, d) in enumerate(r))
    if s < u:
        r.append((t, c))
    else:
        r[i] = (t, c)
print(len(r))

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

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

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

print(max(accumulate(imos)))

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

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

imos = [0] * (2 * 10 ** 5 + 2)
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[2 * ps - 1] += 1
            imos[2 * pt + 1] -= 1
            ps, pt = s, t
    imos[2 * ps - 1] += 1
    imos[2 * pt + 1] -= 1

print(max(accumulate(imos)))

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

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

combined = []
for c, p in programs.items():
    p.sort()
    ps, pt = p[0]
    for s, t in p[1:]:
        if pt == s:
            pt = t
        else:
            combined.append((ps, pt, c))
            ps, pt = s, t
    combined.append((ps, pt, c))
combined.sort()

recorders = [(-1, None)]
for s, t, c in combined:
    end, channel = recorders[0]
    if end < s or c == channel:
        heapreplace(recorders, (t, c))
    else:
        heappush(recorders, (t, c))
print(len(recorders))

Solution (Python):

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

imos = [0] * (10 ** 5 + 1)
for i in range(10 ** 5 + 1):
    for j in range(C):
        if table[i][j] == 1:
            imos[i] += 1
        if table[i][j] == -1:
            imos[i + 1] -= 1

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

print(ans)

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 heapq import heapreplace, heappush

n, v = map(int, input().split())
programs = [tuple(map(int, input().split())) for _ in range(n)]
programs.sort()
tmp = [None] * v
combined = []
for s, t, c in programs:
    c -= 1
    prev = tmp[c]
    if prev is not None:
        ps, pt, pc = prev
        if pt == s:
            tmp[c] = (ps, t, c)
        else:
            combined.append((ps, pt, pc))
            tmp[c] = (s, t, c)
    else:
        tmp[c] = (s, t, c)
for prev in tmp:
    if prev is not None:
        combined.append(prev)
combined.sort()

recorders = [(-1, None)]
for s, t, c in combined:
    end, channel = recorders[0]
    if end < s or c == channel:
        heapreplace(recorders, (t, c))
    else:
        heappush(recorders, (t, c))
print(len(recorders))

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

ss = [0] * N
tt = [0] * N
cc = [0] * N

for n in range(N):
    ss[n], tt[n], cc[n] = map(int, input().split(' '))

L = 10 ** 5 * 2 + 2
timeline = [[0] * L for c in range(C)]




for n in range(N):
    timeline[cc[n] - 1][ss[n] * 2] += 1
    timeline[cc[n] - 1][tt[n] * 2] -= 1


num = [0] * L
for c in range(C):
    for t in range(L):
        if timeline[c][t] > 0:
            num[t - 1] += timeline[c][t]
        if timeline[c][t] < 0:
            num[t] += timeline[c][t]

stack = 0
max_ = 0
for i in range(L):
    stack += num[i]
    if stack > max_:
        max_ = stack

print(max_)

Solution (Python):
N,C=list(map(int,input().split()))
A=[list(map(int,input().split())) for _ in range(N)]
T=0
for i in A:
    T=max(i[1],T)
timelist=[0 for _ in range((T)*2)]
ch=[[] for _ in range(C)]
for item in A:
    ch[item[2]-1].append(item)


count=0
for channel in ch:
    count+=1
    for item in channel:
        starttime=item[0]
        endtime=item[1]
        for time in range(starttime*2-2,endtime*2-2,2):
            timelist[time]+=1
            if(timelist[time]>count):
                timelist[time]=count
            timelist[time+1]+=1
            if(timelist[time+1]>count):
                timelist[time+1]=count
        timelist[time+2]+=1
        if(timelist[time+2]>count):
                timelist[time+2]=count
print  (max (timelist))

Solution (Python):
L = 100005

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

arr = [[0]*L for j in range(c)]
for _ in range(n):
    s,t,col = map(lambda x:int(x)-1, input().split())
    arr[col][s] += 1
    arr[col][t] -= 1

imos = [0]*L

for i in range(c):
    for p in range(L):
        if arr[i][p] == 1: imos[p] += 1
        if arr[i][p] == -1: imos[p+1] -= 1

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

print(ans)

Solution (Python):
L = 100005

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

arr = [[0]*L for j in range(c)]
for _ in range(n):
    s,t,col = map(lambda x:int(x)-1, input().split())
    arr[col][s] += 1
    arr[col][t] -= 1

imos = [0]*L

for i in range(c):
    for p in range(L):
        if arr[i][p] == 1: imos[p] += 1
        if arr[i][p] == -1: imos[p+1] -= 1

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

print(ans)

Solution (Python):
n, c = list(map(int, input().split()))
tv = []
for i in range(n):
    x, y, z = list(map(int, input().split()))
    tv.append([x, y, z])
channels = [[0 for _ in range(max(tv, key=lambda lst: lst[1])[1] + 1)] for _ in range(c + 1)]
for program in tv:
    start = program[0]
    end = program[1]
    channel = program[2]
    for time in range(start, end+1):
        channels[channel][time] = 1
res = 0
for time in range(len(channels[0])):
    now = 0
    for channel in range(c+1):
        now += channels[channel][time]
    if res < now:
        res = now
print(res)

Solution (Python):
def main():
    n,cc=[int(i) for i in input().split()]
    rec=[]
    for i in range(n):
        s,t,c=[int(k) for k in input().split()]
        rec.append([float(s),float(t),c])
    slot=[[float(-1),-1] for i in range(cc)]
    rec.sort(key=lambda rec:rec[0])
    for r in rec:
        for k,s in enumerate(slot):
            tmp=0
            if s[1]!=r[2]:
                
                tmp=r[0]
                r[0]=r[0]-0.5
            if s[0]<=r[0]:
                s[0]=r[1]
                s[1]=r[2]
                break
            r[0]=tmp
    print(len([i for i in slot if i[0]!=-1 and i[1]!=-1]))

if __name__=='__main__':
    main()

Solution (Python):



import numpy as np

nc = raw_input()
nc = nc.split()
n,c = map(int,nc)

tt = np.zeros([(10**5),c],int)

for i in range(n):
    stc = raw_input()
    stc = stc.split()
    s,t,c = map(int,stc)
    j = s
    while j <= t:
        tt[j-1][c-1] = 1
        j += 1

ans = np.max(np.sum(tt, axis=1))

print ans

Solution (Python):
from heapq import heappop as pop, heappush as push

peak, curr = 0, 0

stuff = []
n, c = map(int, raw_input().split())
for _ in xrange(n):
  stuff.append(map(float, raw_input().split()))
  stuff[-1][-1] = int(stuff[-1][-1]) - 1
  
stuff = sorted(stuff)
has_camera = [False] * c
last_ending = [-1] * c
ending = []
for st, end, ch in stuff:
  while ending and ending[0][0] <= st - 0.5:
    cend, cch = pop(ending)
    if last_ending[cch] == cend:
        has_camera[cch] = False
        curr -= 1
  if not has_camera[ch]:
    has_camera[ch] = True
    curr += 1
  push(ending, (end, ch))
  last_ending[ch] = end
  peak = max(peak, curr)
  
print peak

Solution (Python):
def inpl(): return tuple(map(int, input().split()))

N, C = inpl()
P = sorted([inpl() for _ in range(N)])

R = [[[-1, 0, -1]] for _ in range(30)]
for s, t, c in P:
    i = 0
    
    sr = [i for i in range(30) if R[i][-1][2] == c and R[i][-1][1] <= s]
    if sr:
        R[min(sr)].append([s, t, c])
    else:
        r = [i for i in range(30) if R[i][-1][1] <= s - 0.5]
        R[min(r)].append([s, t, c])

for i in range(30):
    if len(R[i]) == 1:
        print(i)
        break
else:
    print(30)

Solution (Python):
n, c = list(map(int, input().split()))
tv = []
for i in range(n):
    x, y, z = list(map(int, input().split()))
    tv.append([x, y, z])
channels = [[0 for _ in range(max(tv, key=lambda lst: lst[1])[1] + 1)] for _ in range(c + 1)]
for program in tv:
    start = program[0]
    end = program[1]
    channel = program[2]
    for time in range(start, end+1):
        channels[channel][time] = 1
res = 0
for time in range(len(channels[0])):
    now = 0
    for channel in range(c+1):
        now += channels[channel][time]
    if res < now:
        res = now
print(res)

Solution (Python):
N,C=map(int,input().split())
channel=[tuple(map(int,input().split())) for i in range(N)]
channel=sorted(channel,key=lambda cha: cha[0])

n=0
while(channel!=[]):
    c=[]
    n+=1
    pro=channel[0]
    channel.remove(pro)
    for i in channel:
        if i[0]>pro[1]:
            pro=i
        elif(i[0]==pro[1] and i[2]==pro[2]):
            pro=i
        else:
            c.append(i)
    channel=c
print(n)

Solution (Python):



def solve():
    n, c = map(int, input().split())
    c_info = [[int(i) for i in input().split()] for _ in range(n)]
    c_info.sort(key=lambda x: (x[2], x[0]))
    info = []
    cnt = 0
    
    while cnt < n:
        if cnt == n - 1:
            info.append(c_info[cnt])
            break
        if c_info[cnt][1] == c_info[cnt + 1][0] and c_info[cnt][2] == c_info[cnt + 1][2]:
            tc = c_info[cnt][2]
            t = [c_info[cnt][0], c_info[cnt + 1][1], tc]
            cnt += 1
            while cnt < n - 1 and t[1] == c_info[cnt + 1][0] and tc == c_info[cnt + 1][2]:
                t = [t[0], c_info[cnt + 1][1], tc]
                cnt += 1
            info.append(t)
            if cnt == n - 1:
                break
        else:
            info.append(c_info[cnt])
        cnt += 1

    tarr = [0] * (2 + 10 ** 5)
    for elem in info:
       tarr[elem[0]] += 1
       tarr[elem[1] + 1] -= 1
    
    ans = 1
    tans = 0
    for elem in tarr:
        tans += elem
        ans = max(ans, tans)
    print(ans)

if __name__=="__main__":
    solve()

Solution (Python):
st=input().split()
N=int(st[0]);C=int(st[1])
s=[0 for i in range(N)];t=[0 for i in range(N)];c=[0 for i in range(N)]
MT=0
for i in range(N):
    st=input().split()
    s[i]=int(st[0])-1;t[i]=int(st[1])-1;c[i]=int(st[2])-1
for i in range(N):
    if t[i]>MT:
        MT=t[i]
CBC=[[0 for i in range(MT+1)] for i in range(C)]
for i in range(N):
    for j in range(s[i]-1,t[i]):
        CBC[c[i]][j]=1
MaxC=0
for i in range(MT+1):
    NowC=0
    for j in range(C):
        if CBC[j][i]==1:
            NowC+=1
    if NowC>MaxC:
        MaxC=NowC
print(MaxC)

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

MAX_N = 10**5+3
imos = [0] * MAX_N
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, raw_input().split())
cs = [None] * c
for i in range(c):
    cs[i] = list()
for i in range(n):
    [s, t, ci] = map(int, raw_input().split())
    cs[ci - 1].append((s, t))
starts = []
ends = []
for i in range(c):
    if len(cs[i]) == 0: continue
    cs[i].sort()
    j = 0
    k = 0
    while j + k < len(cs[i]) - 1:
        a = cs[i][j+k][1]
        b = cs[i][j+k+1][0]
        if a == b:
            k += 1
        else:
            start = cs[i][j][0]
            end = cs[i][j+k][1]
            starts.append(start)
            ends.append(end)
            j += k + 1
            k = 0
    start = cs[i][j][0]
    end = cs[i][j+k][1]
    starts.append(start)
    ends.append(end)
starts.sort()
ends.sort()
i = 0
j = 0
d = 0
while i < len(starts) and j < len(ends):
    if starts[i] < ends[j]:
        i += 1
    elif starts[i] == ends[j]:
        i += 1
    else:
        j += 1
    d = max(d, i - j)
print d

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

su = [0]*(10**5+1)
Q = [[] for i in range(C)]
for i in range(N):
    s, t, c = map(int, input().split())
    Q[c-1].append([s, t])
R = [[] for i in range(C)]
for i in range(C):
    q = Q[i]; q.sort()
    r = R[i]
    if len(q) == 0:
        continue
    r.append(q[0])
    for j in range(1, len(q)):
        if r[-1][1] == q[j][0]:
            r[-1][1] = q[j][1]
        else:
            r.append(q[j])
    for a, b in r:
        su[a-1] += 1
        su[b] -= 1
ans = 0; tmp = 0
for i in range(10**5+1):
    tmp += su[i]
    ans = max(ans, tmp)
print(ans)

Solution (Python):
from collections import deque
n, c = map(int, raw_input().split())
l = deque()
for _ in xrange(n):
    s, t, c = map(int, raw_input().split())
    l.append((s, t, c))
def comp(t1, t2):
    if t1[0] == t2[0]:
        return cmp(t1[1], t2[1])
    return cmp(t1[0], t2[0])
l, cnt, rec = sorted(l, cmp = comp), 0, deque()
for s, t, c in l:
    f = False
    for i, (rt, rc) in enumerate(rec):
        if c == rc:
            if s >= rt:
                rec[i] = (t, c)
                f = True
                break
        else:
            if s > rt:
                rec[i] = (t, rc)
                f = True
                break
    if not f:
        rec.append((t, c))
print len(rec)

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 i in range(s - 1, t):
        r[i][c - 1] = 1

ans = 0
for i in range(100000):
    val = sum(r[i])
    if val > ans:
        ans = val

print(ans)