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 <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);

const long double PI = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899;

struct Vec2{
    long double x,y;

    Vec2(long double x = 0, long double y = 0): x(x),y(y) {};
    Vec2 operator+(const Vec2& v) const {return Vec2(x+v.x, y+v.y);}
    Vec2& operator+=(const Vec2& v) {x += v.x; y += v.y; return *this;}
    Vec2 operator-(const Vec2& v) const {return Vec2(x-v.x, y-v.y);}

    long double dot(const Vec2& v) const {return x*v.x + y*v.y;}
    long double cross(const Vec2& v) const {return x*v.y - y*v.x;}
    long double norm2() const {return x*x + y*y;}
    long double norm() const {return sqrt(norm2());}

    int ort() const{
        if(y >= 0) return x > 0 ? 1 : 2;
        else return x > 0 ? 4 : 3;
    }
    long double arg(){
        if(equals(x,0) && equals(y,0)) return -1;
        if(equals(x,0)){
            if(y > 0) return 90.0;
            else return 270.0;
        }else if(equals(y,0)){
            if(x > 0) return 0.0;
            else return 180.0;
        }else{
            long double x1 = abs(x);
            long double y1 = abs(y);
            long double a = atan((long double)y1/x1)/ PI * 180;
            if(0 < y && 0 < x) return a;
            else if(0 < y) return 180-a;
            else if(0 < x) return 360-a;
            else return 180+a;
        }
    }

};

bool cmp_vec2arg(const Vec2& a, const Vec2& b){ // <$B$rDj5A(B
    int ao = a.ort(), bo = b.ort();
    if(ao != bo) return ao < bo;
    else return a.cross(b) > 0;
}

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);
    double A,B; cin >> A >> B;
    int H,M; cin >> H >> M;
    double ah = H * 30 + 0.5 * M;
    double bh = 6 * M;
    double th = abs(ah-bh);
    if(th > 180) th = 360-th;

    double x = sqrt(A*A + B*B - 2 * A*B*cos(PI*th/180));
    cout << x << endl;

}