This page is still under construction.

Parts of this page are still being built. What you see may change.

Taking Stones 2

Time limit2sMemory limit1024 MB

Summary
Sum, over all N! removal orders of a colored row of weighted stones, the weights of stones removed while both current neighbors have the opposite color.
Level

Medium7 of 10

Topics
Combinatorics, Math, Dynamic programming, Implementation
Solved
No attempts yet

Problem

NN stones are lined up in a row. Each stone is either white or black.

Number the stones from the left as stone 1, stone 2, ..., stone NN. The weight of stone ii is AiA_i.

You will repeatedly pick one of the lined-up stones and take it, for a total of NN times, until every stone is gone.

When you take a stone, if that stone is neither the leftmost nor the rightmost among the stones currently lined up, and both stones adjacent to the stone you took have a color different from the stone you took, you gain a score equal to the weight of the stone you took.

There are N!N! different ways to take the stones, depending on the order. Find the sum of the scores over all N!N! possible ways.

Input

The first line gives a positive integer NN. (1≤N≤2×1051 \le N \le 2 \times 10^5)

The second line gives a string SS of length NN consisting only of B and W.

The ii-th character SiS_i of SS is the color of the ii-th stone from the left. B means the stone is black and W means the stone is white.

The third line gives NN integers A1,A2,⋯ ,ANA_1, A_2, \cdots, A_N. (1≤Ai≤1091 \le A_i \le 10^9)

AiA_i is the weight of stone ii.

Output

On the first line, print the sum of the scores over all N!N! ways, modulo 998 244 353998\ 244\ 353.

Hint

There are 8 ways that gain a score by taking the second stone from the left, and 8 ways that gain a score by taking the third stone. So the total score is 8×4+8×5=728 \times 4 + 8 \times 5 = 72 points.

Examples1

  1. Example 1

    Input
    4
    WBWB
    6 4 5 3
    
    Expected output
    72