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;
            }

            Point hPt = GetPoint(hLen, hKaku);
            Point mPt = GetPoint(mLen, mKaku);

            var res = Math.Sqrt(Math.Pow(hPt.x - mPt.x, 2) + Math.Pow(hPt.y - mPt.y, 2));
            System.Console.WriteLine(res);
            
        }

        private static Point GetPoint(int len, double kaku) {
            if (kaku == 0) {
                return new Point(0, len);
            }
            if (kaku == 90) {
                return new Point(len, 0);
            }
            if (kaku == 180) {
                return new Point(0, len * -1);
            }
            if (kaku == 270) {
                return new Point(len * -1, 0);
            }



            if (0 < kaku && kaku < 90) {
                // var tmpKaku = kaku * Math.PI / 180;
                // var y = Math.Cos(kaku) * len;
                // var x = Math.Sin(kaku) * len;

                var tmpKaku = (90 - kaku) * Math.PI / 180;
                var y = Math.Sin(tmpKaku) * len;
                var x = Math.Cos(tmpKaku) * len;
                return new Point(x, y);
            }
            else if (90 < kaku && kaku < 180) {
                var tmpKaku = (kaku - 90) * Math.PI / 180;
                var y = Math.Sin(tmpKaku) * len * -1;
                var x = Math.Cos(tmpKaku) * len;
                return new Point(x, y);
            }
            else if (180 < kaku && kaku < 270) {
                // var tmpKaku = (kaku - 180) * Math.PI / 180;
                // var y = Math.Cos(tmpKaku) * len * -1;
                // var x = Math.Sin(tmpKaku) * len * -1;
                var tmpKaku = (270 - kaku) * Math.PI / 180;
                var y = Math.Sin(tmpKaku) * len * -1;
                var x = Math.Cos(tmpKaku) * len * -1;
                return new Point(x, y);
            }
            else {
                // var tmpKaku = (kaku - 270) * Math.PI / 180;
                // var y = Math.Sin(tmpKaku) * len;
                // var x = Math.Cos(tmpKaku) * len * -1;
                var tmpKaku = (kaku - 270) * Math.PI / 180;
                var y = Math.Sin(tmpKaku) * len;
                var x = Math.Cos(tmpKaku) * len * -1;
                return new Point(x, y);
            }
        }

        class Point {
            public readonly double x;
            public readonly double y;
            public Point(double x, double y) {
                this.x = x;
                this.y = 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));
        }
    }
}