Penalty calculation

No attempts yetTime limit1sMemory limit256 MB

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 (1in1 \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+(f1)×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 (1n1001 \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 1t1<t2<<tn3001 \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.