1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>

using namespace std;
using ll = long long;

void solve() {
    ll x, d, h, m;
    cin >> x >> d >> h >> m;
    ll cur = (d * 24 + h - (d == 29 && h >= 3)) * 60 + m;
    ll fin = (x + 22 + 2 + (x == 5)) * 24 * 60 - (x == 5) * 60;
    cout << fin - cur << "\n";
}

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

    int q = 1;
    // cin >> q;
    while (q--) {
        solve();
    }
}