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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <bits/stdc++.h>

using namespace std;
#define fors(u, n, s) for(int u = (s); u<(n); u++)
#define foru(u, n) fors(u, n, 0)
#define f first
#define s second
#define vec vector
#define pb push_back
typedef long long ll;

int get_time_pure(int d, int h, int m){
	return m + 60*(h + 24*d);
}

int get_time(int d, int h, int m){
	int time = get_time_pure(d, h, m);
	if(time >= get_time_pure(6, 2, 0)) time -= 60;
	return time;
}

const int rounds[5] = {
	get_time(1, 24, 0),
	get_time(2, 24, 0),
	get_time(3, 24, 0),
	get_time(4, 24, 0),
	get_time(6, 24, 0),	
};

void solve() {
	int x, d, h, m; cin >> x >> d >> h >> m;

	d -= 23; x--;

	cout << rounds[x] - get_time(d, h, m) << endl;

}

int main()
{
	// cin.tie(0); cout.tie(0);
	// ios_base::sync_with_stdio(0);

	srand(time(NULL));

	solve();

	return 0;
}