Under construction

Still being built. Things may change

Unloaded Die

Time limit1sMemory limit512 MB

Summary
Given probabilities of the six faces of a loaded die, change one face's label so the expected value is exactly 3.5, minimizing the absolute label change.
Level

Easy3 of 10

Topics
Math, Greedy, Implementation
Solved
No attempts yet

Problem

A six-sided die has its faces labeled 1 through 6. The die is fair if every face is equally likely to land face up, and loaded if it is not fair. For example, a die whose face marked 6 comes up twice as often as any other face is loaded.

The expected result of rolling a die is the average of the face labels, weighted by the probability that each face comes up. Every face of a fair die is equally likely, so its expected result is (1+2+3+4+5+6)/6=3.5(1+2+3+4+5+6)/6 = 3.5.

You are given a loaded die and you want to unload it so that it behaves more like a fair one. You can erase the number on one face and write a new number there. The new number does not have to be an integer and does not have to be positive. Pick the face and the new number so that:

  • the expected result of rolling the die becomes exactly 3.53.5;
  • the difference between the old label and the new label on the face you change is as small as possible.

The expected result can always be brought to 3.53.5 this way.

Input

The first line holds six space-separated nonnegative real numbers v1v_1 v2v_2 v3v_3 v4v_4 v5v_5 v6v_6. Here viv_i is the probability that face ii, currently labeled with the number ii, comes up.

The six numbers sum to exactly 11, and each one is given as a decimal with at most six digits after the decimal point.

Output

Print on the first line the smallest possible absolute difference between the new label and the old label, rounded to exactly three digits after the decimal point. Round a value that is exactly halfway up.

Examples2

  1. Example 1

    Input
    0.16666 0.16667 0.16667 0.16666 0.16667 0.16667
    
    Expected output
    0.000
    
  2. Example 2

    Input
    0.2 0.2 0.1 0.2 0.2 0.1
    
    Expected output
    1.000