Embassy

No attempts yetTime limit1sMemory limit128 MB

Problem

There are NN participants standing in a single line in front of an embassy. An embassy official talks to exactly one participant for exactly one unit of time, so the participant standing in the kk-th position of the queue finishes at time kk.

Participants are numbered from 11 to NN in the order they enter. Participant ii has a train departure time did_i (in time units) and a ticket change fee wiw_i. If a participant finishes at or before time did_i, they catch their train. However, if they finish after time did_i, they miss their train and must change their ticket, which costs a fee of wiw_i.

A fund covers the sum of all such ticket change fees and wants to make that sum as small as possible. You may arrange the participants in the queue in any order. Find the minimum total fee the fund must pay.

Input

The first line contains the number of participants NN.

Each of the next NN lines describes one participant: the (i+1)(i+1)-th line contains did_i and wiw_i of participant ii, separated by a single space.

All numbers are positive integers not greater than 3000030000.

Output

Print, on a single line, the minimum total fee the fund must pay.