1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <bits/stdc++.h>
using namespace std;

int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	int x, d, h, m;
	cin >> x >> d >> h >> m;
	
	int tmp = h * 60 + m;
	
	if(x <= 4){
		if(d == x + 23) cout << 24 * 60 - tmp;//dzien kiedy sie konczy
		else cout << 2 * 24 * 60 - tmp;//dzien rozpoczecia
	}
	else{//ostatnia runda
		if(d == 27) cout << 3 * 24 * 60 - 60 - tmp;
		else if(d == 28) cout << 2 * 24 * 60 - 60 - tmp;
		else{
			if(h >= 3) cout << 24 * 60 - tmp;
			else cout << 23 * 60 - tmp;
		}
	}
}