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
50
51
52
53
54
55
56
/* -----------------------
Autor: Tomasz Boguslawski
-------------------------- */
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<fstream>
#include<iomanip>
#include<string>
#include<sstream>
#include<cstring>
#include<map>
#include<vector>
#include<set>
#include<queue>
#include<algorithm>
#include <fstream>
#include<math.h>

#define LL long long
#define FOR(x, b, e) for(LL x = b; x <= (e); x++)
#define FORS(x, b, e, s) for(LL x = b; x <= (e); x+=s)
#define FORD(x, b, e) for(LL x = b; x >= (e); x--)
#define VAR(v, n) __typeof(n) v = (n)
#define ALL(c) (c).begin(), (c).end()
#define FOREACH(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define DEBUG if (debug)
#define MIN(a,b) ((a>b)?b:a)
#define MAX(a,b) ((a>b)?a:b)

using namespace std;

int minute(int d, int h, int m)
{
   int minu = d * 1440 + h * 60 + m;
   if (d>=29 && h>=3) minu -= 60;
   return minu;
}


/// MAIN
int main(int argc, char* argv[])
{
    // magic formula, which makes streams work faster:
	ios_base::sync_with_stdio(0);
	int x, d, h, m;
	cin >> x; cin >> d; cin >> h; cin >> m;
	int endMinute;
	if (x==1) endMinute=minute(24,23,59);
	else if (x==2) endMinute=minute(25,23,59);
	else if (x==3) endMinute=minute(26,23,59);
	else if (x==4) endMinute=minute(27,23,59);
	else endMinute=minute(29,23,59);
	cout << endMinute-minute(d,h,m)+1 << "\n";
	return 0;
}