1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
#include <bits/stdc++.h>

using namespace std;

int x, d, h, m;
constexpr int D = 60 * 24;
int koniec[6] = {-1, 24, 25, 26, 27, 29};

bool check() {
    return x == 5 && (h < 2 || d < 29);
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> x >> d >> h >> m;
    cout << D - 60 * h   - m + D * (koniec[x] - d) - (check() ? 60 : 0) << '\n';
}