1
2
3
4
5
6
7
8
#include <bits/stdc++.h>
using namespace std;
int32_t main(){
    int x, d, h, m; cin >> x >> d >> h >> m;
    int mx = ((x+24+(x == 5 ? 1 : 0))*24*60);
    int start = (d*24*60) + (h*60)  + m;
    cout << mx - start - (x == 5 and start < 41880 ? 60 : 0);
}