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
33
34
35
#include <bits/stdc++.h>
#define pii pair<int, int>
#define For(i, l, r) for (int i=l;(l<=r?i<=r:i>=r);(l<=r?i++:i--))
#define DEBUG
#ifdef DEBUG
auto operator<<(auto &o,auto p)->decltype(p.first,o){return o<<'('<<p.first<<", "<<p.second<<')';}
auto operator<<(auto &o,auto x)->decltype(x.end(),o){o<<'{';int i=2;for(auto &e:x)o<<(", ")+i<<e,i=0;return o<<'}';}
#define LOG(X...)cerr<<"["#X"]: ",[](auto...$){((cerr<<$<<"; "),...)<<endl;}(X);
#else
#define LOG(x...)(void)0
#endif
#define int long long
using namespace std;

const int inf=1e9+1, M = 1LL << 40;

void solve(){
    int x, d, h, m;
    cin >> x >> d >> h >> m;
    int res = (60 - m) + (23 - h) * 60 + (x + 23 - d) * 24 * 60;
    if (x == 5){
        res += 24 * 60;
        if (d < 29 || h < 2)
            res -= 60;
    }
    cout << res << '\n';
}

signed main(){
    cin.tie(0)->sync_with_stdio(0);
    int t = 1;
    //cin >> t;
    while(t--)
        solve();
}