atcoder#ARC132F. [ARC132F] Takahashi The Strongest

[ARC132F] Takahashi The Strongest

Score : 900900 points

Problem Statement

Takahashi, Aoki, and Snuke will play a game with kk rounds of rock-paper-scissors.

Let us call a string of length kk consisting of P, R, S a strategy. The game proceeds as follows.

  • Each participant chooses a strategy.
  • Play kk rounds of rock-paper-scissors. In the ii-th round, each participant plays the hand corresponding to the ii-th character in the chosen strategy: paper for P, rock for R, and scissors for S.

Aoki will randomly choose one strategy from the nn strategies a1,,ana_1,\dots,a_n with equal probability. Snuke will randomly choose one strategy from the mm strategies b1,,bmb_1,\dots,b_m with equal probability. Their choices are independent of each other.

Takahashi will be happy if he is the only winner in at least one of the kk rounds. For each of the 3k3^k possible strategies, find the probability that he becomes happy when choosing that strategy and print it multiplied by nmnm as an integer (it can be proved that this value is an integer).

Notes

In the game of rock-paper-scissors with three players, the following three scenarios make Takahashi the only winner.

  • Takahashi plays paper, while Aoki and Snuke play rock.
  • Takahashi plays rock, while Aoki and Snuke play scissors.
  • Takahashi plays scissors, while Aoki and Snuke play paper.

Constraints

  • 1k121 \leq k \leq 12
  • 1n,m3k1 \leq n,m \leq 3^k
  • Each of aia_i and bib_i is a string of length kk consisting of P, R, S.
  • a1,,ana_1,\dots,a_n are distinct.
  • b1,,bmb_1,\dots,b_m are distinct.

Input

Input is given from Standard Input in the following format:

kk nn mm

a1a_1

\vdots

ana_n

b1b_1

\vdots

bmb_m

Output

Print 3k3^k values. The ii-th value should be the answer when Takahashi chooses the ii-th lexicographically smallest possible strategy.

2 1 3
RS
RP
RR
RS
3
3
3
0
1
0
0
1
0

Aoki chooses the strategy RS.

If Snuke chooses the strategy RP, the strategies that can meet Takahashi's objective are PP, PR, PS.

If Snuke chooses the strategy RR, the strategies that can meet Takahashi's objective are PP, PR, PS.

If Snuke chooses the strategy RS, the strategies that can meet Takahashi's objective are PP, PR, PS, RR, SR.

Therefore, the probabilities when Takahashi chooses PP, PR, PS, RP, RR, RS, SP, SR, SS are 11, 11, 11, 00, 13\frac 13, 00, 00, 13\frac 13, 00, respectively. Print them multiplied by 33.

3 5 4
RRP
SSS
RSR
PPP
RSS
PPS
SRP
SSP
RRS
4
7
7
6
9
10
4
7
8
4
8
7
4
8
8
3
7
7
3
7
6
4
8
8
1
5
5