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
from sys import stdin, stdout

MAX_M = 60
MAX_H = 24
MAX_DAY = {
        1: 24, 2: 25, 3: 26, 4: 27, 5: 29
}

r, d, h, m = [int(x) for x in stdin.readline().split()]
result = 0

if (r == 5) and (
        (d < MAX_DAY[5]) or
        (d == MAX_DAY[5]) and (h < 2)
        ):
    result -= 60

if (m > 0):
    result += MAX_M - m
    h += 1
if (h > 0):
    result += (MAX_H - h) * MAX_M
    d += 1
result += (MAX_DAY[r] + 1 - d) * MAX_H * MAX_M

stdout.write(str(result))