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
29
30
31
32
#include <bits/stdc++.h>
using namespace std;

#define all(a) (a).begin(), (a).end()

typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pii;

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

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

    if (x <= 4) {
        int mins = 24*60-h*60-m;
        if (d-x == 22) mins += 24*60;
        cout<<mins<<'\n';
        return 0;
    }

    int mins = 24*60-h*60-m;
    if (d < 29 || (d==29 && h<2)) mins -= 60;
    mins += 24*60*(29-d);
    cout<<mins<<'\n';

    return 0;
}