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
37
38
39
40
41
#include <bits/stdc++.h>
using namespace std;


vector<int> end_day = {
    {},
    {24},
    {25},
    {26},
    {27},
    {29}
};

int to_minutes(int d, int h, int m) {
    int days = d - 23;
    return days * 24 * 60 + h * 60 + m;
}

int main() {
    int x, d, h, m;
    cin >> x >> d >> h >> m;

    int end_d = end_day[x];
    int end_h = 24;
    int end_m = 0;

    int start = to_minutes(d, h, m);
    int end = to_minutes(end_d, end_h, end_m);

    int result = end - start;

    int change = to_minutes(29, 2, 0);

    if (start < change && end >= change) {
        result -= 60;
    }

    cout << result << "\n";

    return 0;
}