{"raw_statement":[{"iden":"problem statement","content":"You are given a positive integer $N$, a string $S$ of length $N$ consisting of `#` and `.`, and a length-$N$ sequence of positive integers $R=(R_1,R_2,\\dots,R_N)$.\nThere is a forest with $N$ sections arranged in a single horizontal line. The sections are numbered $1,2,\\dots,N$ from left to right.\nSome sections have trees. Specifically, section $i$ has a tree if and only if the $i$\\-th character of $S$ is `#`. It is guaranteed that the following operation can be performed at least once.\nYou can repeat the following operation as many times as you like:\n\n*   Choose two sections without trees. Let sections $i$ and $j$ (where $i < j$) be the chosen sections from left to right. Then, all trees between sections $i$ and $j$ are removed, and you gain a reward of $R_i+R_j$.\n\nHere, you cannot perform an operation that removes no trees.\nFind the number of ways to perform the **first** operation to achieve the maximum possible total reward. Two ways are considered distinct if and only if there exists a section chosen in one way but not in the other."},{"iden":"constraints","content":"*   $3\\leq N\\leq 2\\times 10^5$\n*   The length of $S$ is $N$, and each character is `#` or `.`.\n*   $1\\leq R_i\\leq 10^9$ $(1\\leq i\\leq N)$\n*   The operation can be performed at least once.\n*   $N$ and $R_i$ are integers."},{"iden":"input","content":"The input is given from Standard Input in the following format:\n\n$N$\n$S$\n$R_1$ $R_2$ $\\dots$ $R_N$"},{"iden":"sample input 1","content":"8\n...###..\n20 25 1 1 30 2 1 1"},{"iden":"sample output 1","content":"2\n\nThere are six ways to perform the first operation, as follows:\n\n*   Choose sections $1$ and $7$. The trees at sections $4,5,6$ are removed, and you gain a reward of $21$.\n*   Choose sections $1$ and $8$. The trees at sections $4,5,6$ are removed, and you gain a reward of $21$.\n*   Choose sections $2$ and $7$. The trees at sections $4,5,6$ are removed, and you gain a reward of $26$.\n*   Choose sections $2$ and $8$. The trees at sections $4,5,6$ are removed, and you gain a reward of $26$.\n*   Choose sections $3$ and $7$. The trees at sections $4,5,6$ are removed, and you gain a reward of $2$.\n*   Choose sections $3$ and $8$. The trees at sections $4,5,6$ are removed, and you gain a reward of $2$.\n\nNo matter which operation is performed, all trees are removed, so a second operation cannot be performed. The maximum possible total reward is $26$."},{"iden":"sample input 2","content":"5\n.#.#.\n211 182 192 182 211"},{"iden":"sample output 2","content":"2\n\nThe maximum possible total reward is $825$.\nNote that the goal is not to maximize the reward obtained in the first operation. If you choose sections $1$ and $5$ first, you can gain a reward of $422$, but no operation can be performed afterwards, and the total reward cannot reach $825$."},{"iden":"sample input 3","content":"11\n#..#.##.#..\n192 192 192 211 182 192 182 192 182 211 182"},{"iden":"sample output 3","content":"3"}],"translated_statement":null,"sample_group":[],"show_order":["default"],"formal_statement":null,"simple_statement":null,"has_page_source":true}