Pizza delivery

아직 제출이 없습니다시간 제한2초메모리 제한1024 MB

문제

JAG Pizza is the famous pizza shop. Since the number of delivery orders has been increasing, it has been busier than before.

One day, several orders came to this shop at the same time! There were NN orders, and NN customers who placed the order. The ii-th customer placed the ii-th order.

Through past orders, this shop knows information for each customer. For the ii-th customer, it takes t_it\_i hours for delivering the pizza from the shop, and also takes t_it\_i hours for going back to the shop. Moreover, his or her "irritability" is a_ia\_i. The bigger irritability a person has, the easier to be angry.

JAG Pizza has to deliver orders for customers, and keep their minds on less customer stress. To formulate the amount of stress which the ii-th customer feels, let h_ih\_i be the time from order to delivery, and let p_ip\_i be the number of other customers whose delivery time is faster than that of ii-th customer. The amount of stress for the ii-th customer (s_is\_i) is formulated as follows: s_i=a_i×(h_i+p_i)s\_i = a\_i \times (h\_i + p\_i).

For less customer stress, and gaining high satisfaction rates, a better delivery plan is necessary. When you think about it, you must take the following things into account:

  • There is only one delivery person.
  • A delivery person cannot deliver several orders in parallel. It means that he or she can deliver a single order at once, and when achieved, he or she gets back to the shop for delivering the next order.
  • You can assume that it tooks no time for preparing an order, passing it from the shop to a delivery person, and passing it from a delivery person to a customer.

You are the delivery planner of JAG Pizza. Above these information and conditions, you have to minimize the total amount of stress for all customers.

입력

The input consists of a single test case of the following format.

NN

t_1t\_1 a_1a\_1

\vdots

t_Nt\_N a_Na\_N

The first line is the number NN of customers (1N100,0001 ≤ N ≤ 100\\,000).

The ii-th of the following NN lines consists of two integers t_it\_i and a_ia\_i, which represent that it takes t_it\_i (1t_i1,0001 ≤ t\_i ≤ 1\\,000) hours for delivering the pizza from the shop to the ii-th customer, and also takes t_it\_i hours for going back to the shop. Moreover, its irritability is a_ia\_i (1a_i1,0001 ≤ a\_i ≤ 1\\,000).

출력

Print the minimum total amount of stress.