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
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <numeric>

int from_start_of_pa(int d, int h, int m) {
    int total_minutes = (d - 23) * 24 * 60 + h * 60 + m;
    if (d == 29 && h >= 3) {
        total_minutes -= 60;
    }
    return total_minutes;
}

const std::vector<int> end_of_round_times = {
    0,                                
    from_start_of_pa(24, 24, 0),
    from_start_of_pa(25, 24, 0),
    from_start_of_pa(26, 24, 0),
    from_start_of_pa(27, 24, 0),
    from_start_of_pa(29, 24, 0)
};

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);

    int x, d, h, m;
    std::cin >> x >> d >> h >> m;

    std::cout << end_of_round_times[x] - from_start_of_pa(d, h, m) << "\n";
}