Problem:
Score: 300 points

Problem Statement

Consider an analog clock whose hour and minute hands are A and B centimeters long, respectively.

An endpoint of the hour hand and an endpoint of the minute hand are fixed at the same point, around which each hand rotates clockwise at constant angular velocity. It takes the hour and minute hands 12 hours and 1 hour to make one full rotation, respectively.

At 0 o'clock, the two hands overlap each other. H hours and M minutes later, what is the distance in centimeters between the unfixed endpoints of the hands?

Constraints

All values in input are integers.

1 \leq A, B \leq 1000

0 \leq H \leq 11

0 \leq M \leq 59

Input

Input is given from Standard Input in the following format:

A B H M

Output

Print the answer without units. Your output will be accepted when its absolute or relative error from the correct value is at most 10^{-9}.

Sample Input 1

3 4 9 0

Sample Output 1

5.00000000000000000000

The two hands will be in the positions shown in the figure below, so the answer is 5 centimeters.

Sample Input 2

3 4 10 40

Sample Output 2

4.56425719433005567605

The two hands will be in the positions shown in the figure below. Note that each hand always rotates at constant angular velocity.

Solution in Rust (1.42.0) (judge verdict: Wrong Answer)

//use itertools::Itertools;
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use std::f64::consts::PI;
use std::io::Read;
use std::usize::MAX;

macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next, $($r)*}};}
macro_rules! input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($next, $t);input_inner!{$next $($r)*}};}
macro_rules! read_value {($next:expr, ( $($t:tt),* )) => {( $(read_value!($next, $t)),* )};($next:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()};($next:expr, chars) => {read_value!($next, String).chars().collect::<Vec<char>>()};($next:expr, usize1) => {read_value!($next, usize) - 1};($next:expr, [ $t:tt ]) => {{let len = read_value!($next, usize);(0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()}};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

fn solve() {
    input! {
        a: f64,
        b: f64,
        h: f64,
        m: f64
    }

    let mut hrad: f64 = h * 30.0 + (m / 60.0) * 30.0;
    if hrad >= 180.0 {
        hrad = 360.0 - hrad;
    }
    let mut mrad: f64 = m * 6.0;
    if mrad >= 180.0 {
        mrad -= 360.0 - mrad;
    }

    if hrad == mrad {
        println!("{}", (a - b).abs());
        return;
    }

    let mut rad = (hrad - mrad).abs();

    let before = if hrad < mrad { a } else { b };

    let after = if hrad >= mrad { a } else { b };

    //println!("{}", rad);

    if rad == 90.0 {
        println!("{}", (a.powf(2.0) + b.powf(2.0)).sqrt());
    } else if rad > 90.0 {
        let deg = (180.0 - rad) / 180.0 * PI;
        let afterlong = after * deg.cos();
        let yoko = before + afterlong;
        let tate = after * deg.sin();
        println!("{}", (yoko.powf(2.0) + tate.powf(2.0)).sqrt());
    } else {
        let deg = rad / 180.0 * PI;
        let afterlong = after * deg.cos();

        let yoko = if before > afterlong {
            before - afterlong
        } else {
            afterlong - before
        };

        let tate = after * deg.sin();
        println!("{}", (yoko.powf(2.0) + tate.powf(2.0)).sqrt());
    }
}
fn main() {
    let thd = std::thread::Builder::new().stack_size(104_857_600);
    thd.spawn(|| solve()).unwrap().join().unwrap();

    /*
    // 入力を一括で読み込む場合
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut input = buf.split_whitespace();

    // inputに対しnext()で読み込んでいく
    let q: usize = input.next().unwrap().parse().unwrap();
    */
}

const LARGE_PRIME: u64 = 1_000_000_007;

// @〜でsnippet