f = open('mobil.in.txt')
[n] = map(int, f.readline().split())
free_minutes, free_sms, price_minute, price_sms = map(float, f.readline().split())
free_seconds = free_minutes * 60
sms = 0
all_calls_seconds = 0

for i in range(0, n):
    s = f.readline().split()[2]
    if s == 'SMS':
        sms += 1
    else:
        call_minutes, call_seconds = map(int, s.split(':'))
        all_calls_seconds += call_minutes * 60 + call_seconds
f.close()

total_sms_cost = 0
if sms > free_sms:
    total_sms_cost = (sms - free_sms) * price_sms

total_calls_cost = 0
if all_calls_seconds > free_seconds:
    total_calls_cost = ((all_calls_seconds - free_seconds) / 60) * price_minute

f = open('mobil.out.txt', 'w')
f.write(str(total_calls_cost+total_sms_cost))
f.close()
