1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
#include<bits/stdc++.h>
using namespace std;
const int M=24*60;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  int x,d,h,m; cin>>x>>d>>h>>m;
  if(x<=4){
    if(d==x+22)cout<<M*2-(h*60+m)<<endl;
    else cout<<M-(h*60+m)<<endl;
  }
  else{
    if(d==27)cout<<M*3-(h*60+m)-60<<endl;
    else if(d==28)cout<<M*2-(h*60+m)-60<<endl;
    else cout<<M-(h*60+m)-(h<2?60:0)<<endl;
  }
  return 0;
}