peterverebics/CodeNet_Python_118 huggingface dataset:
H1,M1,H2,M2,K=map(int,input().split())
if H2-H1<0:
    print(0)
else:
    if M2-M1<0:
        print(0)
    else:
        if M2>=M1:
            print(((H2-H1)*60+(M2-M1))-K)
        else:
            print(((H2-H1-1)*60+(M1-M2))-K)
h1, m1, h2, m2, k = map(int, input().split())

if k == 60*(h2-h1)+(m2-m1)-k:
  print('0')
else:
  print(60*(h2-h1)+(m2-m1)-k)
H1, M1, H2, M2, K = map(int, input().split())
h=(H2-H1)*60
m=M2-M1
print(h-m-K)
A,B,C,D,E = map(int, input().split())
print((C*60+D)-(A*60+D)-E)
# s = input()
# n = int(input())
h1, m1, h2, m2, k = map(int, input().split())
# l = list(map(int, input().split()))
if m1 <= m2:
    t = (h2 - h1)*60 + m2 - m1
else:
    t = (h2 - h1 - 1)*60 + (60 - abs(m1 - m2))
if t <= k:
    print(0)
elif t%k == 0:
    print(t - k)
else:
    print(t - t%k)
h_1,m_1,h_2,m_2,k = map(int,input().split())

judge = h_2*60+m_2 - (h_1*60+m_2)
print(judge-k)
def main():
    H1, M1, H2, M2, K = (int(i) for i in input().split())
    h = H2 - H1
    m = 0
    if M2 - M1 >= 0:
        m = M2 - M1
    elif H1 != H2:
        m = (60 - M2) + M1
    ans = h*60 + m - K
    if ans > 0:
        print(ans)
    else:
        print(0)


if __name__ == '__main__':
    main()
H1, M1, H2, M2, K = map(int, input().split())
if(H1 > H2): H2 += 24
T1 = H1 * 60 + M1
T2 = H2 * 60 - M2
T = T2 - T1
print(T - K)
t = list(input())
a = 0
b = 0

for i in range(len(t)):
    if i == 0 and t[i] == '?':
        t[i] = 'D'
    
    if 0 < i < len(t) - 1 and t[i] == '?':
        if t[i-1] == 'P':
            t[i] = 'D'
        else:
            t[i] = 'P'

    if i == len(t) -1 and t[i] == '?':
        t[i] = 'D'

print(''.join(t))
h1, m1, h2, m2, k = map(int, input().split())
h1 = 12 - h1
h2 = h2 -12
x = abs(h2 + h1) * 60 - k
print(x)
H1, M1, H2, M2, K = map(int,input().split())
T1 = H1*60 + M1
T2 = H2*60 - M2
T = T2 - T1
print(T - K)
H1, M1, H2, M2, K = map(int, input().split())

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

print(start - (end - K))
H, M, h, m, K = map(int, input().split())
wake = H * 60 + M
sleep = h * 60 + M
spinner = sleep - wake
oops = spinner - K
print(oops)
h1, m1, h2, m2, k = map(int, input().split())

h = h2 - h1
m = m2 - m1

if m < 0:
  h = h - 1
  m = 60 - m
  
total = h + m

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

h = (h2 - h1)*60
m = m2 - m1

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

total = h + m

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

h = abs(h1-h2)
m = abs(m1-m2)

ans = h*60+m
ans = ans-k

print(ans)
li = list(map(int,input().split()))
h1, m1, h2, m2, k = li
life_time = (h2 - h1)*60 + (m2 - m1)
time = life_time - k # 分
T = input() #ここで標準入力

trade = T.replace('?','D')
print(trade)
h1, h2, m1, m2, k = map(int,input().split())
print (60 * (h1-h2) + m1 - m2 - k)
from math import ceil, floor

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

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

if diff % k == 0:
    print('%d' % max(0, k*(ceil(diff/k)-1)))
else:
    print('%d' % max(0, k*(floor(diff/k))))
h1, m1, h2, m2, k= map(int, input().split())
h3 = h2 - h1
m3 = m2 - m1
if m3 < 0:
    h3 -= 1
    
ans = (h3 * 60) + abs(m3) - k
print(ans)
h1, m1, h2, m2, k = [int(i) for i in input().split()]

awake = 60*h2+m2 - 60*h1+m1
if awake >= 0:
  print(awake-k)
else:
  print(60*24+awake-k)
t=input(str())
t=list(t)
for i in range(len(t)-1):
    if t[i]=='?':
        if t[i+1]=='D' :
            t[i]='P'
        elif t[i + 1] == '?':
            if t[i-1]=='P':
                t[i]='D'
            else:
                t[i]='P'
        else:
            t[i]='D'
    if t[-1]=='?':
        t[-1]='D'
print(''.join(t))
h,m,H,M,k = map(int,input().split())
v = H*60+M
u = h*60+M
print(max(v-k-u,0))
H1, M1, H2, M2, K = map(int, input().split())
print((H2 - H1) * 60 + abs(M1 - M2) - K)
h1,m1,h2,m2,k = map(int,input().split())
if h2 < h1:
    h2 += 12
if m2 < m1:
	m2 += 60
if m2 < m1:
    h2 -= 1
m = m2-m1
h = h2-h1
print(60*h+m-k)
S = input()
ans=""

for i in range(len(S)):
    if S[i] == "?":
        ans += "D"
    else:
        ans += S[i]

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

h1 = H1 * 60
m1 = M1
h2 = H2 * 60
m2 = M2

print((h2 - m2) - (h1 + m1) - K)
num_list = list(map(int, input().split())) 

a=num_list[2]-num_list[0]
b=num_list[3]-num_list[1]
if b>0:
    a=a-1
a=a*60
c=b+a-num_list[4]
if c<0:
    c=0
print(c)
def main():
    H1,M1,H2,M2,K = [int(x) for x in input().split()]
    diff = (H2-H1)*60 + abs(M2-M1)
    if diff <= 0:
        print(0)
    else:
        print((diff - 1) // K * K)

if __name__ == '__main__':
    main()
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

print(ans)
#!/usr/bin/env python3
a, b, c, d, k = map(int, input().split())
print((((c - a) * 60 + (d - b) - 1) // k) * k)
A, B, C ,D, K = map(int,input().split())

ans = (C-A)* 60 + B - D - K

print(ans)
H,M,h,m,K = map(int,input().split())

ans=(h*60+m)-(H*60+m)-K

print(ans)
ip = [int(s) for s in input().split(' ')]

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

total = (h * 60) + m - ip[4]

if total >= ip[4]:
    print(str(total))
else:
    print(str(0))
a,b,c,d,e =map(int ,input().split())
g=0
h=0
f=c-a
if d-b<0:
  g=60+d-b
  f-=1
g+=f*60
if g<e :
  h=0
else:
  h=g-e
print(h)
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=(H2*60+M2)-(H1*60+M1)
if T%K==0:
    T=T-K
else:
    T=math.floor(T/K)*K

print(T)
h1, m1, h2, m2, k = map(int, input().split())
hk = k // 60
mk = k - 60 * hk

if m1+mk >=60:
    h1 += 1
    m1 = m1 + mk -60
else:
    m1 = m1 + mk
h1 += hk

if m2- m1< 0:
    h2 -= 1
    m2 = m2- m1+ 60
h = h2 - h1
print(h*60 + m2)
import math
import re
import copy

wake_up_hour,wake_up_minute,sleep_hour,sleep_minute,study_time = map(int, input().split())

Total_Minutes = (sleep_hour) *60 + (sleep_minute) - ((wake_up_hour) * 60 + (wake_up_minute))



if Total_Minutes > study_time:
    print("You can finish the study")
    start_before_minute= ((sleep_hour*60 +  sleep_minute) - study_time) % 60
    start_before_hour= ((sleep_hour*60 +  sleep_minute) - study_time) // 60 
    print("Start before: ", start_before_hour, start_before_minute, )
else:
    print("You are lazy!!!. wake up early")
def main():
    array = list(map(int, input().split()))

    now = array[0]*60+array[1]
    finish = array[2]*60+array[3]
    if now > finish:
        finish += 24*60
    K = array[4]
    ans = 0
    for _ in range(int(1e15)):
        if now + K < finish:
            ans += K
            now += K
        else:
            break

    print(ans)


if __name__ == '__main__':
    main()
h1,m1,h2,m2,k =(int(x) for x in input().split())  

hrtom= (h2-h1)

if m2-m1 < 0 : 
    min = (h2-h1)*60 - (m2-m1) - k

else:
     min = (h2-h1)*60 + (m2-m1) -k 
    
print(min)
H1,H2,M1,M2,K=map(int, input().split())
print(((60*(H2-H1))+(M2-M1)-K))
HMK = list(map(int, input().split()))
H1 = HMK[0]
M1 = HMK[1]
H2 = HMK[2]
M2 = HMK[3]
K = HMK[4]
if H2 < H1:
	H2 += 24
ans = ((H2 - H1) * 60 + (M1 + M2)) - K
print(ans)
from math import ceil, floor

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

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

if diff % k == 0:
    print('%d' % max(0, k*(ceil(diff/k)-1)))
else:
    print('%d' % max(0, k*(floor(diff/k))))
h1, m1, h2, m2 ,k = map(int, input().split())
t1 = h1*60 + m2
t2 = h2*60 + m2 - k
ans = (t2-t1)%1440
print(ans)
H1,M1,H2,M2,K=map(int, input().split())

if H1 > H2:
  hour = H2+(24-H1)
else:
  hour = H2-H1

if M1 > M2:
  hour -= 1
  minutes = abs(M2-M1)
else:
  minutes = M2-M1

print(hour*60+minutes-K)
H1,M1,H2,M2,K = map(int,input().split())

h = H2 - H1
m = M2 - M1
s = 0
if h > 0:
    s = h * 60 + m
else:
    s = (24 + h) * 60 + m


if s - K > 0:
    s -= K
else:
    s = 0
print(s)
def main():
    T = input()
    # ?D -> PD
    # ?P -> DP
    # ?? -> PD 
    # ??? -> PDD

    T = T.replace("?D", "PD")
    T = T.replace("?P", "DP")
    T = T.replace("??", "PD")
    T = T.replace("?", "D")

                    
    print(T)

if __name__=="__main__":
    main()
H1,M1,H2,M2,K = map(int,input().split())
print((H2-H1)*60 + (M1 + M2) - K)
H1, M1, H2, M2, K = [ int(i) for i in input().strip().split(' ')]
print(H2 * 60 + M2 - (H1 * 60 + M2) - K)
sh,sm,eh,em,k = map(int,input().split())

if eh == 0:
    eh = 24
if em == 0:
    em = 60

h = eh - sh
m = em - sm

if m < 0:
    m = m + 60
    h -= 1

totalm = 60*h + m
ans = totalm - k
print(abs(ans))
def main():
    h1,m1,h2,m2,k = map(int, input().split())
    x = 60*abs(h2-h1)+abs(m2-m1)-1
    print(int(k*int(x/k)))

main()
h,m,a,b,k=map(int,input().split())
m_to_hour = m /60
b_to_hour = b /60
h_hour = h + m_to_hour
a_hour = a + b_to_hour
re = a_hour - h_hour
to_min =( re )*60
print(int(to_min-k))
#!/usr/bin/env python3
# atcoder 
# Türkler var mı?
# Herkese memnün oldum


def çözmek():
    h, m, H, M, K = map(int, input().split(" "))
    if H:
        H = H * 60
    if h: 
        h = h * 60
    res = H + M - K - h + m
    print(res)
if __name__ == "__main__":
    çözmek()
a, b, c, d,e  = map(int,input().split())
minute = (c-a)*60-(d-b)
print(((minute-1)//e)*e)
h1, m1, h2, m2, k = map(int, input().split())

start_mins = h1 * 60 + m1
end_min = h2 * 60 + m1

is_up = end_min - start_mins
can_start = is_up - k
print(can_start)
a,b,c,d,e = map(int,input().split())

f = c - a
g = d - b
if g < 0:
  g = 60 - g
  f -=1
total = 60 * f + g
if total - e <= 0:
  print('0')
else:
    total -= e 
    print(total)
h1,m1,h2,m2,k=map(int,input('').split(' '))
p=0
while(1):
    m1=m1+k
    if m1>60:
        m1=m1-60
        h1=h1+1
    
    if h1>=h2 and m1>=m2:
        p=p-k
        break

    p=p+k

print(p)
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)
list = input().split()
 
h1 = int(list[0]) * 60
m1 = int(list[1])
h2 = int(list[2]) * 60
m2 = int(list[3])
 
diff = h2 + m2 - h1 + m1 - int(list[4])
 
print(diff)
def main():
    H1, M1, H2, M2, K = (int(i) for i in input().split())
    h = H2 - H1
    m = 0
    if H1 == H2:
        m = M2 - M1
    elif M1 != M2:
        m = (60 - M2) + M1
    ans = h*60 + m - K
    if ans > 0:
        print(ans)
    else:
        print(0)


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

h = abs(h2-h1)
m = (m2-m1)
if m < 0:
    m+=60

ans = h*60+m
ans = ans-k

print(ans)
h1, m1, h2, m2, k = map(int,input().split())
 
h=h2 - h1
if h <= 0:
    h = 24+h
m=m2 - m1
 
du=h*60+m-k
 
print(du)
x = list(map(int, input().split()))
h = (x[2] - x[0])*60
m = x[3] - x[1]
if m < 0:
    m = 60 - x[0] + x[3]
ans = max(m+h-x[-1], 0)
print(ans)
H_1,M_1,H_2,M_2,K = map(int,input().split())
print(H_2*60+M_2-H_1*60+M_1-K)
h1,m1,h2,m2,k = map(int ,input().split())

h = (h2-h1)*60
m = m2 -m1
print((h+m-1)//k*k)
import math
import sys
input = sys.stdin.readline

h1, m1, h2, m2, t = map(int, input().split())
diff = max(h2 - h1 - 1, 0) * 60 + (60 - m1) + m2
print(max(diff - t, 0))
h1, m1, h2, m2, k = map(int, input().split())
t1 = h1 * 60 + m1
t2 = h2 * 60 + m1
h1, m1,h2,m2,k = map(int,input().split())
print(abs((h2*60+m2 - h1*60+m1)-k))
h1, m1, h2, m2, k = map(int, input().split())

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

print((mm // k - 1) * k if mm % k == 0 else (mm // k) * k)
#スペース区切りの整数の入力
h1, m1, h2, m2, k = map(int, input().split())

if(h1>h2):
  h2 = h2 + 24

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)
H_1, M_1, H_2, M_2, K = map(int, input().split())

H = ((H_2-H_1)*60+M_1+M_2)-K

print(H)
a,b,c,d,e=(int(x)for x in input().split())
x=(c-a)*60
z1=b-d
z2=abs(z1)
z3=60-z2
if z3>=30:
    y=x-e+30
if z3<30:
    y=x-e

if y<e:
    print("0")
else:
    print(y)
h1,m1,h2,m2,k = map(int,input().split())

time = (h2 - h1) * 60
if m1 < m2:
    time += m2 - m1
else:
    time -= m2 - m1
print(time - k)
h_1 , m_1, h_2, m_2 , k = map(int, input().split())
# study_time = ((h_2*60 + m_2) - (h_1*60 + m_1))
if h_2 < h_1:
  h_2 += 24
study_time = ((h_2*60 + m_2) - (h_1*60 + m_1))
print(k*((study_time//k) - 1))
i = list(map(int, input().split()))
print((i[2]-i[0])*60-(i[3]-i[1])-i[4])
h1, m1, h2, m2, K = list(map(int, input().split()))
if h2-h1*60 + m2-m1 <= K:
    print(0)
else:
    print(h2-h1*60 + m2-m1 - K)
h1,m1,h2,m2,k=map(int,input().split())
minute=(h2-h1)*60+(m2-m1)-2
t=minute//k
#print(t*k)
if minute<k:
    print(0)
else:
    print(t*k)
H = input().split()
sdy =0
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())

h = h2 - h1
m = m2 - m1

if m < 0:
    h -= 1
    m = 60 - m2 + m1

print(60*h + m - k)
h1,m1,h2,m2,k=map(int,input().split())
t=h2*60+m2-(h1*60+m1)
t-=0.5
g=t//k
print(int(g*k))
H1, M1, H2, M2, K = map(int, input().split())

Minites = 0
if M1 < M2:
    Minites += 60 + M1 - M2
    H2 -= 1
else:
    Minites += M1 - M2

if H1 > H2:
    Minites += 60*(24 + H2 - H1)
else:
    Minites += 60*(H2 - H1)

print(Minites - 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 = h1 - h2
hm = h * 60

print(hm + m1 - m2 - k)
H1, M1, H2, M2, K = map(int,input().split())

hour = (H2-H1)*60
mini = M2-M1
sum = hour + mini

ans = sum // K
amari = sum % K

if amari == 0:
    print(K*(ans-1))
else:
    print(K*ans)
H1, M1, H2, M2, K = map(int, input().split())

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

wake_time = h2*60 + m2 - h1 *60 + m1;

if wake_time > k:
    print(wake_time - k);
else:
    print(0);
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,m1,h2,m2,k = map(int,input().split())

d=h2*60+m2-h1*60+m1-k
print(d)
h1 , m1 , h2 , m2 , k = map(int , input().split())
diff = (h2-h1)*60 + abs(m2-m1)
ans = diff - k
print(diff,ans)
if ans <=0:
	print(0)
else:
	print(ans)
H1, M1, H2, M2, K = map(int, input().split())
t = H2 - H1
t1 = abs(M2 - M1)
l = t*60  + t1
if K < l/2:
  print(l-K)
elif K > l/2:
  print(K)
else:
  print(0)
#-*-coding:utf-8-*-

import sys

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

if __name__ == "__main__":
    main()
h1,m1,h2,m2,k=map(int,input().split())
minute=(h2-h1)*60+(m2-m1)
#print(minute)
if minute<k:
    print(0)
elif minute%k==0:
    print(minute-k)
elif minute%k!=0:
    print(minute)
h1, m1,h2, m2, k = map(float, input().split())
 
 
m3=k%60
h3=(k-m3)/60
ans=(h2-h3-h1)*60 + (m2-m3-m1)
 
print(ans)
h1, m1, h2, m2, k = [int(arg) for arg in input().split()]
print((h2-h1)*60 - (m2-m1) - k)
H,M,h,m,K = map(int,input().split())
A = H*60 + M
B = h*60 + m
X = B - A - K
print(min(X,0))
h1, m1, h2, m2 ,k = map(int, input().split())

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

if __name__ == '__main__':
    main()
h1,h2,m1,m2,k = map(int, input().split())
print( 60*(h2-h1) + (m2-m1) -k )
a,b,c,d,e = map(int,input().split())

f = c - a
g = d - b
if g < 0:
  g = -g
  f -=1
total = 60 * f + g
if total - e <= 0:
  print('0')
else:
    total -= e 
    print(total)
a,b,c,d,e=map(int,input().split())

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

print((h2-h)*60-(m2-m)-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])

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

a = h*60 + m - k
print(a)
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((mm // k - 1) * k if mm % k == 0 else (mm // k) * k)
h1,m1,h2,m2,k =(int(x) for x in input().split())  

hrtom= (h2-h1)

if (m2-m1 < 0) and (h2-h1 >=0) : 
    min = (h2-h1)*60 - (m2-m1) - k
    print(min)
    
elif (m2-m1 >= 0) and (h2-h1 >=0 ):
    min = (h2-h1)*60 + (m2-m1) - k 
    print(min)
else: 
    print('0')
#A - Study Scheduling

def answ():
    h1, m1, h2,m2,k = map(int, input().split())
    if h1 > h2:
        h2 +=24
    h = h2 - h1
    m = m2 - m1
    if m < 0:
        m = m + 60
        h = h - 1
    time = h*60 + m 
    return time - k
answ()
# coding: utf-8
# Your code here!

list = input().split()

h = int(list[2])-int(list[0])
if int(list[1]) < int(list[3]) or int(list[1]) == int(list[3]):
    m = int(list[3])-int(list[1])
else:
    m  = int(list[1])-int(list[3])
    h = h-1 
    
#print(h)
#print(m)

ans_m = h*60 + m
#print(ans_m)

ans = ans_m/int(list[4])
if ans_m%int(list[4])==0:
    print(int(ans-1)*int(list[4]))
else:
    print(ans*int(list[4]))
a,b,c,d,e =map(int ,input().split())
g=0
h=0
if d-b<0:
  g=60+d-b
  c-=1
f=c-a
g+=f*60
if g<e :
  h=0
else:
  h=g-e
print(h)
h1, m1, h2, m2, k = list(map(int, input().split()))
if m2 < m1:
    th = h2 - h1 - m1/60
    tm = m2 -m1 % 60
else:
    tm = m2 - m1
    th = h2 -h1
if k > (th*60 + tm):
    print (0)
else:
    print(th*60 + tm - k)
def main():
    array = list(map(int, input().split()))

    now = array[0]*60+array[1]
    finish = array[2]*60+array[3]
    K = array[4]
    ans = 0
    for _ in range(1000000):
        if now + K < finish:
            ans += K
            now += K
        else:
            break

    print(ans)


if __name__ == '__main__':
    main()
a=list(map(int,input().split()))
print((a[2]-a[0])*60-(a[3]-a[1])-a[4])
h1,h2,m1,m2,k = map(int, input().split())
print( 60*(h2-h1) + m2-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

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

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

time = H2*60+M1 - (H1*60+M1)
print(time - K)
h1, m1,h2, m2, k = map(float, input().split())
 
 
m3=k%60
h3=(k-m2)/60
ans=(h2-h3-h1)*60 + (m2-m3-m1)
 
print(ans)
H1,M1,H2,M2,K=map(int, input().split())
a=(H2-H1)*60+(M2-M1)
if H1>H2:a+=24*60
if M1>M2:a+=60
print(a-K)
H1,M1,H2,M2,K=map(int,input().split())
if H2-H1<0:
    print(0)
else:
    if M2-M1<0:
        print(0)
    else:
        if (H2-H1)*60+(M2-M1)<=K:
            print(0)
        else:
            print(((H2-H1)*60+(M2-M1))-K)
h1,m1,h2,m2,k =(int(x) for x in input().split())  
 
hrtom= (h2-h1)
 
if (m2-m1 < 0) and (h2-h1 >=0) : 
    min = (h2-h1)*60 - (m2-m1) - k
    print(min)
    
elif (m2-m1 >= 0) and (h2-h1 >=0 ):
    min = (h2-h1)*60 + (m2-m1) - k 
    print(min)

elif (h2-h1) <=0 :
    min = (h1-h2)*60 +(m2-m1) -k 
    print(min) 
else:
    print('0')
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()
    m = (H2 - H1) * 60 + (M2 - M1) - 1
    print(m // K * K)


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

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

print(int(time // k) * k)
import sys

"""
H1時M1分起床
H2時M2分就寝
K分勉強
"""
 
H1, M1, H2, M2, K = map(int, sys.stdin.read().split())
 
awake_time = H1 *60 + M1
sleep_time = H2 *60 + M1
start_limit_time = sleep_time - K
 
can_study_time = start_limit_time - awake_time
 
print(can_study_time)
def main():
    array = list(map(int, input().split()))

    now = array[0]*60+array[1]
    finish = array[2]*60+array[3]
    K = array[4]
    ans = 0
    for _ in range(int(1e15)):
        if now + K < finish:
            ans += K
            now += K
        else:
            break

    print(ans)


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

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

print((time // k) * k)
h1,m1,h2,m2,k = map(int, input().split())
m = 60*(h2-h1) + (m2 - m1) -1
print(k*(m//k))
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))

h1,m1,h2,m2,k=getNM()


a=h2*60+m2-h1*60-m1
if a%k==0:
    print(k*(a//k-1))
else:
    print(k*(a//k))
a,b,c,d,e=map(int, input().split())
print(((60*(b-a))+(d-c)-e))
H1, M1, H2, M2, K = map(int, input().split())
t = H2 - H1
t1 = abs(M2 - M1)
l = t*60  + t1
if K < l:
  print(l-K)
elif K == l:
  print(0)
H1,M1,H2,M2,K = (int(x) for x in input().split())
Wake  = 60*H1+M1
Sleep = 60*H2+M2

Activate = 60*H2+M2 - 60*H1+M1
CanStudy = Activate - K
print(CanStudy)
# coding: utf-8
# Your code here!

list = input().split()

h = int(list[2])-int(list[0])
if int(list[1]) < int(list[3]) or int(list[1]) == int(list[3]):
    m = int(list[3])-int(list[1])
else:
    m  = int(list[1])-int(list[3])
    h = h-1 
    
#print(h)
#print(m)

ans_m = h*60 + m
#print(ans_m)

ans = int(ans_m/int(list[4]))
#print(ans)
if ans_m%int(list[4])==0:
    print(int(ans-1)*int(list[4]))
else:
    print(ans*int(list[4]))
#!/usr/bin/env pypy3

import math

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

if h1 > h2:
    h2 += 24

if m2 < m1:
    h2 -= 1
    m2 = 60

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

res = allMin - k
if res < 0:
    res = 0

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

minutes = (h2-h1)*60 - (m2-m1)
print(max(0,minutes-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
valid_time = valid_time - 1

execution_time = valid_time // K

ans = execution_time * K

print(ans)
h1, m1, h2, m2, K = list(map(int, input().split()))
if abs(h1-h2)*60 + abs(m1-m2) <= K:
    print('{}'.format(0))
else:
    print('{}'.format(abs(h1-h2)*60 + abs(m1-m2) - K))
a, b, c, d, e = map(int, input().split())
f = (c-a)*60
print(f-e)
def main():
    hs,ms,he,me,k = map(int,input().split())
    h = he - hs
    m = me - ms
    h *= 60
    if m >= 0:
        h += m
    else:
        h += -m - 60
    print(h - k)
if __name__=='__main__':
    main()
H1, M1, H2, M2, K = map(int,input().split())

latest = H2*60+M2-K  #[min]
earliest = H1*60

study = latest-earliest
print(study)
h1, m1, h2, m2, k = map(int, input().split(" "))
diff = (h2-h1)*60 + (m2-m1) - 1
print(int(diff/k)*k)
h1 , m1 , h2 , m2 , k = map(int, input().split())

h = h2 - h1
m = abs(m2-m1)

print(h*60+m-k)
t = input()
ans=t.replace('?D','PD')
ans=ans.replace('P?','PD')
ans=ans.replace('??','PD')
ans=ans.replace('?','D')
print(ans)
def compute():
  import sys
  for aline in sys.stdin:
    aline = aline.strip()
    eles = aline.split(' ')
    eles = [int(ele) for ele in eles]
    # h1 m1 h2 m2 k
    res = 60*(h2-h1) + (m2-m1) -k
    return res
#!/usr/bin/env pypy3

import math

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

if m1 < m2:
    h2 -= 1
    m2 = 60

if h1 > h2:
    h2 += 24

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

res = allMin - k
if res < 0:
    res = 0

print(res)
H1,M1,H2,M2,K=map(int,input().split())
if M2<M1:
    print((H2-H1-1)*60+(M1-M2)-K)
else:
    print((H2-H1)*60+(M2-M1)-K)
h1,m1,h2,m2,k = map(int,input().split())
 
#print(h1,m1,h2,m2,k)
t = 0
if m1 > m2:
    t =(h2-h1-1)*60+m2-m1-k
else:
    t =(h2-h1)*60+m2-m1-k

if t > 0:
    print(t)
else:
    print(0)
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 time % K == 0:
    a = a-1

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

hk = K//60
mk = K%60

ans = (H2 - hk)*60 + (M2 - mk) - (H1*60 + M2)
print(max(ans, 0))