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 <iostream>
#include <vector>

using namespace std;

int main() {
    vector<int> round = {2160, 2160, 2160, 2160, 3600};    
    
    int x, d, h, m;
    scanf("%d%d%d%d", &x, &d, &h, &m);

    int result = 0;
    if (x < 5) {
        int start_day = 23 + x - 1;
        if (d == start_day) {
            result = 2160 - (h * 60 + m - 720);
        } else {
            result = 1440 - (h * 60 + m);
        }
    } else {
        int start_day = 27;
        if (d == start_day) {
            result = 3600 - (h * 60 + m - 720) - 60;
        } else if (d == start_day + 1) {
            result = 2820 - (h * 60 + m);
        } else {
            if (h <= 2) 
                result = 1380 - (h * 60 + m);
            else 
                result = 1440 - (h * 60 + m);
        }
    }

    printf("%d\n", result);
    return 0;
}