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
#include <bits/stdc++.h>

using i64 = long long;
using u64 = unsigned long long;
using u32 = unsigned;

using u128 = unsigned __int128;
using i128 = __int128;

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int x, d, h, m;
    std::cin >> x >> d >> h >> m;
    
    const int day = x + (x == 5 ? 24 : 23);
    if (x == 5 && (d < 29 || h < 2)) {
        h++;
    }
    const int ans = (day - d + 1) * 1440 - 60 * h - m;
    
    std::cout << ans << "\n";
    
    return 0;
}