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

int adjust(int x) {
  if (x >= 6*1440 - 600) return x-60;
  return x;
}

int main () {
  ios_base::sync_with_stdio(0); cin.tie(0);
  int x, d, h, m;
  cin >> x >> d >> h >> m;
  int e = adjust((x-1 + (x == 5)) * 1440 + 2160);
  int s = adjust((d-23) * 1440 + (h-12) * 60 + m);
  cout << e-s << '\n';
}