#AGC055D. [AGC055D] ABC Ultimatum

[AGC055D] ABC Ultimatum

Score : 12001200 points

Problem Statement

Let's call a string TT of length 3N3N, containing exactly NN letters A, NN letters B, and NN letters C, good, if it can be split into NN (not necessarily contiguous) subsequences of length 33, so that the letters from each subsequence form ABC, BCA, or CAB.

You are given a string SS of length 3N3N, consisting of characters A, B, C, and ?. Count the number of ways to replace each ? with one of A, B, and C, so that the resulting string is good. As this number can be very large, output it modulo 998244353998244353.

Constraints

  • 1N151\le N \le 15.
  • SS is a string of length 3N3N, consisting of A, B, C, and ?.

Input

Input is given from Standard Input in the following format:

NN

SS

Output

Print the answer modulo 998244353998244353.

1
???
3

There are 33 good strings you can obtain: ABC, BCA, and CAB.

2
AA????
2

There are 22 good strings you can obtain: AABBCC and AABCBC.

3
?A?A?A?A?
0

It's impossible to obtain a good string, as there are already 44 A's.

9
?????????A??B??C???????????
331653164