1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    short x, d, h, m, t;
    cin>>x>>d>>h>>m;
    d -= 22+x;
    h += 24*d -12;
    m += 60*h;
    if(x != 5){
        t = 2160 - m;
    } else {
        t = 3600 - m;
        if(t > 1260) t -= 60;
    }
    cout<<t;
    return 0;
}