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 <algorithm>
#include <iostream>
#include <vector>
#include <list>
#include <cassert>
using namespace std;

#define FOR(i, n) for (int i = 0, __n = (n); i < __n; i++)

int main()
{
  int x, d, h, m;
  scanf("%d%d%d%d", &x, &d, &h, &m);

  int d1 = 24 + x, h1 = 0, m1 = 0;
  if (x == 5)
    d1++;

  int mins = ((d1 - d) * 24 + (h1 - h)) * 60 + (m1 - m);

  if (x == 5 && (d < 29 || d == 29 && h < 2))
    mins -= 60;

  printf("%d\n", mins);
  return 0;
}