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

int mG = 60;
int mD = 24*60;

int main(){
	using namespace std;
	ios::sync_with_stdio(false), cin.tie(nullptr);

	int x, d, h, m;
	cin >> x >> d >> h >> m;
	
	if(x == 5){
		int res = (29 - d) * mD + (24 - h) * mG - m;
		if(d < 29 || (d == 29 && h <= 2)){
			res -= 60; // bo czas jeszcze przeskoczy
		}
		cout << res << '\n';
		return 0;
	}

	cout << (23 + x - d) * mD + (24 - h) * mG - m << '\n';

	return 0;
}