P29961 [洛谷] [ICPC2022 Xi'an R] Hotel
普及+
题目描述

Problem Description

You are doing volunteer work for a programming competition in an ancient hotel. Unfortunately, the hotel provides no phone signal or tap water since it can be dated back to the Qin Dynasty, and you have to assign the contestants to the hotel rooms manually instead of using the internet apps. Fortunately, the hotel has sufficient rooms, and you have taken a computer that lets you do some computation locally.

There are $n$ teams, each with exactly $3$ contestants. There are $2$ types of rooms in the hotel, the single room and double room, which can accommodate at most $1$ and $2$ contestants, respectively. To avoid embarrassing contestants, if two contestants are assigned to a double room, they must come from the same team and have the same gender.

The cost of each room of the same type is the same, but different types may have different costs. Your program needs to calculate the minimum price the host has to pay. The teams are waiting in the registration hall now, and the competition finance officer relies on you to save costs and make a fortune by the residual value. Be quick, or the finance officer will sue you for violating his reputation!

Input Format

The first line of input contains three integers $n$, $c_1$ and $c_2$ ($1 \leq n, c_1, c_2 \leq 1\,000$), denoting the number of teams, the cost of a single room and a double room respectively.

In the following $n$ lines, each line contains a string $S$ with exactly $3$ uppercase English letters. The letters in a string denote the genders of the contestants in one team and will be represented by $\texttt{A}$ to $\texttt{Z}$, respecting the diversity of human beings.

Output Format

The output should contain a single integer, denoting the minimum cost of hotel allocation for contestants.

Sample Input and Output

Sample Input #1

3 1 3
MMM
MMM
FFF

Sample Output #1

9

Sample Input #2

3 3 1
ABC
DEF
GHI

Sample Output #2

9

Sample Input #3

10 438 438
WWW
SOU
PUN
ETC
OME
CFI
NAL
GOO
DHO
TEL

Sample Output #3

12264

Notes

Source: The 2022 ICPC Asia Xi'an Regional Contest Problem F.

Author: fstqwq.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 1 3 MMM MMM FFF
样例输出
9