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

constexpr int END_D = 23, END_H = 24, END_M = 0;

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

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

    if(x == 5)
    {
        if(d != 29 || h < 2)
            ++h;
        --d;
    }

    int result = 60*(24*(x+END_D-d)+END_H-h)+END_M-m;

    std::cout << result << '\n';

    return 0;
}