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

constexpr int toMin(const int &d, const int &h, const int &m, const int &zone = 0){
    
    return m + 60*((h-zone) + 24*d);
}


constexpr int rnds[6] = {0, toMin(25, 0, 0), toMin(26, 0, 0), toMin(27, 0, 0), toMin(28, 0, 0), toMin(30, 0, 0, 1)};

int main(){
    int x, d, h, m;
    cin >> x >> d >> h >> m;
    int tchange = toMin(29, 2, 0);
    int t = toMin(d, h, m);
    if(t >= tchange) t = toMin(d, h, m, 1);
    cout << rnds[x] - t << '\n';

}