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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <cstdio>
using namespace std;

int x, d, h, m;
int main() {
    scanf("%d %d %d %d", &x, &d, &h, &m);
    int result = 0;

    int day_in_minutes = 24*60;
    int half_day_in_minutes = 12*60;
    int time_after_0 = h*60 + m;
    int time_after_12 = (h-12)*60 + m;

    if (x==5){

        // First day
        if (d==27) {
            result = half_day_in_minutes - time_after_12;
            result += day_in_minutes;
            result += day_in_minutes;
            result -= 60;
        }

        // Second day
        else if (d==28) {
            result = day_in_minutes - time_after_0;
            result += day_in_minutes;
            result -= 60;
        }

        // Third day before time change
        else if (h < 2) {
            result = day_in_minutes - time_after_0;
            result -= 60;
        }

        // Third day after time change
        else {
            result = day_in_minutes - time_after_0;
        }

    } else {

        // First day
        if (d==22+x) {
            result = half_day_in_minutes - time_after_12;
            result += day_in_minutes;
        }

        // Second day
        else result = day_in_minutes - time_after_0;
    }

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