1
 2
 3
 4
 5
 6
 7
 8
 9
10
#include <bits/stdc++.h>
using namespace std;
int x, d, h, m;

int main()
{
    cin>>x>>d>>h>>m;
    cout<<((24+x - d) * 1440 - h*60 - m - ( x==5 && (d!=29 || h<3) ? 60 : 0) + (x==5? 1440 : 0) );
    return 0;
}