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
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#define pr pair
#define f first
#define s second
#define ll long long
#define mp make_pair
#define pll pr<ll,ll>
#define pii pr<int,int>
#define piii pr<int,pii>
using namespace std;
const int ed[5]={36000,37440,38880,40320,43140};
int main()
{
	ios_base::sync_with_stdio(0);
	int a,x,y,z;
	cin>>a>>x>>y>>z;
	if(x==29&&y>2) y--;
	x=x*24+y;
	x=x*60+z;
	a--;
	cout<<ed[a]-x<<endl;
	return 0;
}