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 C# (Mono-mcs 6.8.0.105) (judge verdict: Accepted)

using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

namespace ABC168
{
    public class Solve
    {
        public static void Main(string[] args)
        {
            new ABC_C();
        }
    }
    public class ABC_A
    {
        public ABC_A()
        {
            var n = Ex.Read;

            int i = n.LastOrDefault() - '0';
            if (i == 2 || i == 4 || i == 5 || i == 7 || i == 9) "hon".Cw();
            else if (i == 3) "bon".Cw();
            else "pon".Cw();
        }
    }
    public class ABC_B
    {
        public ABC_B()
        {
            var k = Ex.ReadInt;
            var s = Ex.Read;

            if (s.Length <= k) s.Cw();
            else
            {
                (string.Join("", s.Take(k)) + "...").Cw();
            }
        }
    }
    public class ABC_C
    {
        public ABC_C()
        {
            var l = Ex.ReadIntArray();
            var a = l[0];
            var b = l[1];
            var h = l[2];
            var m = l[3];

            double sh = 30 * h + m * .5;
            double lo = m * 6;
            var d = Math.Abs(sh - lo);
            //$"{sh} {lo} {d} {Math.Cos(d)}".Cw();
            d = Math.Min(360 - d, d);
            //$"{sh} {lo} {d} {Math.Cos(d)}".Cw();
            var c = a * a + b * b - 2 * a * b * Math.Cos(d * Math.PI / 180.0);
            //var c = a * a + b * b - 2 * a * b * Math.Abs(Math.Cos(d));
            //if (d % 90 == 0) c = a * a + b * b - 2 * a * b * Math.Abs(Math.Ceiling(Math.Cos(d)));
            //c.Cw();
            Math.Sqrt(c).Cw();
        }
    }
    public class ABC_D
    {
        public ABC_D()
        {
        }
    }
    public class ABC_E
    {
        public ABC_E()
        {
        }
    }
    public class ABC_F
    {
        public ABC_F()
        {
        }
    }
    public static class Ex
    {
        public static void Cw(this object s) { Console.WriteLine(s); }

        public static List<string> FastSort(this List<string> s) { s.Sort(StringComparer.Ordinal); return s.ToList(); }
        public static void yesno(this bool b) { (b ? "yes" : "no").Cw(); }
        public static void YesNo(this bool b) { (b ? "Yes" : "No").Cw(); }
        public static void YESNO(this bool b) { (b ? "YES" : "NO").Cw(); }

        public static string Read { get { return Console.ReadLine().Trim(); } }
        public static int ReadInt { get { return int.Parse(Read); } }
        public static long ReadLong { get { return long.Parse(Read); } }
        public static double ReadDouble { get { return double.Parse(Read); } }
        public static string[] ReadArray() { return Read.Split(' '); }
        public static int[] ReadIntArray() { return Read.Split(' ').Select(int.Parse).ToArray(); }
        public static long[] ReadLongArray() { return Read.Split(' ').Select(long.Parse).ToArray(); }
        public static string[] ReadArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public static int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public static long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}