1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
#include <bits/stdc++.h>

using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
    int x, d, h, m; cin >> x >> d >> h >> m;
    d -= 22;
    int res = (23 - h) * 60 + (60 - m);
    if (x <= 4) {
        if (x != d) cout << res << "\n";
        else cout << 24 * 60 + res << "\n";
    } else {
        if (d < 7 || h < 2) cout << res + (7 - d) * 24 * 60 - 60 << "\n";
        else cout << res << "\n";
    }
}