405007: GYM101736 G Game

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

G. Gametime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

Our little Cactus friend is back with an interesting game! This game features a wheel which consists of n compartments connected in a loop. Each compartment has a hole leading out of the loop. To play, the ball is randomly put into one of the compartments, and the player simply watches it roll around the loop. After some time, the ball will exit through one of the holes, and the game ends. Once the ball exists the wheel, the player is given a score based on the hole from which it exited, and the compartments that the it had visited (counting multiplicity).

More precisely, if the ball is at compartment i for 1 ≤ i < n, it may exit the wheel with probability pi or it may move on to compartment i + 1 with probability 1 - pi. If the ball is at compartment n, it may exit the wheel with probability pn or move on to compartment 1 with probability 1 - pn. The player begins with a score of 0. Each time the ball visits compartment i, the player gains ai score. If the last compartment the ball was in before it exited the loop was compartment j, the player gains an additional bj score.

All that is left is for Cactus to assign probabilities. To make things interesting, he wants to assign probabilities so that 0.01 ≤ pi ≤ 0.99. Since the score counting contraption cannot handle very large numbers, Cactus wants to minimize the expected score. Your task is to calculate the minimum possible expected score while the probabilities satisfy the given restriction. You may assume that the initial compartment is chosen uniformly at random.

Input

The first line of input contains a single integer n (2 ≤ n ≤ 500), the number of compartments in the wheel.

Each of the next n lines contains two space-separated integers ai and bi, (1 ≤ ai, bi ≤ 106), describing the ith compartment. ai is the score gained each time the ith compartment is visited, and bi is the score gained if the ith compartment is the last compartment visited.

Output

Print, on a single line, the minimum possible expected score. Your answer will be considered correct if it is within 10 - 6 absolute or relative error.

ExamplesInput
3
1 100
1 100
1 1
Output
4.0227937347
Input
2
420 3
1 1
Output
214.6262626263

加入题单

上一题 下一题 算法标签: