Problem:
Score : 1000 points

Problem Statement

#nck {
width: 30px;
height: auto;
}

There are two (6-sided) dice: a red die and a blue die.
When a red die is rolled, it shows i with probability p_i percents, and when a blue die is rolled, it shows j with probability q_j percents.

Petr and tourist are playing the following game.
Both players know the probabilistic distributions of the two dice.
First, Petr chooses a die in his will (without showing it to tourist), rolls it, and tells tourist the number it shows.
Then, tourist guesses the color of the chosen die.
If he guesses the color correctly, tourist wins. Otherwise Petr wins.

If both players play optimally, what is the probability that tourist wins the game?

Constraints

0 ≤ p_i, q_i ≤ 100

p_1 + ... + p_6 = q_1 + ... + q_6 = 100

All values in the input are integers.

Input

The input is given from Standard Input in the following format:

p_1 p_2 p_3 p_4 p_5 p_6
q_1 q_2 q_3 q_4 q_5 q_6

Output

Print the probability that tourist wins.
The absolute error or the relative error must be at most 10^{-9}.

Sample Input 1

25 25 25 25 0 0
0 0 0 0 50 50

Sample Output 1

1.000000000000

tourist can always win the game: If the number is at most 4, the color is definitely red. Otherwise the color is definitely blue.

Sample Input 2

10 20 20 10 20 20
20 20 20 10 10 20

Sample Output 2

0.550000000000

Solution in Rust (1.15.1) (judge verdict: Accepted)

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::Read;
#[allow(dead_code)]
fn getline() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok().unwrap();
    ret
}
fn get_word() -> String {
    let mut stdin = std::io::stdin();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}

#[allow(dead_code)]
fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }

fn petrs_belief(p: &[f64], q: &[f64], x: f64) -> f64 {
    let mut sum = 0.0;
    for i in 0 .. 6 {
        let t1 = p[i] * x;
        let t2 = q[i] * (1.0 - x);
        sum += if t1 > t2 { t1 } else { t2 };
    }
    sum
}

fn solve() {
    let p: Vec<f64> = (0 .. 6).map(|_| get::<f64>() / 100.0).collect();
    let q: Vec<f64> = (0 .. 6).map(|_| get::<f64>() / 100.0).collect();
    let mut lo = 0.0;
    let mut hi = 1.0;
    for _ in 0 .. 50 {
        let mid1 = (lo * 2.0 + hi) / 3.0;
        let mid2 = (lo + 2.0 * hi) / 3.0;
        let f1 = petrs_belief(&p, &q, mid1);
        let f2 = petrs_belief(&p, &q, mid2);
        if f1 < f2 {
            hi = mid2;
        } else {
            lo = mid1;
        }
    }
    println!("{}", petrs_belief(&p, &q, lo));
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}