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
#include <vector>
#include <iostream>

using namespace std;

typedef long long int ll;

int x, d, h, m;
int ending_days[] = {24, 25, 26, 27, 29};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> x >> d >> h >> m;

    int current_minute = d * 60 * 24 + h * 60 + m;
    int ending_minute = ending_days[x-1]*60*24 + 24 * 60;

    if (x == 5 && !(d == 29 && h >= 3)){
        ending_minute -= 60;
    }

    cout << ending_minute - current_minute << endl;
        
    return 0;
}