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 Go (1.14.1) (judge verdict: Accepted)

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

func main() {
	list := getStdinIntArr()
	A := list[0]
	B := list[1]
	H := list[2]
	M := list[3]

	aPosM := 60*H + M          // max 720
	bPosM := M % 60            // max 60
	bPosM = bPosM * (720 / 60) // to max 720

	if aPosM == bPosM {
		ans := math.Abs(float64(A) - float64(B))
		fmt.Printf("%.19f", ans)
	} else {
		AFloat := float64(A)
		BFloat := float64(B)
		aPosRad := 2.0 * math.Pi * float64(aPosM) / 720.0
		bPosRad := 2.0 * math.Pi * float64(bPosM) / 720.0
		rad := math.Abs(aPosRad - bPosRad)
		ans := AFloat*AFloat + BFloat*BFloat - 2.0*AFloat*BFloat*math.Cos(rad)
		ans = math.Sqrt(ans)
		fmt.Printf("%.19f", ans)
	}

	fmt.Printf("\n")
}

var sc = bufio.NewScanner(os.Stdin)

func getStdin() string {
	sc.Scan()
	return sc.Text()
}
func getStdinIntArr() []int {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.Atoi(val)
	}
	return rtn
}