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
// Source: https://usaco.guide/general/io

#include <bits/stdc++.h>
using namespace std;

int main() {
	int d, h, m, r; cin >> r >> d >> h >> m;
    if(r < 5){
        if(d%2 == r%2){
            cout  << 24*60 + (24*60 - (h*60 + m)); 
        }
        else{
            cout << (24*60 - (h*60 + m)); 
        }
    }
    else{
        if(d == 27){
            cout << 47*60 +  (24*60 - (h*60 + m));
        }
        else if(d == 28){
            cout << 23*60 +  (24*60 - (h*60 + m));
        }
        else{
            if(h < 2) {
                cout << (23*60 - (h*60 + m)) << "\n";
            } else {
                cout << (24*60 - (h*60 + m)) << "\n";
            }
        }
    }

}