from sys import stdin
#開始蒐集
people1=[]
people2=[]
for _ in range(int(input())):
ty,s,e=map(int,stdin.readline().split())
if ty==1:
people1.extend([x for x in range(s,e)])
elif ty==2:
people2.extend([x for x in range(s,e)])
people1=set(people1)
people2=set(people2)
good=list(people1.difference(people2))
#結束蒐集,處理區間
del people1,people2
collect=[];temp=[]
for _ in range(len(good)):
try:
temp.append(good[_])
if good[_]+1==good[_+1]:
continue
else:
collect.append(temp)
temp=[]
except:
collect.append(temp)
del temp
#輸出
print(len(collect))
for opt in collect:
print(opt[0],opt[-1]+1)