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
#include <cstdio>
#include <cstdlib>
#include <cstdint>
#include <vector>
#include <map>
#include <algorithm>
#include <set>
#include <time.h>
#include <queue>

using namespace std;

int main () {
	int x, d, h, m;
	scanf("%d %d %d %d", &x, &d, &h, &m);
	if (x <= 4) {
		printf("%d\n", 1440 * (x - d + 24) - 60 * h - m);
		return 0;
	}
	int res = 1440 * (x - d + 25) - 60 * h - m;
	if (d < 29 || h < 2) {
		res -= 60;
	}
	printf("%d\n", res);
	return 0;
}