1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <bits/stdc++.h>
#define rep(i, p, k) for (int i = (p); i < (k); ++i)
#define all(v) (v).begin(), (v).end()
#define ll long long
#ifndef DEBUG
#define debug(...)
#else
#include "debug.h"
#endif
using namespace std;

int main() {
  cin.tie(0)->sync_with_stdio(0);
  int x, d, h, m;
  cin >> x >> d >> h >> m;
  if (x <= 4) {
    cout << (24 - h) * 60 - m + (d - x == 22 ? 24 * 60 : 0) << '\n';
  } else {
    if (d < 29 || h < 2) h++;
    cout << (29 - d) * 24 * 60 + (24 - h) * 60 - m << '\n';
  }
}