#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define rep(i,n) for(i=0;i<n;i++)
int main(){
    double a,b,h,m;
    scanf("%lf%lf%lf%lf",&a,&b,&h,&m);
    double c=abs(h*30+m*0.5-m*6);
    if(c>180) c=360-c;
    double ans=a*a+b*b-2*a*b*cos(c);
    printf("%f",ans);
    return 0;
}