1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long x, d, h, m;
  cin >> x >> d >> h >> m;
  long long end_day = 23 + x;
  end_day += x == 5;
  long long end_hour = end_day * 24 + 23;
  long long end_minute = end_hour * 60 + 60;

  long long start_time = (d * 24 + h) * 60 + m;
  if(x == 5){
    if(d < 29){
      end_minute -= 60;
    }else if(d == 29 and h < 2){
      end_minute -= 60;
    }
  }
  cout << end_minute - start_time;
}