Buggy python submission (verdict: Time Limit Exceeded):
n,C=map(int,input().split())
N=10**5+1
INF = 2**31-1
 
LV = N.bit_length()
N0 = 2**LV
data = [0]*(2*N0)
lazy = [0]*(2*N0)
 
def gindex(l, r):
    L = l + N0; R = r + N0
    lm = (L // (L & -L)) >> 1
    rm = (R // (R & -R)) >> 1
    while L < R:
        if R <= rm:
            yield R
        if L <= lm:
            yield L
        L >>= 1; R >>= 1
    while L:
        yield L
        L >>= 1
 
def propagates(*ids):
    for i in reversed(ids):
        v = lazy[i-1]
        if not v:
            continue
        lazy[2*i-1] += v; lazy[2*i] += v
        data[2*i-1] += v; data[2*i] += v
        lazy[i-1] = 0
 
def update(l, r, x):
    L = N0 + l; R = N0 + r
    while L < R:
        if R & 1:
            R -= 1
            lazy[R-1] += x; data[R-1] += x
        if L & 1:
            lazy[L-1] += x; data[L-1] += x
            L += 1
        L >>= 1; R >>= 1
    for i in gindex(l, r):
        data[i-1] = min(data[2*i-1], data[2*i]) + lazy[i-1]
 
def query(l, r):
    propagates(*gindex(l, r))
    L = N0 + l; R = N0 + r
 
    s = INF
    while L < R:
        if R & 1:
            R -= 1
            s = min(s, data[R-1])
        if L & 1:
            s = min(s, data[L-1])
            L += 1
        L >>= 1; R >>= 1
    return s

a=[[0 for i in range(N)]for i in range(C)]

for i in range(n):
    s,t,c=map(int,input().split())
    recs,rect=a[c-1][s],a[c-1][t]
    if recs==0 and rect==0:
        update(s-1,t,-1)
    elif recs==0 and rect==1:
        update(s-1,t-1,-1)
    elif recs==1 and rect==0:
        update(s,t,-1)
    elif recs==1 and rect==1 and s<t-1:
        update(s,t-1,-1)
    a[c-1][s],a[c-1][t]=1,1
print(-query(0,N+1))

Fixed submission:
import sys
import math
from itertools import accumulate as acc

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


a=[[0 for i in range(10**5+1)] for i in range(C+1)]

rec=[0 for i in range(10**5+1)]

for i in range(N):
    s,t,c=map(int,input().split())
    recs,rect=a[c][s],a[c][t]
    if recs==0 and rect==0:
        rec[s-1]+=1
        rec[t]-=1
    elif recs==0 and rect==1:
        rec[s-1]+=1
        rec[t-1]-=1
    elif recs==1 and rect==0:
        rec[s]+=1
        rec[t]-=1
    elif recs==1 and rect==1:
        rec[s]+=1
        rec[t-1]-=1

    a[c][s],a[c][t]=1,1

tmp=0
ans=0
for i in range(10**5):
    tmp+=rec[i]
    ans=max(tmp,ans)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,C=map(int,input().split())
N=10**5+1
INF = 2**31-1
 
LV = N.bit_length()
N0 = 2**LV
data = [0]*(2*N0)
lazy = [0]*(2*N0)
 
def gindex(l, r):
    L = l + N0; R = r + N0
    lm = (L // (L & -L)) >> 1
    rm = (R // (R & -R)) >> 1
    while L < R:
        if R <= rm:
            yield R
        if L <= lm:
            yield L
        L >>= 1; R >>= 1
    while L:
        yield L
        L >>= 1
 
def propagates(*ids):
    for i in reversed(ids):
        v = lazy[i-1]
        if not v:
            continue
        lazy[2*i-1] += v; lazy[2*i] += v
        data[2*i-1] += v; data[2*i] += v
        lazy[i-1] = 0
 
def update(l, r, x):
    L = N0 + l; R = N0 + r
    while L < R:
        if R & 1:
            R -= 1
            lazy[R-1] += x; data[R-1] += x
        if L & 1:
            lazy[L-1] += x; data[L-1] += x
            L += 1
        L >>= 1; R >>= 1
    for i in gindex(l, r):
        data[i-1] = min(data[2*i-1], data[2*i]) + lazy[i-1]
 
def query(l, r):
    propagates(*gindex(l, r))
    L = N0 + l; R = N0 + r
 
    s = INF
    while L < R:
        if R & 1:
            R -= 1
            s = min(s, data[R-1])
        if L & 1:
            s = min(s, data[L-1])
            L += 1
        L >>= 1; R >>= 1
    return s

a=[[0 for i in range(N)]for i in range(C)]

for i in range(n):
    s,t,c=map(int,input().split())
    recs,rect=a[c-1][s],a[c-1][t]
    if recs==0 and rect==0: update(s-1,t,-1)
    elif recs==0 and rect==1: update(s-1,t-1,-1)
    elif recs==1 and rect==0: update(s,t,-1)
    elif recs==1 and rect==1 and s<t-1: update(s,t-1,-1)
    a[c-1][s],a[c-1][t]=1,1
print(-query(0,N+1))

Fixed submission:
import sys
import math
from itertools import accumulate as acc

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


a=[[0 for i in range(10**5+1)] for i in range(C+1)]

rec=[0 for i in range(10**5+1)]

for i in range(N):
    s,t,c=map(int,input().split())
    recs,rect=a[c][s],a[c][t]
    if recs==0 and rect==0:
        rec[s-1]+=1
        rec[t]-=1
    elif recs==0 and rect==1:
        rec[s-1]+=1
        rec[t-1]-=1
    elif recs==1 and rect==0:
        rec[s]+=1
        rec[t]-=1
    elif recs==1 and rect==1:
        rec[s]+=1
        rec[t-1]-=1

    a[c][s],a[c][t]=1,1

tmp=0
ans=0
for i in range(10**5):
    tmp+=rec[i]
    ans=max(tmp,ans)
print(ans)