qyliang/CodeNanoFix huggingface dataset:
Buggy code:
from collections import defaultdict as dd
N, C = tuple(map(int, input().split()))
events = []
tmax = 0
dic=dd(list)
for i in range(N):
    s, t, c = map(int, input().split())
    dic[c].append((s,t))
eps = 0.5
for k,v in dic.items():
    v1 = sorted(v)
    lev = len(v)
    prev = [-1,-1]
    for i,val in enumerate(v1):
        if tmax < val[1]:
            tmax = val[1]
        if prev == [-1,-1]:
            prev[0] = val[0]
            prev[1] = val[1] # end_time
            if lev != 1:
                continue
            else:
                events.append((prev[0]-eps, 1))
                events.append((prev[1], 0))
                break
        if prev[1] == val[0]:# prev_end == now_start
            prev[1] = val[1]
            if i == lev - 1:
                events.append((prev[0] - eps, 1))
                events.append((prev[1], 0))
                break
        else:
            events.append((prev[0]-eps, 1))
            events.append((prev[1], 0))
            prev = val
            if i==lev-1:
                events.append((val[0]-eps, 1))
                events.append((val[1], 0))
                break
events.sort()
print("1")
exit()
idx = 0
cnt = 0
res = 0
events.append((0,-1))
for t in range(tmax + 1):
    while events[idx][0] <= t:
        event = events[idx]
        if event[1] == 1:
            cnt += 1
            if res < cnt:
                res = cnt
        elif event[1] == 0:
            cnt -= 1
        else:
            break
        idx += 1
print(res)

Fixed code:
from collections import defaultdict as dd
N, C = tuple(map(int, input().split()))
events = []
tmax = 0
dic=dd(list)
for i in range(N):
    s, t, c = map(int, input().split())
    dic[c].append((s,t))
eps = 0.5
for k,v in dic.items():
    v1 = sorted(v)
    lev = len(v1)
    prev = [-1,-1]
    for i,val in enumerate(v1):
        if tmax < val[1]:
            tmax = val[1]
        if prev == [-1,-1]:
            prev[0] = val[0]
            prev[1] = val[1] # end_time
            if lev != 1:
                continue
            else:
                events.append((prev[0]-eps, 1))
                events.append((prev[1], 0))
                break
        if prev[1] == val[0]:# prev_end == now_start
            prev[1] = val[1]
            if i == lev - 1:
                events.append((prev[0] - eps, 1))
                events.append((prev[1], 0))
                break
        else:
            events.append((prev[0]-eps, 1))
            events.append((prev[1], 0))
            prev[0] = val[0]
            prev[1] = val[1]
            if i==lev-1:
                events.append((val[0]-eps, 1))
                events.append((val[1], 0))
                break
events.sort()
idx = 0
cnt = 0
res = 0
events.append((0,-1))
for t in range(tmax + 1):
    while events[idx][0] <= t:
        event = events[idx]
        if event[1] == 1:
            cnt += 1
            if res < cnt:
                res = cnt
        elif event[1] == 0:
            cnt -= 1
        else:
            break
        idx += 1
print(res)
Buggy code:
import sys
input = sys.stdin.readline

N, C = [int(x) for x in input().split()]
imos = [0]*(10**6 + 2)
stc = [[] for _ in range(31)]
for _ in range(N):
    tmp = [int(x) for x in input().split()]
    stc[tmp[2]].append([tmp[0], tmp[1]])
print(stc)
for i in range(C + 1):
    if len(stc[i]) == 0:
        continue
    stc[i].sort()
    s, t = stc[i][0][0], stc[i][0][1]
    new_stc_i = []
    flag = 1
    for j in range(1, len(stc[i])):
        flag = 0
        if t == stc[i][j][0]:
            t = stc[i][j][1]
            flag = 1
        else:
            new_stc_i.append([s, t])
            s = stc[i][j][0]
            t = stc[i][j][1]
    if flag:
        new_stc_i.append([s, t])
    stc[i] = new_stc_i

for i in range(C + 1):
    stc_i = stc[i]
    for j in stc_i:
        s, t = j 
        s *= 10
        t *= 10
        imos[max(0, s - 5)] += 1
        imos[t] -= 1

from itertools import accumulate

csum = list(accumulate(imos))

print(max(csum))

Fixed code:
import sys
input = sys.stdin.readline

N, C = [int(x) for x in input().split()]
imos = [0]*(10**6 + 2)
stc = [[] for _ in range(31)]
for _ in range(N):
    tmp = [int(x) for x in input().split()]
    stc[tmp[2]].append([tmp[0], tmp[1]])

for i in range(C + 1):
    if len(stc[i]) == 0:
        continue
    stc[i].sort()
    s, t = stc[i][0][0], stc[i][0][1]
    new_stc_i = []
    flag = 1
    for j in range(1, len(stc[i])):
        flag = 0
        if t == stc[i][j][0]:
            t = stc[i][j][1]
            flag = 1
        else:
            new_stc_i.append([s, t])
            s = stc[i][j][0]
            t = stc[i][j][1]
    if flag:
        new_stc_i.append([s, t])
    stc[i] = new_stc_i

for i in range(C + 1):
    stc_i = stc[i]
    for j in stc_i:
        s, t = j 
        s *= 10
        t *= 10
        imos[max(0, s - 5)] += 1
        imos[t] -= 1

from itertools import accumulate

csum = list(accumulate(imos))

print(max(csum))
Buggy code:
import sys
from collections import *
import heapq
import math
# from math import gcd
import bisect
import copy
from itertools import permutations,accumulate,combinations,product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n,c=map(int,input().split())
stc=[list(map(int,input().split())) for i in range(n)]
stc.sort()
lst=[0]*c
for i in range(n):
    for j in range(c):
        if lst[j]==0:
            lst[j]=stc[i]
            break
        else:
            if lst[j][2]==stc[i][2]:
                lst[j]=stc[i]
                break
            elif lst[j][1]<stc[i][1]:
                lst[j]=stc[i]
                break

ans=0
for i in range(c):
    if lst[i]!=0:
        ans+=1
print(ans)

Fixed code:
import sys
from collections import *
import heapq
import math
# from math import gcd
import bisect
import copy
from itertools import permutations,accumulate,combinations,product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n,c=map(int,input().split())
stc=[list(map(int,input().split())) for i in range(n)]
stc.sort()
lst=[0]*c
for i in range(n):
    s,t,ctmp=stc[i]
    for j in range(c):
        if lst[j]==0:
            lst[j]=stc[i]
            break
        else:
            if lst[j][2]==ctmp:
                lst[j]=stc[i]
                break
            elif lst[j][1]<s:
                lst[j]=stc[i]
                break
# print(lst)
ans=0
for i in range(c):
    if lst[i]!=0:
        ans+=1
print(ans)
Buggy code:
n,C=map(int,input().split())
stc=[[int(i) for i in input().split()] for _ in range(n)]
dp=[0]*(2*10**5+2)
for j in range(C):
  tmp=[0]*(2*10**5+2)
  for s,t,c in stc:
    if j == c:
      tmp[2*s-1]+=1
      tmp[2*t]-=1
  dp[0]+=tmp[0]>0
  for i in range(2*10**5+1):
    tmp[i+1]+=tmp[i]
    dp[i+1]+=tmp[i+1]>0
print(max(dp))


Fixed code:
n,C=map(int,input().split())
stc=[[int(i) for i in input().split()] for _ in range(n)]
dp=[0]*(2*10**5+2)
for j in range(1,C+1):
  tmp=[0]*(2*10**5+2)
  for s,t,c in stc:
    if j == c:
      tmp[2*s-1]+=1
      tmp[2*t]-=1
  for i in range(2*10**5+1):
    tmp[i+1]+=tmp[i]
    dp[i+1]+=tmp[i+1]>0
print(max(dp))
Buggy code:
N,C = map(int,input().split())
T = [[0 for i in range(C)] for j in range(10**5+1)]

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

ans = 0
for i in range(1,10**5+1):
    a = 0
    for j in range(C):
        if T[i][j] or T[i][j-1]:
            a += 1
    ans = max(ans,a)
print(ans)

Fixed code:
N,C = map(int,input().split())
T = [[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())
    T[c-1][s] += 1
    T[c-1][t] -= 1
for i in range(C):
    for j in range(10**5):
        T[i][j+1] += T[i][j]

ans = 0
for i in range(1,10**5+1):
    a = 0
    for j in range(C):
        if T[j][i] or T[j][i-1]:
            a += 1
    ans = max(ans,a)
print(ans)
Buggy code:
import sys
input=sys.stdin.buffer.readline
n,c=map(int,input().split())
a=[ [0 for _ in range(10**5+2)] for _ in range(c)]
for _ in range(n):
    s,t,cc=map(int,input().split())
    cc-=1
#    print(s-1,end=' s-1\n')
    a[cc][s-1]+=1
    a[cc][t]-=1
    '''for i in range(s-1,t):
        a[cc][i]=1'''
for i in range(c):
    for j in range(1,10**5+1):
        a[i][j]+=a[i][j-1]

ans=1
for j in range(0,10**5):
    su=0
#    print(c,'hello')
    for i in range(c):
#        print('asdf hello')
#        print(j,i,a[i][j])
        assert a[i][j]<=1
        su+=a[i][j]
    ans=max(ans,su)
print(ans)


Fixed code:
import sys
input=sys.stdin.buffer.readline
n,c=map(int,input().split())
a=[ [0 for _ in range(10**5+2)] for _ in range(c)]
for _ in range(n):
    s,t,cc=map(int,input().split())
    cc-=1
#    print(s-1,end=' s-1\n')
    #a[cc][s-1]+=1
    #a[cc][t]-=1
    for i in range(s-1,t):
        a[cc][i]=1
'''for i in range(c):
    for j in range(1,10**5+1):
        a[i][j]+=a[i][j-1]
'''
ans=1
for j in range(0,10**5+1):
    su=0
#    print(c,'hello')
    for i in range(c):
#        print('asdf hello')
#        print(j,i,a[i][j])
        su+=a[i][j]
    ans=max(ans,su)
print(ans)
Buggy code:
n,c = map(int,input().split())
L = [[] for i in range(c)]
for i in range(n):
    s,t,k = map(int,input().split())
    L[k-1].append([s,t])
for i in range(c):
    L[i].sort()
for i in range(c):
    d = [0]*(10**5+1)
    T = []
    for j in range(len(L[i])):
        d[L[i][j][0]] += 1
        d[L[i][j][1]] -= 1
    for j in range(10**5):
        d[j+1] += d[j]
    cur = 0
    start = 0
    end = 0
    for j in range(10**5+1):
        if d[j] == 1 and cur == 0:
            start = j
            cur = 1
        elif d[j] == 0 and cur == 1:
            end = j
            cur = 0
            T.append([start*2-1, end*2])
    L[i] = T
dp = [0]*(10**5)*2+3
ans = 0
for i in range(c):
    for j in range(len(L[i])):
        dp[L[i][j][0]] += 1
        dp[L[i][j][1]] -= 1
for j in range(1,(10**5)*2+3):
    dp[j] = dp[j-1]+dp[j]
    ans = max(ans, dp[j])
print(ans)


Fixed code:
n,c = map(int,input().split())
L = [[] for i in range(c)]
for i in range(n):
    s,t,k = map(int,input().split())
    L[k-1].append([s,t])
for i in range(c):
    L[i].sort()
for i in range(c):
    d = [0]*(10**5+1)
    T = []
    for j in range(len(L[i])):
        d[L[i][j][0]] += 1
        d[L[i][j][1]] -= 1
    for j in range(10**5):
        d[j+1] += d[j]
    cur = 0
    start = 0
    end = 0
    for j in range(10**5+1):
        if d[j] == 1 and cur == 0:
            start = j
            cur = 1
        elif d[j] == 0 and cur == 1:
            end = j
            cur = 0
            T.append([start*2-1, end*2])
    L[i] = T
dp = [0]*(10**5)*3
ans = 0
for i in range(c):
    for j in range(len(L[i])):
        dp[L[i][j][0]] += 1
        dp[L[i][j][1]] -= 1
for j in range(1,(10**5)*3):
    dp[j] = dp[j-1]+dp[j]
    ans = max(ans, dp[j])
print(ans)
Buggy code:
N,C=map(int,input().split())
from collections import defaultdict
Cbef=defaultdict(int)
time=defaultdict(int)
TV=[tuple(map(int,input().split())) for i in range(N)]
TV.sort(key=lambda x:x[0])
for s,t,c in TV:
    if Cbef[c]==s:
        time[s]+=1
        time[t]-=1
        Cbef[c]=t
    else:
        time[s-1]+=1
        time[t]-=1
        Cbef[c]=t
ans=0
now=time[0]
ans=now
for i in range(1,10**5+1):
    now+=time[i]
print(ans)

Fixed code:
N,C=map(int,input().split())
from collections import defaultdict
Cbef=defaultdict(int)
time=defaultdict(int)
TV=[tuple(map(int,input().split())) for i in range(N)]
TV.sort(key=lambda x:x[0])
for s,t,c in TV:
    if Cbef[c]==s:
        time[s]+=1
        time[t]-=1
        Cbef[c]=t
    else:
        time[s-1]+=1
        time[t]-=1
        Cbef[c]=t
ans=0
now=time[0]
ans=now
for i in range(1,10**5+1):
    now+=time[i]
    ans=max(ans,now)
print(ans)
Buggy code:
import sys
input = sys.stdin.buffer.readline
from operator import itemgetter

def main():
    N,C = map(int,input().split())
    ch = [[] for _ in range(C)]
    
    for _ in range(N):
        s,t,c = map(int,input().split())
        ch[c-1].append((s,t))
    
    for x in ch:
        x.sort(key=itemgetter(0))
    
    print(ch)
    imos = [0 for _ in range(10**5+2)]
    for x in ch:
        now = -1
        for st,ft in x:
            if st == now:
                imos[st] += 1
            else:
                imos[st-1] += 1
            imos[ft] -= 1
            now = ft
                
    for i in range(10**5+1):
        imos[i+1] += imos[i]
    
    print(max(imos))
    
if __name__ == "__main__":
    main()


Fixed code:
import sys
input = sys.stdin.buffer.readline
from operator import itemgetter

def main():
    N,C = map(int,input().split())
    ch = [[] for _ in range(C)]
    l = 0
    for _ in range(N):
        s,t,c = map(int,input().split())
        l = max(l,t)
        ch[c-1].append((s,t))
    
    for x in ch:
        x.sort(key=itemgetter(0))

    imos = [0 for _ in range(l+2)]
    for x in ch:
        now = -1
        for st,ft in x:
            if st == now:
                imos[st] += 1
            else:
                imos[st-1] += 1
            imos[ft] -= 1
            now = ft
                
    for i in range(l+1):
        imos[i+1] += imos[i]
    
    print(max(imos))
    
if __name__ == "__main__":
    main()
Buggy code:
N, C = map(int, input().split())
dic = []
L = 0
for i in range(N):
  s, t, c = map(int, input().split())
  dic += [(c-1,s,t)]
  if t+1>L:
    L = t+1

sm = [0]*L
for c in range(C):
  tt = [0]*(L)
  for i in range(N):
    if dic[i][0]==c:
      tt[dic[i][1]*2-1] += 1
      tt[dic[i][2]*2] -= 1
  for i in range(1,L):
    tt[i] += tt[i-1]
  for i in range(L):
    if tt[i]>0:
      sm[i] += 1
print(max(sm))

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

L = 2*100000+1
sm = [0]*L
for c in range(C):
  tt = [0]*(L)
  for i in range(N):
    if dic[i][0]==c:
      tt[dic[i][1]*2-1] += 1
      tt[dic[i][2]*2] -= 1
  for i in range(1,L):
    tt[i] += tt[i-1]
  for i in range(L):
    if tt[i]>0:
      sm[i] += 1
print(max(sm))
Buggy code:
n, c = map(int, input().split(" "))

time = list()
for i in range(0, n):
    s, t, c = map(int, input().split(" "))
    time.append((s, t, c))

time_sorted = sorted(time, key=lambda x: (x[2], x[1]))

time_joined = list()
prev = None
for current in time_sorted:
    if prev is None:
        prev = current

    elif prev[2] == current[2] and prev[1] == current[0]:
        prev = (prev[0], current[1], current[2])

    else:
        time_joined.append(prev)
        prev = current

# time_joined.append(prev)
print(time_joined)

time_list = list()
for s, t, c in time_joined:
    time_list.append((s - 0.5, "s"))
    time_list.append((t, "t"))

time_list_sorted = sorted(time_list, key=lambda x: x[0])

current = 0
ans = 0

for t, s in time_list_sorted:
    if s == "s":
        current += 1
        ans = max(ans, current)
    else:
        current -= 1

print(ans)


Fixed code:
n, c = map(int, input().split(" "))

time = list()
for i in range(0, n):
    s, t, c = map(int, input().split(" "))
    time.append((s, t, c))

time_sorted = sorted(time, key=lambda x: (x[2], x[1]))

time_joined = list()
prev = None
for current in time_sorted:
    if prev is None:
        prev = current

    elif prev[2] == current[2] and prev[1] == current[0]:
        prev = (prev[0], current[1], current[2])

    else:
        time_joined.append(prev)
        prev = current

time_joined.append(prev)
# print(time_joined)

time_list = list()
for s, t, c in time_joined:
    time_list.append((s - 0.5, "s"))
    time_list.append((t, "t"))

time_list_sorted = sorted(time_list, key=lambda x: x[0])

current = 0
ans = 0

for t, s in time_list_sorted:
    if s == "s":
        current += 1
        ans = max(ans, current)
    else:
        current -= 1

print(ans)
Buggy code:
import numpy as np

def main():
    input_string = list(map(int,input().split()))
    N = input_string[0]
    C = input_string[1]
    data = []
    for i in range(N):
        data.append(list(map(int,input().split())))

    data_np = np.array(data).reshape(N,3)

    max_time = max(data_np[:,1])
    schedule = np.zeros([max_time,C])

    for i in range(N):
        start = data[i][0]-1
        end = data[i][1]-1
        channel = data[i][2]-1
        for j in range(end-start+1):
            if start+j-1<0:continue
            schedule[start+j-1][channel] = 1

#    for c in range(C):
#        for t in range(max_time):
#            if t==0:continue
#            if schedule[t][c]==1 and schedule[t-1][c]==0:
#                schedule[t-1][c]=1

    #max_N =0
    #for t in range(max_time):
    #    sum_of_ch = sum(schedule[t])

    temp = list(map(sum,list(schedule)))
    max_N = max(temp)


    #    if sum_of_ch>max_N:
    #        max_N = int(sum_of_ch)
    print(max_N)







main()


Fixed code:
def main():
    input_string = list(map(int,input().split()))
    N = input_string[0]
    C = input_string[1]
    data = []
    max_time = 0
    for i in range(N):
        data.append(list(map(int,input().split())))
        max_num = max(data[i])
        if max_num>max_time:
            max_time=max_num

    #data_np = np.array(data).reshape(N,3)
    #data_np = np.array(data)

    #max_time = int(max(data))
    #print("max",max_time)
    schedule = [[0]*C for i in range(max_time)]
    #schedule = np.zeros([max_time,C])

    for i in range(N):
        start = data[i][0]-1
        end = data[i][1]-1
        channel = data[i][2]-1
        for j in range(end-start+1):
            if start+j-1<0:continue
            schedule[start+j-1][channel] = 1

#    for c in range(C):
#        for t in range(max_time):
#            if t==0:continue
#            if schedule[t][c]==1 and schedule[t-1][c]==0:
#                schedule[t-1][c]=1

    #max_N =0
    #for t in range(max_time):
    #    sum_of_ch = sum(schedule[t])

    temp = list(map(sum,list(schedule)))
    max_N = int(max(temp))


    #    if sum_of_ch>max_N:
    #        max_N = int(sum_of_ch)
    print(max_N)







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

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

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

print(max(ct))


Fixed code:
N, C = map(int, input().split())

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

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

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

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

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

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

Fixed code:
N,C = map(int,input().split())

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

history = {}
for i in range(N):
  s,t,c = map(int,input().split())
  s *= 2
  t *= 2
  #print(history)
  if (t-1) in history and c in history[t-1]:
    history[t-1].pop(c)
  else:
    if t in history:
      history[t][c] = dec
    else:history[t] = {c:dec}
  if (s) in history and c in history[s]:
    history[s].pop(c)
  else:
    #history[s-0.5][c] = inc
    if s-1 in history:
      history[s-1][c] = inc
    else:
      history[s-1] = {c:inc}
maximum = 0
counter = 0
for i in range(100000*2):
  if i in history:
    for func in history[i].values():
      counter = func(counter)
    if counter > maximum:
      maximum = counter
#print(history)
print(maximum)
Buggy code:
from heapq import *
from itertools import accumulate as ac
n,c=map(int,input().split())
a=sorted([list(map(int,input().split()))for i in range(n)])
b=[[]for i in range(c+1)]
for i,j,h in a:
    if len(b[h])>0:
        if b[h][-1][1]==i:
            b[h][-1][1]=j
    else:
        b[h].append([i,j])
s=[0]*(10**5+2)
for i in b:
    for h,w in i:
        s[h]+=1
        s[w]-=1
print(sum(list(ac(s))))

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

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