시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
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

1 2
1
3

예제 출력 1

2

예제 입력 2

2 4
1 1
1 2

예제 출력 2

4

예제 입력 3

1 2
1
1

예제 출력 3

3

예제 입력 4

3 10
1 1 1
2 1 3

예제 출력 4

149