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

typedef long long ll;
typedef unsigned long long ull;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(a) (int)a.size()
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define endl '\n'
#define fast ios_base::sync_with_stdio(0);cin.tie(0);
#define vc vector
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pulul pair<ull,ull>

ll conv(int d, int h, int m)
{
    ll res=0;
    for(int i=23; i<d; ++i)
    {
        if(i==29)
            res+=23*60;
        else
            res+=24*60;
    }
    res+=1LL*h*60+m;
    if(d==29 and h>=3)
        res-=60;
    return res;
}
void solve()
{
    int x,d,h,m;
    cin >> x >> d >> h >> m;

    int kon;
    if(x<5)
        kon=24+x;
    else
        kon=30;

    cout << conv(kon,0,0)-conv(d,h,m);
}



int main() 
{
    fast;
    int t=1;
    //cin >> t;
    while(t--) 
    solve();
    return 0;
}