|시간 제한||메모리 제한||제출||정답||맞은 사람||정답 비율|
|1 초||256 MB||0||0||0||0.000%|
Rikka has $n$ disks of distinct sizes on three rods. Each move consists of taking the upper disk from one of the stacks and placing it on top of another stack. No disk can be placed on top of a smaller disk.
Given the configuration of disks $S$ and $T$, find the number of ways can Rikka transform from $S$ to $T$ in no more than $m$ moves.
As the number of ways can be very large, find it modulo $998\,244\,353$.
Two sequences of moves are different if they have different lengths, or the configurations are different after some moves.
The first line contains two integers $n$ and $m$ ($1 \leq n \leq 100$, $0 \leq m \leq 100$).
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$, the configuration $S$ ($1 \le a_i \le 3$). These mean that the $i$-th smallest disk is on rod $a_i$.
The third line contains $n$ integers $b_1, b_2, \ldots, b_n$, the configuration $T$ given in the same format ($1 \le b_i \le 3$).
Print one integer: the number of ways modulo $998\,244\,353$.
1 2 1 3
2 4 1 1 1 2
1 2 1 1
3 10 1 1 1 2 1 3