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: MEDIUM_HARD

Solutions:
(a, ta) = list(map(int, input().split(' ')))
(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
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)


(a, ta) = map(int, input().split())
(b, tb) = map(int, input().split())
(fh, fm) = map(int, input().split(':'))
start = fh * 60 + fm
stb = 5 * 60
(bl, al) = ([], [])
while stb < 24 * 60:
	bl.append((stb, stb + tb))
	stb += b

def inter(x, y):
	if x[0] >= y[1] or y[0] >= x[1]:
		return 0
	return 1
my = (start, start + ta)
ans = 0
for z in bl:
	ans += inter(my, z)
print(ans)


(a, ta) = map(int, input().split())
(b, tb) = map(int, input().split())
(h, m) = 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, A) = map(int, input().split())
(b, B) = 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)


import sys
(a, ta) = map(int, input().split())
(b, tb) = map(int, input().split())
(h, m) = map(int, input().split(':'))
(s, t) = (h * 60 + m, min(h * 60 + m + ta, 24 * 60))
ans = 0
for x in range(5 * 60, 24 * 60, b):
	if s < x + tb and t > x:
		ans += 1
print(ans)


(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)


from functools import cmp_to_key
from collections import deque, Counter
from heapq import heappush, heappop
from math import log, ceil
import sys
import os
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def ii():
	return int(inp())

def si():
	return str(inp())

def li(lag=0):
	l = list(map(int, inp().split()))
	if lag != 0:
		for i in range(len(l)):
			l[i] += lag
	return l

def mi(lag=0):
	matrix = list()
	for i in range(n):
		matrix.append(li(lag))
	return matrix

def lsi():
	return list(map(str, inp().split()))

def print_list(lista, space=' '):
	print(space.join(map(str, lista)))

def bisect_left(a, x):
	left = 0
	right = len(a)
	while left < right:
		mid = (left + right) // 2
		if a[mid] < x:
			left = mid + 1
		else:
			right = mid
	return left

def bisect_right(a, x):
	left = 0
	right = len(a)
	while left < right:
		mid = (left + right) // 2
		if a[mid] > x:
			right = mid
		else:
			left = mid + 1
	return left

def bisect_elements(a, x):
	return bisect_right(a, x) - bisect_left(a, x)
MOD = 10 ** 9 + 7
maxN = 5
FACT = [0] * maxN
INV_FACT = [0] * maxN

def add(x, y):
	return (x + y) % MOD

def multiply(x, y):
	return x * y % MOD

def power(x, y):
	if y == 0:
		return 1
	elif y % 2:
		return multiply(x, power(x, y - 1))
	else:
		a = power(x, y // 2)
		return multiply(a, a)

def inverse(x):
	return power(x, MOD - 2)

def divide(x, y):
	return multiply(x, inverse(y))

def allFactorials():
	FACT[0] = 1
	for i in range(1, maxN):
		FACT[i] = multiply(i, FACT[i - 1])

def inverseFactorials():
	n = len(INV_FACT)
	INV_FACT[n - 1] = inverse(FACT[n - 1])
	for i in range(n - 2, -1, -1):
		INV_FACT[i] = multiply(INV_FACT[i + 1], i + 1)

def coeffBinom(n, k):
	if n < k:
		return 0
	return multiply(FACT[n], multiply(INV_FACT[k], INV_FACT[n - k]))

def create_graph(n, m, undirected=1, unweighted=1):
	graph = [[] for i in range(n)]
	if unweighted:
		for i in range(m):
			[x, y] = li(lag=-1)
			graph[x].append(y)
			if undirected:
				graph[y].append(x)
	else:
		for i in range(m):
			[x, y, w] = li(lag=-1)
			w += 1
			graph[x].append([y, w])
			if undirected:
				graph[y].append([x, w])
	return graph

def create_tree(n, unweighted=1):
	children = [[] for i in range(n)]
	if unweighted:
		for i in range(n - 1):
			[x, y] = li(lag=-1)
			children[x].append(y)
			children[y].append(x)
	else:
		for i in range(n - 1):
			[x, y, w] = li(lag=-1)
			w += 1
			children[x].append([y, w])
			children[y].append([x, w])
	return children

def dist(tree, n, A, B=-1):
	s = [[A, 0]]
	(massimo, massimo_nodo) = (0, 0)
	distanza = -1
	v = [-1] * n
	while s:
		(el, dis) = s.pop()
		if dis > massimo:
			massimo = dis
			massimo_nodo = el
		if el == B:
			distanza = dis
		for child in tree[el]:
			if v[child] == -1:
				v[child] = 1
				s.append([child, dis + 1])
	return (massimo, massimo_nodo, distanza)

def diameter(tree):
	(_, foglia, _) = dist(tree, n, 0)
	(diam, _, _) = dist(tree, n, foglia)
	return diam

def dfs(graph, n, A):
	v = [-1] * n
	s = [[A, 0]]
	v[A] = 0
	while s:
		(el, dis) = s.pop()
		for child in graph[el]:
			if v[child] == -1:
				v[child] = dis + 1
				s.append([child, dis + 1])
	return v

def bfs(graph, n, A):
	v = [-1] * n
	s = deque()
	s.append([A, 0])
	v[A] = 0
	while s:
		(el, dis) = s.popleft()
		for child in graph[el]:
			if v[child] == -1:
				v[child] = dis + 1
				s.append([child, dis + 1])
	return v

def parents_children_root_unrooted_tree(tree, n, root=0):
	q = deque()
	visited = [0] * n
	parent = [-1] * n
	children = [[] for i in range(n)]
	q.append(root)
	while q:
		all_done = 1
		visited[q[0]] = 1
		for child in tree[q[0]]:
			if not visited[child]:
				all_done = 0
				q.appendleft(child)
		if all_done:
			for child in tree[q[0]]:
				if parent[child] == -1:
					parent[q[0]] = child
					children[child].append(q[0])
			q.popleft()
	return (parent, children)

def all_longest_path_passing_from_node(parent, children, n):
	q = deque()
	visited = [len(children[i]) for i in range(n)]
	downwards = [[0, 0] for i in range(n)]
	upward = [1] * n
	longest_path = [1] * n
	for i in range(n):
		if not visited[i]:
			q.append(i)
			downwards[i] = [1, 0]
	while q:
		node = q.popleft()
		if parent[node] != -1:
			visited[parent[node]] -= 1
			if not visited[parent[node]]:
				q.append(parent[node])
		else:
			root = node
		for child in children[node]:
			downwards[node] = sorted([downwards[node][0], downwards[node][1], downwards[child][0] + 1], reverse=True)[0:2]
	s = [node]
	while s:
		node = s.pop()
		if parent[node] != -1:
			if downwards[parent[node]][0] == downwards[node][0] + 1:
				upward[node] = 1 + max(upward[parent[node]], downwards[parent[node]][1])
			else:
				upward[node] = 1 + max(upward[parent[node]], downwards[parent[node]][0])
		longest_path[node] = downwards[node][0] + downwards[node][1] + upward[node] - min([downwards[node][0], downwards[node][1], upward[node]]) - 1
		for child in children[node]:
			s.append(child)
	return longest_path
(a, ta) = li()
(b, tb) = li()
t = si()
inb = [0]
continua = True
tmax = 59 + 60 * 18
while continua:
	if inb[-1] + b <= tmax:
		inb.append(inb[-1] + b)
	else:
		continua = False
h = int(t[0:2])
m = int(t[3:5])
t = (h - 5) * 60 + m
count = 0
for el in inb:
	if el < t + ta and el + tb > t:
		count += 1
print(count)


[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)


(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)


(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)


(a, ta) = map(int, input().split())
(b, tb) = map(int, input().split())
(h, m) = map(int, input().split(':'))
ms = (h - 5) * 60 + m
first = 0
lastt = 19 * 60 - 1
curt = 0
res = 0
while curt <= lastt:
	if curt < ms + ta and curt + tb > ms:
		res += 1
	curt += b
print(res)


(a, ta) = map(int, input().split())
(b, tb) = map(int, input().split())
dep = str(input())
t = int(dep[0]) * 10 * 60 + int(dep[1]) * 60 + int(dep[3]) * 10 + int(dep[4]) - 5 * 60
depb = t - tb
if depb < 0:
	depb = 0
else:
	depb = depb - depb % b + b
c = 0
while depb < t + ta and depb <= 1439 - 5 * 60:
	c += 1
	depb += b
print(c)


(a, ta) = list(map(int, input().strip().split()))
(b, tb) = list(map(int, input().strip().split()))
s = str(input())
ha = int(s[0:2])
ma = int(s[3:5])
l = []
lb = ha * 60 + ma
ub = lb + ta
start = 300
c = 0
while start < 24 * 60:
	if max(lb, start) < min(ub, start + tb):
		c += 1
	start += b
print(c)


(f1, t1) = [int(i) for i in input().split(' ')]
(f2, t2) = [int(i) for i in input().split(' ')]
time = [str(i) for i in input().split(' ')]
time = time[0]
(th, tm) = time.split(':')
th = int(th)
tm = int(tm)
tt = (th - 5) * 60 + tm
bs = tt - t2 + 1
bf = tt + t1 - 1
count = 0
if bs < 0:
	bs = 0
ct = 18 * 60 + 59
if bf > ct:
	bf = ct
time = 0
for i in range(int((18 * 60 + 59) / f2) + 1):
	if bs <= time <= bf:
		count += 1
	time = time + f2
print(count)


(a, ta) = map(int, input().split())
(b, tb) = map(int, input().split())
(h, m) = map(int, input().split(':'))
sa = h * 60 + m
ea = sa + ta
c = 0
i = 0
sb = 0
eb = sa
while sb < ea and sb <= 1439:
	if eb > sa:
		c += 1
	sb = 5 * 60 + b * i
	eb = sb + tb
	i += 1
print(c)


import sys
sys.stderr = sys.stdout

def dm(x, m):
	return x - x % m

def buses(a, ta, b, tb, t0):
	s1 = max(t0 - tb, -1) // b
	s2 = min(t0 + ta - 1, 1139) // b
	return s2 - s1

def main():
	(a, ta) = readinti()
	(b, tb) = readinti()
	(h, m) = map(int, input().split(':'))
	t0 = h * 60 + m - 300
	print(buses(a, ta, b, tb, t0))

def readint():
	return int(input())

def readinti():
	return map(int, input().split())

def readintt():
	return tuple(readinti())

def readintl():
	return list(readinti())

def readinttl(k):
	return [readintt() for _ in range(k)]

def readintll(k):
	return [readintl() for _ in range(k)]

def log(*args, **kwargs):
	print(*args, **kwargs, file=sys.__stderr__)
main()


(a, t_a) = map(int, input().split())
(b, t_b) = map(int, input().split())
(h, m) = 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)


(a, ta) = map(int, input().split())
(b, tb) = map(int, input().split())
time = input().split(':')
mins = int(time[0]) * 60 + int(time[1])
ans = 0
for i in range(300, 1440, b):
	if i + tb > mins and i < mins + ta:
		ans += 1
print(ans)


import datetime as DT

def bus(a, t_a, b, t_b, t):
	t1 = DT.datetime.strptime(t, '%H:%M')
	t2 = DT.datetime(1900, 1, 1)
	t_start = (t1 - t2).total_seconds() / 60.0 - 300
	t_end = t_start + t_a
	t_elapsed = 0
	z = 0
	while t_elapsed <= 23 * 60 + 59 - 300:
		start = t_elapsed
		end = start + t_b
		if max(t_start, start) < min(t_end, end):
			z += 1
		t_elapsed += b
	return z
a = input().split(' ')
b = input().split(' ')
t = input()
print(bus(int(a[0]), int(a[1]), int(b[0]), int(b[1]), t))


(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 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(int(end / b) - math.ceil(start / b) + 1)


(a, t_a) = map(int, input().split())
(b, t_b) = map(int, input().split())
(hh, mm) = 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) = map(int, input().split())
(b, tb) = map(int, input().split())
(hour, minutes) = 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(count)


(a, ta) = map(int, input().split())
(b, tb) = map(int, input().split())
(c, d) = map(int, input().split(':'))
mins = (c - 5) * 60 + d
buses = [i * b for i in range(2000)]
st = mins - tb
end = mins + ta
ans = 0
for el in buses:
	if el > st:
		ans += 1
	if el >= end or el >= 19 * 60:
		ans -= 1
		break
print(ans)


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)


f = lambda k: map(int, input().split(k))
(a, u) = f(' ')
(b, v) = f(' ')
(h, m) = f(':')
t = h * 60 + m - 300
(x, y) = (max(t - v, -1), min(t + u - 1, 1139))
print(y // b - x // b)


R = lambda : map(int, input().split())
(a, ta) = R()
(b, tb) = R()
s = input().split(':')
st = 5 * 60
fi = 24 * 60
mins = int(s[0]) * 60 + int(s[1])
res = 0
for i in range(max(mins - tb + 1, st), min(mins + ta, fi)):
	if (i - st) % b == 0:
		res += 1
print(res)


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)


R = lambda : map(int, input().split())
(a, ta) = R()
(b, tb) = R()
(h, m) = map(int, input().split(':'))
initial_time = 5 * 60
final_time = 23 * 60 + 59
bus_itime = h * 60 + m
bus_ftime = bus_itime + ta
c = 0
for i in range(initial_time, final_time + 1, b):
	if i >= bus_itime and i < bus_ftime:
		c += 1
	elif i + tb > bus_itime and i < bus_ftime:
		c += 1
	if i >= bus_ftime:
		break
print(c)


import sys
import bisect
from bisect import bisect_left as lb
input_ = lambda : sys.stdin.readline().strip('\r\n')
from math import log
from math import gcd
from math import atan2, acos
from random import randint
sa = lambda : input_()
sb = lambda : int(input_())
sc = lambda : input_().split()
sd = lambda : list(map(int, input_().split()))
se = lambda : float(input_())
sf = lambda : list(input_())
flsh = lambda : sys.stdout.flush()
mod = 10 ** 9 + 7
gp = []
cost = []
dp = []
mx = []
ans1 = []
ans2 = []
special = []
specnode = []
a = 0
kthpar = []

def dfs(root, par):
	if par != -1:
		dp[root] = dp[par] + 1
	for i in range(1, 20):
		if kthpar[root][i - 1] != -1:
			kthpar[root][i] = kthpar[kthpar[root][i - 1]][i - 1]
	for child in gp[root]:
		if child == par:
			continue
		kthpar[child][0] = root
		dfs(child, root)

def hnbhai():
	(a, ta) = sd()
	(b, tb) = sd()
	(hh, mm) = input().split(':')
	hh = int(hh)
	mm = int(mm)
	time = 60 * hh + mm
	tot = 0
	for i in range(5 * 60, 24 * 60, b):
		if i + tb > time and time + ta > i:
			tot += 1
	print(tot)
for _ in range(1):
	hnbhai()


(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) = map(int, input().split())
(b, tb) = map(int, input().split())
(h, m) = map(int, input().split(':'))
start = h * 60 + m
end = start + ta
ans = 0
for i in range(5 * 60, 24 * 60, b):
	if i == end:
		continue
	if i + tb == start:
		continue
	if max(start, i) <= min(end, i + tb):
		ans += 1
print(ans)


f = lambda k: map(int, input().split(k))
(a, u) = f(' ')
(b, v) = f(' ')
(h, t) = f(':')
t += (h - 5) * 60
print(min(t + u - 1, 1139) // b - max(t - v, -1) // b)


(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())
(h, m) = map(int, input().split(':'))
start = 5 * 60
end = 24 * 60
depart = h * 60 + m
not_before = max(start, depart - tb + 1)
not_after = min(end, depart + ta)
first_b = (not_before - start + b - 1) // b
first_time = start + first_b * b
print(1 + (not_after - first_time - 1) // b)


(a, ta) = map(int, input().split())
(b, tb) = map(int, input().split())
s = input()
h = int(s[:2])
m = int(s[3:])
x1 = h * 60 + m
y1 = x1 + ta
ans = 0
for x2 in range(300, 1440, b):
	y2 = x2 + tb
	x = max(x1, x2)
	y = min(y1, y2)
	if x < y:
		ans += 1
print(ans)


(a, ta) = map(int, input().split())
(b, tb) = map(int, input().split())
(hh, mm) = map(int, input().split(':'))
t0 = hh * 60 + mm
print(len([t for t in range(300, 1440, b) if t0 - tb < t < t0 + ta]))


(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)


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)


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)


(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)


def minutes(h):
	return h[0] * 60 + h[1]
(a, ta) = [int(z) for z in input().split()]
(b, tb) = [int(z) for z in input().split()]
depart = [int(z) for z in input().split(':')]
departM = minutes(depart)
Arrival = departM + ta
start = minutes([5, 0])
finish = minutes([23, 59])
period = [300]
c = 1
while True:
	if period[c - 1] + b > finish:
		break
	period.append(b + period[c - 1])
	c += 1
n = 0
for p in period:
	if p + tb <= departM:
		continue
	if p >= Arrival:
		break
	n += 1
print(n)


(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)


import sys
from bisect import bisect_right as rb
from collections import deque
from queue import PriorityQueue
from math import *
input_ = lambda : sys.stdin.readline().strip('\r\n')
ii = lambda : int(input_())
il = lambda : list(map(int, input_().split()))
ilf = lambda : list(map(float, input_().split()))
ip = lambda : input_()
fi = lambda : float(input_())
ap = lambda ab, bc, cd: ab[bc].append(cd)
li = lambda : list(input_())
pr = lambda x: print(x)
prinT = lambda x: print(x)
f = lambda : sys.stdout.flush()
mod = 10 ** 9 + 7
(a, ta) = il()
(b, tb) = il()
s = ip().split(':')
time = 60 * int(s[0]) + int(s[1])
ans = 0
for i in range(5 * 60, 24 * 60, b):
	if i + tb > time and time + ta > i:
		ans += 1
print(ans)


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)))


def main():
	(a, ta) = map(int, input().split())
	(b, tb) = map(int, input().split())
	(h, m) = 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))))
main()


def calc(cur, start, interv):
	if cur < start:
		return 0
	return int((cur - start) / interv + 1)
[a, ta] = list(map(int, input().split()))
[b, tb] = list(map(int, input().split()))
[hh, mm] = list(map(int, input().split(':')))
bs = 5 * 60
be = 23 * 60 + 59
s = hh * 60 + mm
e = hh * 60 + mm + ta
a = calc(max(s - tb, bs - 1), bs, b)
b = calc(min(e - 1, be), bs, b)
print(b - a)


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) = 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()
	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)
run()


import sys
input = sys.stdin.readline

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def lcm(a, b):
	return a * b / gcd(a, b)

def main():
	(a, ta) = map(int, input().split())
	(b, tb) = map(int, input().split())
	(hh, mm) = map(int, input().split(':'))
	secs = hh * 60 + mm - (5 * 60 - 1)
	curr = 0
	i = 0
	ans = 0
	x1 = hh * 60 + mm
	y1 = x1 + ta
	for x2 in range(5 * 60, 24 * 60, b):
		y2 = x2 + tb
		x = max(x1, x2)
		y = min(y1, y2)
		if x < y:
			ans += 1
	print(ans)
	return
main()