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
33
#include <bits/stdc++.h>
using namespace std;
const int HOUR = 60;
const int DAY_HOURS = 24;
const int DAY_MINUTES = DAY_HOURS * HOUR;
int main() {
//	 ifstream cin("tests/0b.in");
	// ifstream cin("D:/cpp/_tests/1c-zmi/0a.in");

	cin.tie(NULL);
	cout.tie(NULL);
	ios_base::sync_with_stdio(false);

	int x, d, h, m, result;
	cin >> x;
	cin >> d;
	cin >> h;
	cin >> m;

	d = d - 22;
	result = (DAY_HOURS - h) * 60 - m;
	if (x == d) {
		result += DAY_MINUTES;
	}
	if (x == 5) {
		if (d < 7) {
			result += (DAY_MINUTES - HOUR);
		} else if (h < 3) {
			result -= HOUR;
		}
	}
	cout << result;
}