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
29
30
31
32
#include <bits/stdc++.h>

using namespace std;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int x, d, h, m;

	cin >> x >> d >> h >> m;

	if (x < 5) {
		int days = 23 + x - d;
		int hours = 23 - h;
		int minutes = 59 - m;
		int result = 24 * 60 * days + 60 * hours + minutes;
		cout << result + 1 << '\n';
	} else {
		int days = 24 + x - d;
		int hours = 23 - h;
		int minutes = 59 - m;
		int result = 24 * 60 * days + 60 * hours + minutes;
		if (result > 20 * 60 + 59) {
			result -= 60;
		}
		cout << result + 1 << '\n';
	}

	return 0;
}