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

typedef long long LL;
typedef vector<int> VI;

#define FOR(x,b,e) for(x=b;x<=e;x++)
#define FORD(x,b,e) for(x=b;x>=e;x--)
#define REP(x,n) for(x = 0; x<(n);x++)

#define ALL(c) (c).begin(), (c).end()
#define VAR(v,n) __typeof(n) v = (n)
#define SIZE(x) (int)x.size()
#define FOREACH(x,c) for(VAR(x, (c).begin()); x != (c).end(); x++)
#define PB push_back
#define ST first
#define ND second

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

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

    if(x<5){
        if(d == x+22){
            cout<<2160 - ((h-12)*60+m);
        }
        else {
            cout<<1440 - h*60 - m;
        }
    }
    else{
        if(d == x+22){
        cout<<3540 - ((h-12)*60+m);
        }
        else if(d == 28){
            cout<<2820 - h*60 - m;
        }
        else if(d==29 && (h == 0 || h == 1)){
             cout<<1380 - h*60 - m;
        }
        else {
            cout<<1380 - (h-1)*60 - m;
        }

    }



return 0;
}