peterverebics/CodeNet_Python_118 huggingface dataset:
h1, m1, h2, m2, k = map(int, input().split())

wake = 60 * h1 + m1
sleep = 60 * h2 + m2
waking = sleep - wake
res = waking - k
print(res)
t = [list(map(int, s.split())) for s in open(0)][0]
print((t[2]*60 + t[3]) - (t[0]*60 + t[1]) - t[4])
h1,m1,h2,m2,k = map(int,input().split())
time = (h2-h1)*60 + m2-m1
print(time-k)
h1, m1, h2, m2, k = map(int, input().split())
h = 0

m = m2 - m1
if m < 0:
    m += 60
    h -= 1
h = h2 - h1 + h
print((h * 60) + m - k)
h1,m1,h2,m2,k = list(map(int,input().split()))

h_m = (h2 - h1)*60
m = m2 - m1
tz = h_m + m

print(tz-k)
h, m, i, n, k = map(int, input().split())

fun1 = 60 * h + m
fun2 = 60 * i + n

sa = fun2-fun1

if sa > k:
    ans = sa -k
else:
    ans = 0

print(ans)
H1,M1,H2,M2,K=map(int,input().split())

t1=60*H1 + M1
t2=60*H2 + M2
t=t2 - K
ans=t-t1
print(max(0,ans))
a=list(map(int,input().split()))
s=a[0]*60+a[1]
g=a[2]*60+a[3]
print(max(g-s-a[4],0))
h1, m1, h2, m2, k = map(int, input().split())
time1 = h1 * 60 + m1
time2 = h2 * 60 + m2
ans = time2 - (time1 + k)
print(ans)
H1, M1, H2, M2, K = map(int, input().split())

ans = (H2 - H1 - 1) * 60

tmp = 60 - M1 + M2

print(ans + tmp - K)
h1,m1,h2,m2,k=map(int,input().split())
diff=(h2*60 + m2) - (h1*60 + m1)
print(diff-k)
import sys
input = sys.stdin.readline

H1, M1, H2, M2, K  = map(int, input().split())


start = H1 * 60 + M1
end = H2 * 60 + M2

print(end - K - start)
s = input()
h1, m1, h2, m2, k = s.split(' ')

h = int(h1) - int(h2)
m = 0
if int(m1) >= int(m2):
    m = int(m1) - int(m2)
else:
    h = h -1
    m = 60 + int(m1) - int(m2)
    
t = abs(h * 60 + m) - int(k)

print(t)
a,b,c,d,k = map(int, input().split())
e = (c * 60 + d) - (a * 60 + b)
print(e- k)
h1, m1, h2, m2, k = map(int, input().split())

a = m2 - m1
if a < 0:
    mm = (h2 - h1 - 1) * 60 + (60 + a)
else:
    mm = (h2 - h1) * 60 + a


print(0 if mm - k <= 0 else mm - k)
import sys
input = sys.stdin.readline

# from collections import deque

def linput(_t=int):
    return list(map(_t, input().split()))

def gcd(n,m):
    while m: n,m = m, n%m
    return n

def lcm(n,m): return n*m//gcd(n,m)

def main():
    # N = int(input())
    # vA = [int(input()) for _ in [0,]*N]
    h,m,H,M,K = linput()

    res = 60*H + M - 60*h - m - K

    print(res)
    # print(("No","Yes")[res%2])
    # print(*vR, sep="\n")

main()
import sys
import math
from collections import deque
from collections import defaultdict

def main():
    h1, m1, h2, m2, k = list(map(int,sys.stdin.readline().split()))
    h_v = h2 - h1 - 1
    m_v = (60 - m1) + m2
    time = h_v * 60 + m_v
    ans = time - k
    print(ans)
    return 0

if __name__ == "__main__":
    main()
a,b,c,d,e=map(int,input().split())

if -(a*60+b)+(c*60+d)-e <0:
        print(0)
        exit()
print(-(a*60+b)+(c*60+d)-e)
h1,m1,h2,m2,k = map(int, input().split())
T = (h2-h1)*60 + m2-m1-k
print(T)
import math

h1, m1, h2, m2, k = map(int, input().split(" "))

t1 = h1 * 60 + m1
t2 = h2 * 60 + m2

print(t2 - t1 - k)
h1,m1,h2,m2,k=input().split()

h1 = int(h1)
m1 = int(m1)
h2 = int(h2)
m2 = int(m2)
k = int(k)

if h1 > h2:
  h2 += 24
  
h = h2 - h1
hm = h * 60

print(hm - m1 + m2 - k)
import datetime

H_1, M_1, H_2, M_2, K = map(int, input().split())

end_time = datetime.time(H_2, M_2, 00)

limit_time = datetime.datetime.combine(datetime.date(year=2017, month=10, day=10), end_time) - datetime.timedelta(minutes=K)

start_time = datetime.time(H_1, M_1, 00)

dif = limit_time - datetime.datetime.combine(datetime.date(year=2017, month=10, day=10), start_time)

print(dif.seconds//60)
H1,M1,H2,M2,K  = map(int,input().split())

print((H2*60+M2) - (H1*60+M1) -K)
h1, m1, h2, m2, k = map(int, input().split())
st = h1 * 60 + m1
fin = h2 * 60 + m2
x = fin - k
print(x - st)
input = input()
split = input.split()
H1 = split[0]
M1 = split[1]
H2 = split[2]
M2 = split[3]
K = split[4]
h = int(H2)*60 - int(H1)*60 + int(M2) - int(M1) - int(K)
print(h)
h1, m1, h2, m2, k = map(int,input().split())
x = 60*max(0, h2-h1-1)
if h1 == h2:
    x += (m2-m1)
else:
    x += (60-m1 + m2)
print(x - k)
h1, m1, h2, m2, k = map(int, input().split())
t1 = h1 * 60 + m1
t2 = h2 * 60 + m2

if t1 > t2:
    print(720 - t1 + t2 - k)
else:
    print(t2 - t1 - k)
h1,m1,h2,m2,k = map(int,input().split())
start = h1*60+m1
end = h2*60+m2
print(max(end-k-start,0))
h1, m1, h2, m2, t = (int(x) for x in input().split())
s1 = h1 * 60 + m1
s2 = h2 * 60 + m2
ans = s2 - s1 - t
print(ans)
def main():
    h1, m1, h2, m2, k = map(int, input().split())
    x1 = h1*60+m1
    x2 = h2*60+m2
    print(x2-x1-k)

if __name__ == "__main__":
    main()
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

a, b, c, d, k = map(int, readline().split())

x = 60 * a + b
y = 60 * c + d

print(y - x - k)
H,M,h,m,K = map(int,input().split())
A = H*60 + M
B = h*60 + m
X = B - A - K
print(X)
h, m, x, y, k = map(int, input().split())
mi = x*60 + y - (h*60+m) - k
print(mi)
def Int():
    return int(input())
def Ints():
    return map(int,input().split())
def IntList():
    return list(Ints())
def IntMat(N):
    return [IntList() for i in range(N)]

import sys
sys.setrecursionlimit(4100000)
rl = sys.stdin.readline

H1,M1,H2,M2,K = Ints()

S = (H2-H1)*60+(M2-M1)

print(S-K)
h1, m1,h2,m2,k = map(int,input().split())
if h2 * 60 + m2 >h1* 60 + m1:
    r = (h2 * 60 + m2)  -(h1* 60 + m1) - k
else:
    r = (h2 * 60 + m2) + 24 * 60 - (h1* 60 + m1)  - k
print(r)
h1,m1,h2,m2,k = map(int,input().split())

time = (h2-h1)*60 + m2-m1

print(max(time-k, 0))
h1,m1,h2,m2,k=map(int,input().split())

t1 = h1*60 + m1
t2 = h2*60 + m2

ans = max(0,(t2 - k) - t1)

print(ans)
H_1, M_1, H_2, M_2, K = map(int, input().split())
print((H_2-H_1)*60 + (M_2 - M_1) - K)
h1, m1, h2, m2, k = map(int, input().split())

time1 = 60 * h1 + m1
time2 = 60 * h2 + m2
print(max(time2 - time1 - k, 0))
time = map(int, input().split())
list1=[]
for i in time:
    list1.append(i)
time1 = (list1[2]*60+list1[3])-(list1[0]*60+list1[1])
minute = time1  - list1[4]
print(minute)
h_1,m_1,h_2,m_2,k = map(int,input().split())

judge = h_2*60+m_2 - (h_1*60+m_1)
if judge - k>=0:
  ans = judge - k
else:
  ans = 0

print(ans)
h1, m1, h2, m2, k = map(int, input().split())
print(max(abs(60*h2+m2 - 60*h1-m1) - k, 0))
h1,m1,h2,m2,k=list(map(int,input().split()))

s=60*h1+m1
t=60*h2+m2-k

print(t-s)
def readInt():
    return list(map(int, input().split()))
    
h_1, m_1, h_2, m_2, k = readInt()
t_1 = h_1*60 + m_1
t_2 = h_2*60 + m_2
# print(t_1, t_2)
w_t = t_2 - t_1
print(w_t-k)
h1, m1, h2, m2, k = map(int, input().split())

deltaH = h2 - h1
deltaM = m2 - m1
delta = deltaH * 60 + deltaM - k

print(delta)
h1,m1,h2,m2,k=map(int,input().split())
print(h2*60+m2-h1*60-m1-k)
h1, m1, h2, m2, k = map(int, input().split())


if m1 > m2:
    h = h2 - h1 - 1
    m = 60 - m1 + m2
else:
    h = h2 - h1
    m = m2 - m1

if k > h*60 + m:
    print(0)
else:
    print(h*60 + m - k)
H1, M1, H2, M2, K = map(int,input().split())

wake = H1 * 60 + M1
sleep = H2 * 60 + M2 - K
ans = 0
if wake <= sleep:
    ans = sleep - wake
else:
    time = 24 * 60
    ans = time - wake + sleep

print(ans)
h1,m1,h2,m2,k = map(int,input().split())

total_time = (h2*60+m2)-(h1*60+m1)

print(total_time-k)
a,b,c,d,e=map(int,input().split())

ans1=(c-a)*60+d-b - e

print(max(0,ans1))
h1, m1, h2, m2, k = map(int, input().split(" "))

start = h1*60+m1
end = h2*60+m2
total = end - start - k

print(total)
[H1,M1,H2,M2,K]=input().split();
H1=int(H1);
H2=int(H2);
M1=int(M1);
M2=int(M2);
K=int(K);
d1=60*H1+M1;
d2=60*H2+M2-K;
print(d2-d1);
list = list(map(int,input().split()))
print((list[2]-list[0])*60+(list[3]-list[1])-list[4])
h1, m1, h2, m2, k = map(int, input().split())

ans = (h2 - h1) * 60 + (m2 -m1) - k

print(ans)
h1, m1, h2, m2, k = map(int, input().split())
print(h2*60 + m2 - h1*60 - m1 - k)
a,b,c,d,k=map(int,input().split())

if c*60+d-a*60-b<k:
    print(0)
else:
    print(c*60+d-a*60-b-k)
h1,m1,h2,m2,k = map(int, input().split())
print((h2*60+m2)-(h1*60+m1)-k)
H1, M1, H2, M2, K = map(int, input().split())

A = 60 * H1 + M1
B = 60 * H2 + M2
print(B - A - K)
h1,m1,h2,m2,k = map(int,input().split())
h3 = k//60
m3 = k%60
print((h2-h3-h1)*60+m2-m3-m1)
h1, m1, h2, m2, k = map(int, input().split())

j1 = h1*60 + m1
j2 = h2*60 + m2

if j2-j1 < k:
    print(0)
else:
    a = j2-j1-k
    print(a)
H1,M1,H2,M2,K = map(int,input().split())
t = (H2 - H1)*60 + (M2-M1)
print(t - K)
a,b,c,d,e = list(map(int, input().split()))

print((c-a)*60 + (d-b) - e)
#デフォルト
import itertools
from collections import defaultdict
import collections
import math
import sys
sys.setrecursionlimit(200000)
mod = 1000000007

h1, m1, h2, m2, k = map(int, input().split())

minute = ((h2 * 60) + m2) - ((h1 * 60) + m1)

print(minute - k)
hmk = input('')

h1 = int(hmk.split(' ')[0])
m1 = int(hmk.split(' ')[1])
h2 = int(hmk.split(' ')[2])
m2 = int(hmk.split(' ')[3])
k = int(hmk.split(' ')[4])

min1 = h1*60 + m1
min2 = h2*60 + m2

if min1 > min2:
    min2+=60*24

a = min2 - min1 - k
print(a)
H1,M1,H2,M2,K=map(int,input().split())

m=(H2*60+M2)-(H1*60+M1)

print(m-K)
h1,m1,h2,m2,k = map(int, input().split())
ans = max((h2 - h1) * 60 + (m2 - m1) - k, 0)
print(ans)
H1, M1, H2, M2, K = map(int, input().split())
print(H2*60+M2 - H1*60+M1 - K)
h1, m1, h2, m2, k = map(int, input().split())

sabunh = h2 - h1
sabunm = m2 - m1 
zikantai = sabunh * 60 + sabunm
ans = 0
zikantai -= k
while(zikantai > 0):
    zikantai -= k
    ans += k
print(ans)
from math import ceil

h1, m1, h2, m2, k = map(int, input().split())

diff = int((h2-h1)*60 + (m2-m1))

print(max(0, int(k*(ceil(diff/k)-1))))
h1, m1, h2, m2, k= map(int, input().split())

s = h1 * 60 + m1
e = h2 * 60 + m2

ans = s - e - k
print(ans)
H, M, h, m, K = map(int, input().split())
print(((60*h + m - 60*H - M)//K - 1)*K)
h1,m1,h2,m2,k = map(int,input().split())
t1 = h1*60+m1
t2 = h2*60+m1
d = t2-t1
print(d-k)
from sys import stdin

h1, m1, h2, m2, k = [int(x) for x in stdin.readline().rstrip().split()]

allMin1 = h1 * 60
allMin2 = h2 * 60

diff = (allMin2 + m2 - allMin1 + m1)

if diff < 0 :
	diff += 24 * 60

ans = diff - k

if ans >= 0 :
	if ans > k :
		print(ans)
	else :
		print(k)
else :
	print(0)
h1, m1, h2, m2, K = list(map(int, input().split()))
print(h2-h1*60 + m2-m1 - K)
def main():
    h1, m1, h2, m2, k = map(int, input().split())
    time = (h2 * 60 + m2 - 1) - (h1 * 60 + m1)
    cnt = time // k
    print(k * cnt)



if __name__ == "__main__":
    main()
h1,m1,h2,m2,k=map(int,input().split())
minute=(h2-h1)*60+(m2-m1)-2
t=minute//k
print(t*k)
h1, m1, h2, m2, k = map(int, input().split())
print(min(0, (h2*60+m2) - (h1*60+m1) - k))
H = list(map(int,input().split()))

h = H[2]-H[0]
m = H[3]-H[1]

if h < 0:
    h = h + 24

if m < 0:
    h -= 1
    m *= -1

mini = h*60 + m - H[4]

if mini < 0:
    mini = 0

print(mini)
h1, m1, h2, m2, k = list(map(int, input().split()))

if m2 >= m1:
	time = (h2 - h1) * 60 + abs(m1 - m2) - k
else:
	time = abs(m1 - m2) - k

print(time)
H1, M1, H2, M2, K = map(int, input().split())
kh, km = K//60, K%60
H2 -= kh
M2 -= km
if M2 < 0:
    M2 += 60
    H2 -= 1
    
H2 -= H1
M2 -= H1
if M2 < 0:
    M2 += 60
    H2 -= 1

    
print(H2 * 60 + M2 + 10)
x = list(map(int, input().split()))
h = (x[2] - x[0])*60
m = abs(x[1] - x[3])
ans = max(m+h-x[-1], 0)
print(ans)
h = list(map(int, input().split()))
tmp = 0
if h[0] > h[2]:
    tmp = (24 - abs(h[0] - h[2])) * 60
else:
    tmp = (h[2] - h[0]) * 60

if h[1] > h[3]:
    tmp += (60 - abs(h[1] - h[3]) - 30)
else:
    tmp += h[3] - h[1]

ans = 0
while tmp > 0:
    tmp -= h[4]
    if tmp > 0:
        ans += h[4]

print(ans)
#スペース区切りの整数の入力
h1, m1, h2, m2, k = map(int, input().split())


asa = h1 * 60 + m1
yoru = h2 * 60 + m2


if(((yoru - asa )%k) == 0):
  ans = int((yoru - asa )/k)-1
else:
  ans = int((yoru - asa )/k)
print(ans* k)
H1,M1,H2,M2,K=map(int,input().split())
if M1>M2:
    print(max((H2-H1-1)*60+(M1-M2)-K,0))
else:
    print(max((H2-H1)*60+(M2-M1)-K,0))
h1, m1, h2, m2, k = map(int, input().split())
if h1 <= 12 and h2 >= 12:
    h1 = 12 - h1
    h2 = h2 -12
    x = (h2 + h1) * 60 + m1 + m2 - k
    
elif h1 < 12 and h2 < 12 or h1 >= 12 and h2 >= 12:
    x = abs(h2 - h1) * 60 + m1 + m2 - k
    
else:
    h1 = h1 -12
    h2 = 12 - h2
    x = h2 + h1 * 60 + m1 + m2 - k
  
print(x)
h1, m1, h2, m2, k = map(int,input().split())
x = 60*max(0, h2-h1-1)
x += (60-m1 + m2)
if x%k == 0:
    print((x//k - 1)*k)
else:
    print((x//k)*k)
h,m,H,M,k = map(int,input().split())
v = H*60+M
u = h*60+M+k
print(v-u)
h1, m1, h2, m2, k = [int(i) for i in input().split()]

time = 60*h2+m2 - 60*h1+m1 - k
if time > 0:
  print(time)
else:
  print(0)
from sys import stdin

h1, m1, h2, m2, k = [int(x) for x in stdin.readline().rstrip().split()]

allMin1 = h1 * 60

allMin2 = h2 * 60

diff = (allMin2 + m2 - allMin1 + m1)
# if diff < 0 :
	# diff += 24 * 60

ans = diff - k

if ans >= 0 :
	print(ans)
else :
	print(0)
#import numpy as np
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as comb_with

#A = int(input())
H1,M1,H2,M2,K= map(int,input().split())
#A = list(map(int,input().split()))
#B = list(map(int,input().split()))
#S= str(input())

H=(H2-H1)*60
m=H-K
print(m)
h, m, h2, m2, k = map(int, input().split())
print(12*h2+m2-(12*h+m+k))
h1,m1,h2,m2,k=map(int,input().split())
h3=abs(h2-h1)
print(h3*60-k)
H1, M1, H2, M2, K = map(int,input().split())
import math
p=(H2-H1)*60
if M1-M2<0:
    a=M1-M2+60
    p-=60
else:
    a=M1-M2
p+=a
time = K*math.floor(p/K)
if p%K==0:
    time=time-K
print(time)
h1, m1, h2, m2, k = map(int, input().split())

time = (h2 - h1) * 60 + (m2 - m1) - 1

import math

print(math.floor(time // k) * k)
h1,m1,h2,m2,k=map(int,input().split())
print(h1*60+m1-k-m2-60*h2)
H1,M1,H2,M2,K = map(int,input().split())
 
tmp = K
if (M1 < M2):
  H = H2 - H1 - 1
  M = M1 - M2
  if M < 0:
    M = 60 - M
    
else:
  H = H2 - H1
  M = M2 - M1
 
T = H * 60 + M
 
ans = 0
while T > tmp:
  T = T - K
  ans += K
 
print(ans)
h1, n1, h2, n2, k = map(int,input().split())
h = h2-h1
n = n2-n1
wake = 60*h + n-1
ans = int(wake/k)
print(ans*k)
H1,M1,H2,M2,K = map(int,input().split())
print((H2-H1)*60 + (M1 - M2) - K)
H1, H2, H3, H4, K = map(int, input().split())
up = H1*60 + H2
down = H3*60 - H4
print(down - up - K)
h1, m1, h2, m2, K = list(map(int, input().split()))
if abs(h1-h2)*60 + abs(m1-m2) <= 120:
    print('{}'.format(0))
else:
    print('{}'.format(abs(h1-h2)*60 + abs(m1-m2) - K))
h1, m1, h2, m2, k = map(int, input().split())
t1 = h1 * 60 + m1
t2 = h2 * 60 + m1
print(t2-t1 - k)
[h1,m1,h2,m2,k] = [int(i) for i in input().split()]

print((h2 - h1) * 60 + (m1 - m2) - k)
A,B,C,D,E=map(int,input().split())
print(C*60-A*60-E if C*60-A*60-E>=0 else 0)
h = list(map(int, input().split()))

if h[1] > h[3]:
    print((h[2]-h[0])*60+h[3]-h[1]-h[4])
else:
    print((h[2]-h[0]-1)*60+60-h[3]+h[1]-h[4])
H = input().split()
sdy =0
if int(H[2]) > int(H[0]):
  sdy = int(H[2])*60 +int(H[3])-int(H[0])*60 +int(H[1]) - int(H[4])
else:
  H[2] = (int(H[2])+24)
  sdy = int(H[2])*60 +int(H[3])-int(H[0])*60 +int(H[1]) - int(H[4])
print(sdy)
H1,M1,H2,M2,K = map(int,input().split())
K_time = (H2*60+M2) - (H1*60-M1)
print(K_time - K)
H1, M1, H2, M2, K = [int(s) for s in input().split()]
if H2 < H1:
    H2 += 24
elif H2 == H1 and M1 > M2:
    H2 += 24
print(H2 * 60 + M2 - H1 * 60 + M1 - K)
import sys
input = lambda: sys.stdin.readline().rstrip()

h1, m1, h2, m2, k = map(int, input().split())

m = (h2 - h1)*60
a = m2 - m1 if m2 - m1 >= 0 else 60 + m2 - m1
if m + a - k >= 0:
    print(m + a - k)
else:
    print(0)
a,b,c,d,e=map(int,input().split())

x=((c*60-d)-(a*60+b))-e

if x<0:
    x=x+1440
print(x)
h1,m1,h2,m2,k=map(int,input().split())

ans=(h2-h1-1)*60+(60-m1)-(m2-0)-k
print(ans)
def main():
    H1,M1,H2,M2,K = [int(x) for x in input().split()]
    if M2 >= M1:
        print(((H2-H1)*60 + M2-M1 - 1) // K * K)
    else:
        print(((H2-H1)*60 + M1+M2-60 - 1) // K * K)

if __name__ == '__main__':
    main()
H1, M1, H2, M2, K = map(int, input().rstrip().split())
minutes = M2 - M1
hours = 0
if minutes < 0:
    minutes += 60
    hours += 1
hours = H2 - H1
minutes += hours * 60
answer = minutes - K
if answer < 0:
    answer = 0
print(answer)
h1, m1, h2, m2, k = [int(i) for i in input().split()]

awake = 60*h2+m2 - (60*h1+m1) - k
print(k)
h1, m1, h2, m2, k = map(int, input().split())

# 時間を、0時0分からの経過時間に変換する。
start = (60 * h1) + m1
end = (60 * h2) + m2 - k

print(start-end)
H1,M1,H2,M2,K = map(int,input().split())

if (M1 < M2):
  H = H2 - H1 - 1
  M = M1 - M2
else:
  H = H2 - H1
  M = M2 - M1

T = H * 60 + M

if T > K:
  print(T - K)
else:
  print("0")
h1,m1,h2,m2,k=map(int,input().split())
s=abs(h2-h1)*60+abs(m2-m1)
n=s-k
print(n)
h1,m1,h2,m2,k=map(int,input().split())
h3=h2-h1
h3=h3*60+m1+m2

print(h3-k)
h1, m1, h2, m2, k = map(int, input().split())
hm1 = h1 + m1/60
hm2 = h2 + m2/60
diff = hm2 - hm1
if diff > k/60:
    ans = int((diff - k/60)*60)
else:
    ans = 0
print(ans)
H_1, M_1, H_2, M_2, K = map(int, input().split())

H_ = H_2 * 60 + M_2 - K
H = H_ - (H_1*60+M_2)
print(H)
hmk = input('')

h1 = int(hmk.split(' ')[0])
m1 = int(hmk.split(' ')[1])
h2 = int(hmk.split(' ')[2])
m2 = int(hmk.split(' ')[3])
k = int(hmk.split(' ')[4])

h = h2 - h1
m = m2 - m1
if m < 0:
    m = m1 - m2
    h-=1

a = h*60 + m - k
print(a)
#デフォルト
import itertools
from collections import defaultdict
import collections
import math
import sys
sys.setrecursionlimit(200000)
mod = 1000000007

h1, m1, h2, m2, k = map(int, input().split())

minute = ((h2 * 60) + m2) - (h1 * 60) + m1

print(minute - k)
h1,m1,h2,m2,k = map(int,input().split())

time = (h2 - h1) * 60 - (m2 - m1)
print(time - k)
FH, FM, TH, TM, K = map(int, input().split())
M = (TH-FH)*60+(TM-FM)
ans = M // K-(1 if M%K == 0 else 0)
print(ans*K)
import bisect
import copy
import heapq
import sys
import itertools
import math
import queue
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def main():
    H1, M1, H2, M2, K = read_values()
    m1 = H1 * 60 + M1
    m2 = H2 * 60 + M2 - 1

    m = m2 - m1 
    print((m // K) * K)


if __name__ == "__main__":
    main()
#スペース区切りの整数の入力
h1, m1, h2, m2, k = map(int, input().split())

asa = h1 * 60 + m1 + 1
yoru = h2 * 60 + m2 -1




ans = int((yoru - asa )/k)

print(ans* k)
import time
import datetime
from datetime import timedelta
H1,M1,H2,M2,K=map(int,input().split())


delta1=timedelta(minutes=M1,hours=H1)
delta2=timedelta(minutes=M2,hours=H2)

delta=delta2-delta1
delta_minutes=delta.total_seconds()/60
if delta_minutes>30:
  print(delta_minutes-30)
else:
  print(0)
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

a,b,c,d,k = inpl()
sa = c*60+d - (a*60-b)
print(sa-k)
H1, M1, H2, M2, K = map(int, input().split())

hour = H2 - H1
if M1 > M2:
    hour -= 1

minute = abs(M2 - M1)

ans = hour * 60 + minute - K
if ans < 0:
    ans = 0

print(ans)
A,B,C,D,E=map(int,input().split())
print(C*60-A*60-E)
h,m,h2,m2,k=map(int,input().split())
print(h2*60+m2-h*60+m-k)
#a = input()
a, b, c, d, e = map(int, input().split())
# get a string
#s = raw_input()
# output
start = a*60+b
end = c*60+d
result = end - start
print(result)
H1, M1, H2, M2, K = map(int, input().split())

print((H2 * 60) +  M2 - (H1 * 60) + M1 - K)
T = input()
t = T.count("?")
num =[]
for i in range(0,t+1):
    st = T.replace("?" , "D", i)
    for n in range(0,t+1):
        ste = st.replace("?","P",n)
        for q in range(0,t+1):
            stes = ste.replace("?","D",q)
            num.append(stes)
            print(num)
s = stes.count("DD")
f = stes.count("PD")
ans = s + f
print(ans)
h1,h2,m1,m2,k = map(int,input().split())

a = 60*h2 + m2
b = 60+h1 + m1
print(a-b-k)
H1, M1, H2, M2, K = list(map(int, input().split()))
time = H2*60+M1-H2*60-M2
print(time-K)
abc = [int(e) for e in input().split()]

H1 = abc[0]
M1 = abc[1]
H2 = abc[2]
M2 = abc[3]
K = abc[4]

start_time = H1 + M1/60
end_time = H2 + M2/60
valid_time = (end_time-start_time) * 60

if valid_time % K == 0:
    valid_time = valid_time - 1

execution_time = valid_time // K

ans = execution_time * K

print(int(ans))
H1,M1,H2,M2,K = map(int,input().split())
print(max(0, 60*H2 + M2 - (60*H1 + M2) - K))
h_1 , m_1, h_2, m_2 , k = map(int, input().split())
study_time = abs((h_2*60 + m_2) - (h_1*60 + m_1))
print(k*((study_time//k) - 1))
H1,M1,H2,M2,K=map(int, input().split())

M1 += H1*60
M2 += H2*60
out = int((M2-M1-1)/K)
print(out*K)
s=list(input())
for i in range(s.count("?")):
  s[s.index("?")]="D"
print("".join(s))
H1, M1, H2, M2, K = map(int, input().split())

H = (H2 - H1) * 60
M = M2 - M1

res = (H+M) - 30

if res > K:
    print((H+M) - 30)
else:
    print(0)
h1, m1, h2, m2, k = map(int, input().split())

H = (h2-h1)*60
M = abs(m1-m2)

print(H-M-k)
H1, M1, H2, M2, K = map(int,input().split())

if H1 == 0:
    H1 = 24
if H2 == 0:
    H2 = 24

if H2 <= H1:
    print(0)


time2m = H2 * 60 + M2
time1m = H1 * 60 + M1

study_time = time2m - K - time1m

if study_time <= 0:
    print(0)
else:
    print(study_time)
H_1, M_1, H_2, M_2, K = map(int, input().split())

time =(H_2 * 60 + M_2)-(H_1 * 60 + M_1)

a = time // K

if a == 0 :
    print(0)
    exit(0)

if time % K == 0:
    a = a-1

print(a*K)
H1, M1, H2, M2, K = input().split()
H1, M1, H2, M2, K = int(H1), int(M1), int(H2), int(M2), int(K)
allm1 = H1*60+M1
allm2 = H2*60+M2
 
m = allm2 - allm1
 
if m == K:
    print('0')
    exit()
 
i = 0
while True:
    m = m - K
    if m <= 0:
        break
    else:
    	i = i + 1
 
print(i*K)
time = list(map(int, input().split()))
h1,m1 = time[0],time[1]
h2,m2 = time[2],time[3]
k = time[4]
ans = 0
full = (h2*60+m2) - (h1*60+m1)
while full - k > 0:
    full-=k
    ans+=k
print(ans)
H1,M1,H2,M2,K=map(int,input().split())

t1=60*H1 + M1
t2=60*H2 + M2
ans=0
tmp=t1
while(1):
    tmp+=K
    if tmp>=t2:
        break
    ans+=K

print(ans)
H1, M1, H2, M2, K = map(int, input().split())

A=60*H2+M1 - K

print(A-60*H1-M1)
string = input()
nums = string.split(' ')

hour = int(nums[2]) - int(nums[0])
minute = int(nums[1]) - int(nums[3])
time = hour * 60 + minute - int(nums[4])

if time > 0:
    print(time)
else:
    print(0)
#!/usr/bin/env python3

h1, m1, h2, m2, k = list(map(int, input().split()))


if h2*60+m2-h1*60+m1 < 0:
    print((h2+24)*60+m2-h1*60+m1-k)
else:
    print(h2*60+m2-h1*60+m1-k)
h1, m1, h2, m2, k = map(int, input().split())
t1 = h1*60+m2
t2 = h2*60+m2
print(t2-t1-k)
h1, m1, h2, m2, k = map(int, input().split())
h = h2-h1
if m1 > m2:
    m2 += 60
m = m2-m1
a = h*60
m += a
b = k
if k != m:
    while k+b != m and k < m:
        if k+b == m:
            k = 0
            break
        k += b
else:
    k = 0
print(k)
import math
#S=input()
#N=int(input())
#A,B,C=input().split()
H1,M1,H2,M2,K=map(int,input().split())
#A=list(map(int,input().split()))
T=math.floor(((H2-H1)*60+(M2-M1))/K)*K
if ((H2-H1)*60+(M2-M1))%K==0:
    T=T-K
if T<=0:
    T==0
print(T)
import datetime

def main():
    H1, M1, H2, M2, K = map(int, input().split())

    start = H1*60 + M1
    sleep = H2*60 + M2

    print( K * ( abs((sleep - 1)-start) // K) )


if __name__ == "__main__":
    main()
h1,m1,h2,m2,k = map(int ,input().split())

h = (h2-h1)*60
m = m2-m1-1
ans = 0
while ans+k < h+m: ans += k
print(ans)
h1, m1, h2, m2, k = map(int, input().split())
piyo = h2*60 + m2 - (h1*60 + m1)
result = (piyo // k - 1) * k
print(result)
H1, M1, H2, M2, K = map(int, input().split())
print(max(60 * (H2 - H1) - (M2 - M1) - K, 0))
H1, M1, H2, M2, K = list(map(int, input().split()))
print(H1, M1)
a,b,c,d,e=(int(x)for x in input().split())
x=(c-a)*60
z1=b-d
z2=abs(z1)
if z2>=30:
    y=x-e+30
if z2<30:
    y=x-e

if y<e:
    print("0")
else:
    print(y)
H1, M1, H2, M2, K = map(int, input().split())
print(60 * (H2 - H1) - (M2 - M1) - K)
h1, m1, h2, m2, k = map(int, input().split())
pos = 60 * (h2 - h1) + abs(m2 - m1)
print(pos - k)
h1,m1,h2,m2,k = map(int,input().split())
if m2 < m1:
    m2 += 60
    h1 -= 1
time = (h2 - h1) * 60 + (m2 - m1)

print(time - k)