ГлавнаяСборникиТурнирыРазделыФорумыУчастникиПечатьПомощьО системе

Разделы > Неотсортированные > задача:


Проходной балл

Задачи раздела

• Поезд
• Покер
• Последовательность
• Почтовые цифры
• Премьер-министр
• Прогрессия
• Пропущенные цифры
• Простая задача
• Проходной балл
• Прямоугольники
• Радиовышки
• Разложение на простые множители
• Разложение на слагаемые
• Рим цифрасын санга айландыруу
• Роботы
• Саптан тузулгон создук
• Симметричная матрица

Обратная связь

Если у вас есть предложения или пожелания по работе Contester, посетите форум сайта www.contester.ru.

Лимит времени 1000/1000/4000/4000 мс. Лимит памяти 265000/265000/65000/65000 Кб.

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 whose 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 whose 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 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 - identifier 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 value of M.

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