There are N 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 k-th position of the queue finishes at time k.
Participants are numbered from 1 to N in the order they enter. Participant i has a train departure time di (in time units) and a ticket change fee wi. If a participant finishes at or before time di, they catch their train. However, if they finish after time di, they miss their train and must change their ticket, which costs a fee of wi.
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.
The first line contains the number of participants N.
Each of the next N lines describes one participant: the (i+1)-th line contains di and wi of participant i, separated by a single space.
All numbers are positive integers not greater than 30000.
Print, on a single line, the minimum total fee the fund must pay.