Under construction

Still being built. Things may change

Black and White

Time limit5sMemory limit1024 MB

Summary
Count the spanning trees of a wheel-shaped graph for each k, where k is the number of trees' roads controlled by the White gang.
Level

Hard9 of 10

Topics
Graph, Dynamic programming, Combinatorics, Divide and conquer
Solved
No attempts yet

Problem

In a new region, Sam found n+1n + 1 cities connected by two-way roads. Exactly nn of these cities lie on a circle, and one city is the capital located at the center. Number the cities on the circle from 11 to nn in traversal order, and give the capital number n+1n + 1. Each road either connects the capital with a city on the circle, or connects two adjacent cities on the circle. That is, a road connects cities (n+1)(n + 1) and vv, or cities vv and (v mod n+1)(v \bmod n + 1), where v∈[1,n]v \in [1, n].

Each road is controlled by one of two rival gangs: the White gang or the Black gang. Sam wants to choose and secure the minimum number of roads so that every city can reach every other city. In other words, Sam wants to choose a spanning tree of the city graph. Any spanning tree contains exactly nn roads.

To secure a road, Sam has to make a deal with the leader of the gang that controls it. Sam does not yet know which gang will be more willing to negotiate, so for each integer k∈[0,n]k \in [0, n] he asks you to count the number of spanning trees that contain exactly kk roads controlled by the White gang, with the remaining n−kn - k roads controlled by the Black gang. Since the answers can be large, output them modulo 998 244 353998\,244\,353.

Input

The first line contains one integer nn (3≤n≤50 0003 \le n \le 50\,000).

The second line contains a string ss of length nn describing the roads between cities on the circle. If sis_i is -, there is no road between city ii and city (i mod n+1)(i \bmod n + 1). If sis_i is W, the road is controlled by the White gang. If sis_i is B, the road is controlled by the Black gang.

The third line contains a string tt of length nn describing the roads between the capital and the cities on the circle. If tit_i is -, there is no road between the capital and city ii. If tit_i is W, the road is controlled by the White gang. If tit_i is B, the road is controlled by the Black gang.

Output

Print n+1n + 1 integers aka_k. The kk-th of them is the number of spanning trees in which exactly kk roads are controlled by the White gang.

Examples4

  1. Example 1

    Input
    3
    ---
    WBW
    
    Expected output
    0 0 1 0
    
  2. Example 2

    Input
    3
    WWW
    BBB
    
    Expected output
    1 6 9 0
    
  3. Example 3

    Input
    5
    BWB-B
    WB-W-
    
    Expected output
    0 2 6 3 0 0
    
  4. Example 4

    Input
    4
    ----
    ----
    
    Expected output
    0 0 0 0 0