1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
#include <bits/stdc++.h>
#define endl '\n'

using namespace std;

int outs[6] = {-1, 36000, 37440, 38880, 40320, 43140};

int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(nullptr);

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

   int in = m + 60 * (h + 24 * d);
   if (d == 29 && h > 2) in -= 60;
   cout << outs[x] - in;

   return 0;
}