1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
using namespace std;

int main() {
    int x, d, h, m;
    cin >> x >> d >> h >> m;
    d -= x-1 + 23;
    

    int final_time;
    if(x == 5) {
        final_time = (24 + 24 + 12) * 60;
        h += d < 2 || h < 2 ? 1 : 0;    
    }
    else {
        final_time = (24 + 12) * 60;
    }

    h -= 12;

    int current_time = m + (h + d*24) * 60;
    cout << final_time - current_time << "\n";
}