#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#define PI 3.141592
#include <stdio.h>
#include <iostream>
#include "conio.h"

int main(){
  int A, B, H, M;
  cin >> A >> B >> H >> M;
  int ac = H * 0.5 - 0.5 * H / 360 * 360;
  int bc = H * 6 - H * 6 / 360 * 360;
  int c = 0;
  int out = 0;
  
  if (ac > bc){
    c = ac - bc;
  }
  else{
    c = bc - ac;
  }
  
  out = (int)pow(A, 2.0) + (int)pow(B, 2.0) - 2 * A * B * double cos(double c);
  
  cout << out << endl;
}
  
