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

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007


def A():
    n,a,b = LI()
    print(min(n*a,b))
    return


def B():
    s = S()
    print(s.count("1"))
    return


def C():
    n = list(map(int, S()))
    k = 0
    s = sum(n)
    for i in range(len(n)):
        k *= 10
        k += n[i]
    if k%s == 0:
        print("Yes")
    else:
        print("No")
    return


def D():
    n = I()
    a = LI()
    ans = float("inf")
    for i in range(n):
        m = 0
        while a[i]%2 == 0:
            m += 1
            a[i] //= 2
        ans = min(m,ans)
    print(ans)
    return


def E():
    n = I()
    f = LIR(n)
    p = LIR(n)

    return


def F():
    n,k = LI()
    a = LI()
    d = defaultdict(int)
    for i in a:
        d[i] += 1
    d = list(d.values())
    d.sort()
    ans = 0
    for i in range(len(d)-k):
        ans += d[i]
    print(ans)
    return


def G():
    n,c = LI()
    ch = LIR(n)
    T = [[0 for i in range(100002)] for j in range(c+1)]
    for s,t,cha in ch:
        T[cha-1][s] += 1
        T[cha-1][t+1] -= 1
    for i in range(c):
        for j in range(100000):
            T[i][j+1] += T[i][j]
            if T[i][j] >= 1:
                T[i][j] = 1
    ans = 0
    for i in range(100001):
        m = 0
        for j in range(c+1):
            m += T[j][i]
        ans = max(m,ans)
    print(ans)
    return


def H():
    return


def I_():
    return


def J():
    return


if __name__ == "__main__":
    G()

Solution (Python):
n,c=map(int,input().split())
table=[[0]*10**5for 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 sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from itertools import accumulate

n,ch = li()
MAX_T = 10**5+1

program = [[0]*MAX_T for _ in range(ch)]

endset = [set() for _ in range(ch)]
stc = []

for _ in range(n):
    s,t,c = li()
    c -= 1
    
    stc.append((s,t,c))
    endset[c].add(t)
    
stc.sort(key=lambda x:x[0])
    
for s,t,c in stc:
    if s in endset[c]:
        program[c][s] += 1
        program[c][t] -= 1
    else:
        program[c][s-1] += 1
        program[c][t] -= 1
    
for ci in range(ch):
    program[ci] = list(accumulate(program[ci]))
    
print(max([sum(time_span) for time_span in zip(*program)]))

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

_l = [[0 for _ in range(2*int(1e5+1))] for _ in range(C+1)]

for s,t,c in STC:
  if _l[c][2*s] == -1:
    _l[c][2*s] = 0
    _l[c][2*t] = -1
  else:
    _l[c][2*s-1] = 1
    _l[c][2*t] -= 1

import numpy as np

_l = np.array(_l)

ac = (_l.sum(axis=0)).cumsum()
print(max(ac))

Solution (Python):
from itertools import accumulate
N, C = map(int, input().split())
TimeTable = [[0] * (10 ** 5 + 2) for i in range(C + 1)]
for i in range(N):
    s, t, c = map(int, input().split())
    TimeTable[c][s] += 1
    TimeTable[c][t + 1] -= 1

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


ans = 0
for i in range(10 ** 5 + 2):
    cnt = 0
    for c in range(C + 1):
        cnt += min(TimeTable[c][i], 1)
    ans = max(ans, cnt)

print(ans)

Solution (Python):
from operator import itemgetter
n, c = map(int, input().split())
tmp_info = [list(map(int, input().split())) for i in range(n)]

tmp_info = sorted(tmp_info, key=itemgetter(2,1))
info = []
for i in range(n):
    if not info:
        info.append(tmp_info[i])
    elif info[-1][1] == tmp_info[i][0] and info[-1][2] == tmp_info[i][2]:
        info[-1][1] =tmp_info[i][1]
    else:
        info.append(tmp_info[i])
info = sorted(info, key=itemgetter(1))
n = len(info)
li = []

for i in range(n):
    li = sorted(li, reverse=True)
    for j in range(len(li)):
        if info[i][0] > li[j]:
            li[j] = info[i][1]
            break
    else:
        li.append(info[i][1])
        
print(len(li))

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

times = [0] * 2 * (10 ** 5 + 1)
channel = [[0] * 2 * (10 ** 5 + 1) for _ in range(C)]
for i in range(N):
    s, t, c = items[i]
    c -= 1
    channel[c][2 * s - 1] += 1
    channel[c][2 * t] -= 1

for c in range(C):
    for i in range(len(times) - 1):
        channel[c][i + 1] += channel[c][i]
        if channel[c][i + 1] >= 1:
            times[i + 1] += 1

print(max(times))

Solution (Python):
from numpy import cumsum
n, c = [int(item) for item in input().split()]
stc = [[int(item) for item in input().split()] for _ in range(n)] 
stc.sort(key=lambda x: (x[2], x[0]))

timeline = [0] * (10**5 + 1)
prev_c = -1 
for s, t, c in stc:
    if prev_c != c:
        prev_t = -100
    if prev_t != s:
        timeline[s-1] += 1
        timeline[t] += -1
    else:
        timeline[s] += 1
        timeline[t] += -1
    prev_t = t
    prev_c = c

print(max(cumsum(timeline)))

Solution (Python):
import sys
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()
 
n, c = na()
stc = []
for i in range(n):
    stc.append(na())
stc.sort(key=lambda x: (x[2], x[0]))

nstc=[]
for i in range(n):
    if(len(nstc)>0 and nstc[-1][2]==stc[i][2] and nstc[-1][1]==stc[i][0]):
        nstc[-1][1]=stc[i][1]
    else:
        nstc.append(stc[i])
n=len(nstc)
h=[0]*200005
for i in range(n):
    h[2*nstc[i][0]-1]+=1
    h[2*nstc[i][1]]+=-1
for i in range(len(h)-1):
    h[i]+=h[i-1]
print(max(h))

Solution (Python):
from heapq import heappush, heappop


N, C = map(int, input().split())
s, t, c = zip(*(map(int, input().split()) for _ in range(N)))


Q = []
p = [0 for _ in range(C + 1)]
ans = 0
for x, y, z in sorted(zip(s, t, c)):
    while Q and (Q[0] < x or Q[0] == x == p[z]):
        p[z] = 0
        heappop(Q)
    p[z] = y
    heappush(Q, y)
    ans = max(ans, len(Q))


print(ans)

Solution (Python):
N,C=map(int,input().split())
from collections import defaultdict
cannel={i:[] for i in range(1,1+C)}
check=[tuple(map(int,input().split())) for i in range(N)]
check.sort(key=lambda x:x[0])
for x in check:
    s,t,c=x
    if cannel[c]==[]:
        cannel[c].append((max(0,s-1),t))
    elif s-cannel[c][-1][1]<=1:
        cannel[c][-1]=(cannel[c][-1][0],t)
    else:
        cannel[c].append((max(0,s-1),t))
start=defaultdict(int)
end=defaultdict(int)
for c in range(1,1+C):
    for x in cannel[c]:
        start[x[0]]+=1
        end[x[1]]+=1
ans=0
now=0
for i in range(10**5+1):
    now+=start[i]-end[i]
    ans=max(ans,now)
print(ans)

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

data = []

for i in range(n):
    s,t,h = map(int,input().split())
    data.append((s,t,h))

data.sort()

record = []

for s,t,h in data:
    flag = False
    for track in record:
        if track[0]<=s and track[1]==h:
            track[0]=t
            track[1]=h
            flag = True
            break
        elif track[0]<s and track[1]!=h:
            track[0]=t
            track[1]=h
            flag = True
            break
    if not flag:
        record.append([t,h])

print(len(record))

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


R = [[stc[0][1],stc[0][2]]]
for s,t,c in stc[1:]:
    for i in range(len(R)):
        tr,cr = R[i][0],R[i][1]
        if c == cr and tr <=s:
            R[i] = [t,c]
            break
        if c!=cr and tr <s:
            R[i] = [t,c]
            break
    else:
        R.append([t,c])

print(len(R))

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())
STC = [[int(i) for i in input().split()] for i in range(N)]
STC.sort()

R = [[STC[0][1], STC[0][2]]]
for s, t, c in STC[1:]:
    for i in range(len(R)):
        t_r, c_r = R[i][0], R[i][1]
        if c == c_r and t_r <= s:
            R[i] = [t, c]
            break
        if c != c_r and t_r < s:
            R[i] = [t, c]
            break
    else:
        R.append([t, c])
        
print(len(R))

Solution (Python):
n,c = map(int,input().split())
sortls = [list(map(int,input().split())) for i in range(n)]
sortls.sort(key = lambda k:(k[2],k[0]))
sortls.append([sortls[-1][0],sortls[-1][1],sortls[-1][2]+1])
count = 0;ls = [];start = -1;tf = False
while True:
    if tf:
        if sortls[count][1] == sortls[count+1][0] and sortls[count][2] == sortls[count+1][2]:
            pass
        else:
            ls.append([start,sortls[count][1],sortls[count][2]])
            tf = False
    elif sortls[count][1] != sortls[count+1][0] or sortls[count][2] != sortls[count+1][2]:
        ls.append(sortls[count])
    elif sortls[count][2] == sortls[count+1][2]:
        start = sortls[count][0]
        tf = True
    else:
        ls.append(sortls[count])
    count += 1
    if count > n-1:break

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

Solution (Python):
import sys
sys.setrecursionlimit(1000000)



'''
n=int(input())
for i in range(n):
    a[i]=int(input())
    a[i],b[i]=map(int,input().split())
a=[int(x) for x in input().split()]
n,m=map(int,input.split())
from operator import itemgetter
a = [(1, "c", 1), (1, "b", 3), (2, "a", 0), (1, "a", 2)]
print(sorted(a))  
print(sorted(a, key=itemgetter(0)))  
print(sorted(a, key=itemgetter(0, 2)))  
print(sorted(a, key=lambda x: x[0] * x[2]))  
print(sorted(a, reverse=True))  
a.sort()  
try: 
    for i in range():
        k=b[i]
except IndexError as e:
    print(i)
'''

test_data1 = '''\
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
'''

test_data2 = '''\
2
1 1 1 1 1 0 0 0 0 0
0 0 0 0 0 1 1 1 1 1
0 -2 -2 -2 -2 -2 -1 -1 -1 -1 -1
0 -2 -2 -2 -2 -2 -1 -1 -1 -1 -1
'''

test_data3 = '''\

'''
td_num=1

def GetTestData(index):
    if index==1:
        return test_data1
    if index==2:
        return test_data2
    if index==3:
        return test_data3

if False:
    with open("../test.txt", mode='w') as f:
        f.write(GetTestData(td_num))
    with open("../test.txt") as f:
        
        n,c=map(int,f.readline().split())
        s=[0]*n
        t=[0]*n
        ch=[0]*n
        for i in range(n):
            s[i],t[i],ch[i]=map(int,f.readline().split())
        
else:
    for i in range(1):
        
        n,c=map(int,input().split())
        s=[0]*n
        t=[0]*n
        ch=[0]*n
        for i in range(n):
            s[i],t[i],ch[i]=map(int,input().split())
        

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

for i in range(n):
    for j in range(2*s[i]-1,2*t[i]):
        table[ch[i]-1][j]=1
ans=0
for i in range(2*10**5+2):
    tt=0
    for x in range(c):
        tt+=table[x][i]
    ans=max(ans,tt)
print(ans)

Solution (Python):
import sys
from collections import deque
import copy
import bisect
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, C] = [int(input_raw[0]), int(input_raw[1])]
    dic_s = {}
    dic_t = {}
    max_t = 0
    for i in range(N):
        input_raw = read_func().strip().split()
        [s, t, c] = [int(input_raw[0]), int(input_raw[1]), int(input_raw[2])]
        max_t = max(t, max_t)
        if c not in dic_s:
            dic_s[c] = [s]
            dic_t[c] = [t]
        else:
            dic_s[c].append(s)
            dic_t[c].append(t)

    for c in dic_s:
        dic_s[c].sort()
        dic_t[c].sort()

    max_count = 0

    for s in range(1, max_t):
        t = s + 1
        count = 0
        for c in dic_s:
            idx_s = bisect.bisect_left(dic_s[c], t) - 1
            idx_t = bisect.bisect_left(dic_t[c], s)

            if idx_t >= len(dic_t[c]) or idx_s < 0:
                continue
            if dic_s[c][idx_t] <= s or t <= dic_t[c][idx_s]:
                count += 1
        max_count = max(count, max_count)
    print max_count




if __name__ == '__main__':
    main()

Solution (Python):
def recording(N: int, C: int, info: list) -> int:
    _, max_time, _ = max(info, key=lambda x: x[1])
    max_time = 2*max_time

    
    
    
    recorders = [[0] * C for _ in range(max_time + 1)]

    
    
    
    for s, t, ch in info:
        recorders[2*s-1][ch-1] += 1
        recorders[2*t][ch-1] -= 1

    
    for t in range(max_time):
        for ch in range(C):
            recorders[t+1][ch] += recorders[t][ch]

    
    return max(
        sum(used > 0 for used in recorders[t])
        for t in range(max_time+1))


if __name__ == "__main__":
    N = 0
    N, C = map(int, input().split())
    info = [tuple(map(int, input().split())) for _ in range(N)]
    ans = recording(N, C, info)
    print(ans)

Solution (Python):
def recording(N: int, C: int, info: list) -> int:
    _, max_time, _ = max(info, key=lambda x: x[1])
    max_time = 2*max_time

    
    
    
    cum = [[0] * C for _ in range(max_time + 1)]

    
    
    
    for s, t, ch in info:
        cum[2*s-1][ch-1] += 1
        cum[2*t][ch-1] -= 1

    
    for t in range(max_time):
        for ch in range(C):
            cum[t+1][ch] += cum[t][ch]

    
    return max(sum(used > 0 for used in cum[t]) for t in range(max_time+1))


if __name__ == "__main__":
    N = 0
    N, C = map(int, input().split())
    info = [tuple(map(int, input().split())) for _ in range(N)]
    ans = recording(N, C, info)
    print(ans)

Solution (Python):

from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import itertools
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return list(sys.stdin.readline())
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
mod = 1000000007


def C():
    N = I()
    F = LIR(N)
    P = LIR(N)
    ans = -1*float("INF")
    kaiten = list((itertools.product([0,1], repeat=10)))
    del kaiten[0]
    for patern in kaiten:
        i = list(patern)
        anskaiten = [0 for i in range(N)]
        for youbi, n in enumerate(i):
            if n == 1:
                for nn,f in enumerate(F):
                    if f[youbi] == 1:
                        anskaiten[nn] += 1
        ansb = 0
        
        for k, p in enumerate(P):
            ansb += p[anskaiten[k]]
        ans = max(ans, ansb)
    print(ans)
        
def D():

    N, C = LI()
    STC = LIR(N)
    ans = 0
    
    
    channel = [[0]*(10**5+2) for i in range(C+1)]

    
    
    
    
    
    
    for s,t,c in STC:
        channel[c][s] += 1
        channel[c][t + 1] -= 1
    
    
    
    
    for cha in channel:
        for num, CH in enumerate(cha):
            if num == 10 ** 5 + 1:
                break
            cha[num + 1] += CH
    
    
    
    for i in range(10 ** 5 + 1):
        bf = 0
        for cha in channel:
            if cha[i]: bf += 1
        ans = max(ans, bf)
    print(ans)

if __name__ == '__main__':
    D()

Solution (Python):
import sys

def main():
    input = sys.stdin.readline
    N, C = map(int, input().split())
    dic = [[] for _ in range(C + 1)]
    for _ in range(N):
        s, t, c = input().split()
        dic[int(c)].append([int(s), int(t)])
    for c in range(C + 1):
        l = len(dic[c])
        if l == 1:
            continue
        dic[c] = sorted(dic[c])
        i = 0
        while i < l - 1:
            if i < l - 1 and dic[c][i][1] == dic[c][i + 1][0]:
                dic[c][i + 1][0] += 1
            else:
                i += 1
    f = [0 for _ in range(100002)]
    for c in range(C + 1):
        for t in dic[c]:
            f[t[0]] += 1
            f[t[1] + 1] -= 1
    ans = 0
    for i in range(1, 100001):
        f[i] += f[i - 1]
        if ans < f[i]:
            ans = f[i]
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007


def A():
    return


def B():
    return


def C():
    n = I()
    f = LIR(n)
    po = [1]*11
    for i in range(n):
        k = 0
        p = 1
        for j in range(10):
            k += p*f[i][j]
            p *= 2
            po[j+1] = p
        f[i] = k
    p = LIR(n)
    ans = -float("inf")
    for i in range(1,1024):
        k = 0
        for j in range(n):
            c = i&f[j]
            s = 0
            for l in po:
                if c&l:s += 1
            k += p[j][s]
        ans = max(ans,k)
    print(ans)

def D():
    n,C = LI()
    T = [[0 for i in range(100002)] for j in range(C)]
    for i in range(n):
        s,t,c = LI()
        c -= 1
        T[c][s] += 1
        T[c][t+1] -= 1
    for c in range(C):
        for i in range(100000):
            T[c][i+1] += T[c][i]
    ans = 0
    for i in range(100000):
        k = 0
        for c in range(C):
            if T[c][i]:k += 1
        ans = max(ans, k)
    print(ans)

def E():
    return


def F():
    return


def G():
    return


def H():
    return


if __name__ == "__main__":
    D()

Solution (Python):
import sys

def main():
    input = sys.stdin.readline
    N, C = map(int, input().split())
    dic = [[] for _ in range(C + 1)]
    for _ in range(N):
        s, t, c = input().split()
        dic[int(c)].append([int(s), int(t)])
    for c in range(C + 1):
        l = len(dic[c])
        if l == 1:
            continue
        dic[c] = sorted(dic[c])
        i = 0
        while i < l - 1:
            if i < l - 1 and dic[c][i][1] == dic[c][i + 1][0]:
                dic[c][i + 1][0] += 1
            else:
                i += 1
    f = [0 for _ in range(100002)]
    for c in range(C + 1):
        for t in dic[c]:
            f[t[0]] += 1
            f[t[1] + 1] -= 1
    ans = 0
    for i in range(1, 100001):
        f[i] += f[i - 1]
        if ans < f[i]:
            ans = f[i]
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007


def A():
    return


def B():
    return


def C():
    return


def D():
    n,C = LI()
    T = [[0 for i in range(200002)] for j in range(C)]
    for i in range(n):
        s,t,c = LI()
        c -= 1
        T[c][2*s] += 1
        T[c][2*t+1] -= 1
    for c in range(C):
        for i in range(200000):
            T[c][i+1] += T[c][i]
    ans = 0
    for i in range(200000):
        k = 0
        for c in range(C):
            if T[c][i]:k += 1
        ans = max(ans, k)
    print(ans)

def E():
    return


def F():
    return


def G():
    return


def H():
    return


if __name__ == "__main__":
    D()

Solution (Python):
import sys

def main():
    input = sys.stdin.readline
    N, C = map(int, input().split())
    P = [list(map(int, input().split())) for _ in range(N)]
    P = sorted(P, key=lambda x: x[0])

    V = []
    for p in P:
        flag = True
        for i in range(len(V)):
            if V[i][0] < p[0]:
                V[i] = [p[1], p[2]]
                flag = False
                break
            elif V[i][0] == p[0] and V[i][1] == p[2]:
                V[i] = [p[1], p[2]]
                flag = False
                break
            else:
                continue

        if flag:
            V.append([p[1], p[2]])

    print(len(V))


if __name__ == '__main__':
    main()

Solution (Python):
N, C = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(N)]
L.sort(key=lambda x: x[0])
R = [(L[0][1], L[0][2])]
for s, t, c in L[1:]:
    for i, (t_r, c_r) in enumerate(R):
        if c == c_r and t_r <= s:
            R[i] = (t, c)
            break
        if c != c_r and t_r < s:
            R[i] = (t, c)
            break
    else:
        R.append((t, c))
print(len(R))

Solution (Python):

def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n,c=IL()
imos=[[0]*30 for i in range(pow(10,5))]
for i in range(n):
    s,t,c=IL()
    for j in range(s-1,t):
        imos[j][c-1]=1
ans=0
for i in range(pow(10,5)):
    ans=max(ans,sum(imos[i]))
print(ans)

Solution (Python):
from collections import defaultdict


def main():
    N, C = list(map(int, input().split(' ')))
    s = []
    t = []
    c = []
    channels = defaultdict(lambda: set())
    for i in range(N):
        si, ti, ci = list(map(int, input().split(' ')))
        for t in range(si-1, ti):
            channels[t].add(ci)
    n_recorders = 0
    for t in channels:
        n_recorders = max(n_recorders, len(channels[t]))
    print(n_recorders)



main()

Solution (Python):
START = 0
END = 1


def main():
    N, C = map(int, input().split())
    active = [0] * (C+1)
    seq = []
    for _ in range(N):
        s, t, c = map(int, input().split())
        seq += [(s, START, c), (t, END, c)]
    seq.sort()
    ans = 0
    para = 0
    for i in range(len(seq)):
        time, op, channel = seq[i]
        if op == START:
            if active[channel] == 0:
                para += 1
            active[channel] += 1
        else:
            active[channel] -= 1
            if active[channel] == 0:
                para -= 1
        ans = max(ans, para)
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18

N,C=rl()
stc = [rl() for _ in range(N)]
stc.sort(key=lambda x:(x[2],x[0]))
nstc = []
for s,t,c in stc:
    if len(nstc) != 0 and nstc[-1][2] == c and nstc[-1][1] == s:
        nstc[-1][1] = t
    else:
        nstc.append([s,t,c])

n = len(nstc)

TT=[0]*(2*10**5+5)
for i in range(n):
    TT[2*nstc[i][0] - 1] += 1
    TT[2*nstc[i][1]] -= 1
for i in range(1,len(TT)):
    TT[i] += TT[i-1]
print(max(TT))

Solution (Python):
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18

N,C=rl()
st = [[] for _ in range(C)]
TT1 = [0 for _ in range(10**5+2)]
for i in range(N):
    s,t,c = rl()
    TT1[s] += 1
    TT1[t+1] -= 1
    st[c-1].append([s,t])
for st_i in range(len(st)):
    st_ = st[st_i]
    if len(st_) <= 1: continue
    st_.sort(key=lambda x:x[0])
    l = []
    new = 0
    lst_ = len(st_)
    for i in range(lst_):
        if new == 0:
            s,t = st_[i]
            if i != lst_ -1 and t==st_[i+1][0]:
               new = 1
               continue
            else:
                l.append([s,t])
        else:
            t = st_[i][1]
            if i != lst_ -1 and t==st_[i+1][0]:
                new = 1
                continue
            else:
                l.append([s,t])
    st[st_i] = l


TT2 = [0 for _ in range(10**5+2)]

for st_ in st:
    if len(st_) == 0: continue
    for i in range(len(st_)):
        TT2[st_[i][0]] += 1
        TT2[st_[i][1]+1] -= 1

for i in range(1,len(TT1)):
    TT1[i] += TT1[i-1]
    TT2[i] += TT2[i-1]

print(min(max(TT1),max(TT2)))

Solution (Python):
import pprint

N, C = map(int, input().split())
stc = []

max_time = 0
for _ in range(N):
    tmp = list(map(int,input().split()))
    max_time = max(max_time,tmp[1])
    stc.append(tmp)

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



ongoings = []

ans = 0

for prog in stc:
    
    flag = False
    for og in ongoings:
        if og[2] == prog[2]:
            og[1] = prog[1]
            flag = True
            break
        elif og[1] < prog[0]:
            og[1] = prog[1]
            og[2] = prog[2]
            flag = True
            break
    if not flag:
        ongoings.append(prog)
    
    ans = max(ans,len(ongoings))

print(ans)

Solution (Python):
n, c = map(int, input().split())
program = [tuple(map(int, input().split())) for _ in range(n)]
program.sort()
recorder = [(0, -1)] * c

for s, t, co in program:
    done = 0
    for i in range(c):
        
        f, cp = recorder[i]
        if (f == s or f == s-1) and co == cp:
            recorder[i] = (t, co)
            done = 1
            break
    if done == 0:
        for i in range(c):
            f, cp = recorder[i]
            if f < s:
                recorder[i] = (t, co)
                break
ret = 0
for i in range(c):
    if recorder[i][0] != 0:
        ret += 1
print(ret)

Solution (Python):
N, C = map(int, input().split())
S, T = set(), set()
for _ in range(N):
    s, t, c = map(int, input().split())
    S.add((s, c))
    T.add((t, c))

ST = S & T
S -= ST
T -= ST

S = sorted(S)
T = sorted(T)
ans = 0
cnt = 0
si, ti = 0, 0
while si < len(S):
    if S[si][0] <= T[ti][0]:
        cnt += 1
        ans = max(ans, cnt)
        si += 1
    else:
        cnt -= 1
        ti += 1

print(ans)

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

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

for i in range(n-1) :
    if A[i][2] == A[i+1][2] and A[i+1][0] - A[i][1] <= 1 :
        A[i+1][0] = A[i][0]
        A[i] = [-10, 0, 0]
for i in range(n) :
    A[i][0] -= 1



T = [0 for i in range(10**5+10)]
ans = 0
for i in range(n) :
    if A[i][0] != -11 :
        T[A[i][0]] += 1
        T[A[i][1]] -= 1

for i in range(len(T)-1) :
    T[i+1] += T[i]

print(max(T))

Solution (Python):

N,C = map(int, input().split())
st = [[] for _ in range(C)]
for _ in range(N):
    si,ti,ci = map(int, input().split())
    st[ci-1].append((si,ti))
    
T_MAX = int(1e5)
imos = [0]*(T_MAX+1)
for ch in range(C):
    if st[ch]==[]: continue
    st[ch].sort()
    prev_s, prev_t = st[ch][0]
    for si,ti in st[ch][1:]:
        if si!=prev_t:
            imos[prev_s-1] += 1
            imos[prev_t] -= 1
        else:
            imos[prev_s-1] += 1
            imos[prev_t-1] -= 1
        prev_s,prev_t = si,ti
    else:
        imos[prev_s-1] += 1
        imos[prev_t] -= 1

ans = 1
wa = 0
for imosi in imos:
    wa += imosi
    ans = max(ans, wa)
print(ans)

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


print(ans)