1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
#include <iostream>

int main()
{
    int x, d, h, m;
    std::cin >> x >> d >> h >> m;
    auto calc_time = [](int day, int hour, int minute) { return day * 24 * 60 + hour * 60 + minute; };
    const int change_time = calc_time(29, 2, 0);
	const int start_time = calc_time(d, h, m);
    const int end_day = x + 22 + (x == 5 ? 1 : 0);
    const int end_time = calc_time(x + 23 + (x == 5 ? 1 : 0), 24, 0);
    const bool decrease_1hour = x == 5 && start_time < change_time;
    const int result  = end_time - start_time - (decrease_1hour ? 60 : 0);
    std::cout << result;
    return 0;
}