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
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define rep(a,b) for(int a = 0; a < (b); ++a)
#define all(t) t.begin(), t.end()
#define pb push_back
#define fi first
#define se second
#define each(a,x) for(auto &a:x)
#define vi vector<int>
#define vll vector<ll>
#define vull vector<ull>
#define pi pair<int,int>
#define pll pair<ll,ll>
#define nl '\n'
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2")
#pragma GCC target("bmi")
#pragma GCC target("bmi2")
#pragma GCC target("lzcnt")
#pragma GCC target("popcnt")
const int N = 1e6+1234,INF = 2e9+1234;
const ll INF_L = (ll)2e18+1234, mod = 998244353;
void solve()
{
    int x,d,h,m;cin>>x>>d>>h>>m;int ans=0;
    if(x==1 and d==23) ans=24*60-(h*60+m)+24*60;
    else if(x==1) ans=24*60-(h*60+m);
    else if(x==2 and d==24) ans=24*60-(h*60+m)+24*60;
    else if(x==2) ans=24*60-(h*60+m);
    else if(x==3 and d==25) ans=24*60-(h*60+m)+24*60;
    else if(x==3) ans=24*60-(h*60+m);  
    else if(x==4 and d==26) ans=24*60-(h*60+m)+24*60;
    else if(x==4) ans=24*60-(h*60+m);
    else if(x==5 and d==27) ans=24*60-(h*60+m)+48*60-60;
    else if(x==5 and d==28) ans=24*60-(h*60+m)+24*60-60;
    else if(x==5 and d==29) ans=24*60-(h*60+m)-(h<2)*60;
    else ans=0;
    cout << ans << nl;
}
int main()
{ 
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int T=1;
    //cin >> T;
    while(T--) solve();
    return 0;
}