1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
#include <bits/stdc++.h>

using namespace std;
int x,d,h,m,i;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> x >> d >> h >> m;
	if(x<5) {
		cout << (23+x-d)*24*60+(23-h)*60+60-m;
	}
	else if (d==29 && h>2) cout << (23-h)*60+60-m;
	else cout << (24+x-d)*24*60+(23-h)*60-m;
}