A - Takahashi san

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 100

問題文

キーエンスでは、役割や年齢、立場の違いに関係なく「さん」付けして呼ぶという文化があります。 新入社員が社長を呼ぶときも「中田さん」と呼びます。

ある人の苗字と名前がそれぞれ文字列 S,T として与えられます。

苗字、スペース( )、敬称(san)をこの順に連結した文字列を出力してください。

制約

  • S,T は以下の各条件を満たす文字列
    • 長さ 1 以上 10 以下
    • 先頭の文字は英大文字
    • 先頭以外の文字は英小文字

入力

入力は以下の形式で標準入力から与えられる。

S T

出力

苗字、スペース( )、敬称(san)をこの順に連結した文字列を出力せよ。


入力例 1

Takahashi Chokudai

出力例 1

Takahashi san

苗字(Takahashi)、スペース( )、敬称(san)をこの順に連結した文字列を出力します。


入力例 2

K Eyence

出力例 2

K san

Score : 100 points

Problem Statement

Keyence has a culture of addressing everyone with the honorific "san," regardless of their role, age, or position. Even a new employee would call the president "Nakata-san." [Translator's note: this is a bit unusual in Japan.]

You are given a person's surname and first name as strings S and T, respectively.

Print the concatenation of the surname, a space ( ), and the honorific (san) in this order.

Constraints

  • Each of S and T is a string that satisfies the following conditions.
    • The length is between 1 and 10, inclusive.
    • The first character is an uppercase English letter.
    • All characters except the first one are lowercase English letters.

Input

The input is given from Standard Input in the following format:

S T

Output

Print the concatenation of the surname, a space ( ), and the honorific (san) in this order.


Sample Input 1

Takahashi Chokudai

Sample Output 1

Takahashi san

Print the concatenation of the surname (Takahashi), a space ( ), and the honorific (san) in this order.


Sample Input 2

K Eyence

Sample Output 2

K san
B - Arithmetic Progression

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 100

問題文

初項が A、末項が B、公差が D であるような等差数列を出力してください。

なお、そのような等差数列が存在する入力のみが与えられます。

制約

  • 1 \leq A \leq B \leq 100
  • 1\leq D \leq 100
  • 初項が A、末項が B、公差が D であるような等差数列が存在する
  • 入力は全て整数

入力

入力は以下の形式で標準入力から与えられる。

A B D

出力

初項が A、末項が B、公差が D であるような等差数列の項を順に空白区切りで出力せよ。


入力例 1

3 9 2

出力例 1

3 5 7 9

初項が 3、末項が 9、公差が 2 であるような等差数列は (3,5,7,9) です。


入力例 2

10 10 1

出力例 2

10

初項が 10、末項が 10、公差が 1 であるような等差数列は (10) です。

Score: 100 points

Problem Statement

Print an arithmetic sequence with first term A, last term B, and common difference D.

You are only given inputs for which such an arithmetic sequence exists.

Constraints

  • 1 \leq A \leq B \leq 100
  • 1 \leq D \leq 100
  • There is an arithmetic sequence with first term A, last term B, and common difference D.
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

A B D

Output

Print the terms of the arithmetic sequence with first term A, last term B, and common difference D, in order, separated by spaces.


Sample Input 1

3 9 2

Sample Output 1

3 5 7 9

The arithmetic sequence with first term 3, last term 9, and common difference 2 is (3,5,7,9).


Sample Input 2

10 10 1

Sample Output 2

10

The arithmetic sequence with first term 10, last term 10, and common difference 1 is (10).

C - Base 2

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 200

問題文

01 からなる長さ 64 の数列 A=(A_0,A_1,\dots,A_{63}) が与えられます。

A_0 2^0 + A_1 2^1 + \dots + A_{63} 2^{63} を求めてください。

制約

  • A_i0 または 1

入力

入力は以下の形式で標準入力から与えられる。

A_0 A_1 \dots A_{63}

出力

答えを整数として出力せよ。


入力例 1

1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

出力例 1

13

A_0 2^0 + A_1 2^1 + \dots + A_{63} 2^{63} = 2^0 + 2^2 + 2^3 = 13 です。


入力例 2

1 0 1 0 1 0 0 0 0 1 0 0 1 1 0 1 1 1 1 0 0 0 1 0 0 1 1 1 1 1 1 0 0 0 0 1 0 1 0 1 0 1 1 1 1 0 0 1 1 0 0 0 0 1 0 1 0 1 0 1 0 0 0 0

出力例 2

766067858140017173

Score : 200 points

Problem Statement

You are given a sequence A=(A_0,A_1,\dots,A_{63}) of length 64 consisting of 0 and 1.

Find A_0 2^0 + A_1 2^1 + \dots + A_{63} 2^{63}.

Constraints

  • A_i is 0 or 1.

Input

The input is given from Standard Input in the following format:

A_0 A_1 \dots A_{63}

Output

Print the answer as an integer.


Sample Input 1

1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Sample Output 1

13

A_0 2^0 + A_1 2^1 + \dots + A_{63} 2^{63} = 2^0 + 2^2 + 2^3 = 13.


Sample Input 2

1 0 1 0 1 0 0 0 0 1 0 0 1 1 0 1 1 1 1 0 0 0 1 0 0 1 1 1 1 1 1 0 0 0 0 1 0 1 0 1 0 1 1 1 1 0 0 1 1 0 0 0 0 1 0 1 0 1 0 1 0 0 0 0

Sample Output 2

766067858140017173
D - Piano

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 200

問題文

無限に長いピアノの鍵盤があります。 この鍵盤内の連続する区間であって、白鍵 W 個と黒鍵 B 個からなるものは存在しますか?

文字列 wbwbwwbwbwbw を無限に繰り返してできる文字列を S とおきます。

S の部分文字列であって、W 個の wB 個の b からなるものは存在しますか?

S の部分文字列とは S の部分文字列とは、ある 2 つの正整数 l,r\ (l\leq r) に対して、Sl 文字目、l+1 文字目、\dotsr 文字目をこの順に繋げてできる文字列のことをいいます。

制約

  • W,B は整数
  • 0\leq W,B \leq 100
  • W+B \geq 1

入力

入力は以下の形式で標準入力から与えられる。

W B

出力

S の部分文字列であって、W 個の wB 個の b からなるものが存在するならば Yes を、存在しないならば No を出力せよ。


入力例 1

3 2

出力例 1

Yes

S の最初の 15 文字は wbwbwwbwbwbwwbw であり、S11 文字目から 15 文字目までを取り出してできる文字列 bwwbw3 個の w2 個の b からなる部分文字列の一例です。


入力例 2

3 0

出力例 2

No

3 個の w0 個の b からなる文字列は www のみですが、これは S の部分文字列ではありません。


入力例 3

92 66

出力例 3

Yes

Score: 200 points

Problem Statement

There is an infinitely long piano keyboard. Is there a continuous segment within this keyboard that consists of W white keys and B black keys?

Let S be the string formed by infinitely repeating the string wbwbwwbwbwbw.

Is there a substring of S that consists of W occurrences of w and B occurrences of b?

What is a substring of S? A substring of S is a string that can be formed by concatenating the l-th, (l+1)-th, \dots, r-th characters of S in this order for some two positive integers l and r (l\leq r).

Constraints

  • W and B are integers.
  • 0\leq W,B \leq 100
  • W+B \geq 1

Input

The input is given from Standard Input in the following format:

W B

Output

If there is a substring of S that consists of W occurrences of w and B occurrences of b, print Yes; otherwise, print No.


Sample Input 1

3 2

Sample Output 1

Yes

The first 15 characters of S are wbwbwwbwbwbwwbw. You can take the 11-th through 15-th characters to form the string bwwbw, which is a substring consisting of three occurrences of w and two occurrences of b.


Sample Input 2

3 0

Sample Output 2

No

The only string consisting of three occurrences of w and zero occurrences of b is www, which is not a substring of S.


Sample Input 3

92 66

Sample Output 3

Yes
E - Dango

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 300

問題文

正の整数 L に対して、 レベル L のダンゴ文字列とは、以下の条件を満たす文字列です。

  • o- からなる長さ L+1 の文字列である。
  • 先頭の文字と末尾の文字のうちちょうど一方が - であり、そのほかの L 文字はすべて o である。

例えば、ooo- はレベル 3 のダンゴ文字列ですが、-ooo-ooo-oo- などはダンゴ文字列ではありません(より正確には、どのような正の整数 L に対してもレベル L のダンゴ文字列ではありません)。

2 種類の文字 o - からなる、長さ N の文字列 S が与えられます。 次の条件を満たすような正整数 X のうち、最大のものを求めてください。

  • S の連続する部分文字列であって、レベル X のダンゴ文字列であるものが存在する。

ただし、そのような整数が存在しない場合、-1 と出力してください。

制約

  • 1\leq N\leq 2\times10^5
  • So - からなる長さ N の文字列

入力

入力は以下の形式で標準入力から与えられる。

N
S

出力

S にレベル X のダンゴ文字列が含まれるような最大の X の値を 1 行で出力せよ。 そのような値が存在しない場合、-1 を出力せよ。


入力例 1

10
o-oooo---o

出力例 1

4

たとえば、S3 文字目から 7 文字目までに対応する部分文字列 oooo- は、レベル 4 のダンゴ文字列です。 S の部分文字列であってレベル 5 以上のダンゴ文字列であるようなものは存在しないため、4 と出力してください。


入力例 2

1
-

出力例 2

-1

S の連続する部分文字列は空文字列と -2 種類だけです。 これらはダンゴ文字列ではないため、-1 と出力してください。


入力例 3

30
-o-o-oooo-oo-o-ooooooo--oooo-o

出力例 3

7

Score : 300 points

Problem Statement

For a positive integer L, a level-L dango string is a string that satisfies the following conditions.

  • It is a string of length L+1 consisting of o and -.
  • Exactly one of the first character and the last character is -, and the other L characters are o.

For instance, ooo- is a level-3 dango string, but none of -ooo-, oo, and o-oo- is a dango string (more precisely, none of them is a level-L dango string for any positive integer L).

You are given a string S of length N consisting of the two characters o and -. Find the greatest positive integer X that satisfies the following condition.

  • There is a contiguous substring of S that is a level-X dango string.

If there is no such integer, print -1.

Constraints

  • 1\leq N\leq 2\times10^5
  • S is a string of length N consisting of o and -.

Input

The input is given from Standard Input in the following format:

N
S

Output

Print the greatest positive integer X such that S contains a level-X dango string, or -1 if there is no such integer.


Sample Input 1

10
o-oooo---o

Sample Output 1

4

For instance, the substring oooo- corresponding to the 3-rd through 7-th characters of S is a level-4 dango string. No substring of S is a level-5 dango string or above, so you should print 4.


Sample Input 2

1
-

Sample Output 2

-1

Only the empty string and - are the substrings of S. They are not dango strings, so you should print -1.


Sample Input 3

30
-o-o-oooo-oo-o-ooooooo--oooo-o

Sample Output 3

7
F - Invisible Hand

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 300

問題文

りんご市場に N 人の売り手と M 人の買い手がいます。

i 番目の売り手は、A_i 円以上でならりんごを売ってもよいと考えています。

i 番目の買い手は、B_i 円以下でならりんごを買ってもよいと考えています。

次の条件を満たすような最小の整数 X を求めてください。

条件:りんごを X 円で売ってもよいと考える売り手の人数が、りんごを X 円で買ってもよいと考える買い手の人数以上である。

制約

  • 1 \leq N,M \leq 2\times 10^5
  • 1\leq A_i,B_i \leq 10^9
  • 入力は全て整数である

入力

入力は以下の形式で標準入力から与えられる。

N M
A_1 \ldots A_N
B_1 \ldots B_M

出力

答えを出力せよ。


入力例 1

3 4
110 90 120
100 80 120 10000

出力例 1

110

りんごを 110 円で売ってもよいと考える売り手は 1,2 番目の 2 人であり、りんごを 110 円で買ってもよいと考える買い手は 3,4 番目の 2 人であるため、110 は条件を満たします。

110 未満の整数が条件を満たすことはないため、これが答えです。


入力例 2

5 2
100000 100000 100000 100000 100000
100 200

出力例 2

201

入力例 3

3 2
100 100 100
80 120

出力例 3

100

Score : 300 points

Problem Statement

There are N sellers and M buyers in an apple market.

The i-th seller may sell an apple for A_i yen or more (yen is the currency in Japan).

The i-th buyer may buy an apple for B_i yen or less.

Find the minimum integer X that satisfies the following condition.

Condition: The number of people who may sell an apple for X yen is greater than or equal to the number of people who may buy an apple for X yen.

Constraints

  • 1 \leq N,M \leq 2\times 10^5
  • 1\leq A_i,B_i \leq 10^9
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

N M
A_1 \ldots A_N
B_1 \ldots B_M

Output

Print the answer.


Sample Input 1

3 4
110 90 120
100 80 120 10000

Sample Output 1

110

Two sellers, the 1-st and 2-nd, may sell an apple for 110 yen; two buyers, the 3-rd and 4-th, may buy an apple for 110 yen. Thus, 110 satisfies the condition.

Since an integer less than 110 does not satisfy the condition, this is the answer.


Sample Input 2

5 2
100000 100000 100000 100000 100000
100 200

Sample Output 2

201

Sample Input 3

3 2
100 100 100
80 120

Sample Output 3

100
G - Online games

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 400

問題文

あるオンラインゲームがあり、 N 人のプレイヤーが登録しています。
サービス開始日から 10^{100} 日を迎えた今日、 開発者である高橋君がログイン履歴を調べたところ、 i 番目のプレイヤーはサービス開始日を 1 日目として、 A_i 日目から B_i 日間連続でログインし、 それ以外の日はログインしていなかったことが判明しました。 すなわち、i 番目のプレイヤーはサービス開始日から、A_i , A_i+1 , \ldots , A_i+B_i-1 日目に、 かつそれらの日にのみログインしていたことが分かりました。
1\leq k\leq N をみたす各整数 k について、 サービス開始日から今日までの間で、ちょうど k 人がログインしていた日数を答えてください。

制約

  • 1 \leq N \leq 2\times 10^5
  • 1 \leq A_i \leq 10^9
  • 1 \leq B_i \leq 10^9
  • 入力は全て整数である。

入力

入力は以下の形式で標準入力から与えられる。

N
A_1 B_1
A_2 B_2
:
A_N B_N

出力

次のように空白区切りで N 個の整数を出力せよ。

D_1 D_2 \cdots D_N

ただし、 D_i はちょうど i 人がゲームにログインしていた日数を表す。


入力例 1

3
1 2
2 3
3 1

出力例 1

2 2 0

1 番目のプレイヤーは 1 日目と 2 日目に、 2 番目のプレイヤーは 2 日目と 3 日目と 4 日目に、 3 番目のプレイヤーは 3 日目だけにログインしています。 よって、1, 4 日目には 1 人が、2, 3 日目には 2 人がログインしており、 それ以外の日は誰もログインしていない事が分かります。 答えはちょうど 1 人がログインした日数が 2 日、 ちょうど 2 人がログインした日数が 2 日、 ちょうど 3 人がログインした日数が 0 日となります。


入力例 2

2
1000000000 1000000000
1000000000 1000000000

出力例 2

0 1000000000

2 人以上のプレイヤーがちょうど同じ期間にログインしていることもあり得ます。

Score : 400 points

Problem Statement

There is an online game with N registered players.
Today, which is the 10^{100}-th day since its launch, the developer Takahashi examined the users' login history. It turned out that the i-th player logged in for B_i consecutive days from Day A_i, where Day 1 is the launch day, and did not log in for the other days. In other words, the i-th player logged in on Day A_i, A_i+1, \ldots, A_i+B_i-1, and only on those days.
For each integer k such that 1\leq k\leq N, find the number of days on which exactly k players logged in.

Constraints

  • 1 \leq N \leq 2\times 10^5
  • 1 \leq A_i \leq 10^9
  • 1 \leq B_i \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 B_1
A_2 B_2
:
A_N B_N

Output

Print N integers with spaces in between, as follows:

D_1 D_2 \cdots D_N

Here, D_i denotes the number of days on which exactly k players logged in.


Sample Input 1

3
1 2
2 3
3 1

Sample Output 1

2 2 0

The first player logged in on Day 1, 2, the second player logged in on Day 2, 3, 4, and the third player logged in on Day 3 only.

Thus, we can see that Day 1, 4 had 1 player logged in, Day 2, 3 had 2 players logged in, and the other days had no players logged in.

The answer is: there were 2 days with exactly 1 player logged in, 2 days with exactly 2 players logged in, and 0 days with exactly 3 players logged in.


Sample Input 2

2
1000000000 1000000000
1000000000 1000000000

Sample Output 2

0 1000000000

There may be two or more players who logged in during the same period.

H - Ranges on Tree

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 500

問題文

N 頂点の根付き木が与えられます。頂点 1 が根です。
i = 1, 2, \ldots, N-1 について、i 番目の辺は頂点 u_i と頂点 v_i を結んでいます。

i = 1, 2, \ldots, N について、頂点 i を根とする部分木に含まれる頂点全体からなる集合を S_i で表します。(各頂点は自身を根とする部分木に含まれます。すなわち、i \in S_i です。)

また、整数 l, r について、l 以上 r 以下の整数全体からなる集合を [l, r] で表します。 すなわち、[l, r] = \lbrace l, l+1, l+2, \ldots, r \rbrace です。

整数の 2 つ組を N 個並べた列 \big((L_1, R_1), (L_2, R_2), \ldots, (L_N, R_N)\big) であって以下の条件を満たすものを考えます。

  • 1 \leq i \leq N を満たすすべての整数 i について、1 \leq L_i \leq R_i
  • 1 \leq i, j \leq N を満たすすべての整数の組 (i, j) について次が成り立つ
    • S_i \subseteq S_j ならば、[L_i, R_i] \subseteq [L_j, R_j]
    • S_i \cap S_j = \emptyset ならば、[L_i, R_i] \cap [L_j, R_j] = \emptyset

そのような \big((L_1, R_1), (L_2, R_2), \ldots, (L_N, R_N)\big) が少なくとも 1 つ存在することが示せます。 それらのうち、登場する整数の最大値 \max \lbrace L_1, L_2, \ldots, L_N, R_1, R_2, \ldots, R_N \rbrace が最小のものを 1 つ出力してください。(複数ある場合はどれを出力しても正解となります。)

制約

  • 2 \leq N \leq 2 \times 10^5
  • 1 \leq u_i, v_i \leq N
  • 入力はすべて整数
  • 与えられるグラフは木である

入力

入力は以下の形式で標準入力から与えられる。

N
u_1 v_1
u_2 v_2
\vdots
u_{N-1} v_{N-1}

出力

下記の形式で N 行出力せよ。すなわち、i = 1, 2, \ldots, N について、i 行目に L_iR_i を空白区切りで出力せよ。

L_1 R_1
L_2 R_2
\vdots
L_N R_N

入力例 1

3
2 1
3 1

出力例 1

1 2
2 2
1 1

(L_1, R_1) = (1, 2), (L_2, R_2) = (2, 2), (L_3, R_3) = (1, 1) が問題文中の条件を満たします。
実際、[L_2, R_2] \subseteq [L_1, R_1], [L_3, R_3] \subseteq [L_1, R_1], [L_2, R_2] \cap [L_3, R_3] = \emptyset が成り立ちます。
また、\max \lbrace L_1, L_2, L_3, R_1, R_2, R_3 \rbrace = 2 であり、これが最小です。


入力例 2

5
3 4
5 4
1 2
1 4

出力例 2

1 3
3 3
2 2
1 2
1 1

入力例 3

5
4 5
3 2
5 2
3 1

出力例 3

1 1
1 1
1 1
1 1
1 1

Score : 500 points

Problem Statement

You are given a rooted tree with N vertices. The root is Vertex 1.
For each i = 1, 2, \ldots, N-1, the i-th edge connects Vertex u_i and Vertex v_i.

For each i = 1, 2, \ldots, N, let S_i denote the set of all vertices in the subtree rooted at Vertex i. (Each vertex is in the subtree rooted at itself, that is, i \in S_i.)

Additionally, for integers l and r, let [l, r] denote the set of all integers between l and r, that is, [l, r] = \lbrace l, l+1, l+2, \ldots, r \rbrace.

Consider a sequence of N pairs of integers \big((L_1, R_1), (L_2, R_2), \ldots, (L_N, R_N)\big) that satisfies the conditions below.

  • 1 \leq L_i \leq R_i for every integer i such that 1 \leq i \leq N.
  • The following holds for every pair of integers (i, j) such that 1 \leq i, j \leq N.
    • [L_i, R_i] \subseteq [L_j, R_j] if S_i \subseteq S_j
    • [L_i, R_i] \cap [L_j, R_j] = \emptyset if S_i \cap S_j = \emptyset

It can be shown that there is at least one sequence \big((L_1, R_1), (L_2, R_2), \ldots, (L_N, R_N)\big). Among those sequences, print one that minimizes \max \lbrace L_1, L_2, \ldots, L_N, R_1, R_2, \ldots, R_N \rbrace, the maximum integer used. (If there are multiple such sequences, you may print any of them.)

Constraints

  • 2 \leq N \leq 2 \times 10^5
  • 1 \leq u_i, v_i \leq N
  • All values in input are integers.
  • The given graph is a tree.

Input

Input is given from Standard Input in the following format:

N
u_1 v_1
u_2 v_2
\vdots
u_{N-1} v_{N-1}

Output

Print N lines in the format below. That is, for each i = 1, 2, \ldots, N, the i-th line should contain L_i and R_i separated by a space.

L_1 R_1
L_2 R_2
\vdots
L_N R_N

Sample Input 1

3
2 1
3 1

Sample Output 1

1 2
2 2
1 1

(L_1, R_1) = (1, 2), (L_2, R_2) = (2, 2), (L_3, R_3) = (1, 1) satisfies the conditions.
Indeed, we have [L_2, R_2] \subseteq [L_1, R_1], [L_3, R_3] \subseteq [L_1, R_1], [L_2, R_2] \cap [L_3, R_3] = \emptyset.
Additionally, \max \lbrace L_1, L_2, L_3, R_1, R_2, R_3 \rbrace = 2 is the minimum possible value.


Sample Input 2

5
3 4
5 4
1 2
1 4

Sample Output 2

1 3
3 3
2 2
1 2
1 1

Sample Input 3

5
4 5
3 2
5 2
3 1

Sample Output 3

1 1
1 1
1 1
1 1
1 1
I - Make Pair

実行時間制限: 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.