HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Sections > Unsorted > problem:


Passing score

Section problems

• Монополия
• Муравей
• Ball
• Huge parking
• Islands areas
• Train
• Премьер-министр
• Progression
• Passing score
• Jedi vs Sith
• Сортировка времени
• Variant 21
• Variant 22
• Variant 23
• Variant 24
• Variant 25
• Variant 26

Feedback

If you notice incorrect translations in Contester, please let author know.

Time limit 1000/1000/4000/4000 ms. Memory limit 265000/265000/65000/65000 Kb.

Problem description

There are a lot of programming competitions around the world. One of the most serious of them has two tours - regional and final. According to rules next students are invited to the final tour:

  1. Last year winners are invited to the final tour regardless of this year result on the regional tour;
  2. All students who's score is not less than passing score are invited to final tour;
  3. If there isn't any student from some region who passed according to first and second rules, then the student who's score in regional tour is biggest in his region is invited to final tour (if there is any participant from this region at all);
  4. Only M students at most can be invited to final tour.

We know that all students have different scores on regional tour. Help jury in finding minimum passing score so that all rules are satisfied from the information about regional tour.

Input

On the first line there are 3 integers N (number of participants), M (maximum number of participants can be invited), R (number of different regions which could come to the olympiad), where 1<= M < N. On next N lines there are results of every participant. On each line there are 4 integers: id - unique number of student (1 <= id <= N), region - idetifier of region of student (1 <= region <= R), score - participant's score on regional tour (0 <= score <= 109), last number indicates whether participant was winner last year (value is 1) or not (value is 0). We know that there is always a way to satisfy all rules. 1 <= R <= M < N <= 100000.

Output

Write calculated minimum passing score.

Example

stdin stdout

9 6 5
6 1 799 0
2 4 995 0
1 4 989 1
7 2 538 0
5 4 984 0
8 2 1000 0
3 2 998 0
4 2 823 1
9 1 543 0

985

Для отправки решений необходимо выполнить вход.

www.contester.ru