実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
高橋君の家には、高橋君、高橋君の父、高橋君の母の 3 人が住んでおり、全員が毎晩風呂で髪を洗います。
風呂には、高橋君の父、高橋君の母、高橋君の順に入り、それぞれシャンプーを A,B,C ミリリットル使います。
今朝の時点で、ボトルには V ミリリットルのシャンプーが残っていました。このまま補充しない時、初めてシャンプーが不足するのは誰が使おうとした時ですか?
制約
- 1 \leq V,A,B,C \leq 10^5
- 入力に含まれる値は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
V A B C
出力
初めてシャンプーが不足するのが、高橋君の父が使おうとしたときならば F、高橋君の母が使おうとしたときならば M、高橋君が使おうとしたときならば T を出力せよ。
入力例 1
25 10 11 12
出力例 1
T
シャンプーは 25 ミリリットル残っています。
- まず高橋君の父が 10 ミリリットル使い、残りは 15 ミリリットルになります。
- 次に高橋君の母が 11 ミリリットル使い、残りは 4 ミリリットルになります。
- 最後に高橋君が 12 ミリリットル使おうとしますが、4 ミリリットルしか残っておらず、不足しています。
入力例 2
30 10 10 10
出力例 2
F
シャンプーは 30 ミリリットル残っています。
- まず高橋君の父が 10 ミリリットル使い、残りは 20 ミリリットルになります。
- 次に高橋君の母が 10 ミリリットル使い、残りは 10 ミリリットルになります。
- 続いて高橋君が 10 ミリリットル使い、残りは 0 ミリリットルになります。
- 翌日、高橋君の父が 10 ミリリットル使おうとしますが、0 ミリリットルしか残っておらず、不足しています。
入力例 3
100000 1 1 1
出力例 3
M
Score : 100 points
Problem Statement
Three people live in Takahashi's house: Takahashi, his father, and his mother. All of them wash their hair in the bathroom each night.
His father, his mother, and Takahashi take a bath in this order and use A, B, and C milliliters of shampoo, respectively.
This morning, the bottle contained V milliliters of shampoo. Without refilling, who will be the first to run short of shampoo to wash their hair?
Constraints
- 1 \leq V,A,B,C \leq 10^5
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
V A B C
Output
If the first person to run short of shampoo to wash their hair is Takahashi's father, print F; if it is Takahashi's mother, print M; if it is Takahashi, print T.
Sample Input 1
25 10 11 12
Sample Output 1
T
Now, they have 25 milliliters of shampoo.
- First, Takahashi's father uses 10 milliliters, leaving 15.
- Next, Takahashi's mother uses 11 milliliters, leaving 4.
- Finally, Takahashi tries to use 12 milliliters and runs short of shampoo since only 4 is remaining.
Sample Input 2
30 10 10 10
Sample Output 2
F
Now, they have 30 milliliters of shampoo.
- First, Takahashi's father uses 10 milliliters, leaving 20.
- Next, Takahashi's mother uses 10 milliliters, leaving 10.
- Then, Takahashi uses 10 milliliters, leaving 0.
- Next day, Takahashi's father tries to use 10 milliliters and runs short of shampoo since only 0 is remaining.
Sample Input 3
100000 1 1 1
Sample Output 3
M
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
消毒液の入ったボトルがあり、その消毒液によってちょうど M 本の手を消毒することができます。
N 人の宇宙人が順に手の消毒を行いに来ます。
i 人目 (1\leq i\leq N) の宇宙人は H_i 本の手を持っており、それぞれ自身のすべての手を 1 回ずつ消毒したいと考えています。
何人目の宇宙人までがすべての手を消毒できるか求めてください。
ただし、ある宇宙人が消毒を始める時点で、自身のすべての手を消毒する分の消毒液が残っていなかったとしても、その宇宙人はその消毒液を使い切ってしまうものとします。
制約
- 1\leq N,M\leq 100
- 1\leq H_i\leq 100
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N M H_1 H_2 \ldots H_N
出力
何人目の宇宙人までが自身のすべての手を消毒できるか出力せよ。
入力例 1
5 10 2 3 2 5 3
出力例 1
3
次の手順で宇宙人は自身の手を消毒します。
- 1 人目の宇宙人は自身の 2 本の手を消毒します。残りの消毒液によって、10-2=8 本の手を消毒できます。
- 2 人目の宇宙人は自身の 3 本の手を消毒します。残りの消毒液によって、8-3=5 本の手を消毒できます。
- 3 人目の宇宙人は自身の 2 本の手を消毒します。残りの消毒液によって、5-2=3 本の手を消毒できます。
- 4 人目の宇宙人は 5 本の手を持っていますが、消毒液は 3 本分しかないため消毒液を使い切り、かつ自身のすべての手を消毒できません。
よって、3 人目の宇宙人までが自身のすべての手を消毒できるため、3 を出力します。
入力例 2
5 10 2 3 2 3 5
出力例 2
4
入力例 3
1 5 1
出力例 3
1
すべての宇宙人が自身の手を消毒することができます。
Score : 100 points
Problem Statement
There is a bottle of disinfectant that can disinfect exactly M hands.
N aliens come one by one to disinfect their hands.
The i-th alien (1 \leq i \leq N) has H_i hands and wants to disinfect all of their hands once.
Determine how many aliens can disinfect all of their hands.
Here, even if there is not enough disinfectant left for an alien to disinfect all of their hands when they start, they will use up the remaining disinfectant.
Constraints
- 1 \leq N, M \leq 100
- 1 \leq H_i \leq 100
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M H_1 H_2 \ldots H_N
Output
Print the number of aliens who can disinfect all of their hands.
Sample Input 1
5 10 2 3 2 5 3
Sample Output 1
3
The aliens disinfect their hands in the following steps:
- The first alien disinfects their two hands. The remaining disinfectant can disinfect 10-2=8 hands.
- The second alien disinfects their three hands. The remaining disinfectant can disinfect 8-3=5 hands.
- The third alien disinfects their two hands. The remaining disinfectant can disinfect 5-2=3 hands.
- The fourth alien has five hands, but there is only enough disinfectant for three hands, so they use up the disinfectant without disinfecting all of their hands.
Thus, the first three aliens can disinfect all of their hands, so print 3.
Sample Input 2
5 10 2 3 2 3 5
Sample Output 2
4
Sample Input 3
1 5 1
Sample Output 3
1
All aliens can disinfect their hands.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
正整数 A,B が与えられます。
A+B を(十進法で)計算する時、繰り上がりが生じないなら Easy 、生じるなら Hard と出力してください。
制約
- A,B は整数
- 1 \le A,B \le 10^{18}
入力
入力は以下の形式で標準入力から与えられる。
A B
出力
繰り上がりが生じないなら Easy 、生じるなら Hard と出力せよ。
入力例 1
229 390
出力例 1
Hard
229+390 を計算する際、十の位から百の位へと繰り上がりが発生します。よって、答えは Hard です。
入力例 2
123456789 9876543210
出力例 2
Easy
繰り上がりは発生しません。答えは Easy です。
また、入力が 32bit 整数に収まらないこともあります。
Score : 200 points
Problem Statement
You are given positive integers A and B.
Let us calculate A+B (in decimal). If it does not involve a carry, print Easy; if it does, print Hard.
Constraints
- A and B are integers.
- 1 \le A,B \le 10^{18}
Input
Input is given from Standard Input in the following format:
A B
Output
If the calculation does not involve a carry, print Easy; if it does, print Hard.
Sample Input 1
229 390
Sample Output 1
Hard
When calculating 229+390, we have a carry from the tens digit to the hundreds digit, so the answer is Hard.
Sample Input 2
123456789 9876543210
Sample Output 2
Easy
We do not have a carry here; the answer is Easy.
Note that the input may not fit into a 32-bit integer.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
英小文字からなる文字列 S が良い文字列であるとは、すべての 1 以上の整数 i について次の性質が成り立つことであるとします。
- S にちょうど i 回現れる文字はちょうど 0 種類またはちょうど 2 種類ある
文字列 S が与えられるので、 S が良い文字列か判定してください。
制約
- S は英小文字からなる長さ 1 以上 100 以下の文字列
入力
入力は以下の形式で標準入力から与えられる。
S
出力
S が良い文字列ならば Yes を、そうでないならば No を出力せよ。
入力例 1
commencement
出力例 1
Yes
文字列 commencement にちょうど i 回現れる文字の種類数は以下のとおりです。
- i=1:
o,tの 2 種類 - i=2:
c,nの 2 種類 - i=3:
e,mの 2 種類 - i\geq 4: 0 種類
よって、commencement は良い文字列の条件を満たします。
入力例 2
banana
出力例 2
No
文字列 banana にちょうど 1 回現れる文字は b の 1 種類だけであり、良い文字列の条件を満たしません。
入力例 3
ab
出力例 3
Yes
Score: 200 points
Problem Statement
A string S consisting of lowercase English letters is a good string if and only if it satisfies the following property for all integers i not less than 1:
- There are exactly zero or exactly two different letters that appear exactly i times in S.
Given a string S, determine if it is a good string.
Constraints
- S is a string of lowercase English letters with a length between 1 and 100, inclusive.
Input
The input is given from Standard Input in the following format:
S
Output
Print Yes if S is a good string, and No otherwise.
Sample Input 1
commencement
Sample Output 1
Yes
For the string commencement, the number of different letters that appear exactly i times is as follows:
- i=1: two letters (
oandt) - i=2: two letters (
candn) - i=3: two letters (
eandm) - i\geq 4: zero letters
Therefore, commencement satisfies the condition of a good string.
Sample Input 2
banana
Sample Output 2
No
For the string banana, there is only one letter that appears exactly one time, which is b, so it does not satisfy the condition of a good string.
Sample Input 3
ab
Sample Output 3
Yes
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
N 頂点 M 辺の単純無向グラフが与えられます。頂点には 1, 2, \dots, N の番号が、辺には 1, 2, \dots, M の番号が付けられています。
辺 i \, (i = 1, 2, \dots, M) は頂点 u_i, v_i を結んでいます。
このグラフがパスグラフであるか判定してください。
単純無向グラフとは
単純無向グラフとは、自己ループや多重辺を含まず、辺に向きの無いグラフのことをいいます。
パスグラフとは
頂点に 1, 2, \dots, N の番号が付けられたN 頂点のグラフがパスグラフであるとは、(1, 2, \dots, N) を並べ変えて得られる数列 (v_1, v_2, \dots, v_N) であって、以下の条件を満たすものが存在することをいいます。
制約
- 2 \leq N \leq 2 \times 10^5
- 0 \leq M \leq 2 \times 10^5
- 1 \leq u_i, v_i \leq N \, (i = 1, 2, \dots, M)
- 入力される値は全て整数
- 入力で与えられるグラフは単純
入力
入力は以下の形式で標準入力から与えられる。
N M u_1 v_1 u_2 v_2 \vdots u_M v_M
出力
与えられたグラフがパスグラフなら Yes、そうでないなら No と出力せよ。
入力例 1
4 3 1 3 4 2 3 2
出力例 1
Yes
与えらえたグラフは下図のようであり、これはパスグラフです。

入力例 2
2 0
出力例 2
No
与えらえたグラフは下図のようであり、これはパスグラフではありません。

入力例 3
5 5 1 2 2 3 3 4 4 5 5 1
出力例 3
No
与えらえたグラフは下図のようであり、これはパスグラフではありません。

Score : 300 points
Problem Statement
You are given a simple undirected graph with N vertices and M edges. The vertices are numbered 1, 2, \dots, N, and the edges are numbered 1, 2, \dots, M.
Edge i \, (i = 1, 2, \dots, M) connects vertices u_i and v_i.
Determine if this graph is a path graph.
What is a simple undirected graph?
A simple undirected graph is a graph without self-loops or multiple edges whose edges do not have a direction.
What is a path graph?
A graph with N vertices numbered 1, 2, \dots, N is said to be a path graph if and only if there is a sequence (v_1, v_2, \dots, v_N) that is a permutation of (1, 2, \dots, N) and satisfies the following conditions:
Constraints
- 2 \leq N \leq 2 \times 10^5
- 0 \leq M \leq 2 \times 10^5
- 1 \leq u_i, v_i \leq N \, (i = 1, 2, \dots, M)
- All values in the input are integers.
- The graph given in the input is simple.
Input
The input is given from Standard Input in the following format:
N M u_1 v_1 u_2 v_2 \vdots u_M v_M
Output
Print Yes if the given graph is a path graph; print No otherwise.
Sample Input 1
4 3 1 3 4 2 3 2
Sample Output 1
Yes
Illustrated below is the given graph, which is a path graph.

Sample Input 2
2 0
Sample Output 2
No
Illustrated below is the given graph, which is not a path graph.

Sample Input 3
5 5 1 2 2 3 3 4 4 5 5 1
Sample Output 3
No
Illustrated below is the given graph, which is not a path graph.

実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
頂点に 1 から N の、辺に 1 から M の番号がついた N 頂点 M 辺の無向グラフが与えられます。辺 i は頂点 u_i と頂点 v_i を結ぶ辺です。
グラフから辺を取り除いてグラフを単純にするためには、少なくとも何本の辺を取り除く必要がありますか?
ここでグラフが単純であるとは、グラフが自己ループや多重辺を含まないことをいいます。
制約
- 1 \leq N \leq 2 \times 10^5
- 0 \leq M \leq 5 \times 10^5
- 1 \leq u_i \leq N
- 1 \leq v_i \leq N
- 入力される値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N M u_1 v_1 u_2 v_2 \vdots u_M v_M
出力
グラフを単純にするために取り除く必要がある辺の本数の最小値を出力せよ。
入力例 1
3 5 1 2 2 3 3 2 3 1 1 1
出力例 1
2
辺 3 と辺 5 を取り除くとグラフを単純にすることが出来て、これが取り除く辺の本数が最小となる選び方の 1 つです。よって答えは 2 本です。
入力例 2
1 0
出力例 2
0
入力例 3
6 10 6 2 4 1 5 1 6 6 5 3 5 1 1 4 6 4 4 2 5 6
出力例 3
3
Score : 300 points
Problem Statement
You are given an undirected graph with N vertices and M edges, where the vertices are numbered 1 through N and the edges are numbered 1 through M. Edge i connects vertices u_i and v_i.
To make the graph simple by removing edges, what is the minimum number of edges that must be removed?
Here, a graph is called simple if and only if it does not contain self-loops or multi-edges.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 0 \leq M \leq 5 \times 10^5
- 1 \leq u_i \leq N
- 1 \leq v_i \leq N
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M u_1 v_1 u_2 v_2 \vdots u_M v_M
Output
Print the minimum number of edges that must be removed to make the graph simple.
Sample Input 1
3 5 1 2 2 3 3 2 3 1 1 1
Sample Output 1
2
By removing edges 3 and 5, the graph becomes simple. This is one of the ways to remove the minimum number of edges, so the answer is 2.
Sample Input 2
1 0
Sample Output 2
0
Sample Input 3
6 10 6 2 4 1 5 1 6 6 5 3 5 1 1 4 6 4 4 2 5 6
Sample Output 3
3
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 400 点
問題文
以下の条件を満たす正整数を 良い整数 とします。
- 条件:一つ以上の 2 の冪(1,2,4,8,16,\dots)を(重複と並び替えを許して)選んで文字列として結合し、それを整数として解釈することで得られる。
良い整数のうち N 番目に小さいものを求めてください。 ただし N 番目に小さい良い整数は 10^9 以下であることが保証されます。
制約
- N は正整数
- N 番目に小さい良い整数は 10^9 以下
入力
入力は以下の形式で標準入力から与えられる。
N
出力
答えを出力せよ。
入力例 1
10
出力例 1
21
良い整数を小さい方から列挙すると 1, 2, 4, 8, 11, 12, 14, 16, 18, 21, \dots です。
入力例 2
69
出力例 2
328
入力例 3
1099898
出力例 3
819264512
Score : 400 points
Problem Statement
We call a positive integer a good integer if it satisfies the following condition.
- Condition: It can be obtained by choosing one or more powers of 2 (1, 2, 4, 8, 16, \dots) (repetition and reordering allowed), concatenating them as strings, and interpreting the result as an integer.
Find the N-th smallest good integer. It is guaranteed that the N-th smallest good integer is at most 10^9.
Constraints
- N is a positive integer.
- The N-th smallest good integer is at most 10^9.
Input
The input is given from Standard Input in the following format:
N
Output
Output the answer.
Sample Input 1
10
Sample Output 1
21
Listing good integers in ascending order gives 1, 2, 4, 8, 11, 12, 14, 16, 18, 21, \dots.
Sample Input 2
69
Sample Output 2
328
Sample Input 3
1099898
Sample Output 3
819264512
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 500 点
問題文
文字列の多重集合 X,Y があります。はじめ、両方ともに空です。
Q 個のクエリが与えられるので、順に処理してください。i 番目のクエリでは、整数 T_i と文字列 S_i が与えられるので、T_i=1 ならば X に S_i を追加し、T_i=2 ならば Y に S_i を追加してください。
各クエリの処理後、以下の値を出力してください。
- Y に含まれる文字列のうち、X のどの要素も接頭辞として持たないものの個数
制約
- Q は 1 以上 2 \times 10^5 以下の整数
- T_i \in \{1,2\}
- S_i は長さ 1 以上 5 \times 10^5 以下の英小文字のみからなる文字列
- \displaystyle \sum_{i=1}^Q |S_i| \leq 5 \times 10^5
入力
入力は以下の形式で標準入力から与えられる。
Q T_1 S_1 T_2 S_2 \vdots T_Q S_Q
出力
Q 行出力せよ。i 行目 (1 \leq i \leq Q) には、i 番目のクエリの処理後の答えを出力せよ。
入力例 1
4 1 at 2 watcoder 2 atcoder 1 wa
出力例 1
0 1 1 0
i=1,2,3,4 番目のクエリの処理後の答えはそれぞれ以下のようになります。
- i=1: Y は空なので、求める個数は 0 です。
- i=2:
watcoderは X のどの要素も接頭辞として持たないので、求める個数は 1 です。 - i=3:
watcoderは X のどの要素も接頭辞として持たず、atcoderはatを接頭辞として持つので、求める個数は 1 個です。 - i=4:
watcoderはwaを、atcoderはatを接頭辞として持つので、求める個数は 0 個です。
入力例 2
10 1 w 1 avko 2 atcoder 1 bzginn 2 beginner 1 atco 2 contest 1 ntxcdg 1 atc 1 contest
出力例 2
0 0 1 1 2 1 2 2 2 1
Score : 500 points
Problem Statement
There are two multisets of strings, X and Y, both initially empty.
You are given Q queries to process in order. In the i-th query, you receive an integer T_i and a string S_i. If T_i=1, insert S_i into X; if T_i=2, insert S_i into Y.
After processing each query, print this value:
- the number of strings in Y that have no element of X as a prefix.
Constraints
- Q is an integer between 1 and 2 \times 10^5, inclusive.
- T_i \in \{1,2\}
- Each S_i is a string of length between 1 and 5\times 10^5, inclusive, consisting of lowercase English letters.
- \displaystyle \sum_{i=1}^Q |S_i| \leq 5 \times 10^5
Input
The input is given from Standard Input in the following format:
Q T_1\ S_1 T_2\ S_2 \vdots T_Q\ S_Q
Output
Print Q lines. The i-th line (1 \leq i \leq Q) should contain the count after processing the i-th query.
Sample Input 1
4 1 at 2 watcoder 2 atcoder 1 wa
Sample Output 1
0 1 1 0
The counts after processing the queries for i=1,2,3,4 are as follows.
- i=1: Y is empty, so the count is 0.
- i=2:
watcoderhas no element of X as a prefix, so the count is 1. - i=3:
watcoderhas no element of X as a prefix, whileatcoderhasatas a prefix, so the count is 1. - i=4:
watcoderhaswaas a prefix, andatcoderhasatas a prefix, so the count is 0.
Sample Input 2
10 1 w 1 avko 2 atcoder 1 bzginn 2 beginner 1 atco 2 contest 1 ntxcdg 1 atc 1 contest
Sample Output 2
0 0 1 1 2 1 2 2 2 1
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 500 点
問題文
2N 人の生徒が一列に並んでおり、左から順に生徒 1 , 生徒 2 , \ldots , 生徒 2N と番号が付いています。 2N 人の生徒はどの 2 人も互いに仲が良いか悪いかのどちらかであり、 具体的には 1\leq i\leq M について生徒 A_i と生徒 B_i の仲が良く、これら以外のどの 2 人も仲が悪いです。
先生は以下の操作を N 回繰り返して、 2 人組のペアを N 組作ることにしました。
- 隣り合う 2 人であって仲が良いような 2 人をペアとして選び、列から抜く。
- 抜けた 2 人が列の端でなかったならば、その後、列を詰める。すなわち、抜けた 2 人の左右にいた 2 人が新しく隣り合う。
このとき、 N 回の操作方法としてあり得るものの数を 998244353 で割った余りを求めてください。 ただし N 回の操作方法が異なるとは、ある 1\leq i\leq N が存在して、 i 回目の操作で 選ばれた 2 人組がペアとして異なることをいいます。
制約
- 1 \leq N \leq 200
- 0 \leq M \leq N(2N-1)
- 1 \leq A_i < B_i \leq 2N
- (A_i, B_i) はすべて異なる。
- 入力は全て整数である。
入力
入力は以下の形式で標準入力から与えられる。
N M A_1 B_1 A_2 B_2 \vdots A_M B_M
出力
操作方法としてあり得るものの数を 998244353 で割った余りを出力せよ。
入力例 1
2 3 1 2 1 4 2 3
出力例 1
1
1 度目の操作で生徒 2 と生徒 3 を選び、
2 度目の操作で生徒 1 と生徒 4 を選ぶのが
唯一の操作方法です。
1 度目の操作で生徒 1 と生徒 2 を選ぶと、
生徒 3 と生徒 4 が残りますが、この 2 人は仲が悪いため 2 度目の操作でペアにすることができません。
よって、 1 を出力します。
入力例 2
2 2 1 2 3 4
出力例 2
2
1 度目の操作で生徒 1 と生徒 2 を選び、 2 度目の操作で生徒 3 と生徒 4 を選ぶのが 1 通り、 1 度目の操作で生徒 3 と生徒 4 を選び、 2 度目の操作で生徒 1 と生徒 2 を選ぶのが 1 通りであわせて 2 通りあります。 この 2 つが区別されることに注意してください。
入力例 3
2 2 1 3 2 4
出力例 3
0
1 度目の操作で選べるペアが無いため条件をみたす操作方法は無く、 0 を出力します。
Score : 500 points
Problem Statement
There are 2N students standing in a row, numbered 1, 2, \ldots, 2N from left to right. For all pairs of two students, they are on good or bad terms. Specifically, for each 1\leq i\leq M, Student A_i and Student B_i are on good terms; for the remaining pairs of two students, they are on bad terms.
The teacher is going to do the following operation N times to form N pairs of two students.
- Choose two adjacent students who are on good terms, pair them, and remove them from the row.
- If the removed students were not at an end of the row, close up the gap so that the two students who were to the left and right of the removed students are now adjacent.
Find the number, modulo 998244353, of possible ways to do the operation N times. Two ways to do the operation N times are considered different when there exists 1\leq i\leq N such that the pair of students chosen in the i-th operation is different in those two ways.
Constraints
- 1 \leq N \leq 200
- 0 \leq M \leq N(2N-1)
- 1 \leq A_i < B_i \leq 2N
- All pairs (A_i, B_i) are distinct.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M A_1 B_1 A_2 B_2 \vdots A_M B_M
Output
Print the number of possible ways to complete the procedure, modulo 998244353.
Sample Input 1
2 3 1 2 1 4 2 3
Sample Output 1
1
The only way to complete the procedure is to choose Students 2 and 3 in the first and Students 1 and 4 in the second.
If Students 1 and 2 are chosen in the first operation, Students 3 and 4 will remain, who are on bad terms and thus cannot be paired in the second operation.
Thus, you should print 1.
Sample Input 2
2 2 1 2 3 4
Sample Output 2
2
There are two ways to complete the procedure: one way is to choose Students 1 and 2 in the first operation and Students 3 and 4 in the second, and the other way is to choose Students 3 and 4 in the first operation and Students 1 and 2 in the second. Note that these two ways are distinguished.
Sample Input 3
2 2 1 3 2 4
Sample Output 3
0
Since no pair can be chosen in the first operation, there is no way to complete the procedure, so you should print 0.