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 minuty(int d, int h, int m) 
{
        return (d - 23) * 24 * 60 + h * 60 + m;
}
int main() 
{
    int x, d, h, m;
    cin >> x >> d >> h >> m;
    int e_d;
    if (x < 5) e_d = 23 + x;
    else e_d = 29;
    int e_h = 24;
    int e_m = 0;
    int start = minuty(d, h, m);
    int end = minuty(e_d, e_h, e_m);
    int res = end - start;
    int c = minuty(29, 2, 0);
    if (start < c && end > c) 
    {
        res -= 60;
    }
    cout << res;
}