A string $$$s$$$ of length $$$n$$$, consisting of lowercase letters of the English alphabet, is given.
You must choose some number $$$k$$$ between $$$0$$$ and $$$n$$$. Then, you select $$$k$$$ characters of $$$s$$$ and permute them however you want. In this process, the positions of the other $$$n-k$$$ characters remain unchanged. You have to perform this operation exactly once.
For example, if $$$s=\texttt{"andrea"}$$$, you can choose the $$$k=4$$$ characters $$$\texttt{"a_d_ea"}$$$ and permute them into $$$\texttt{"d_e_aa"}$$$ so that after the operation the string becomes $$$\texttt{"dneraa"}$$$.
Determine the minimum $$$k$$$ so that it is possible to sort $$$s$$$ alphabetically (that is, after the operation its characters appear in alphabetical order).
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Then $$$t$$$ test cases follow.
The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 40$$$) — the length of the string.
The second line of each test case contains the string $$$s$$$. It is guaranteed that $$$s$$$ contains only lowercase letters of the English alphabet.
For each test case, output the minimum $$$k$$$ that allows you to obtain a string sorted alphabetically, through the operation described above.
4 3 lol 10 codeforces 5 aaaaa 4 dcba
2 6 0 4
In the first test case, we can choose the $$$k=2$$$ characters $$$\texttt{"_ol"}$$$ and rearrange them as $$$\texttt{"_lo"}$$$ (so the resulting string is $$$\texttt{"llo"}$$$). It is not possible to sort the string choosing strictly less than $$$2$$$ characters.
In the second test case, one possible way to sort $$$s$$$ is to consider the $$$k=6$$$ characters $$$\texttt{"_o__force_"}$$$ and rearrange them as $$$\texttt{"_c__efoor_"}$$$ (so the resulting string is $$$\texttt{"ccdeefoors"}$$$). One can show that it is not possible to sort the string choosing strictly less than $$$6$$$ characters.
In the third test case, string $$$s$$$ is already sorted (so we can choose $$$k=0$$$ characters).
In the fourth test case, we can choose all $$$k=4$$$ characters $$$\texttt{"dcba"}$$$ and reverse the whole string (so the resulting string is $$$\texttt{"abcd"}$$$).
The Olympic Games have just started and Federico is eager to watch the marathon race.
There will be $$$n$$$ athletes, numbered from $$$1$$$ to $$$n$$$, competing in the marathon, and all of them have taken part in $$$5$$$ important marathons, numbered from $$$1$$$ to $$$5$$$, in the past. For each $$$1\le i\le n$$$ and $$$1\le j\le 5$$$, Federico remembers that athlete $$$i$$$ ranked $$$r_{i,j}$$$-th in marathon $$$j$$$ (e.g., $$$r_{2,4}=3$$$ means that athlete $$$2$$$ was third in marathon $$$4$$$).
Federico considers athlete $$$x$$$ superior to athlete $$$y$$$ if athlete $$$x$$$ ranked better than athlete $$$y$$$ in at least $$$3$$$ past marathons, i.e., $$$r_{x,j} \lt r_{y,j}$$$ for at least $$$3$$$ distinct values of $$$j$$$.
Federico believes that an athlete is likely to get the gold medal at the Olympics if he is superior to all other athletes.
Find any athlete who is likely to get the gold medal (that is, an athlete who is superior to all other athletes), or determine that there is no such athlete.
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Then $$$t$$$ test cases follow.
The first line of each test case contains a single integer $$$n$$$ ($$$1\le n\le 50\,000$$$) — the number of athletes.
Then $$$n$$$ lines follow, each describing the ranking positions of one athlete.
The $$$i$$$-th of these lines contains the $$$5$$$ integers $$$r_{i,1},\,r_{i,2},\,r_{i,3},\,r_{i,4},\, r_{i,5}$$$ ($$$1\le r_{i,j}\le 50\,000$$$) — the ranking positions of athlete $$$i$$$ in the past $$$5$$$ marathons. It is guaranteed that, in each of the $$$5$$$ past marathons, the $$$n$$$ athletes have distinct ranking positions, i.e., for each $$$1\le j\le 5$$$, the $$$n$$$ values $$$r_{1,j},\, r_{2, j},\, \dots,\, r_{n, j}$$$ are distinct.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$50\,000$$$.
For each test case, print a single integer — the number of an athlete who is likely to get the gold medal (that is, an athlete who is superior to all other athletes). If there are no such athletes, print $$$-1$$$. If there is more than such one athlete, print any of them.
4 1 50000 1 50000 50000 50000 3 10 10 20 30 30 20 20 30 10 10 30 30 10 20 20 3 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 6 9 5 3 7 1 7 4 1 6 8 5 6 7 3 2 6 7 8 8 6 4 2 2 4 5 8 3 6 9 4
1 -1 1 5
Explanation of the first test case: There is only one athlete, therefore he is superior to everyone else (since there is no one else), and thus he is likely to get the gold medal.
Explanation of the second test case: There are $$$n=3$$$ athletes.
Explanation of the third test case: There are $$$n=3$$$ athletes.
Explanation of the fourth test case: There are $$$n=6$$$ athletes.
On a circle lie $$$2n$$$ distinct points, with the following property: however you choose $$$3$$$ chords that connect $$$3$$$ disjoint pairs of points, no point strictly inside the circle belongs to all $$$3$$$ chords. The points are numbered $$$1, \, 2, \, \dots, \, 2n$$$ in clockwise order.
Initially, $$$k$$$ chords connect $$$k$$$ pairs of points, in such a way that all the $$$2k$$$ endpoints of these chords are distinct.
You want to draw $$$n - k$$$ additional chords that connect the remaining $$$2(n - k)$$$ points (each point must be an endpoint of exactly one chord).
In the end, let $$$x$$$ be the total number of intersections among all $$$n$$$ chords. Compute the maximum value that $$$x$$$ can attain if you choose the $$$n - k$$$ chords optimally.
Note that the exact position of the $$$2n$$$ points is not relevant, as long as the property stated in the first paragraph holds.
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow.
The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 100$$$, $$$0 \le k \le n$$$) — half the number of points and the number of chords initially drawn.
Then $$$k$$$ lines follow. The $$$i$$$-th of them contains two integers $$$x_i$$$ and $$$y_i$$$ ($$$1 \le x_i, \, y_i \le 2n$$$, $$$x_i \ne y_i$$$) — the endpoints of the $$$i$$$-th chord. It is guaranteed that the $$$2k$$$ numbers $$$x_1, \, y_1, \, x_2, \, y_2, \, \dots, \, x_k, \, y_k$$$ are all distinct.
For each test case, output the maximum number of intersections that can be obtained by drawing $$$n - k$$$ additional chords.
4 4 2 8 2 1 5 1 1 2 1 2 0 10 6 14 6 2 20 9 10 13 18 15 12 11 7
4 0 1 14
In the first test case, there are three ways to draw the $$$2$$$ additional chords, shown below (black chords are the ones initially drawn, while red chords are the new ones):
We see that the third way gives the maximum number of intersections, namely $$$4$$$.
In the second test case, there are no more chords to draw. Of course, with only one chord present there are no intersections.
In the third test case, we can make at most one intersection by drawing chords $$$1-3$$$ and $$$2-4$$$, as shown below:
You are given a sequence of $$$n$$$ integers $$$a_1, \, a_2, \, \dots, \, a_n$$$.
Does there exist a sequence of $$$n$$$ integers $$$b_1, \, b_2, \, \dots, \, b_n$$$ such that the following property holds?
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 20$$$) — the number of test cases. Then $$$t$$$ test cases follow.
The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 10$$$).
The second line of each test case contains the $$$n$$$ integers $$$a_1, \, \dots, \, a_n$$$ ($$$-10^5 \le a_i \le 10^5$$$).
For each test case, output a line containing YES if a sequence $$$b_1, \, \dots, \, b_n$$$ satisfying the required property exists, and NO otherwise.
5 5 4 -7 -1 5 10 1 0 3 1 10 100 4 -3 2 10 2 9 25 -171 250 174 152 242 100 -205 -258
YES YES NO YES YES
In the first test case, the sequence $$$b = [-9, \, 2, \, 1, \, 3, \, -2]$$$ satisfies the property. Indeed, the following holds:
In the second test case, it is sufficient to choose $$$b = [0]$$$, since $$$a_1 = 0 = 0 - 0 = b_1 - b_1$$$.
In the third test case, it is possible to show that no sequence $$$b$$$ of length $$$3$$$ satisfies the property.
The numbers $$$1, \, 2, \, \dots, \, n \cdot k$$$ are colored with $$$n$$$ colors. These colors are indexed by $$$1, \, 2, \, \dots, \, n$$$. For each $$$1 \le i \le n$$$, there are exactly $$$k$$$ numbers colored with color $$$i$$$.
Let $$$[a, \, b]$$$ denote the interval of integers between $$$a$$$ and $$$b$$$ inclusive, that is, the set $$$\{a, \, a + 1, \, \dots, \, b\}$$$. You must choose $$$n$$$ intervals $$$[a_1, \, b_1], \, [a_2, \, b_2], \, \dots, [a_n, \, b_n]$$$ such that:
One can show that such a family of intervals always exists under the given constraints.
The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 100$$$, $$$2 \le k \le 100$$$) — the number of colors and the number of occurrences of each color.
The second line contains $$$n \cdot k$$$ integers $$$c_1, \, c_2, \, \dots, \, c_{nk}$$$ ($$$1 \le c_j \le n$$$), where $$$c_j$$$ is the color of number $$$j$$$. It is guaranteed that, for each $$$1 \le i \le n$$$, it holds $$$c_j = i$$$ for exactly $$$k$$$ distinct indices $$$j$$$.
Output $$$n$$$ lines. The $$$i$$$-th line should contain the two integers $$$a_i$$$ and $$$b_i$$$.
If there are multiple valid choices of the intervals, output any.
4 3 2 4 3 1 1 4 2 3 2 1 3 4
4 5 1 7 8 11 6 12
1 2 1 1
1 2
3 3 3 1 2 3 2 1 2 1 3
6 8 3 7 1 4
2 3 2 1 1 1 2 2
2 3 5 6
In the first sample, each number can be contained in at most $$$\left\lceil \frac{4}{3 - 1} \right\rceil = 2$$$ intervals. The output is described by the following picture:
In the second sample, the only interval to be chosen is forced to be $$$[1, \, 2]$$$, and each number is indeed contained in at most $$$\left\lceil \frac{1}{2 - 1} \right\rceil = 1$$$ interval.
In the third sample, each number can be contained in at most $$$\left\lceil \frac{3}{3 - 1} \right\rceil = 2$$$ intervals. The output is described by the following picture:
An ant moves on the real line with constant speed of $$$1$$$ unit per second. It starts at $$$0$$$ and always moves to the right (so its position increases by $$$1$$$ each second).
There are $$$n$$$ portals, the $$$i$$$-th of which is located at position $$$x_i$$$ and teleports to position $$$y_i \lt x_i$$$. Each portal can be either active or inactive. The initial state of the $$$i$$$-th portal is determined by $$$s_i$$$: if $$$s_i=0$$$ then the $$$i$$$-th portal is initially inactive, if $$$s_i=1$$$ then the $$$i$$$-th portal is initially active. When the ant travels through a portal (i.e., when its position coincides with the position of a portal):
How long (from the instant it starts moving) does it take for the ant to reach the position $$$x_n + 1$$$? It can be shown that this happens in a finite amount of time. Since the answer may be very large, compute it modulo $$$998\,244\,353$$$.
The first line contains the integer $$$n$$$ ($$$1\le n\le 2\cdot 10^5$$$) — the number of portals.
The $$$i$$$-th of the next $$$n$$$ lines contains three integers $$$x_i$$$, $$$y_i$$$ and $$$s_i$$$ ($$$1\le y_i \lt x_i\le 10^9$$$, $$$s_i\in\{0,1\}$$$) — the position of the $$$i$$$-th portal, the position where the ant is teleported when it travels through the $$$i$$$-th portal (if it is active), and the initial state of the $$$i$$$-th portal.
The positions of the portals are strictly increasing, that is $$$x_1 \lt x_2 \lt \cdots \lt x_n$$$. It is guaranteed that the $$$2n$$$ integers $$$x_1, \, x_2, \, \dots, \, x_n, \, y_1, \, y_2, \, \dots, \, y_n$$$ are all distinct.
Output the amount of time elapsed, in seconds, from the instant the ant starts moving to the instant it reaches the position $$$x_n+1$$$. Since the answer may be very large, output it modulo $$$998\,244\,353$$$.
4 3 2 0 6 5 1 7 4 0 8 1 1
23
1 454971987 406874902 1
503069073
5 243385510 42245605 0 644426565 574769163 0 708622105 208990040 0 786625660 616437691 0 899754846 382774619 0
899754847
5 200000000 100000000 1 600000000 400000000 0 800000000 300000000 0 900000000 700000000 1 1000000000 500000000 0
3511295
Explanation of the first sample: The ant moves as follows (a curvy arrow denotes a teleporting, a straight arrow denotes normal movement with speed $$$1$$$ and the time spent during the movement is written above the arrow). $$$$$$ 0 \stackrel{6}{\longrightarrow} 6 \leadsto 5 \stackrel{3}{\longrightarrow} 8 \leadsto 1 \stackrel{2}{\longrightarrow} 3 \leadsto 2 \stackrel{4}{\longrightarrow} 6 \leadsto 5 \stackrel{2}{\longrightarrow} 7 \leadsto 4 \stackrel{2}{\longrightarrow} 6 \leadsto 5 \stackrel{4}{\longrightarrow} 9 $$$$$$ Notice that the total time is $$$6+3+2+4+2+2+4=23$$$.
Explanation of the second sample: The ant moves as follows (a curvy arrow denotes a teleporting, a straight arrow denotes normal movement with speed $$$1$$$ and the time spent during the movement is written above the arrow). $$$$$$ 0 \stackrel{454971987}{\longrightarrow} 454971987 \leadsto 406874902 \stackrel{48097086}{\longrightarrow} 454971988 $$$$$$ Notice that the total time is $$$454971987+48097086=503069073$$$.
Explanation of the third sample: Since all portals are initially off, the ant will not be teleported and will go straight from $$$0$$$ to $$$x_n+1=899754846+1=899754847$$$.
Andrea has come up with what he believes to be a novel sorting algorithm for arrays of length $$$n$$$. The algorithm works as follows.
Initially there is an array of $$$n$$$ integers $$$a_1,\, a_2,\, \dots,\, a_n$$$. Then, $$$k$$$ steps are executed.
For each $$$1\le i\le k$$$, during the $$$i$$$-th step the subsequence of the array $$$a$$$ with indexes $$$j_{i,1} \lt j_{i,2} \lt \dots \lt j_{i, q_i}$$$ is sorted, without changing the values with the remaining indexes. So, the subsequence $$$a_{j_{i,1}},\, a_{j_{i,2}},\, \dots,\, a_{j_{i,q_i}}$$$ is sorted and all other elements of $$$a$$$ are left untouched.
Andrea, being eager to share his discovery with the academic community, sent a short paper describing his algorithm to the journal "Annals of Sorting Algorithms" and you are the referee of the paper (that is, the person who must judge the correctness of the paper). You must decide whether Andrea's algorithm is correct, that is, if it sorts any array $$$a$$$ of $$$n$$$ integers.
The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1\le n\le 40$$$, $$$0\le k\le 10$$$) — the length of the arrays handled by Andrea's algorithm and the number of steps of Andrea's algorithm.
Then $$$k$$$ lines follow, each describing the subsequence considered in a step of Andrea's algorithm.
The $$$i$$$-th of these lines contains the integer $$$q_i$$$ ($$$1\le q_i\le n$$$) followed by $$$q_i$$$ integers $$$j_{i,1},\,j_{i,2},\,\dots,\, j_{i,q_i}$$$ ($$$1\le j_{i,1} \lt j_{i,2} \lt \cdots \lt j_{i,q_i}\le n$$$) — the length of the subsequence considered in the $$$i$$$-th step and the indexes of the subsequence.
If Andrea's algorithm is correct print ACCEPTED, otherwise print REJECTED.
4 3 3 1 2 3 3 2 3 4 2 1 2
ACCEPTED
4 3 3 1 2 3 3 2 3 4 3 1 3 4
REJECTED
3 4 1 1 1 2 1 3 2 1 3
REJECTED
5 2 3 2 3 4 5 1 2 3 4 5
ACCEPTED
Explanation of the first sample: The algorithm consists of $$$3$$$ steps. The first one sorts the subsequence $$$[a_1, a_2, a_3]$$$, the second one sorts the subsequence $$$[a_2, a_3, a_4]$$$, the third one sorts the subsequence $$$[a_1,a_2]$$$. For example, if initially $$$a=[6, 5, 6, 3]$$$, the algorithm transforms the array as follows (the subsequence that gets sorted is highlighted in red) $$$$$$ [{\color{red}6},{\color{red}5},{\color{red}6},3] \rightarrow [5, {\color{red}6}, {\color{red}6}, {\color{red}3}] \rightarrow [{\color{red}5}, {\color{red}3}, 6, 6] \rightarrow [3, 5, 6, 6] \,.$$$$$$ One can prove that, for any initial array $$$a$$$, at the end of the algorithm the array $$$a$$$ will be sorted.
Explanation of the second sample: The algorithm consists of $$$3$$$ steps. The first one sorts the subsequence $$$[a_1, a_2, a_3]$$$, the second one sorts the subsequence $$$[a_2, a_3, a_4]$$$, the third one sorts the subsequence $$$[a_1,a_3,a_4]$$$. For example, if initially $$$a=[6, 5, 6, 3]$$$, the algorithm transforms the array as follows (the subsequence that gets sorted is highlighted in red) $$$$$$ [{\color{red}6},{\color{red}5},{\color{red}6},3] \rightarrow [5, {\color{red}6}, {\color{red}6}, {\color{red}3}] \rightarrow [{\color{red}5}, 3, {\color{red}6}, {\color{red}6}] \rightarrow [5, 3, 6, 6] \,.$$$$$$ Notice that $$$a=[6,5,6,3]$$$ is an example of an array that is not sorted by the algorithm.
Explanation of the third sample: The algorithm consists of $$$4$$$ steps. The first $$$3$$$ steps do nothing because they sort subsequences of length $$$1$$$, whereas the fourth step sorts the subsequence $$$[a_1,a_3]$$$. For example, if initially $$$a=[5,6,4]$$$, the algorithm transforms the array as follows (the subsequence that gets sorted is highlighted in red) $$$$$$ [{\color{red}5},6,4] \rightarrow [5,{\color{red}6},4] \rightarrow [5,{\color{red}6},4] \rightarrow [{\color{red}5},6,{\color{red}4}]\rightarrow [4,6,5] \,.$$$$$$ Notice that $$$a=[5,6,4]$$$ is an example of an array that is not sorted by the algorithm.
Explanation of the fourth sample: The algorithm consists of $$$2$$$ steps. The first step sorts the subsequences $$$[a_2,a_3,a_4]$$$, the second step sorts the whole array $$$[a_1,a_2,a_3,a_4,a_5]$$$. For example, if initially $$$a=[9,8,1,1,1]$$$, the algorithm transforms the array as follows (the subsequence that gets sorted is highlighted in red) $$$$$$ [9,{\color{red}8},{\color{red}1},{\color{red}1},1] \rightarrow [{\color{red}9},{\color{red}1},{\color{red}1},{\color{red}8},{\color{red}1}] \rightarrow [1,1,1,8,9] \,.$$$$$$ Since in the last step the whole array is sorted, it is clear that, for any initial array $$$a$$$, at the end of the algorithm the array $$$a$$$ will be sorted.
Let us call a point of the plane admissible if its coordinates are positive integers less than or equal to $$$200$$$.
There is an invisible rectangle such that:
In order to guess it, you may ask at most $$$4$$$ queries.
In each query, you choose a nonempty subset of the admissible points and you are told how many of the chosen points are inside or on the boundary of the invisible rectangle.
To ask a query (of the kind described in the statement), you shall print two lines:
When you have identified the perimeter $$$p$$$ of the invisible rectangle, you must print "! $$$p$$$" (without quotes) and terminate your program.
If you ask more than $$$4$$$ queries or if one of the queries is malformed, the interactor terminates immediately and your program receives verdict Wrong Answer.
The interactor may be adaptive (i.e., the hidden rectangle may not be chosen before the beginning of the interaction).
After printing a query do not forget to output end of line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use:
Hacks
To hack a solution, use the following format.
The input has only one line, containing the $$$4$$$ integers $$$x_0$$$, $$$y_0$$$, $$$x_1$$$, $$$y_1$$$ ($$$1\le x_0 \lt x_1\le 200$$$, $$$1\le y_0 \lt y_1 \le 200$$$) — $$$(x_0,y_0)$$$ is the bottom-left vertex of the hidden rectangle and $$$(x_1, y_1)$$$ is the top-right vertex of the hidden rectangle.
Note that for hacks the interaction won't be adaptive.
13 5 123 80
2 2 4 4
1 1 200 200
The following is an example of interaction for the first sample intended to show the format of the queries. $$$$$$ \begin{array}{l|l|l} \text{Query (contestant program)} & \text{Answer (interactor)} & \text{Explanation} \\ \hline \mathtt{?\ 4} & & \text{We choose the $4$ vertices of} \\ \mathtt{13\ 5\ 13\ 80\ 123\ 5\ 123\ 80} & \mathtt{4} &\text{the hidden rectangle.}\\ \hline \mathtt{?\ 5} & & \text{We choose $4$ points just outside the hidden}\\ \mathtt{100\ 4\ 100\ 81\ 12\ 40\ 124\ 40\ 50\ 50} & \mathtt{1}& \text{rectangle and also the point $(50,50)$.}\\ \hline \mathtt{?\ 2} & & \text{We choose the points $(1, 1)$} \\ \mathtt{200\ 200\ 1\ 1} & \mathtt{0} & \text{and $(200,200)$.}\\ \hline \mathtt{!\ 370} & & \text{This is the correct perimeter.} \end{array} $$$$$$
For the second sample, a possible interaction is the following. $$$$$$ \begin{array}{l|l|l} \text{Query (contestant program)} & \text{Answer (interactor)} & \text{Explanation} \\ \hline \mathtt{?\ 4} & & \text{We choose the points $(3, 2)$, $(4, 1)$,} \\ \mathtt{3\ 2\ 4\ 1\ 5\ 2\ 4\ 3} & 2 & \text{$(5, 2)$ and $(4, 3)$.} \\ \hline \mathtt{?\ 7} & & \text{We choose the points $(1, 4)$, $(2, 4)$,} \\ \mathtt{1\ 4\ 2\ 4\ 1\ 5\ 2\ 5\ 5\ 5\ 5\ 6\ 6\ 5} & 1 & \text{$(1, 5)$, $(2, 5)$, $(5, 5)$, $(5, 6)$ and $(6, 5)$.} \\ \hline \mathtt{!\ 8} & & \text{This is the correct perimeter.} \end{array} $$$$$$ The situation is shown in the following picture:
The green points are the ones belonging to the first query, while the orange points are the ones belonging to the second query. One can see that there are exactly two rectangles consistent with the interactor's answers:
You are the organizer of the famous "Zurich Music Festival". There will be $$$n$$$ singers who will perform at the festival, identified by the integers $$$1$$$, $$$2$$$, $$$\dots$$$, $$$n$$$. You must choose in which order they are going to perform on stage.
You have $$$m$$$ friends and each of them has a set of favourite singers. More precisely, for each $$$1\le i\le m$$$, the $$$i$$$-th friend likes singers $$$s_{i,1}, \, s_{i, 2}, \, \dots, \,s_{i, q_i}$$$.
A friend of yours is happy if the singers he likes perform consecutively (in an arbitrary order). An ordering of the singers is valid if it makes all your friends happy.
Compute the number of valid orderings modulo $$$998\,244\,353$$$.
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1\le n,\,m\le 100$$$) — the number of singers and the number of friends correspondingly.
The $$$i$$$-th of the next $$$m$$$ lines contains the integer $$$q_i$$$ ($$$1\le q_i\le n$$$) — the number of favorite singers of the $$$i$$$-th friend – followed by the $$$q_i$$$ integers $$$s_{i,1}, \, s_{i, 2}, \, \dots, \,s_{i, q_i}$$$ ($$$1\le s_{i,1} \lt s_{i,2} \lt \cdots \lt s_{i,q_i}\le n$$$) — the indexes of his favorite singers.
Print the number of valid orderings of the singers modulo $$$998\,244\,353$$$.
3 1 2 1 3
4
5 5 2 1 2 2 2 3 2 3 4 2 4 5 2 1 5
0
100 1 1 50
35305197
5 1 5 1 2 3 4 5
120
2 5 1 2 1 2 1 2 1 1 1 1
2
11 4 5 4 5 7 9 11 2 2 10 2 9 11 7 1 2 3 5 8 10 11
384
Explanation of the first sample: There are $$$3$$$ singers and only $$$1$$$ friend. The friend likes the two singers $$$1$$$ and $$$3$$$. Thus, the $$$4$$$ valid orderings are:
Explanation of the second sample: There are $$$5$$$ singers and $$$5$$$ friends. One can show that no ordering is valid.
Explanation of the third sample: There are $$$100$$$ singers and only $$$1$$$ friend. The friend likes only singer $$$50$$$, hence all the $$$100!$$$ possible orderings are valid.
Explanation of the fourth sample: There are $$$5$$$ singers and only $$$1$$$ friend. The friend likes all the singers, hence all the $$$5!=120$$$ possible orderings are valid.