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

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int x, d, h, m;
    cin >> x >> d >> h >> m;
    x--;
    int rx[] = {24, 24, 24, 24, 24};
    int dx[] = {24, 25, 26, 27, 29};
    int w = 0;
    while (d < dx[x]){
        ++d;
        if (d == 29 and h > 2){
            w -= 60;
        }
        w += 24 * 60;
    }
    if (x == 4 and h <= 2 and d == 29) {
        ++h;
    }
    w += (rx[x] - h - 1) * 60;
    w += 60 - m;
    cout << w << endl;
}