1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
#include <iostream>

int main() {
  int x, d, h, m;
  std::cin >> x >> d >> h >> m;

  int ans = (23 + x - d) * 24 * 60 + (23 - h) * 60 + (60 - m);
  if (x == 5)
    ans += 24 * 60;

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

  std::cout << ans << '\n';

  return 0;
}