William wants to exploit his new independent house for setting up a brand-new server farm, and start earning money immediately! Since his budget is pretty limited, he started this ambitious project by collecting obsolete PCs from the recycling bin for electronic waste. He gathered this way fully functional computers with diverse capabilities. In particular, the -th computer has computing power of nanoFLOPS and is powered via a plug of type , which can be either:
-
L10
, if the plug conforms to the Type L/10amp standard; -
L16
, if the plug conforms to the Type L/16amp standard.
He also found a very long power strip consisting of sockets, where the -th of them can be of three different types :
- =
L10
, if the socket is designed for Type L/10amp plugs; - =
L16
, if the socket is designed for Type L/16amp plugs; - =
bipasso
, if the socket is designed to accommodate both (otherwise incompatible) types.
Task
Help William find the assignment of plugs into compatible sockets which allows for the highest total amount of nanoFLOPS!
Input data
The first line contains two integers , . The second line contains integers . The third line contains space-separated plug types . The fourth line contains space-separated socket types .
Output data
You need to write a single line with an integer: the maximum amount of nanoFLOPS that William can produce by connecting their PCs into compatible plugs.
Constraints and clarifications
# | Points | Constraints |
---|---|---|
1 | 5 | Examples. |
2 | 10 | is equal for all PCs. |
3 | 25 | There are no bipasso sockets. |
4 | 30 | |
5 | 30 | No additional constraints. |
Example 1
stdin
7 5
120 310 570 250 740 460 880
L10 L16 L10 L10 L16 L16 L16
bipasso L10 L16 L10 bipasso
stdout
2900
Explanation
William can arrange in the power socket the PCs corresponding to the following amount of nanoFLOPS (in order): .
Example 2
stdin
10 7
690 950 300 470 520 380 750 990 300 440
L10 L16 L10 L10 L16 L10 L10 L10 L16 L10
L16 L16 bipasso bipasso L16 L10 L16
stdout
4200
Explanation
A possible arrangement is the following: .