You are given a rooted tree of $$$2^n - 1$$$ vertices. Every vertex of this tree has either $$$0$$$ children, or $$$2$$$ children. All leaves of this tree have the same distance from the root, and for every non-leaf vertex, one of its children is the left one, and the other child is the right one. Formally, you are given a perfect binary tree.
The vertices of the tree are numbered in the following order:
Every vertex of the tree has a letter written on it, either A or B. Let's define the character on the vertex $$$x$$$ as $$$s_x$$$.
Let the preorder string of some vertex $$$x$$$ be defined in the following way:
The preorder string of the tree is the preorder string of its root.
Now, for the problem itself...
You have to calculate the number of different strings that can be obtained as the preorder string of the given tree, if you are allowed to perform the following operation any number of times before constructing the preorder string of the tree:
The first line contains one integer $$$n$$$ ($$$2 \le n \le 18$$$).
The second line contains a sequence of $$$2^n-1$$$ characters $$$s_1, s_2, \dots, s_{2^n-1}$$$. Each character is either A or B. The characters are not separated by spaces or anything else.
Print one integer — the number of different strings that can be obtained as the preorder string of the given tree, if you can apply any number of operations described in the statement. Since it can be very large, print it modulo $$$998244353$$$.
4 BAAAAAAAABBABAB
16
2 BAA
1
2 ABA
2
2 AAB
2
2 AAA
1
Name |
---|