#arc175b. B - Parenthesis Arrangement

B - Parenthesis Arrangement

Score: 400400 points

问题陈述

给定一个长度为 2N2N 的字符串 SS,由字符 () 组成。设 SiS_i 表示 SS 中从左数第 ii 个字符。

你可以执行以下两种操作,每种操作可以执行零次或多次,且执行顺序任意:

  • 选择一对整数 (i,j)(i,j),使得 1i<j2N1\leq i < j \leq 2N。交换 SiS_iSjS_j。此操作的成本为 AA

  • 选择一个整数 ii,使得 1i2N1\leq i \leq 2N。将 SiS_i 替换为 ()。此操作的成本为 BB

你的目标是使 SS 成为一个正确的括号序列。找到实现此目标所需的最小总成本。可以证明,目标总是可以通过有限次操作实现。

什么是正确的括号序列?满足以下任一条件的字符串即为正确的括号序列:

  • 它是一个空字符串。
  • 它是由按照 (, AA, ) 顺序连接而成的,其中 AA 是一个正确的括号序列。
  • 它是由按照 AABB 顺序连接而成的,其中 AABB 都是正确的括号序列。

以上为大语言模型 kimi 翻译,仅供参考。

Problem Statement

You are given a string SS of length 2N2N consisting of the characters ( and ). Let SiS_i denote the ii-th character from the left of SS.

You can perform the following two types of operations zero or more times in any order:

  • Choose a pair of integers (i,j)(i,j) such that 1i<j2N1\leq i < j \leq 2N. Swap SiS_i and SjS_j. The cost of this operation is AA.

  • Choose an integer ii such that 1i2N1\leq i \leq 2N. Replace SiS_i with ( or ). The cost of this operation is BB.

Your goal is to make SS a correct parenthesis sequence. Find the minimum total cost required to achieve this goal. It can be proved that the goal can always be achieved with a finite number of operations.

What is a correct parenthesis sequence? A correct parenthesis sequence is a string that satisfies any of the following conditions:

  • It is an empty string.
  • It is formed by concatenating (, AA, ) in this order where AA is a correct parenthesis sequence.
  • It is formed by concatenating AA and BB in this order where AA and BB are correct parenthesis sequences.

Constraints

  • All input values are integers.
  • 1N5×1051 \leq N \leq 5\times 10^5
  • 1A,B1091\leq A,B\leq 10^9
  • SS is a string of length 2N2N consisting of the characters ( and ).

Input

The Input is given from Standard Input in the following format:

NN AA BB

SS

Output

Print the answer in a single line.

Sample Input 1

3 3 2
)))(()

Sample Output 1

5

Here is one way to operate:

  • Swap S3S_3 and S4S_4. SS becomes ))()(). The cost is 33.
  • Replace S1S_1 with (. SS becomes ()()(), which is a correct parentheses sequence. The cost is 22.

In this case, we have made SS a correct bracket sequence for a total cost of 55. There is no way to make SS a correct bracket sequence for less than 55.

Sample Input 2

1 175 1000000000
()

Sample Output 2

0

The given SS is already a correct bracket sequence, so no operation is needed.

Sample Input 3

7 2622 26092458
))()((((()()((

Sample Output 3

52187538