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

int main() {
	ios_base::sync_with_stdio(0);
	int x, d, h, m; cin >> x >> d >> h >> m;
	
	int t_end = (x + 1) * 24 * 60; 
	if (x == 5) t_end += 23 * 60;
	
	int t_start = (d - 23) * 24 * 60 + h * 60 + m;
	if (d == 29 && h > 2) t_start -= 60;
	
	cout << t_end - t_start << endl;
	return 0;
}