Bessie gives FJ the ex
Note that the answer to this problem can be too large to fit into a 32-bit integer, so you probably want to use 64-bit integers (e.g., "long long"s in C or C++).
SAMPLE INPUT:
10
B 2
E 5
S 7
I 10
O 16
M 19
B 3
G 1
I 9
M 2
SAMPLE OUTPUT:
2
The two possible assignments are
(B,E,S,I,G,O,M) = (2, 5, 7, 9, 1, 16, 19) -> 51,765
= (2, 5, 7, 9, 1, 16, 2 ) -> 34,510