import math
def solution(fees, records):
car = {} ; times = {} ; money = {}
for re in records:
time, carnum, inout = re.split()
if inout == 'IN':
car[carnum] = time
if carnum not in money:
times[carnum]=0
money[carnum]=0
elif inout == 'OUT':
intime = car[carnum]
during = (int(time[:2])-int(intime[:2]))*60 + (int(time[3:])-int(intime[3:])) #주차시간
times[carnum] += during
del car[carnum]
time = "23:59"
for carnum in car.keys():
intime = car[carnum]
during = (int(time[:2])-int(intime[:2]))*60 + (int(time[3:])-int(intime[3:])) #주차시간
times[carnum] += during
# return times
for carnum in times.keys():
during = times[carnum]
if during <= fees[0]:
money[carnum] += fees[1]
else:
pay = fees[1] + (math.ceil((during-fees[0])/fees[2])*fees[3])
money[carnum] += pay
answer = []
keyss = list(money.keys())
keyss.sort()
for i in keyss:
answer.append(money[i])
return answer