1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    ll x, d, h, m;
    cin >> x >> d >> h >> m;
    ll t0;
    t0 = x * 24 * 60 + 12 * 60;
    if (x < 5) {
        cout << t0 + 36*60 - ((d-22)*24*60) - (h * 60) - m << '\n';
    }
    else {
        t0 += 59*60;
        ll val = ((d-22)*24*60) + (h * 60) + m;
        if (d == 29 && h > 2) {
            val -= 60;
        }
        cout << t0 - val << '\n';
    }
}