| XAPC 2026 |
|---|
| Finished |
In an orienteering competition, a course is described by a sequence of controls. A competitor must visit the controls in the given order. Each control is denoted by a unique positive integer. The pair of adjacent controls in a sequence is called a leg.
For a mass-start race, course setters often make the race pass in two laps. Different competitors may receive different combinations of parts of these laps, so that they can't simply follow each other. Such variations are made in such way that after both laps every runner completed the same set of legs, but did it in a different order.
You are given two sequences of controls, which describe two laps of one of the runners. It is guaranteed that:
Given two laps for one of the competitors, determine the total number of variations possible for the race. Each variation should respect the given constraints, and union of the laps should have the same set of legs.
Compute the number of possible variations modulo $$$998244353$$$.
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 200000$$$) — the lengths of the two laps.
The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the control points of the first lap.
The third line contains $$$m$$$ integers $$$b_1, b_2, \dots, b_m$$$ ($$$1 \le b_i \le 10^9$$$) — the control points of the second lap.
It is guaranteed that:
Output a single integer — the number of valid variations modulo $$$998244353$$$.
5 61 2 4 5 81 3 4 6 7 8
4
2 36 76 1 7
2
Possible variations for the sample test are:
| Name |
|---|


