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);

    int x, d, h, m;
    cin >> x >> d >> h >> m;
    if (x < 5) {
        cout << 2 * 24 * 60 - 24 * 60 * (d - 23 - x + 1) - h * 60 - m << '\n';
    }
    else if (d < 29 || h < 2) {
        cout << 3 * 24 * 60 - 24 * 60 * (d - 23 - x + 1) - h * 60 - m - 60 << '\n';
    }
    else {
        cout << 3 * 24 * 60 - 24 * 60 * (d - 23 - x + 1) - h * 60 - m << '\n';
    }
    return 0;
}