1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>

using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

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

	int koniec = x == 5 ? 30 : 24 + x;
	int wynik = (koniec - d) * 24 * 60 - h * 60 - m;

	if ((d<29 || d==29 && h<3) && koniec>29) wynik-=60;
	cout << wynik << endl;

	return 0;
}