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
#include <bits/stdc++.h>

using namespace std;

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

    int x, d, h, m;
    cin >> x >> d >> h >> m;

    int start = 24*60*d + 60*h + m;
    int koniec=0;

    if (x <= 4){
        koniec = (23+x)*24*60 + 23*60 + 59;
    }
    else{
        koniec = 29*24*60 + 23*60 + 59;
        if (!(h >= 3 && d==29)) koniec-=60;
    }

    cout << koniec-start+1 << "\n";

    return 0;
}