Rank participants by solved count, then penalty, and count how many solved as many problems as the fifth place but finished below it.
Easy3SortingImplementationInterviewNo attempts yetTime limit2sMemory limit512 MBshake! is a joint programming contest of six universities: Ajou University, Kyung Hee University, Sungkyunkwan University, Inha University, Korea Aerospace University, and Hanyang University ERICA. Each year the first place student receives a laptop, and students through fifth place receive certificates and prizes.
In 2018 the contest runs with ST Unitas. Stella (STELLA) is an AI employee of ST Unitas. Stella admires humans and feels sorry that benefits reach only a few students. Stella decided to give chicken gift cards. To avoid heavy loss to the company, Stella gives gift cards only to students who solved as many problems as the fifth place student but missed the award on penalty.
An AI employee cannot program yet, so you help Stella. Compute how many gift cards Stella must buy when ranks follow the rules below.
The first line has the number of participants N (5≤N≤66).
Each of the next N lines has the solved count and the total penalty of one participant, separated by a space. The solved count is an integer from 0 to 8, and the total penalty is an integer from 0 to 100000. The fifth place student solved at least one problem. No two students who solved at least one problem share both the same solved count and the same penalty.
Print the number of students who solved as many problems as the fifth place student but missed the award.
Consider the records ordered from the top as (7,620), (5,300), (5,420), (4,340), (4,500), (4,510), (2,420). The fifth record is (4,500), and the sixth record still has 4 solved problems, so 1 student misses the award. Compare solved counts first and penalties next.