1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
#include <iostream>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int x, d, h, m, e, z = 29 * 24 * 60 + 2 * 60;
  cin >> x >> d >> h >> m;
  m += 60 * (h + d * 24);
  e = ((x + (x == 5)) + 24) * 24 * 60;
  if (m <= z && e > z + 60)
    m += 60;
  cout << (e - m) << '\n';
}