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: Wrong Answer)

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>



void swap (int *x, int *y) {
  int temp;

  temp = *x;
  *x = *y;
  *y = temp;

  return;
}


int gcd(int a, int b){
  int c;

  while (b > 0){
    c = a % b;
    a = b;
    b = c;
  }

  return a;
}

/* クイックソート */
int dn(const void*a,const void*b){return*(int*)b-*(int*)a;}


long int modpow(long int a,long int n,long int mod){
  long int ans=1;
  while(n>0){
    if(n & 1){
      ans=ans*a%mod;
    }
    a=a*a%mod;
    n/=2;
  }
  return ans;
}

long int modinv(long int a,long int mod){
  return modpow(a,mod-2,mod);
}

int max(int a,int b){
  if(a<b){
    return b;
  }
  else{
    return a;
  }
}

int min(int a,int b){
  if(a<b){
    return a;
  }
  else{
    return b;
  }
}

void chmax(int *a,int b){
  if(*a < b){
    *a = b;
  }

  return;
}

void chmin(int *a,int b){
  if(*a > b){
    *a =b;
  }

  return;
}

/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/

int main(void){
  double a,b,h,m;
  scanf("%lf%lf%lf%lf",&a,&b,&h,&m);

  double pi=3.14159265358979;
  /*

  時計の中心と文字盤の0を結んだ線を基準線と呼ぶことにします．

  時計の中心と文字盤のh(0<=h<12)を結んだ線と基準線が作る角の大きさx(0<=x<180)は
  度数法で(30*h)と表すことができます．
  
  また，m分(0<=m<60)の時の長針と基準線が作る角の大きさy(0<=y<180)は
  度数法で(6*m)と表すことができます．

  これらをまとめてh時m分の時の長針と短針が作る角の大きさは
  abs(30*h-6*m)と表すことができそうです(これが180を超える場合は180を引いてやればいいです)

  が，短針は時間が変わったら30度一気に動くわけではなく，60分かけて30度を動いていくので，それも考慮しなければなりません．

  つまり，30*(m/60)=m/2をxに足してやる必要があります．

  改めて，h時m分の時の長針と短針が作る角の大きさzは
  abs(30*h+m/2-6*m)と表すことができます．

  ここで余弦定理を用いて求める長さが欲しいわけですが，注意しなければいけないのは
  sin(z)の引数(渡してあげるzのこと)は度数法ではなく弧度法でないといけません．

  pi==180\degreeであるのでpi:180==?:zの式を?について解くと
  ?=z*pi/180であることがわかります．

  以上のことより，答えは

  a*a+b*b-2*a*b*cos(z*pi/180)

  となります．
  
  */
  
  //0<=h<12にする
  if(h>=12){
    h-=12;
  }

  //hは基準線とそれが作る角度
  h=30*h+m/2;

  //mは基準線とそれが作る角度
  m*=6;
  
  
  double z=h-m;
  
  if(z<0){
    z*=-1;
  }
  printf("%lf\n",z);
  
  if(z>=180){
    z-=180;
  }
  


  z=z*pi/180;
  
  double ans=a*a+b*b-2*a*b*cos(z);

  printf("%.16lf\n",sqrt(ans));

  return 0;
}