1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
#!/usr/bin/env python3

ROUND_LAST_DAY = [24, 25, 26, 27, 29]
HOURS_IN_DAY = 24
MINUTES_IN_HOUR = 60
DST_CHANGE_DAY = 29
DST_CHANGE_HOUR = 2

x, d, h, m = map(int, input().strip().split())

num_full_days = ROUND_LAST_DAY[x - 1] - d
num_full_hours = (HOURS_IN_DAY - h - 1) + num_full_days * HOURS_IN_DAY
has_dst_change = x == 5 and (d < DST_CHANGE_DAY or (d == DST_CHANGE_DAY and h < DST_CHANGE_HOUR))
if has_dst_change:
    num_full_hours -= 1
num_full_minutes = (MINUTES_IN_HOUR - m) + num_full_hours * MINUTES_IN_HOUR

print(num_full_minutes)