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
#include <iostream>

using namespace std;

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

    int x, d, h, m;
    if (!(cin >> x >> d >> h >> m)) return 0;

    long long start = (long long)(d - 23) * 1440 + h * 60 + m;
    
    if (d == 29 && h >= 3) {
        start -= 60;
    }

    long long koniec;
    if (x == 1) koniec = 2 * 1440;
    else if (x == 2) koniec = 3 * 1440;
    else if (x == 3) koniec = 4 * 1440;
    else if (x == 4) koniec = 5 * 1440;
    else koniec = 7 * 1440 - 60;

    cout << koniec - start << endl;

    return 0;
}