1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
#include <vector>
#include <algorithm>
#include <iostream>

using namespace std;

int main() {
    int x,d,h,m;
    cin>>x>>d>>h>>m;
    int ans = 0;
    ans += 60 - m + (23 - h) * 60;
    if(x < 5) ans += (1 - (d - x - 22)) * 60 * 24;
    if(x == 5) ans += (2 - (d - x - 22)) * 60 * 24 - 60;
    if(x == 5 && d == 29 && h > 2) ans += 60;
    cout<<ans<<endl;
}