1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
#include <bits/stdc++.h>

int main() {
  std::ios_base::sync_with_stdio(0); std::cin.tie(NULL);
  int x, d, h, m;
  std::cin >> x >> d >> h >> m;

  int d0;
  if (x <= 4) d0 = 24 + x - 1;
  else d0 = 29;

  int t = (d0 - d) * (24 * 60) + (23 - h) * (60) + (60 - m);

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

  std::cout << t << "\n";
}