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

using ll = long long;

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

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

    int start_date = 23 + x - 1;
    int end_date = start_date + 1;
    if (x == 5) end_date += 1;

    int days = end_date - d;
    int hours = 23 - h;
    int minutes = 60 - m;
    int result = days * 24 * 60 + hours * 60 + minutes;
    if (x == 5 && (d != 29 || h < 3)) result -= 60;
    cout << result;
}