def sort_student(students):
i = 0
j = 1
student = {}
for student in students:
pass
while j < len(students):
i = 0
while i < len(students) - j:
s = students[i]
t = students[i+1]
if s['sum_f'] < t['sum_f']:
student = students[i]
students[i] = students[i+1]
students[i+1] = student
elif (students[i]['sum_f'] == students[i+1]['sum_f']) and (students[i]['d_f'] < students[i+1]['d_f']):
student = students[i]
students[i] = students[i+1]
students[i+1] = student
elif (students[i]['sum_f'] == students[i+1]['sum_f'])and (students[i]['d_f'] == students[i+1]['d_f']) and (students[i]['number'] > students[i+1]['number']):
student = students[i]
students[i] = students[i+1]
students[i+1] = student
i += 1
j += 1
def printf(students):
for student in students:
print(student['number'], end = ' ')
print(student['d_f'], end = ' ')
print(student['c_f'])
def Printf(student_0):
if len(student_0) > 0:
sort_student(student_0)
printf(student_0)
n, L, H = map(int, input().split())
students = []
students_both = []
student_2 = []
student_3 = []
student_4 = []
for number in range(1,n+1):
number, d_f, c_f = input().split()
d_f = int(d_f)
c_f = int(c_f)
number = int(number)
student = {'number': number,
'd_f': d_f,
'c_f': c_f,
'sum_f': d_f + c_f}
students.append(student)
i = 0
num = 0
while i < n:
student = students[i]
if student['c_f'] >= L and student['d_f'] >= L:
num += 1
if student['c_f'] >= H and student['d_f'] >= H:
students_both.append(student)
elif student['c_f'] < H and student['d_f'] >= H:
student_2.append(student)
elif student['c_f'] < H and student['d_f'] < H and student['d_f'] >= student['c_f']:
student_3.append(student)
else:
student_4.append(student)
i += 1
print(num)
Printf(students_both)
Printf(student_2)
Printf(student_3)
Printf(student_4)