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
#include <algorithm>
#include <iostream>

int timestamp_at(int d, int h, int m) {
	if ((d == 29 && h >= 3) || d > 29) --h;
	return (d - 23) * 24 * 60 + h * 60 + m;
}

int main() {
	int x, d, h, m;
	std::cin >> x >> d >> h >> m;

	int ts_now = timestamp_at(d, h, m);
	
	int ts_end[] {
		0,
		timestamp_at(25, 0, 0),
		timestamp_at(26, 0, 0),
		timestamp_at(27, 0, 0),
		timestamp_at(28, 0, 0),
		timestamp_at(30, 0, 0),
	};

	int answer = ts_end[x] - ts_now;
	
	std::cout << answer << '\n';
}