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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define FORD(i,a,b) for(int i=a;i>=b;--i)
#define PB push_back
#define EB emplace_back
#define FI first
#define SE second
#define umap unordered_map
#define uset unordered_set
#define vi vector<int>
#define vvi vector<vi>
#define vll vector<ll>
#define vvll vector<vll>
#define vpii vector<pii>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ALL(X) (X).begin(),(X).end()
#ifndef DEBUG
//#define endl (char)10
#endif
using namespace std;
using ll = long long;
using ld = long double;

template <class T>
ostream& operator<< (ostream& os, const vector<T>& vec){
    for(auto& t : vec) os << t << " ";
    return os;
}
template<class T, class U>
ostream& operator<< (ostream& os, const pair<T, U>& p){
    os << p.FI << " " << p.SE;
    return os;
}
template<class T, class U>
istream& operator>> (istream& is, pair<T, U>& p){
    is >> p.FI >> p.SE;
    return is;
}
template <class T>
istream& operator>> (istream& is, vector<T>& vec){
    for(auto& p : vec) is >> p;
    return is;
}

void updfs(vvi& V, int x, vi& up) {
	if (V[x].size() == 0) {
		up[x] = 1;
		return;
	}
	up[x] = 3;
	for(int v : V[x]){
		updfs(V, v, up);
		up[x] += up[v];
	} 
}

void ansdfs(vvi& V, int x, vi& ans, vi& up) {
	ans[x] += up[x];
	ans[x] %= 1000000007;
	for(int v : V[x]){
		ans[v] = ans[x];
		ansdfs(V, v, ans, up);
	}
}
int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int x, d, h, m;
    cin >> x >> d >> h >> m;
    d -= x;
    d -= 22;
	int sm = m;
	int tm = (x == 5 ? 59 : 36) * 60;
    if (x == 5) {
		if (d == 0) sm += 60 * (h - 12);
		if (d == 1) sm += 60 * (h + 12);
		if (d == 2) sm += 60 * (h + 35 + (h < 2));
    } else {
		sm += 60 * (d > 0 ? h + 12 : h - 12);
	}
    cout << tm - sm << endl;
    
    
}