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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <bits/stdc++.h>
#include <unordered_map>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef vector<vi> vvi;
typedef vector<bool> vb;

#define eb(x) emplace_back(x)
#define loop(i,a,b) for (int (i) = (a); (i) < b; (i)++)
#define rloop(i,a,b) for (int (i) = (a); (i) >= b; (i)--)

int main()
{
    cin.tie(0)->sync_with_stdio(false);

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

    if (x <= 4)
    {
        int doNastGodz = (60 - m);
        int doKoncDnia = 60*(23 - h);
        if (d < (23 + x))
            cout << doNastGodz + doKoncDnia + 60 * 24;
        else
            cout << doNastGodz + doKoncDnia;
    }
    else
    {
        int tot = 24 * 60 * (29 - d);
        tot += (60 - m) + 60 * (23 - h);
        if (d < 29 || h < 2)
            tot -= 60;
        cout << tot;
    }
    return 0;
}