/* #region Head */

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pll = pair<ll, ll>;
template <class T> using vc = vector<T>;
template <class T> using vvc = vc<vc<T>>;
using vll = vc<ll>;
using vvll = vvc<ll>;
using vld = vc<ld>;
using vvld = vvc<ld>;
using vs = vc<string>;
using vvs = vvc<string>;
template <class T, class U> using um = unordered_map<T, U>;
template <class T> using pq = priority_queue<T>;
template <class T> using pqa = priority_queue<T, vc<T>, greater<T>>;
template <class T> using us = unordered_set<T>;

#define REP(i, m, n) for (ll i = (m), i##_len = (ll)(n); i < i##_len; ++(i))
#define REPM(i, m, n) for (ll i = (m), i##_max = (ll)(n); i <= i##_max; ++(i))
#define REPR(i, m, n) for (ll i = (m), i##_min = (ll)(n); i >= i##_min; --(i))
#define REPD(i, m, n, d) for (ll i = (m), i##_len = (ll)(n); i < i##_len; i += (d))
#define REPMD(i, m, n, d) for (ll i = (m), i##_max = (ll)(n); i <= i##_max; i += (d))
#define REPI(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define ALL(x) begin(x), end(x)
#define SIZE(x) ((ll)(x).size())
#define PERM(c)                                                                                                        \
    sort(ALL(c));                                                                                                      \
    for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))
#define UNIQ(v) v.erase(unique(ALL(v)), v.end());

#define endl '\n'
#define sqrt sqrtl
#define floor floorl
#define log2 log2l

constexpr ll INF = 1'010'000'000'000'000'017LL;
constexpr int IINF = 1'000'000'007LL;
constexpr ll MOD = 1'000'000'007LL; // 1e9 + 7
// constexpr ll MOD = 998244353;
constexpr ld EPS = 1e-12;
constexpr ld PI = 3.14159265358979323846;

template <typename T> istream &operator>>(istream &is, vc<T> &vec) { // vector 入力
    for (T &x : vec) is >> x;
    return is;
}
template <typename T> ostream &operator<<(ostream &os, vc<T> &vec) { // vector 出力 (for dump)
    os << "{";
    REP(i, 0, SIZE(vec)) os << vec[i] << (i == i_len - 1 ? "" : ", ");
    os << "}";
    return os;
}
template <typename T> ostream &operator>>(ostream &os, vc<T> &vec) { // vector 出力 (inline)
    REP(i, 0, SIZE(vec)) os << vec[i] << (i == i_len - 1 ? "\n" : " ");
    return os;
}

template <typename T, typename U> istream &operator>>(istream &is, pair<T, U> &pair_var) { // pair 入力
    is >> pair_var.first >> pair_var.second;
    return is;
}
template <typename T, typename U> ostream &operator<<(ostream &os, pair<T, U> &pair_var) { // pair 出力
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}

// map, um, set, us 出力
template <class T> ostream &out_iter(ostream &os, T &map_var) {
    os << "{";
    REPI(itr, map_var) {
        os << *itr;
        auto itrcp = itr;
        if (++itrcp != map_var.end()) os << ", ";
    }
    return os << "}";
}
template <typename T, typename U> ostream &operator<<(ostream &os, map<T, U> &map_var) { return out_iter(os, map_var); }
template <typename T, typename U> ostream &operator<<(ostream &os, um<T, U> &map_var) {
    os << "{";
    REPI(itr, map_var) {
        auto [key, value] = *itr;
        os << "(" << key << ", " << value << ")";
        auto itrcp = itr;
        if (++itrcp != map_var.end()) os << ", ";
    }
    os << "}";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, set<T> &set_var) { return out_iter(os, set_var); }
template <typename T> ostream &operator<<(ostream &os, us<T> &set_var) { return out_iter(os, set_var); }
template <typename T> ostream &operator<<(ostream &os, pq<T> &pq_var) {
    pq<T> pq_cp(pq_var);
    os << "{";
    if (!pq_cp.empty()) {
        os << pq_cp.top(), pq_cp.pop();
        while (!pq_cp.empty()) os << ", " << pq_cp.top(), pq_cp.pop();
    }
    return os << "}";
}

// dump
#define DUMPOUT cerr
void dump_func() { DUMPOUT << endl; }
template <class Head, class... Tail> void dump_func(Head &&head, Tail &&... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) DUMPOUT << ", ";
    dump_func(move(tail)...);
}

// chmax (更新「される」かもしれない値が前)
template <typename T, typename U, typename Comp = less<>> bool chmax(T &xmax, const U &x, Comp comp = {}) {
    if (comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}

// chmin (更新「される」かもしれない値が前)
template <typename T, typename U, typename Comp = less<>> bool chmin(T &xmin, const U &x, Comp comp = {}) {
    if (comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

// ローカル用
#define DEBUG_

#ifdef DEBUG_
#define DEB
#define dump(...)                                                                                                      \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                                                                    \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl                                        \
            << "    ",                                                                                                 \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif

#define VAR(type, ...)                                                                                                 \
    type __VA_ARGS__;                                                                                                  \
    cin >> __VA_ARGS__;

template <typename T> istream &operator,(istream &is, T &rhs) { return is >> rhs; }
template <typename T> ostream &operator,(ostream &os, const T &rhs) { return os << ' ' << rhs; }

struct AtCoderInitialize {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;
    AtCoderInitialize() {
        ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
        cout << fixed << setprecision(IOS_PREC);
        if (AUTOFLUSH) cout << unitbuf;
    }
} ATCODER_INITIALIZE;

void Yn(bool p) { cout << (p ? "Yes" : "No") << endl; }
void YN(bool p) { cout << (p ? "YES" : "NO") << endl; }

/* #endregion */

// #include <atcoder/all>
// using namespace atcoder;

/* #region AnalogClock */

// h 時 m 分 s 秒の時計の状態を表すクラス
template <typename sec_t, typename slope_t = ll, typename len_t = ld> struct AnalogClock {
    static constexpr ll Y_MAX = 3600 * 12;
    sec_t s;     // 00:00:00 からの秒数
    len_t len_h; // 時針（短針）の長さ
    len_t len_m; // 分針（長針）の長さ
    len_t len_s; // 秒針の長さ

    AnalogClock(ll h, ll m, sec_t s, len_t len_h = 1, len_t len_m = 1, len_t len_s = 1) noexcept
        : s(0), len_h(len_h), len_m(len_m), len_s(len_s) {
        init(h, m, s);
    }

    void init(ll h, ll m, const sec_t s) noexcept {
        h += m / 60;
        m %= 60;
        h %= 12;
        this->s = h * 3600 + m * 60 + s;
        if (this->s > 3600 * 12) { // 念の為
            ll q = (ll)(this->s / 3600 * 12);
            this->s -= 3600 * 12 * q;
        }
    }

    // 秒針は傾き 12*60=720 の直線
    // 分針（長針）は傾き 12 の直線
    // 時針（短針）は傾き 1 の直線

    // 傾き slope の針の現在の位置を [0, Y_MAX) に写像して返す
    sec_t _get_height(const slope_t slope) const noexcept {
        sec_t y = s * slope;
        ll q = (ll)(y / Y_MAX);
        y -= Y_MAX * q;
        while (y < 0) y += Y_MAX;
        while (y > Y_MAX) y -= Y_MAX;
        return y;
    }

    // 傾きが異なる2直線に対して，「ぶつかるまであとどれだけ y を詰めないといけないか」の情報を返す
    pair<sec_t, sec_t> _get_heights(const slope_t slope0, const slope_t slope1) const noexcept {
        assert(slope0 < slope1);
        sec_t y_0 = _get_height(slope0);
        sec_t y_1 = _get_height(slope1);
        if (y_1 > y_0) y_1 -= Y_MAX;

        return {y_0, y_1};
    }

    // 時針（長針）の角速度を傾きの 1 単位としたとき，2つの針の速度の傾きから，交差するまでの時間を求める
    // verified with: yukicoder contest 267 (id=282) #A (No.1236)
    sec_t intersect_by_slope(slope_t slope0, slope_t slope1) const noexcept {
        assert(slope0 > 0);
        assert(slope1 > 0);
        if (slope0 == slope1) return 0;
        if (slope0 > slope1) swap(slope0, slope1);
        // assert slope1 の傾きのほうが大きい

        auto [y_0, y_1] = _get_heights(slope0, slope1);
        return (y_0 - y_1) / (slope1 - slope0);
    }

    // 時針（短針）と分針（長針）が何秒後に交差するかを返す
    sec_t intersect_h_m() const noexcept { return intersect_by_slope(1, 12); }

    // 分針（長針）と秒針が何秒後に交差するかを返す
    sec_t intersect_m_s() const noexcept { return intersect_by_slope(12, 12 * 60); }

    // 時針（短針）と秒針が何秒後に交差するかを返す
    sec_t intersect_h_s() const noexcept { return intersect_by_slope(1, 12 * 60); }

    // 時針（長針）の角速度を傾きの 1 単位としたとき，2つの針の速度の傾きから， sec 秒で何回交差するか数える
    // verified with: dwacon2018_final_a
    ll count_intersect_by_slope(slope_t slope0, slope_t slope1, sec_t sec) const noexcept {
        assert(slope0 > 0);
        assert(slope1 > 0);
        if (slope0 == slope1) return 0;
        if (slope0 > slope1) swap(slope0, slope1);
        // assert slope1 の傾きのほうが大きい

        auto [y_0, y_1] = _get_heights(slope0, slope1);
        assert(y_0 > y_1);

        // 2 直線は，周期 T=Y_MAX/(slope1-slope0) で交差する
        // 少なくとも floor(sec/T) = floor(sec*(slope1-slope0)/Y_MAX) 回は交差する
        ll cnt = (ll)(sec * (slope1 - slope0) / Y_MAX);
        // 補正： 0 <= sec - cnt*T < T
        // <-> 0 <= sec*(slope1-slope0) - cnt*Y_MAX < Y_MAX
        while (sec * (slope1 - slope0) - cnt * Y_MAX < 0) cnt--;
        while (sec * (slope1 - slope0) - cnt * Y_MAX >= Y_MAX) cnt++;

        // 交差するには時間が余分に (y_0-y_1)/(slope1-slope0) 必要
        // 残り時間 t=sec-cnt*T なので，
        // t = sec - cnt*Y_MAX/(slope1-slope0)  >= (y_0-y_1)/(slope1-slope0)
        // <-> sec*(slope1-slope0) - cnt*Y_MAX >= y_0-y_1
        if (sec * (slope1 - slope0) - cnt * Y_MAX >= y_0 - y_1) cnt++;

        return cnt;
    }

    // 時針（短針）と分針（長針）が sec 秒で何回交差するかを数える
    ll count_intersect_h_m(sec_t sec) const noexcept { return count_intersect_by_slope(1, 12, sec); }

    // 分針（長針）と秒針が sec 秒で何回交差するかを数える
    ll count_intersect_m_s(sec_t sec) const noexcept { return count_intersect_by_slope(12, 12 * 60, sec); }

    // 時針（短針）と秒針が sec 秒で何回交差するかを数える
    ll count_intersect_h_s(sec_t sec) const noexcept { return count_intersect_by_slope(1, 12 * 60, sec); }

    // 時針（長針）の角速度を傾きの 1 単位としたとき，2つの針の速度の傾きから，針同士のなす角の大きさを返す
    // verified with: abc030_b
    template <typename angle_degree_t = ld>
    angle_degree_t angle_by_slope(const slope_t slope0, const slope_t slope1) const noexcept {
        assert(slope0 < slope1);
        sec_t y_0 = _get_height(slope0);
        sec_t y_1 = _get_height(slope1);

        angle_degree_t deg01 = (angle_degree_t)360 * abs(y_0 - y_1) / Y_MAX;

        return min(deg01, -deg01 + 360);
    }

    // 時針（短針）と分針（長針）のなす角を返す
    template <typename angle_degree_t = ld> angle_degree_t angle_h_m() const noexcept {
        return angle_by_slope(1, 12); //
    }
    // 分針（長針）と秒針のなす角を返す
    template <typename angle_degree_t = ld> angle_degree_t angle_m_s() const noexcept {
        return angle_by_slope(12, 12 * 60); //
    }
    // 時針（短針）と秒針のなす角を返す
    template <typename angle_degree_t = ld> angle_degree_t angle_h_s() const noexcept {
        return angle_by_slope(1, 12 * 60); //
    }

    len_t distance_of_endpoints_by_slope(const slope_t slope0, const slope_t slope1, const len_t len0,
                                         const len_t len1) const noexcept {
        sec_t y_0 = _get_height(slope0);
        sec_t y_1 = _get_height(slope1);

        complex<len_t> c_0 = polar<len_t>(len0, 2.0l * PI * y_0 / Y_MAX);
        complex<len_t> c_1 = polar<len_t>(len1, 2.0l * PI * y_1 / Y_MAX);
        return abs(c_1 - c_0);
    }
    len_t distance_of_endpoints_h_m() { return distance_of_endpoints_by_slope(1, 12, len_h, len_m); }
    len_t distance_of_endpoints_m_s() { return distance_of_endpoints_by_slope(12, 12 * 60, len_m, len_s); }
    len_t distance_of_endpoints_h_s() { return distance_of_endpoints_by_slope(1, 12 * 60, len_h, len_s); }
};

/* #endregion */

// Problem
void solve() {
    VAR(ll, a, b, h, m); //
    AnalogClock<ll> clk(h, m, 0, a, b);
    cout << clk.distance_of_endpoints_h_m() << endl;
}

// entry point
int main() {
    solve();
    return 0;
}


Measured memory_bytes: 4152