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
// Template generated by Clank
#include<bits/stdc++.h>
using namespace std;
#define st first
#define nd second
#define all(x) x.begin(), x.end()
#define BOOST cin.tie(NULL); ios_base::sync_with_stdio(false);
// #define int ll
typedef long long ll;

int lim[]={0,24,25,26,27,29};

int32_t main(){
    BOOST;

    int x, d, h, m;
    cin >> x >> d >> h >> m;
    int tmp = (lim[x] - d) * 24 * 60 + (24 * 60 - h * 60 - m);
    if(x < 5){
        cout << tmp << "\n";
    } else {
        if(d <= 28 || h < 2) tmp -= 60;
        cout << tmp << "\n";
    }
    return 0;
}