1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <bits/stdc++.h>
using namespace std;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n, d, h, m;
	cin >> n >> d >> h >> m;
	if (n < 5) {
		if (d == 22+n+1) {h += 24;}
		cout << 2880-(h*60 + m);
		return 0;
	}
	else {
		if (d == 28) {h += 24;}
		else if (d == 29) {h += 48;}
		if (h*60 + m < 3000) {
			cout << 4320 - (h*60+m) - 60;
			return 0;
		}
		else {
			cout << 4320 - (h*60+m);
			return 0;
		}
	}
	return 0;
}