1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <bits/stdc++.h>
#define nl '\n'

using namespace std;

int main()
{
	cin.tie(0)->sync_with_stdio(0);
	int x, d, h, m;
	cin>>x>>d>>h>>m;
	if(x < 5){
		int round_end = (24+x)*24*60;
		cout<<round_end - m - 60*h - d*24*60<<nl;
	}else{
		int round_end = (30)*24*60-60;
		int t = m + 60*h + 24*60*d;
		if(t >= 29*24*60 + 3*60){ t -= 60; }
		cout<<round_end - t<<nl;

	}
	return 0;
}