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
x, d, h, m = map(int, input().split())

# Koniec rundy
if x == 1:
    end_d = 24
elif x == 2:
    end_d = 25
elif x == 3:
    end_d = 26
elif x == 4:
    end_d = 27
else:
    end_d = 29

# Naiwna liczba minut (bez korekty zmiany czasu)
start_min = h * 60 + m
naive = (end_d - d + 1) * 1440 - start_min

# Korekta za zmianę czasu (tylko runda 5)
sub = 0
if x == 5:
    if d < 29 or (d == 29 and h < 2):
        sub = 60

print(naive - sub)