import bisect
import sys
n = int(input())
stars = []
for i in range(n):
x, y, z = map(int, input().split())
stars.append((x, y, z))
stars.sort(key = lambda P: (P[0], P[1]))
coor = []
ans = 0
for x,y,z in stars:
if z == 0:
bisect.insort(coor, y)
else:
pos = bisect.bisect_left(coor, y)
if pos>0:
ans += 1
coor.pop(pos-1)
print(ans)



京公网安备 11010502036488号