1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
#include <bits/stdc++.h>
using namespace std;

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

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

    int result = ((23 + x - d) * 24 + (23 - h)) * 60 + (60 - m);
    if(x == 5)          //extra day
        result += 24*60;
    if(x == 5 && result > 22 * 60)
        result -= 60;           //time change
    cout << result << "\n";

    return 0;
}