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
27
28
29
#include <iostream>
using namespace std;

int main() {
    int x, d, h, m;
    int res = 0;

    cin >> x >> d >> h >> m;

    if (x != 5) {
        res += (23 - h) * 60;
        res += 60 - m;
        if (d != 23 + x) {
            res += 24 * 60;
        }
    } else {
        res += (23 - h) * 60;
        res += 60 - m;
        if (d != 23 + x) {
            res += 24 * 60;
        }
        if (d != 24 + x) {
            res += 23 * 60;
        }
    }

    cout << res;
    return 0;
}