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

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie();
	int reg = 36 * 60, five = 59 * 60, x, d, h, m;

	std::cin >> x >> d >> h >> m;

	if (d == 29 && h > 2) {
		--h;
	}

	d -= x + 22;
	m += (h - 12) * 60 + d * 24 * 60;

	if (x == 5) {
		std::cout << five - m;
	}
	else {
		std::cout << reg - m;
	}

	return 0;
}