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

#define int long long
typedef pair<int, int> T;

void solve() {
    int x, d, h, m; cin >> x >> d >> h >> m;
    
    int dzien_koniec = 23 + x + (x == 5 ? 1 : 0);

    int ans = (23 - h) * 60 + (59 - m) + (dzien_koniec - d) * 24 * 60 + 1;
    if (x == 5 && T{d, h} <= T{dzien_koniec, 2}) ans -= 60;
    cout << ans << endl;
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    solve();

    return 0;
}