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

#define ll long long
#define st first
#define nd second
#define ld long double

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int x, d, h, m;
    cin >> x >> d >> h >> m;
    int ts = d*24*60+h*60+m-(22+x)*24*60-12*60;
    if (x < 5) {
        cout << 36*60-ts << '\n';
    }
    else {
        if (d < 29 || h < 2) {
            ts += 60;
        }
        cout << 60*60-ts << '\n';
    }
}