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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include<iostream>
#include<vector>

struct Time {
    int d = 0;
    int h = 0;
    int m = 0;

    void Normalize() {
        while (m >= 60)
        {
            m -= 60;
            ++h;
        }
        while (h >= 24) {
            h -= 24;
            ++d;
        }
    }
};

bool operator == (const Time& lhs, const Time& rhs)
{
    return lhs.d == rhs.d && lhs.h == rhs.h && lhs.m == rhs.m;
}

bool operator != (const Time& lhs, const Time& rhs)
{
    return !(lhs == rhs);
}

Time AdvanceTime(const Time time) {
    Time result{time.d, time.h, time.m + 1};
    result.Normalize();
    if (result.d == 29 && result.h == 2 && result.m == 0) {
        result.h = 3;
    }
    return result;
}

std::vector<Time> end_times{
    {25, 0, 0},
    {26, 0, 0},
    {27, 0, 0},
    {28, 0, 0},
    {30, 0, 0}
};

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

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

    Time time{d, h, m};
    int result = 0;

    while (time != end_times[x - 1]) {
        time = AdvanceTime(time);
        ++result;
    }

    std::cout << result << '\n';
}