Penalty calculation
Time limit1sMemory limit256 MB
Find the earliest submission with the highest score and compute the penalty from its time and attempt count.
- Level
Easy1 of 10
- Topics
- Implementation
- Solved
- No attempts yet
Problem
The penalty rule of the second kriiICPC is too complicated, so the organizers decided to hand the penalty computation to you.
Suppose you sent submissions for one problem. The -th submission () was sent minutes after the contest started and scored points.
The penalty for this problem is defined as follows. Let be the smallest with , that is, the index of the earliest submission among those with the highest score. Then is:
- if , then
- if or , then
Given the submissions you sent for one problem, write a program that computes the penalty you get on it.
Input
The first line contains the number of submissions ().
Each of the next lines contains two integers and separated by a space. It is guaranteed that , and each is 0, 1, or 4.
Output
Print the value of on the first line.