#P14575. 坤班

坤班

Description

Legendary Face Middle School is now recruiting students!

There are nn teachers in the school, and they need to teach mm subjects. Each teacher can use a triple (ai,bi,ci)(a_i,b_i,c_i) to indicate that he teaches aia_i, and can teach at most bib_i classes. If ci=0c_i = 0, it means that teacher ii is unwilling to be a class teacher, otherwise it means that he is willing to be a class teacher.

In particular, because being a class teacher will consume a lot of energy, if a teacher ii chooses to be a class teacher, he can only teach at most bi1b_i - 1 classes.

Of course, each class must have a class teacher, and each subject must have a teacher. It should be noted that a class teacher does not necessarily have to be the subject teacher of the class he or she is assigned to.

The school hopes to form more classes to recruit more outstanding OIers. The admissions team specially invites you, as a Legendary Grandmaster, to help calculate the maximum number of classes that can be formed.

Input Format

The first line reads two positive integers n,mn,m, which represent the number of teachers and the number of subjects in Legendary Face Middle School.

Next nn, each line contains three integers ai,bi,cia_i,b_i,c_i, as described in the question.

Output Format

The output is one line, indicating the maximum number of classes that can be formed in Legendary Face Middle School.

5 2
1 2 1
1 2 1
1 1 0
2 2 1
2 2 1
3

Hint

Sample Explanation

Teachers numbered 1,2,41,2,4 are homeroom teachers for three classes, respectively.

Teachers numbered 1,2,31,2,3 teach Subject 1 to three classes, respectively.

Teacher numbered 44 teaches Subject 2 to one class, and teacher numbered 55 teaches Subject 3 to two classes.

Data range

Subtask nn \leq Special Properties Score
Subtask 1 5×1055 \times 10^5 A 55
Subtask 2 2020 None 1515
Subtask 3 3×1033 \times 10^3 B 2020
Subtask 4 None
Subtask 5 5×1055 \times 10^5 B
Subtask 6 None
  • Special property A: Satisfy i[1,n],ci=0\forall i \in [1,n],c_i = 0.
  • Special property B: i[1,n],bi=1\forall i \in [1,n],b_i = 1.

For 100%100\% of the data:

  • mnm \leq n.
  • i[1,n]\forall i \in [1,n], 1aim1 \leq a_i \leq m, 1bin1 \leq b_i \leq n, ci{0,1}c_i \in \{0,1\}.