1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <bits/stdc++.h>

using namespace std;

#define endl "\n"

const int minutes_in_day = 24*60;

void solve() {

  int x, d, h, m;
  cin >> x >> d >> h >> m;

  const int minutes_till_end_of_day = (24 - h) * 60 - m;

  int ans = minutes_till_end_of_day;

  switch(x) {
    case 5: {
      if(d == 27) ans += minutes_in_day;
      if(d == 27 || d == 28) {
        ans += minutes_in_day - 60;
      } else if(h < 2) {
        ans -= 60;
      }
      break;
    }
    default: {
      if(x + 22 == d) {
        ans += minutes_in_day;
      }
    }
  }
  cout << ans << endl;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  //cin >> t;
  while (t--) {
    solve();
  }
}