1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <bits/stdc++.h>

#define int long long
const std::vector<int> days({24, 25, 26, 27, 29});
void solve() {
    int x, d, h, m;
    std::cin >> x >> d >> h >> m;
    int finish = days[x - 1];
    // for (auto it : days) {
    if (finish >= d) {
        int diff_days = finish - d;
        int diff_hours = 23 - h;
        int diff_minutes = 60 - m;
        if ((d == 29 && h < 2 && x == 5) || (d <= 28 && x == 5)) {
            diff_hours--;
        }
        std::cout << diff_days * 60 * 24 + diff_hours * 60 + diff_minutes;

        return;
    }
    // }

    // assert(false);
}

int32_t main() {
    std::ios_base::sync_with_stdio(0);
    std::cin.tie(0);
    std::cout.tie(0);
    int testcases = 1;
    // std::cin >> testcases;
    while (testcases--) {
        solve();
    }
    return 0;
}