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++ (GCC 9.2.1) (judge verdict: Accepted)

#include<bits/stdc++.h>
using namespace std;

typedef long long int   ll;
#define cases           int t;cin>>t;while(t--)
#define FIO             ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl            "\n"
#define scan(n)         scanf("%d",&n)
#define mod             1000000007
#define maxn            200001
#define PI              3.1415926535897932384626433832795
#define int             ll
#define loop0           for(int i=0;i<n;i++)
#define loop1           for(int i=1;i<=n;i++)
#define inpar0(ar)      for(int i=0;i<n;i++)cin>>ar[i];
#define inpar1(ar)      for(int i=1;i<=n;i++)cin>>ar[i];
#define showar0(ar)     for(int i=0;i<n;i++)cout<<ar[i]<<" ";
#define showar1(ar)     for(int i=1;i<=n;i++)cout<<ar[i]<<" ";
#define manu            cout<<(checkerCounter++)<<endl;
static int checkerCounter = 1;
int binpow(int a,int b){int res=1;while(b>0){if(b%2){res=(res*a)%mod;b--;}a=(a*a)%mod;b/=2;}return res%mod;}
bool isPrime(int n){if(n==1)return false;for(int i=2;i*i<=n;i++){if(n%i==0)return false;}return true;}

signed main(){
    double a,b,h,m;
    cin>>a>>b>>h>>m;
    h=(int)h%12;
    m=(int)m%60;
//    cout<<"H:"<<h<<" M:"<<m<<endl;
    double theta1,theta2;
    theta1=(h*2*PI)/12;
    theta2=(m*2*PI)/60;
    theta1+=(theta2/12);
//    cout<<"th1:"<<theta1<<" th2:"<<theta2<<endl;
//    cout<<"hr:"<<theta1<<" min:"<<theta2<<endl;
    double x1,x2,y1,y2;
    x1=a*(sin(theta1));
    y1=a*(cos(theta1));
    x2=b*(sin(theta2));
    y2=b*(cos(theta2));
//    cout<<"hr:"<<x1<<" "<<y1<<endl;
//    cout<<"min:"<<x2<<" "<<y2<<endl;
    double x=abs(x1-x2);
    double y=abs(y1-y2);
//    cout<<"x: "<<x<<" y:"<<y<<endl;
    x*=x;y*=y;
    double dis=sqrt(x+y);
    cout<<setprecision(30)<<dis<<endl;
}