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

int main(){
	ios_base::sync_with_stdio(false), cin.tie(nullptr);
	int X, D, H, M;
	cin >> X >> D >> H >> M;
	int now = (D * 24 + H) * 60 + M;
	int end = (23 + X + int(X == 5) + 1) * 24 * 60;
	int dst = (29 * 24 + 2) * 60;
	int ans = end - now;
	if(end >= dst && now < dst) ans -= 60;
	cout << (ans) << '\n';
}