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
#include <bits/stdc++.h>

using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int x, d, h, m;
    cin >> x >> d >> h >> m;

    if (x <= 4) {
        int ileDni = (x+23)-d;
        int ileGodz = ileDni * 24 + (23 - h);
        int ileMinut = ileGodz * 60 + (60 - m);
        cout << ileMinut << '\n';
    } else {
        int ileDni = 29-d;
        int ileGodz = (23 - h);
        if (ileDni == 0 && h <= 2) ileGodz -= 1;
        else if (ileDni == 1) ileGodz += 23;
        else if (ileDni == 2) ileGodz += 23+24;
        int ileMinut = ileGodz * 60 + (60 - m);
        cout << ileMinut << '\n';
    }

    return 0;
}