Little W and Little P decided to send letters to each other regarding the most important events during a day. There are $$$n$$$ events during a day: at time moment $$$t_i$$$ something happens to the person $$$p_i$$$ ($$$p_i$$$ is either W or P, denoting Little W and Little P, respectively), so he needs to immediately send a letter to the other person. They can send a letter using one of the two ways:
Help the friends determine the minimum possible total cost of sending all letters.
The first line contains three integers $$$n, c, d$$$ ($$$1 \leq n \leq 10^5$$$, $$$1 \leq c \leq 10^2$$$, $$$1 \leq d \leq 10^8$$$) — the number of letters, the cost of storing a letter for one time unit at Wise R's den and the cost of delivering a letter via Friendly O.
The next $$$n$$$ describe the events. The $$$i$$$-th of them contains an integer $$$t_i$$$ and a character $$$p_i$$$ ($$$0 \leq t_i \leq 10^6$$$, $$$p_i$$$ is either W or P) — the time the $$$i$$$-th event happens and the person the event happens to.
The last line contains a single integer $$$t_{n + 1}$$$ ($$$0 \leq t_{n+1} \leq 10^6$$$) — the time when everybody comes to Wise R for a tea and takes all remaining letters.
It is guaranteed that $$$t_i < t_{i + 1}$$$ for all $$$i$$$ from $$$1$$$ to $$$n$$$.
Print a single integer — the minimum possible cost of delivery of all letters.
5 1 4 0 P 1 W 3 P 5 P 8 P 10
16
10 10 94 17 W 20 W 28 W 48 W 51 P 52 W 56 W 62 P 75 P 78 P 87
916
One of optimal solutions in the first example:
The total cost of delivery is thus $$$1 + 4 + 4 + 5 + 2 = 16$$$ acorns.
Name |
---|