peterverebics/CodeNet_Python_118 huggingface dataset:
h1, m1,h2,m2,k = map(int,input().split())
r = (h2 * 60 + m2)  -(h1* 60 + m2) - k
print(r)
h1,m1,h2,m2,k = map(int,input().split())

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

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

print(ans)
a,b,c,d,e= map(int, input().split())

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

if ans>=0:
    print(ans)
else:
    print(0)
h1, m1, h2, m2, k = map(int, input().split())
t1 = h1 * 60 + m1
t2 = h2 * 60 + m2
print(abs(t2 - t1 - 1) // k * k)
T = input()
ans = T.replace("?", 'D')
print(ans)
a,b,c,d,e=(int(x)for x in input().split())
x=(c-a)*60
y=x-e

if y<e: 
    print("0")
else:
    print(y)
h1, m1, h2, m2, k = map(int, input().split())
H = h2 - h1
if m1 <= m2:
    M = m2 - m1
else:
    M = 60 - m1 + m2
# print(H)
# print(M)
print(H*60 + M - k)
h1, m1, h2, m2, k = map(int, input().split())
print(max(0, h2*60-h1*60+m1-m2-k))
import datetime

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

req_H = K // 60
req_M = K % 60

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_2, 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(' '))
dh=h2-h1
dm=m2-m1
if dm<0:
    dm=dm+60
    dh=dh-1
sm=(dh*60+dm)-((dh)*60+(dm))%k
if sm%k==0:
    sm=sm-k
print(sm)
l=list(map(int,input().split()))
ans=max((l[2]-l[0])*60+l[1]-l[3]-l[-1],0)
print(ans)
h1,m1,h2,m2,k=map(int,input().split())
ans2=h2*60+m2
ans1=h1*60+m1
print(ans2-ans1)
h1, m1, h2, m2, k = [int(i) for i in input().split()]

time = 60*h2+m2 - 60*h1+m1 - k
print(time)
h1, m1, h2, m2, k = input().split()
import datetime

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

dt1 = datetime.datetime(year=2020, month=5, day=30, hour=h1, minute=m1)
dt2 = datetime.datetime(year=2020, month=5, day=30, hour=h2, minute=m2)

dt3 = dt2 - dt1
dt3 = dt3.seconds / 60 - 1
print(int(dt3 / k) * k)
H1,M1,H2,M2,K = list(map(int,input().split()))

Hsa = (H2 - H1)*60
Msa = (M2 - M1)

ans = Hsa - Msa - K

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


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

#print(asa,yoru)

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

print(ans* 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 (h2-h1)*60 + 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))))
h,m,H,M,k = map(int,input().split())
tmp = (60*H+M)-(60*h+m)-0.1
a = tmp//k
ans = k*a
print(int(ans))
H1, M1, H2, M2, K = map(int, input().split())

H = H2 - H1
M = abs(M2 - M1)

answer = H*60 + M - K
print(answer)
H1, M1, H2, M2, K = map(int, input().split())

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

res = (H+M) - K

if res >= K:
    print(res)
else:
    print(0)
#!/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)

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

if H1==H2:
    x=M2-M1
    ms=x-K
else:
    ms=(60-M1)+(H2-H1-1)*60-K
print(max(0, ms))
def resolve():
    h1,m1,h2,m2,k = map(int,input().split())
    T = h2*60 + m2 - (h1*60 - m1)
    print(T-k)

resolve()
L=list(map(int,input().split()))
A=60*L[0]+L[1]
B=60*L[2]+L[3]
if B-A <= L[4]:
	print("0")
elif (B-A)%L[4]==0:
	print(str(((B-A)-L[4])))
else:
	print(str(round((B-A)//L[4])))
a,b,c,d,e=(int(x)for x in input().split())
x=(c-a)*60
z1=(b-d)
z2=abs(z1)
y=x-e+z2

if y<e: 
    print("0")
else:
    print(y)
h1, m1, h2, m2, k = map(int, input().split())
print(h2*60+m2 - h1*60-m2 - k)
H,M,h,m,K = map(int,input().split())
A = H*60 + M
B = h*60 + M
X = B - A - K

print(X)
H1,M1,H2,M2,K = map(int,input().split())
  
print(60 * (H1 - H2) + M2 - M1 - K)
FH, FM, TH, TM, K = map(int, input().split())
M = (TH*60+TM)-(FH*60+FM)
ans = M // K-(1 if M%K == 0 else 0)
print(ans*K)
H1, M1, H2, M2, K = map(int, input().split())
H = H2 - H1
M = 0

if M2 - M1 >= 0:
  M = M2 - M1
else:
  M = M1 - M2 + 60
  H -= 1
  
ans = H*60 + M - K

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

if M2 >= K:
    M2 -= K
else:
    K -= M2
    p = K // 60
    r = K % 60
    H2 -= p
    if r:
        M2 -= 60 - r
    else:
        M2 = 0

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

if M1<M2:
    H = H2-H1-1
    M = 60+5-M1
else:
    H = H2-H1
    M = M2-M1
time = H*60+M
if time>=K:
    print(time-K)
else:
    print(0)
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 h < 0:
    h += 24
if m < 0:
    m = m + 60
    h -= 1

totalm = 60*h + m
ans = totalm - k
print(abs(ans))
h1,m1,h2,m2,k= map(int, input().split())
h1 *= 60
h2 *= 60
sa = h2 + m2 - h1 - m1
syo = sa // k
if sa%k == 0:
    syo -= 1
print(syo * k)
# 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 + (m1 + m2)
if t <= k:
    print(0)
elif t%k == 0:
    print(t - k)
else:
    print(t - t%k)
x = list(map(int, input().split()))
h = (x[2] - x[0])*60
m = x[3] - x[1]
if m < 0:
    h -= 1
    m = 60 - x[0] + x[3]
ans = max(m+h-x[-1], 0)
print(ans)
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
if z3<30:
    y=x-e+30

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

ans = ((rem//K)-1)*K
print(ans)
H1, M1, H2, M2, K = map(int,input().split())
time = (H2 * 60 + M2) - (H1 * 60 + M1) - 1
if time < 0:
    time += 1440
ans = time // K * K
print(ans)
import datetime
h1, m1, h2, m2, k = map(int, input().split())
one = datetime.timedelta(hours=h1, minutes=m1)
two = datetime.timedelta(hours=h2, minutes=m2)
study = datetime.timedelta(minutes=k)

diff_one_two_seconds = (two.total_seconds() - one.total_seconds()) / 60
study_seconds = study.total_seconds()/60
print(diff_one_two_seconds - study_seconds)
a,b,c,d,e = map(int,input().split())
t = 0
if a == b:
    t = d-b
else:
    t = (c-a) * 60 + d-b
print(t-e)
H1,M1,H2,M2,K=map(int,input().split())
if H2-H1<0:
    print(0)
else:
    if M2-M1<0:
        print(0)
    else:
        print(((H2-H1)*60+(M2-M1))-K)
h1, m1, h2, m2, k = map(int, input().split())

start = m2 + 60*h1
end = m2 + 60*h2

print(end-start-k)
H1, M1, H2, M2, K = map(int,input().split())
time = (H2 * 60 + M2) - (H1 * 60 + M1) - 1
ans = time // K * K
print(ans)
h1,m1,h2,m2,k = map(int,input().split())

print(h2*60+m2-h1*60+m1-k)
import sys
input = sys.stdin.readline

t = input()

t_update = ""
for i in t[1:]:
    if i == "?":
        i = "D"
    t_update += i
print(t_update)
import sys
input = sys.stdin.readline

t = input()

t_update = ""
for i in t:
    if i == "?":
        i = "D"
    t_update += i
print(t_update)
(a,b,c,d,e)=map(int,input().split())

if a==c:
    t=d-b
    print(t-e)
    
if c>a:
    if b>d:
        t=60-b+d
        print(t-e)
        
    else:
        t=(c-a)*60+d-b
        print(t-e)
def resolve():
    T = input()
    S = ""
    for i in range(len(T)):
        if T[i] == "D" or T[i] == "?":
            S += "D"
        else:
            S += "P"
    print(S)
resolve()
T = list(str(input()))

for i in range(len(T)):
    if T[i] == '?':
        if T[i - 1] == 'P':
            T[i] = 'D'
        elif T[i + 1] == '?':
            T[i] = 'P'
            T[i + 1] = 'D'
            i= i+1
        else:
            T[i] = 'D'
        

TL=''.join(T)
print(TL)
h1,m1,h2,m2,k=map(int,input().split())
tot=0
if m2>=m1:
	tot+=(m2-m1)+60*(h2-h1)
else:
	h2=h2-1
	m2+=60+m2
	tot+=(h2-h1)*60+(m2-m1)
print(max(0,tot-k))
H1, M1, H2, M2, K = map(int, input().split())


Minites = 0
if M1 < M2:
    Minites += 60 + M1 - M2
    H2 -= 1
Minites += 60*(H2 - H1)
print(Minites - K)
h1, m1, h2, m2, k = map(int, input().split())
h = h2 - h1
if m1>m2:
	h-=1
	m = m2 - m1 + 60
else:
	m = m2 - m1
l = h*60 + m - k
H, M, h, m, K = map(int, input().split())
print((60*h + m - 60*H - M)//K)
h1, m1, h2, m2, k = map(int, input().split())

h1h2 = (h2-h1)*60
m1m2 = abs(m1-m2)

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

h=h2 - h1
if h < 0:
    h = 24+h
m=m2 - h2

du=h*60+m

print((du//k)*k)
h1, m1,h2,m2,k = map(int,input().split())
if(h2*60+m2 < h1*60+m1):
    print((h2*60+m2 - h1*60+m1)-k+24*60)
else:
    print((h2*60+m2 - h1*60+m1)-k)
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 - 30
print(result)
def resolve():
    h1, m1, h2, m2, k = map(int, input().split())
    print((h2-h1)*60 + (m2-m1) - k*10)
    
resolve()
h, m, H, M, K = map(int, input().split())

if M >= m :
    k = (H - h) * 60
    k += M - m
    
else :
    k = (h - h - 1) * 60
    k += 60 - m
    k += M
    
print(k - K)
h1 , m1 , h2 , m2 , k = map(int, input().split())
a1 = abs(h2-h1)*60
a2 = abs(m1-m2)
a  = a1 - a2
if a == k:
    print(0)
else:
    b = a - k
    print(b)
h1,m1,h2,m2,k=map(int,input().split())
ans=(h2-h1)*60
if(m1>0):
	ans+=(60-m1)
if(m2>0):
	ans+=m2
ans-=k
print(ans)
h,m,h2,m2,k=map(int,input().split())
a=h*60+m
b=h2*60+m2
#print(b)
if (b-a)%k==0:
    print((b-a)-k)
else:
    print((b-a)-(b-a)%k)
#coding: utf-8
number = 12 - 10
print(number * 60 + ( 0 - 0) )
h1,m1,h2,m2, k = [int(i) for i in input().split()]


if m2 >= m1:
    minute = m2-m1
else:
    minute = 60 - m1 +m2

time = abs(h2-h1)*60 + minute
if time%k==0:
    print(time - k)
else:
    print((time//k)*60)
def main():
    H1, M1, H2, M2, K = [int(value) for value in input().split(" ")]

    # K(min)-> Time min
    H = K // 60
    M = K % 60
    
    
    NH = H2 - H
    NM = M2 - M
    if NM < 0:
        NH -= 1
        NM = 60 + NM

    RM = (NH - H1)*60 + NM
    print(RM)

if __name__=="__main__":
    main()
H = input().split()
sdy =0
if H[2] > 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)
import re
import copy

wake_up_hour,wake_up_minute,sleep_hour,sleep_minute,study_time = map(int, input().split())
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, )
a=input().split(' ')
a[0]=int(a[0])
a[1]=int(a[1])
a[2]=int(a[2])
a[3]=int(a[3])
a[4]=int(a[4])
b=(a[1]*60)+a[2]
c=(a[2]*60)+a[3]
print(c-b+a[4])
H1,M1,H2,M2,K=map(int,input().split())
if M1>M2:
    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())
x = 60*max(0, h2-h1-1)
x += (60-m1 + m2)

if x%k == 0:
    print(x - k)
else:
    print((x//k-1)*k)
h1, m1, h2, m2, k = [int(_) for _ in input().split()]

x = (h2 - h1) * 60 + m2 - m1 - k
if m1 > m2:
    x -= 60

print(x)
H1,M1,H2,M2,K=map(int, input().split())
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())
awake = 60 * (H2 - H1) - (M2 - M1)
if awake < 0:
    awake += 24 * 60
print(awake - 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())
print((H2-H1)*60 + (M1+M2) - K)
h1, m1, h2, m2, k =map(int, input().split())

ans = (h2-h1)*60+(m1-m2) -k
print(ans)
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 = 24*60 + mini

print(mini)
h1, m1, h2, m2, k = map(int, input().split())
time1 = h1*60+m1
time2 = h2*60+m1
print(time2-time1-k)
H1,M1,H2,M2,K=map(int,input().split())
if M2-M1>=0:
  X=(H2-H1)*60+(M2-M1)
else:
  X=(H2-1-H1)*60+(M2+60-M1)
print(min(0,X-K))
from math import *
from sys import stdin,stdout
input=stdin.buffer.readline

ip=[int(x) for x in input().split()]
h1=ip[0]
m1=ip[1]
h2=ip[2]
m2=ip[3]
k=ip[4]

time=(h2*60+m2)-(h1*60+m1)-1
x=time//k
print(k*x)
"""
H1時M1分起床
H2時M2分就寝
K分勉強
"""
 
H1, M1, H2, M2, K = [int(i) for i in input().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)
#!/usr/bin/env pypy3

import math

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

if m2 < m1:
    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)
a, b, c, d, e = map(int, input().split())
if 0<= a <= 23 and 0<= c<= 23 and 0 <= b <= 59 and 0 <= d<= 23 and e>=1:
    f = abs(c-a)*60
    print(abs(f-e))
h1, m1, h2, m2, k = map(int, input().split())

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

print(max(0, k*(diff//k-1)))
sh,sm,eh,em,k = map(int,input().split())

h = eh - sh
m = em - sm

if m < 0:
    h -= 1

totalm = 60*h + m
ans = totalm - k
print(abs(ans))
H, M, h, m, K = map(int, input().split())
wake = H * 60 + M
sleep = h * 60 + M
if wake < sleep:
    spinner = sleep - wake
    oops = spinner - K
else:
    spinner = wake - sleep
    oops = spinner - K
print(oops)
h1, m1, h2, m2, k = map(int, input().split())
m = m2-m1
m %= 60
m += 60*(h2-h1)
ans = max(0, m-k)
print(ans)
h1,m1,h2,m2,k=map(int,input().split())
ans=h2*60+m2-k-h1*60+m1
print(ans)
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)
print(k*(study_time//k) - k)
h1, m1,h2,m2,k = map(int,input().split())
if h2 * 60 + m2 >h1* 60 + m2:
    r = (h2 * 60 + m2)  -(h1* 60 + m2) - k
else:
    r = (h2 * 60 + m2) + 24 * 60 - (h1* 60 + m2)  - k
print(r)
h1, m1, h2, m2, k = map(int, input().split())

minutes1 = 60*h1 + m1
minutes2 = 60*h2 + m2

rest = minutes2 - minutes1
s, r = divmod(rest, k)

if r == 0:
    print((s-1)*k)
else:
    print(s*k)
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(max(0, can_start))
def compute():
  import sys
  for aline in sys.stdin:
    # h1 m1 h2 m2 k
    eles = aline.strip()
    h1 = int(eles[0])
    m1 = int(eles[1])
    h2 = int(eles[2])
    m2 = int(eles[3])
    k = int(eles[4])
    res = 60*(h2-h1) + m2 - m1 -k
    return res
import datetime
h1, m1, h2, m2, k = map(int, input().split())
ans = 0

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

if delta // k >= 1:
    ans = (delta // k) * k

print(ans)
#list(map(int,input().split()))
a,b,c,d,e=list(map(int,input().split()))
print(max(c*60+d-a*60+b-e,0))
h1,m1,h2,m2,k=map(int,input().split())
h=h2-h1
m=m2-m1
t=h*60+m
print(min(t-k,0))
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


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

h3 = h2 - h1
m3 = m2 - m1
if m3 < 0:
    h2 = h2 - 1
    m3 = 60 - m1 + m2

a = h3 * 60 + m3
ans = a - k

print(ans)
H, M, h, m, K = map(int, input().split())
print(((60*h + m - 60*H - M)//K)*K)
H1, M1, H2, M2, K = map(int, input().split())

# 10:00->15:00
# 10:00->12:00

# 起きている時間を計算する（単位分

import datetime

def get_waking_time(H,I,J,K):
    d1 = datetime.datetime(year=2020, month=5, day=30, hour=H, minute=I, microsecond=0)
    d2 = datetime.datetime(year=2020, month=5, day=30, hour=J, minute=K, microsecond=0)
    delta = d2 -d1
    return delta.seconds/60


print(int(K*((get_waking_time(H1, M2, H2, M2)-1)//K)))
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

print(T - K)
h, m, H, M, k = map(int, input().split())
h = h*60
H = H*60
if h+m > H+M:
    print(1440 - (H-M) - k)
else:
    print(abs((h+m) - (H-M)) - k)
h1, m1, h2, m2, k = map(int, input().split())

h3, m3 = divmod(k, 60)

dh = h2 - h3
dm = m2 - m3
if dm < 0:
    dh -= 1
    dm *= -1



ah = dh - h1
am = dm - m1
if am < 0:
    ah -= 1
    am *= -1

ans = ah * 60 + am
print(ans)
H1,M1,H2,M2,K=map(int, input().split())
if H1 == 0:
  H1 = 24
if H2 == 0:
  H2 = 24
hour = H2-H1
print(H1)
print(H2)
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())
if M1<M2:
    print((H2-H1-1)*60+(M1-M2)-K)
else:
    print((H2-H1)*60+(M2-M1)-K)
a,b,c,d,e=map(int, input().split())
print(60*c+a-60*d-c-e)
H1, M1, H2, M2, K = map(int, input().split())

if H1 > H2:
    H2 += 24

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

print((h2 - m2) - (h1 + m1) - K)
h1, m1, h2, m2, k = map(int, input().split())
pos = 60 * (h2 - h1) + abs(m2 - m1)
if m2 - m1 < 0:
    pos -= 60
print(max(0, pos - k))
def solve():
    H1, M1, H2, M2, K = map(int, input().split())
    print((H2*60 + M2) - (H1*60 + M2) - K)

if __name__ == '__main__':
    solve()
h1, m1, h2, m2, k = map(int, input().split())
if m1 > m2:
    m2 += 60
    h2 -= 1
m = abs(m2-m1)
h = abs(h1-h2)
a = h*60
m += a
b = k
print(m)
if k != m:
    while k+b != m and k+b < m:
        if k+b == m:
            k = 0
            break
        k += b
else:
    k = 0
print(k)
H1,M1,H2,M2,K = list(map(int,input().split()))


minutes = H2*60-H1*60+M1-M2 -K
print(minutes)
h,m,a,b,k=map(int,input().split())
m_to_hour = m /60
b_to_hour = b /60
h_hour = 12.00 - ( h + m_to_hour )
a_hour = (a + b_to_hour) - 12.00
to_min =( h_hour + a_hour )*60
print(int(to_min-k))
h1, m1, h2, m2, k = map(int, input().split())
print((h2 * 60 + m2 - 1 - h1 * 60 - m1) // k * k)
h1, m1, h2, m2, k = map(int, input().split())

time = 60*h2+m2 - 60*h1+m1
if time >= k:
  print(time-k)
else:
  print(60*24+time-k)
H1, M1, H2, M2, K = map(int, input().split())
time = (H2 - H1) * 60 + (M1 - M2)
print(time - K)
H1, M1, H2, M2, K = map(int, input().split())

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

ans = (h2 - m2) - (h1 + m1) - K if (h2 - m2) > (h1 + m1) else (h2 - m2) - (h1 + m1) - K + 24 * 60

print(ans)
okiji,okihun,neji,nehun,benji=map(int,input().split())
if neji>okiji:
    print((neji*60+nehun)-(okiji*60+okihun)-benji)
else:
    print((neji*60+nehun)+(okiji*60+okihun)-benji)
h1,m1,h2,m2,k = map(int,input().split())

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

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

if time < k:
    print(0)
else:
    print(time-k)
H1, M1, H2, M2, K=map(int, input().split())

if H1==H2:
    x=M2-M1
    print(x-K)
else:
    ms=(60-M1)+(H2-H1-1)*60-K
    print(ms)
h1,m1,h2,m2,k = map(int,input().split())
print(k* (((h2-h1)*60 + m2-m1-1)//k ))
h1,m1,h2,m2,k=map(int,input().split())
t=h2*60+m2-(h1*60+m1)
t-=0.5
g=t//k
print(g*k)
#!/usr/bin/env python3

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


if h2*60+m2-h1*60+m1-k < 0:
    print((h2+24)*60+m2-h1*60+m1-k)
else:
    print(h2*60+m2-h1*60+m1-k)
T = list(input())

if T[0] == '?':
    T[0] = 'P'

for i in range(1, len(T)-1):
    if T[i] == '?':
        if T[i-1] == 'P':
            T[i] = 'D'
        elif T[i+1] == 'D':
            T[i] = 'P'
        elif T[i+1] == '?':
            T[i] = 'P'
        else:
            T[i] = 'D'

if T[-1] == '?':
    T[-1] = 'D'

print(''.join(T))
H1, M1, H2, M2, K = [int(x) for x in input().split()]

M = 60 - M1 + 60 * ((H2 - (H1 + 1)) % 24) + M2
print(max(0, M - K))
HMK = list(map(int, input().split()))
H1 = HMK[0]
M1 = HMK[1]
H2 = HMK[2]
M2 = HMK[3]
K = HMK[4]
ans = ((H2 - H1) * 60 + (M1 + M2)) - K
print(ans)
n = list(map(int,input().split()))

start = n[0]*60 + n[1]
end = n[2]*60 + n[3]

zikan = end - start -2
kai = zikan // n[4] * n[4]
print(kai)
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(int(H2 * 60 + M2 - H1 * 60 + M1 - K))
sh,sm,eh,em,k = map(int,input().split())

h = eh - sh
m = em - sm

if m < 0:
    h -= 1

totalm = 60*h + m
ans = totalm - k
print(ans)
h1, m1, h2, m2, k = map(int, input().split())
h1 = 12 - h1
h2 = h2 -12
x = abs(h2 + h1) * 60 + m1 + m2 - k
print(x)
H1, M1, H2, M2, K = map(int,input().split())

awake = (H2-H1)*60 - M2 -M1  #[min]
study = awake-K

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

h = h2 - h1

if m2 == m1:
    m = 0
elif m2 > m1:
    m = m2 - m1
else:
    m = m2 + (60 - m1)





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

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

import math

try:
    print(math.floor(time // k) * k)
except:
    print(0)
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]

if mini < 0:
    mini = 0

print(mini)
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]
print(c)
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

s -= K
print(s)
H = list(map(int,input().split()))

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

if m < 0:
    h -= 1

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

print(mini)
h1,m1,h2,m2,k=map(int,input().split())
if h1==h2:
    print(m2-m1-k)
else:
    print((60-m1)+(h2-h1-1)*60-k)
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

h1,m1,h2,m2,k = map(int,input().split())
A = h1 * 60 + m1
B = h2 * 60 + m2
print((B-1-A)//k*k)
h1,m1,h2,m2,k = map(int, input().split())
res = 60*(h2-h1)
res += (m2-m1)
if m1 > m2:
    res += 60
print(res - k)
h1, m1, h2, m2, K = list(map(int, input().split()))
if abs(h1-h2)*60 + abs(m1-m2) <= K:
    print(0)
else:
    print(abs(h1-h2)*60 + abs(m1-m2) - K)
h1, m1, h2, m2, k = map(int, input().split())

hour = h2 - h1
minute = m2 - m1
time = (hour * 60) - minute

print(time - k)
h, m, x, y, k = map(int, input().split())
mi = x*60 + y - h*60+m - k
print(mi)
T = input()
l = len(T)
ans_l = []

def getans(count,ans):
    if count == l:
        ans_l.append([ans.count('D')+ans.count('PD'),ans])
        return
    if T[count] == '?':
        getans(count+1, ans + 'P')
        getans(count+1, ans + 'D')
    else:
        getans(count+1, ans + T[count])
getans(0,'')
ans_l.sort(reverse=True)
print(ans_l[0][1])
h1, m1, h2, m2, k = map(int, input().split())

ans = (h2 - h1) * 60 - (m2 -m1) - k
if ans < 0:
    print(0)
else:
    print(ans)
h1, m1, h2, m2, k = map(int, input().split())

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

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


print(min(0, (h2 * 60 + m2 - k) - (h1 * 60 + m1)))
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 (H1, M1) > (H2, M2):
	H2 += 24
print(max(0, 60*H2 + M2 - (60*H1 + M2) - K))
h1, m1, h2, m2, k = list(map(int, input().split()))

wake = (h2 * 60 + m2) - (h1 * 60 + m1)
print(wake)
just = False
if ((wake % k) == 0):
    just = True

ans = wake // k
if (just):
    ans -= 1

print(ans*k)
h1, m1, h2, m2, k = map(int, input().split())
 
if h1 <= h2:
    time = h2 * 60 + m2 - h1 * 60 + m1
else:
    time = (h2+24) * 60 + m2 - h1 * 60 + m1
if k >= time:
    print(0)
else:
    print(time - k)
h1,m1,h2,m2,k = map(int,input().split())

#print(h1,m1,h2,m2,k)
if m1 > m2:
    print((h2-h1-1)*60+m1-m2-k)
else:
    print((h2-h1)*60+m1-m2-k)
#!/usr/bin/env python3

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

print(h2*60+m2-h1*60+m1-k)