Buses run between the cities A and B, the first one is at 05:00 AM and the last one departs not later than at 11:59 PM. A bus from the city A departs every a minutes and arrives to the city B in a t_{a} minutes, and a bus from the city B departs every b minutes and arrives to the city A in a t_{b} minutes.

The driver Simion wants to make his job diverse, so he counts the buses going towards him. Simion doesn't count the buses he meet at the start and finish.

You know the time when Simion departed from the city A to the city B. Calculate the number of buses Simion will meet to be sure in his counting.


-----Input-----

The first line contains two integers a, t_{a} (1 ≤ a, t_{a} ≤ 120) — the frequency of the buses from the city A to the city B and the travel time. Both values are given in minutes.

The second line contains two integers b, t_{b} (1 ≤ b, t_{b} ≤ 120) — the frequency of the buses from the city B to the city A and the travel time. Both values are given in minutes.

The last line contains the departure time of Simion from the city A in the format hh:mm. It is guaranteed that there are a bus from the city A at that time. Note that the hours and the minutes are given with exactly two digits.


-----Output-----

Print the only integer z — the number of buses Simion will meet on the way. Note that you should not count the encounters in cities A and B.


-----Examples-----
Input
10 30
10 35
05:20

Output
5

Input
60 120
24 100
13:00

Output
9



-----Note-----

In the first example Simion departs form the city A at 05:20 AM and arrives to the city B at 05:50 AM. He will meet the first 5 buses from the city B that departed in the period [05:00 AM - 05:40 AM]. Also Simion will meet a bus in the city B at 05:50 AM, but he will not count it.

Also note that the first encounter will be between 05:26 AM and 05:27 AM (if we suggest that the buses are go with the sustained speed).

Difficulty: interview

Starter code:

Solutions:
a, A = list(map(int,input().split()))
b, B = list(map(int,input().split()))
c = input()
c = int(c[:2]) * 60 + int(c[-2:])
d = 0
for i in range(5 * 60, 24 * 60, b):
    if i < c + A and i + B > c:
        d += 1
print(d)


a,ta = list(map(int,input().split()))
b,tb = list(map(int,input().split()))
h,m = list(map(int,input().split(":")))
m += h * 60
mint = m - tb
maxt = m + ta
m2 = 300
ans = 0
while 1440 > m2:
    if m2 > mint and maxt > m2:
        ans += 1
    m2 += b
print(ans)


a, t1 = map(int, input().split())
b, t2 = map(int, input().split())
hour, minute = map(int, input().split(':'))
minutef = minute + hour * 60 + t1
minutes = minute + hour * 60 - t2
cnt = 0
time =  300

while time < minutef and time < 240 * 6:
    if time > minutes:
        cnt += 1
    time += b
print(cnt)

import sys
import math
import itertools as it
import operator as op
import fractions as fr


a,ta = map(int, sys.stdin.readline().split())
b,tb = map(int, sys.stdin.readline().split())
sh, sm = map(int, sys.stdin.readline().strip().split(':'))

sme = sh * 60 + sm


start = sme - tb
end = sme + ta

last_bus_B_min = int(math.ceil((19 * 60) / b)) * b + 300
sch_B = list(range(300, last_bus_B_min, b))

t = filter(lambda t: (t > start) and (t < end), sch_B)
print(len(list(t)))

a, ta = map(int, input().split())
b, tb = map(int, input().split())
sl = input().split(':')
s = 60 * int(sl[0]) + int(sl[1])
print(sum(1 for i in range(5 * 60, 24 * 60, b) if i < s + ta and i + tb > s))

#!/usr/bin/env python
a, t_a = list(map(int, input().split()))
b, t_b = list(map(int, input().split()))
hh, mm = list(map(int, input().split(sep = ':')))
start_time = (hh - 5) * 60 + mm
buses = []
for time in range((24 - 5) * 60):
    if time < start_time:
        buses = [item - 1 for item in buses if item != 1]
        if time % b == 0:
            buses.append(t_b)
    elif time == start_time:
        buses = [item - 1 for item in buses if item != 1]
        z = len(buses)
    if time >= start_time and time < start_time + t_a:
        if time % b == 0:
            z += 1
print(z)


a, ta = list(map(int, input().split()))
b, tb = list(map(int, input().split()))
h, m = list(map(int, input().split(':')))

cnt = 1139 // b

ans = 0

beg = h * 60 + m - tb
end = h * 60 + ta + m

for i in range(cnt + 1):
    if beg < b * i + 5 * 60 < end:
        ans += 1

print(ans)


a,b=map(int,input().split())
n,m=map(int,input().split())
t1,t2=map(int,input().split(':'))
h=t1-5
t2=t2
st=t2+h*60
fin=st+b
now=0
ans=0
while now<fin and now<1140:
    if now+m>st:
        ans+=1
    now+=n
print(ans)

[a,ta]=[int(i) for i in input().split()]
[b,tb]=[int(i) for i in input().split()]
[h,m]=[int(i) for i in input().split(':')]
xa=h*60+m
ya=xa+ta
ans=0
for xb in range(300,24*60,b):
    yb=xb+tb
    if(max(xa,xb)<min(ya,yb)): ans+=1
print(ans)

3
# -*- config:utf-8 -*-

from sys import stdin
from math import ceil


def getdata():
    s = stdin.readline()
    s = s.rstrip()
    s = s.split(' ')
    s = [int(i) for i in s]
    a, ta = s
    s = stdin.readline()
    s = s.rstrip()
    s = s.split(' ')
    s = [int(i) for i in s]
    b, tb = s
    s = stdin.readline()
    s = s.rstrip()
    s = s.split(':')
    s = [int(i) for i in s]
    dth, dtm = s
    dtm = dth * 60 + dtm
    return (a, ta, b, tb, dtm)


def getfile():
    f = open("test.txt")
    s = f.readline()
    s = s.rstrip()
    s = s.split(' ')
    s = [int(i) for i in s]
    a, ta = s
    s = f.readline()
    s = s.rstrip()
    s = s.split(' ')
    s = [int(i) for i in s]
    b, tb = s
    s = f.readline()
    s = s.rstrip()
    s = s.split(':')
    s = [int(i) for i in s]
    dth, dtm = s
    dtm = dth * 60 + dtm
    f.close()
    return (a, ta, b, tb, dtm)


def run1():
    starttime = 5 * 60
    endtime = 23 * 60 + 59
    # a,ta,b,tb,dtm=getdata()
    a, ta, b, tb, dtm = getfile()
    b_first_dt = dtm - tb
    if b_first_dt < starttime:
        b_first_dt = 0
    else:
        b_first_dt = b_first_dt - starttime
    b_last_dt = dtm + ta
    if b_last_dt > endtime:
        b_last_dt = endtime - starttime
    else:
        b_last_dt = b_last_dt - starttime
    b_first_dt = ceil(b_first_dt / b) * b
    if b_first_dt > endtime - starttime:
        b_first_dt -= b
    b_last_dt = b_last_dt // b * b
    cnt = (b_last_dt - b_first_dt) // b + 1
    if b_last_dt == (dtm + ta - starttime):
        cnt -= 1
    print(cnt)


def check_time(bus_departure_time, starttime, endtime):
    if bus_departure_time < starttime:
        return starttime
    if bus_departure_time > endtime:
        return endtime
    return bus_departure_time


def get_actual_first(first_bus_departure_time, starttime, endtime, b):
    tmp = ceil((first_bus_departure_time - starttime) / b) * b
    if tmp > (endtime - starttime):
        tmp = endtime - starttime
    return tmp


def get_actual_last(last_bus_departure_time, starttime, endtime, b):
    tmp = (last_bus_departure_time - starttime) // b * b
    if tmp > (endtime - starttime):
        tmp = endtime - starttime
    return tmp


def run():
    starttime = 5 * 60
    endtime = 23 * 60 + 59
    a, ta, b, tb, dtm = getdata()
    # a,ta,b,tb,dtm=getfile()
    first_bus_departure_time = dtm - tb
    last_bus_departure_time = dtm + ta
    first_bus_departure_time = check_time(first_bus_departure_time, starttime, endtime)
    last_bus_departure_time = check_time(last_bus_departure_time, starttime, endtime)
    first_bus_departure_time = get_actual_first(first_bus_departure_time, starttime, endtime, b)
    last_bus_departure_time = get_actual_last(last_bus_departure_time, starttime, endtime, b)
    cnt = (last_bus_departure_time - first_bus_departure_time) // b + 1
    if (dtm + ta - starttime) == last_bus_departure_time:
        cnt -= 1
    if (dtm - starttime) == first_bus_departure_time + tb:
        cnt -= 1
    print(cnt)


def __starting_point():
    run()

__starting_point()

a,ta=list(map(int,input().split(' ')))
#print (a,ta)
b,tb=list(map(int,input().split(' ')))

time=input()

hour=int(time[0:2])
mint=int(time[3:5])
low=(hour-5)*60+mint
up=low+ta
#print(low,up)
ans=0
for i in range(0,19*60,b):
	l=i
	h=i+tb
	if not (h <= low or l >= up):
		ans+=1
print (ans)
#print(hour)


from math import ceil, floor

a, ta = map(int, input().split())
b, tb = map(int, input().split())
h, m = map(int, input().split(":"))

mi = 0
ma = 23*60 + 59 - 5*60
cur = (h - 5) * 60 + m

start = min(ma, max(cur - tb, 0))
end = max(mi, min(ma, cur + ta))

start = ceil(start / b) * b
end = floor(end / b) * b

r = int((end-start) / b) + 1

if start == cur - tb:
    r -= 1

if end == cur + ta:
    r -= 1

print(r)

a, ta = list(map(int, input().split()))
b, tb = list(map(int, input().split()))
hour, minutes = list(map(int, input().split(':')))
time_dep = hour * 60 + minutes - 300
count = 0
for i in range(0, 1140, b):
    if i + tb > time_dep and i < time_dep + ta:
        count += 1
        #print(i, i + tb, count)
print(count)


a,ta = list(map(int,input().split()))
b,tb = list(map(int,input().split()))
h,m  = list(map(int,input().split(':')))

time = (h-5)*60+m
r = time % b
if r >= tb:
    t2 = time + b - r
else:
    t2 = time - r - b * ((time - r - max(time - tb + 1, 0)) // b)
t3 = min(time + ta, 19 * 60) - 1

if t3 < t2:
    print(0)
else:
    print((t3 - t2)//b+1)


a, ta = map(int, input().split())
b, tb = map(int, input().split())
s=input()
ha=int(s[0])*10+int(s[1])
ma=int(s[3])*10+int(s[4])

startH=ha*60+ma
endH=startH+ta
st=300
k=0
while st<endH and st < 1440:
    if st+tb>startH:
        k+=1
    st = st + b
print(k)

a, ta = list(map(int, input().split()))
b, tb = list(map(int, input().split()))
h,m = list(map(int, input().split(":")))
d = 60*h+m
c = 300
r = 0
while c <= d - tb:
    c += b
while c < min(24*60,d + ta):
    c += b
    r += 1
print(r)


def solve(a, t1, t2):
    l1 = t1 - (t1 - 300) % a + a
    if (l1 < 300):
        l1 = 300
    l2 = t2 - (t2 - 300) % a
    if (l2 > 1439):
        l2 = 1439
    if (l2 < l1):
        return 0
    return (l2-l1) // a + 1 - (l2 == t2)
    
def trans(h, m):
    return 60 * h + m
    
data1 = [int(x) for x in input().split()]
data2 = [int(x) for x in input().split()]
data3 = input()
h0 = int(data3[0:2])
m0 = int(data3[-2:])
t0 = trans(h0, m0)
sol = solve(data2[0], t0 - data2[1], t0 + data1[1])
print(sol)

a, ta = map(int, input().split())
b, tb = map(int, input().split())
sl = input().split(':')
s = 60 * int(sl[0]) + int(sl[1])
print(sum(1 for i in range(5 * 60, 24 * 60, b) if i < s + ta and i + tb > s))

a, ta = list(map(int, input().split(' ')))
b, tb = list(map(int, input().split(' ')))
depart = tuple(map(int, input().split(':')))


depart_t = 60*depart[0] + depart[1]

arrival = depart_t + ta


count = 0

ct = 5*60
while ct < arrival and ct < 24*60:
	if ct > depart_t - tb:
		count += 1
	ct += b

print(count)
# busses must be on the road between depart and depart + ta


s=input().split()
a=int(s[0])
ta=int(s[1])
s=input().split()
b=int(s[0])
tb=int(s[1])
s=input().split(':')
hh=int(s[0])
mm=int(s[1])

starttime=hh*60 + mm
endtime=starttime+ta

i=300
l=[]
while(i<1440):
	l.append(i);
	i+= b;
length=len(l)
c=0
for i in range(0, length):
	if(l[i] < endtime and l[i]+tb >starttime):
		c+=1

print(c)

import math

[a, t_a] = map(int,input().split(" "))
[b, t_b] = map(int,input().split(" "))
[h, m] = map(int,input().split(":"))
mm = h * 60 + m

first_bus = 5*60
start = max(first_bus, mm - t_b + 1) - first_bus
end = min(60*23+59, mm + t_a - 1) - first_bus

# print(start, end)
# print(math.ceil(start/b), int(end/b))
print(int(end/b) - math.ceil(start/b) + 1)

def meet(a, b):
    return max(a[0], b[0]) < min(a[1], b[1])

a, ta = list(map(int, input().split()))
b, tb = list(map(int, input().split()))
h, m = list(map(int, input().split(':')))
ts = (h - 5) * 60 + m
ts = (ts, ts + ta)
cnt = 0

i = 0
while i * b <= (23 - 5) * 60 + 59:
    if meet((i*b, i*b + tb), ts):
        cnt += 1
    i += 1

print(cnt)


f1,t1 = [int(x) for x in input().split()]
f2,t2 = [int(x) for x in input().split()]

minutosTotales = 23*60+59-5*60

buses = []
for hora in range(0,minutosTotales+1,f2):
    buses.append((hora,hora+t2))

horaInicio = input().split(":")
horaInicio = (int(horaInicio[0])-5)*60+int(horaInicio[1])

c=0
for bus in buses:
    if not(bus[1]<=horaInicio or horaInicio+t1<=bus[0]):
        c+=1
print(c)


a, t_a = list(map(int, input().split()))
b, t_b = list(map(int, input().split()))
h, m = list(map(int, input().split(':')))

time = h * 60 + m

start = time
end = time + t_a - 1
start_time = 300
end_time = start_time + t_b - 1

intersections = 0

while start_time <= 1439:
    if end >= start_time and end_time >= start:
        intersections += 1

    start_time += b
    end_time = start_time + t_b - 1

print(intersections)


def main():
    a, ta = list(map(int, input().split()))
    b, tb = list(map(int, input().split()))
    h, m = list(map(int, input().split(':')))
    res, lo = 0, h * 60 + m - 300
    hi = lo + ta
    print(sum(max(lo, t) < min(hi, t + tb) for t in range(0, 1140, b)))


def __starting_point():
    main()

__starting_point()