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
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

LL koniec_rundy(LL x){
	vector<LL> koniec = {0, 2160, 3600, 5040, 6480, 9300};
	return koniec[x];
}

LL poczatek_rozwiazywania(LL d, LL h, LL m){
	if(d == 29 && h>=3){
		h--;
	}
	d-=23;
	h-=12;
	if(h<0){
		h+=24;
		d--;
	}
	return d*24*60+h*60+m;
}


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	LL x, d, h, m;
	cin>>x>>d>>h>>m;
	cout<<koniec_rundy(x) - poczatek_rozwiazywania(d, h, m)<<"\n";
	return 0;
}