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# (.NET Core 3.1.201) (judge verdict: Accepted)

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

namespace x
{
    class Program
    {
        static void Main(string[] args)
        {
            var vals = IOUtils.ReadInts();
            var hLen = vals[0];
            var mLen = vals[1];
            var hour = vals[2];
            var min = vals[3];

            var totalMin = hour * 60 + min;

            var hKakuPerMin = 0.5;
            var mKakuPerMin = 6;

            var hKaku = totalMin * hKakuPerMin;
            var mKaku = totalMin * mKakuPerMin % 360;

            if (hKaku == mKaku) {
                System.Console.WriteLine(Math.Abs(hLen - mLen));
                return;
            }
            if (Math.Abs(hKaku - mKaku) == 180) {
                System.Console.WriteLine(hLen + mLen);
                return;
            }

            AxisPoint hPt = AxisPoint.FromDegreeAndLength(hKaku, hLen);
            AxisPoint mPt = AxisPoint.FromDegreeAndLength(mKaku, mLen);

            var res = hPt.GetDistance(mPt);
            System.Console.WriteLine(res);
        }

    }

    sealed class AxisPoint {
        public double X { get; }
        public double Y { get; }

        public AxisPoint(double x, double y) {
            this.X = x;
            this.Y = y;
        }

        public static AxisPoint FromDegreeAndLength(double degree, double length) {
            if (length < 0) throw new ArgumentOutOfRangeException(nameof(length));
            if (degree < 0) throw new ArgumentOutOfRangeException(nameof(degree));

            if (360 <= degree) {
                degree = degree % 360;
            }

            if (degree == 0) {
                return new AxisPoint(0, length);
            }
            if (degree == 90) {
                return new AxisPoint(length, 0);
            }
            if (degree == 180) {
                return new AxisPoint(0, length * -1);
            }
            if (degree == 270) {
                return new AxisPoint(length * -1, 0);
            }

            double radian;
            double x;
            double y;
            if (degree < 90) {
                radian = (90 - degree) * Math.PI / 180;
                y = Math.Sin(radian) * length;
                x = Math.Cos(radian) * length;
            }
            else if (degree < 180) {
                radian = (degree - 90) * Math.PI / 180;
                y = Math.Sin(radian) * length * -1;
                x = Math.Cos(radian) * length;
            }
            else if (degree < 270) {
                radian = (270 - degree) * Math.PI / 180;
                y = Math.Sin(radian) * length * -1;
                x = Math.Cos(radian) * length * -1;
            }
            else {
                radian = (degree - 270) * Math.PI / 180;
                y = Math.Sin(radian) * length;
                x = Math.Cos(radian) * length * -1;
            }
            return new AxisPoint(x, y);
        }

        public double GetDistance(AxisPoint to) {
            return Math.Sqrt(Math.Pow(this.X - to.X, 2) + Math.Pow(this.Y - to.Y, 2));
        }

        public override bool Equals(object obj)
        {
            if (obj == null || GetType() != obj.GetType())
            {
                return false;
            }

            var other = obj as AxisPoint;
            return this.X == other.X && this.Y == other.Y;
        }
        
        public override int GetHashCode()
        {
            return (int)this.X ^ (int)this.Y;
        }

    }
    
    static class IOUtils
    {
        public static (int a, int b) Read2Ints()
        {
            var vals = ReadInts();
            return (vals[0], vals[1]);
        }
        public static (int a, int b, int c) Read3Ints()
        {
            var vals = ReadInts();
            return (vals[0], vals[1], vals[2]);
        }
        public static IEnumerable<int[]> ReadIntLines(int count)
        {
            for (int i = 0; i < count; i++)
            {
                yield return ReadInts();
            }
        }
        public static IEnumerable<long[]> ReadLongLines(int count)
        {
            for (int i = 0; i < count; i++)
            {
                yield return ReadLongs();
            }
        }
        public static int ReadInt()
        {
            return int.Parse(Console.ReadLine());
        }
        public static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }
        public static ulong ReadUlong()
        {
            return ulong.Parse(Console.ReadLine());
        }
        public static int[] ReadInts()
        {
            return Console.ReadLine().Split(' ').Select(v => int.Parse(v)).ToArray();
        }
        public static long[] ReadLongs()
        {
            return Console.ReadLine().Split(' ').Select(v => long.Parse(v)).ToArray();
        }

        public static void WriteNums(params int[] nums)
        {
            Console.WriteLine(string.Join(" ", nums));
        }
    }
}