Under construction

Still being built. Things may change

Password Hacking

Interview

Time limit1sMemory limit512 MB

Summary
Given each password's probability of being correct, find the expected number of attempts when trying passwords in the order that minimizes it.
Level

Easy3 of 10

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

Problem

Passwords are not very secure unless users are disciplined enough to pick ones that are hard to guess. Most users are not that careful and happily use passwords such as "123456". Lists of commonly used passwords circulate, attackers run those lists against systems, and the passwords on them work often enough.

You have done a lot of hacking with such a list, so you have a good idea of how likely each password on it is the correct one. The number of people using "123456" still surprises you. You have a new account to hack, and you decide to try the passwords on the list one at a time until the correct one is found. You are certain that the account uses a password from the given list.

Find the expected number of attempts needed to find the correct password, assuming you try the passwords in the best possible order.

Input

The first line contains a positive integer NN, the number of passwords on the list. Each of the next NN lines contains a password, one space, and the probability that this password is the correct one.

Each password is a string of length 11 to 1212 made up only of letters and digits. Each probability is a real number given with exactly 4 decimal places. NN is at most 500500, and the probabilities sum to 11. No password appears twice on the list.

Output

Print on one line the expected number of attempts needed to find the correct password when the attempts are made in the best possible order.

Every probability has exactly 4 decimal places, so the expected value is exact with 4 decimal places as well. Print it with exactly 4 digits after the decimal point, without rounding to fewer digits. If the answer is 11, print 1.0000.

Examples5

  1. Example 1

    Input
    2
    123456 0.6666
    qwerty 0.3334
    
    Expected output
    1.3334
    
  2. Example 2

    Input
    3
    qwerty 0.5432
    123456 0.3334
    password 0.1234
    
    Expected output
    1.5802
    
  3. Example 3

    Input
    1
    Password1 1.0000
    
    Expected output
    1.0000
    
  4. Example 4

    Input
    4
    alpha 0.2500
    beta 0.2500
    gamma 0.2500
    delta 0.2500
    
    Expected output
    2.5000
    
  5. Example 5

    Input
    5
    e 0.0500
    d 0.1000
    c 0.2000
    b 0.3000
    a 0.3500
    
    Expected output
    2.2000