Consider an old cassette player, whose only working buttons are “play” and “rewind”. You have just one cassette, which you always keep completely rewinded. So, when you want to listen to a particular song , you have to press the “play” button and wait until all the songs stored before finish. Afterwards, when ends, you always rewind the cassette.
You have songs, all with the same duration . You know that you want to listen to song with absolute frequency . (For instance, if and , then you listen to song 1 twice as much as to song 2.) Assume that the cassette is long enough to store all your songs. Your goal is to choose the order to store the songs so as to minimize the expected time to listen to a desired song.
Input is all natural numbers, and consists of several cases. Every case begins with and , followed by the absolute frequencies of the songs. At least one of the frequencies is strictly positive. Assume .
For every case, print with four digits after the decimal point the optimal expected time to listen to a desired song. The input cases have no precision issues.
Input
1 2 6 3 1 2 6 6 10 4 3 0 1 4 100 1 8
Output
1.3333 1.5000 16.2500 100.0000