This page is still under construction.

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

Software Licenses

Time limit1sMemory limit128 MB

Summary
Schedule n licenses, one per month, when license i costs P_i * R_i^t if bought after t months, and minimize total cost.
Level

Medium6 of 10

Topics
Greedy, Sorting, Math, Implementation
Solved
No attempts yet

Problem

You are launching a security company that must obtain licenses for nn different pieces of cryptographic software. Regulations let you obtain at most one license per month.

License ii currently sells for PiP_i dollars, but every license appreciates along an exponential growth curve: the price of license ii grows by a factor of Ri>1R_i > 1 each month. Concretely, if you wait tt months before buying license ii (so t=0t = 0 means buying it in the first month at its current price), it costs Pi⋅RitP_i \cdot R_i^{t} dollars.

Because you may buy at most one license per month, obtaining all nn licenses takes exactly nn months: you buy exactly one license in each of the months t=0,1,…,n−1t = 0, 1, \dots, n - 1. Decide which license to buy in each month so that the total amount paid is as small as possible, and report that minimum total cost.

Input

The first line contains a positive integer nn (1≤n≤1001 \le n \le 100), the number of licenses you must obtain.

Each of the next nn lines contains two numbers PiP_i and RiR_i (Ri>1R_i > 1): the current price of license ii and its monthly growth factor.

Output

Print a single line containing the minimum total cost, rounded to two decimal places.

Examples2

  1. Example 1

    Input
    4
    200.0 1.01
    300 1.12
    400 1.05
    650 1.1
    
    Expected output
    1633.06
    
  2. Example 2

    Input
    2
    100 1.1
    1000 1.05
    
    Expected output
    1110.00