This page is still under construction.

Parts of this page are still being built. What you see may change.

Penalty calculation

Time limit1sMemory limit256 MB

Summary
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 nn submissions for one problem. The ii-th submission (1≤i≤n1 \le i \le n) was sent tit_i minutes after the contest started and scored sis_i points.

The penalty PP for this problem is defined as follows. Let ff be the smallest kk with sk=max⁡{s1,s2,…,sn}s_k = \max\{s_1, s_2, \dots, s_n\}, that is, the index of the earliest submission among those with the highest score. Then PP is:

  • if sf=0s_f = 0, then P=0P = 0
  • if sf=1s_f = 1 or sf=4s_f = 4, then P=tf+(f−1)×20P = t_f + (f - 1) \times 20

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 nn (1≤n≤1001 \le n \le 100).

Each of the next nn lines contains two integers tit_i and sis_i separated by a space. It is guaranteed that 1≤t1<t2<⋯<tn≤3001 \le t_1 < t_2 < \cdots < t_n \le 300, and each sis_i is 0, 1, or 4.

Output

Print the value of PP on the first line.

Examples4

  1. Example 1

    Input
    1
    300 4
    
    Expected output
    300
    
  2. Example 2

    Input
    2
    1 1
    2 4
    
    Expected output
    22
    
  3. Example 3

    Input
    4
    1 0
    2 1
    3 0
    5 4
    
    Expected output
    65
    
  4. Example 4

    Input
    3
    1 0
    10 0
    100 0
    
    Expected output
    0