A - Long Loong

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100 点

問題文

正の整数 X について、レベル X の 龍文字列 とは、1 個の L, X 個の o, 1 個の n, 1 個の g をこの順に並べた長さ (X+3) の文字列です。

正の整数 N が与えられるので、レベル N の龍文字列を出力してください。
大文字と小文字は区別されることに注意してください。

制約

  • 1\leq N\leq 2024
  • N は整数

入力

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

N

出力

レベル N の龍文字列を出力せよ。


入力例 1

3

出力例 1

Looong

1 個の L, 3 個の o, 1 個の n, 1 個の g をこの順に並べた文字列は Looong です。


入力例 2

1

出力例 2

Long

Score: 100 points

Problem Statement

For a positive integer X, the Dragon String of level X is a string of length (X+3) formed by one L, X occurrences of o, one n, and one g arranged in this order.

You are given a positive integer N. Print the Dragon String of level N.
Note that uppercase and lowercase letters are distinguished.

Constraints

  • 1 \leq N \leq 2024
  • N is an integer.

Input

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

N

Output

Print the Dragon String of level N.


Sample Input 1

3

Sample Output 1

Looong

Arranging one L, three os, one n, and one g in this order yields Looong.


Sample Input 2

1

Sample Output 2

Long
B - Adjacent Product

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100 点

問題文

N 個の整数 A_1,A_2,\dots,A_N が与えられます。 また、B_i=A_i\times A_{i+1}\ (1\leq i\leq N-1) と定めます。

B_1,B_2,\dots,B_{N-1} をこの順に空白区切りで出力してください。

制約

  • 2\leq N \leq 100
  • 1\leq A_i \leq 100
  • 入力は全て整数

入力

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

N
A_1 A_2 \dots A_N

出力

B_1,B_2,\dots,B_{N-1} をこの順に空白区切りで出力せよ。


入力例 1

3
3 4 6

出力例 1

12 24

B_1=A_1\times A_2 = 12, B_2=A_2\times A_3 = 24 です。


入力例 2

5
22 75 26 45 72

出力例 2

1650 1950 1170 3240

Score: 100 points

Problem Statement

You are given N integers A_1, A_2, \dots, A_N. Also, define B_i = A_i \times A_{i+1}\ (1 \leq i \leq N-1).

Print B_1, B_2, \dots, B_{N-1} in this order, separated by spaces.

Constraints

  • 2 \leq N \leq 100
  • 1 \leq A_i \leq 100
  • All input values are integers.

Input

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

N
A_1 A_2 \dots A_N

Output

Print B_1, B_2, \dots, B_{N-1} in this order, separated by spaces.


Sample Input 1

3
3 4 6

Sample Output 1

12 24

We have B_1 = A_1 \times A_2 = 12, B_2 = A_2 \times A_3 = 24.


Sample Input 2

5
22 75 26 45 72

Sample Output 2

1650 1950 1170 3240
C - Seek Grid

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200 点

問題文

N \times N のグリッド S と M\times M のグリッド T が与えられます。上から i 行目、左から j 列目のマス目をマス (i,j) と表します。

S,T の各マスの色はそれぞれ N^2個の文字 S_{i,j} \; (1\leq i,j\leq N) および M^2 個の文字 T_{i,j} \; (1\leq i,j\leq M) によって表されます。 S_{i,j} が . のとき S のマス (i,j) は白色、S_{i,j} が # のとき S のマス (i,j) は黒色で塗られています。T についても同様です。

S の中から T を探してください。具体的には、以下の条件を満たす a,b \; (1 \leq a,b \leq N-M+1) を出力してください。

  • すべての i,j \; (1\leq i,j \leq M) について、S_{a+i-1,b+j-1} = T_{i,j}

制約

  • 1 \leq M \leq N \leq 50
  • N,M は整数
  • S_{i,j},T_{i,j} は . または #
  • 条件を満たす a,b はちょうど 1 組存在する。

入力

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

N M
S_{1,1}S_{1,2}\dots S_{1,N}
S_{2,1}S_{2,2}\dots S_{2,N}
\vdots
S_{N,1}S_{N,2}\dots S_{N,N}
T_{1,1}T_{1,2}\dots T_{1,M}
T_{2,1}T_{2,2}\dots T_{2,M}
\vdots
T_{M,1}T_{M,2}\dots T_{M,M}

出力

a,b をこの順に空白区切りで 1 行に出力せよ。


入力例 1

3 2
#.#
..#
##.
.#
#.

出力例 1

2 2

S の 2 行目から 3 行目、2 列目から 3 列目の 2 \times 2 マスが T と一致します。


入力例 2

2 1
#.
##
.

出力例 2

1 2

Score : 200 points

Problem Statement

You are given an N \times N grid S and an M \times M grid T. The cell at the i-th row from the top and the j-th column from the left is denoted by (i,j).

The colors of the cells in S and T are represented by N^2 characters S_{i,j} (1\leq i,j\leq N) and M^2 characters T_{i,j} (1\leq i,j\leq M), respectively. In grid S, cell (i,j) is white if S_{i,j} is ., and black if S_{i,j} is #. The same applies for grid T.

Find T within S. More precisely, output integers a and b (1 \leq a,b \leq N-M+1) that satisfy the following condition:

  • S_{a+i-1,b+j-1} = T_{i,j} for every i,j (1\leq i,j \leq M).

Constraints

  • 1 \leq M \leq N \leq 50
  • N and M are integers.
  • Each of S_{i,j} and T_{i,j} is . or #.
  • There is exactly one pair (a,b) satisfying the condition.

Input

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

N M
S_{1,1}S_{1,2}\dots S_{1,N}
S_{2,1}S_{2,2}\dots S_{2,N}
\vdots
S_{N,1}S_{N,2}\dots S_{N,N}
T_{1,1}T_{1,2}\dots T_{1,M}
T_{2,1}T_{2,2}\dots T_{2,M}
\vdots
T_{M,1}T_{M,2}\dots T_{M,M}

Output

Print a and b in this order, separated by a space on one line.


Sample Input 1

3 2
#.#
..#
##.
.#
#.

Sample Output 1

2 2

The 2 \times 2 subgrid of S from the 2nd to the 3rd row and from the 2nd to the 3rd column matches T.


Sample Input 2

2 1
#.
##
.

Sample Output 2

1 2
D - Unauthorized

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200 点

問題文

ある日、高橋くんはあるウェブサイトに対して N 回の操作を行いました。

i 回目 (1\leq i\leq N) の操作は文字列 S _ i で表され、次の 4 つのうちいずれかです。

  • S _ i= login である。高橋くんはログイン操作を行い、高橋くんがウェブサイトにログインした状態になる。
  • S _ i= logout である。高橋くんはログアウト操作を行い、高橋くんがウェブサイトにログインしていない状態になる。
  • S _ i= public である。高橋くんはウェブサイトの公開ページにアクセスする。
  • S _ i= private である。高橋くんはウェブサイトの非公開ページにアクセスする。

高橋くんがログインしていない状態で非公開ページにアクセスした時、またその時に限り、ウェブサイトは認証エラーを返します。

ログインした状態でさらにログイン操作をしたり、ログインしていない状態でさらにログアウト操作をしてもエラーにはなりません。 また、認証エラーが返されたあとも、高橋くんは操作を続けることができます。

はじめ、高橋くんはログインしていない状態です。

N 回の操作のうち、高橋くんが認証エラーを受け取った回数を出力してください。

制約

  • 1\leq N\leq100
  • N は整数
  • S _ i は login, logout, public, private のいずれか (1\leq i\leq N)

入力

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

N
S _ 1
S _ 2
\vdots
S _ N

出力

高橋くんが認証エラーを受け取った回数を出力せよ。


入力例 1

6
login
private
public
logout
private
public

出力例 1

1

高橋くんが行うそれぞれの操作の結果は以下のようになります。

  • 高橋くんがウェブサイトにログインした状態になる。
  • 高橋くんは非公開ページにアクセスする。高橋くんは現在ログインしているので、エラーは返されない。
  • 高橋くんは公開ページにアクセスする。
  • 高橋くんがウェブサイトにログインしていない状態になる。
  • 高橋くんは非公開ページにアクセスする。高橋くんは現在ログインしていないので、認証エラーが返される。
  • 高橋くんは公開ページにアクセスする。

高橋くんが認証エラーを受け取るのは 5 回目の操作のみなので、1 を出力してください。


入力例 2

4
private
private
private
logout

出力例 2

3

連続で非公開ページにアクセスしようとした場合、操作のたびに認証エラーを受け取ります。

ログインしていない状態からさらにログアウト操作をした場合には認証エラーは返されないことに注意してください。


入力例 3

20
private
login
private
logout
public
logout
logout
logout
logout
private
login
login
private
login
private
login
public
private
logout
private

出力例 3

3

Score : 200 points

Problem Statement

One day, Takahashi performed N operations on a certain web site.

The i‑th operation (1 \le i \le N) is represented by a string S_i, which is one of the following:

  • S _ i= login: He performs a login operation and becomes logged in to the site.
  • S _ i= logout: He performs a logout operation and becomes not logged in to the site.
  • S _ i= public: He accesses a public page of the site.
  • S _ i= private: He accesses a private page of the site.

The site returns an authentication error if and only if he accesses a private page while he is not logged in.

Logging in again while already logged in, or logging out again while already logged out, does not cause an error. Even after an authentication error is returned, he continues performing the remaining operations.

Initially, he is not logged in.

Print the number of operations among the N operations at which he receives an authentication error.

Constraints

  • 1 \le N \le 100
  • N is an integer.
  • Each S_i is one of login, logout, public, private. (1 \le i \le N)

Input

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

N
S_1
S_2
\vdots
S_N

Output

Print the number of times Takahashi receives an authentication error.


Sample Input 1

6
login
private
public
logout
private
public

Sample Output 1

1

The result of each operation is as follows:

  • Takahashi becomes logged in.
  • He accesses a private page. He is logged in, so no error is returned.
  • He accesses a public page.
  • He becomes logged out.
  • He accesses a private page. He is not logged in, so an authentication error is returned.
  • He accesses a public page.

An authentication error occurs only at the 5th operation, so print 1.


Sample Input 2

4
private
private
private
logout

Sample Output 2

3

If he tries to access private pages consecutively while not logged in, he receives an authentication error for each such operation.

Note that logging out again while already logged out does not cause an authentication error.


Sample Input 3

20
private
login
private
logout
public
logout
logout
logout
logout
private
login
login
private
login
private
login
public
private
logout
private

Sample Output 3

3
E - Blue Spring

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300 点

問題文

高橋君は N 日間の鉄道旅行を計画しています。
高橋君はそれぞれの日について、運賃の通常料金を払うか、1 日周遊パスを 1 枚使用するか選ぶことができます。

ここで、1\leq i\leq N について、i 日目の旅行にかかる運賃の通常料金は F_i 円です。
一方、1 日周遊パスは D 枚セットで P 円で発売されており、何セットでも購入することが可能ですが、D 枚単位でしか購入することができません。
また、購入したパスは 1 枚ずつ好きな日に使うことができ、旅行が終了した時点で余っていても構いません。

N 日間の旅行でかかる金額、すなわち 1 日周遊パスの購入にかかった代金と、1 日周遊パスを利用しなかった日における運賃の通常料金の合計金額の和としてあり得る最小値を求めてください。

制約

  • 1\leq N\leq 2\times 10^5
  • 1\leq D\leq 2\times 10^5
  • 1\leq P\leq 10^9
  • 1\leq F_i\leq 10^9
  • 入力はすべて整数

入力

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

N D P
F_1 F_2 \ldots F_N

出力

N 日間の旅行でかかる金額としてあり得る最小値を出力せよ。


入力例 1

5 2 10
7 1 6 3 6

出力例 1

20

1 日周遊パスを 1 セットだけ購入し、1 日目と 3 日目に使用すると、合計金額は (10\times 1)+(0+1+0+3+6)=20 となり、このときかかる金額が最小となります。
よって、20 を出力します。


入力例 2

3 1 10
1 2 3

出力例 2

6

3 日間すべてにおいて運賃の通常料金を支払ったときに最小となります。


入力例 3

8 3 1000000000
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000

出力例 3

3000000000

1 日周遊パスを 3 セット購入し、8 日間すべてにおいて 1 日周遊パスを利用したときに最小となります。
答えが 32 bit 整数型に収まらないことがあることに注意してください。

Score : 300 points

Problem Statement

Takahashi is planning an N-day train trip.
For each day, he can pay the regular fare or use a one-day pass.

Here, for 1\leq i\leq N, the regular fare for the i-th day of the trip is F_i yen.
On the other hand, a batch of D one-day passes is sold for P yen. You can buy as many passes as you want, but only in units of D.
Each purchased pass can be used on any day, and it is fine to have some leftovers at the end of the trip.

Find the minimum possible total cost for the N-day trip, that is, the cost of purchasing one-day passes plus the total regular fare for the days not covered by one-day passes.

Constraints

  • 1\leq N\leq 2\times 10^5
  • 1\leq D\leq 2\times 10^5
  • 1\leq P\leq 10^9
  • 1\leq F_i\leq 10^9
  • All input values are integers.

Input

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

N D P
F_1 F_2 \ldots F_N

Output

Print the minimum possible total cost for the N-day trip.


Sample Input 1

5 2 10
7 1 6 3 6

Sample Output 1

20

If he buys just one batch of one-day passes and uses them for the first and third days, the total cost will be (10\times 1)+(0+1+0+3+6)=20, which is the minimum cost needed.
Thus, print 20.


Sample Input 2

3 1 10
1 2 3

Sample Output 2

6

The minimum cost is achieved by paying the regular fare for all three days.


Sample Input 3

8 3 1000000000
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000

Sample Output 3

3000000000

The minimum cost is achieved by buying three batches of one-day passes and using them for all eight days.
Note that the answer may not fit into a 32-bit integer type.

F - Lining Up 2

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300 点

問題文

人 1, 人 2,\ldots, 人 N の N 人が一列に並んでいます。

並び方の情報が長さ N の数列 A=(A _ 1,A _ 2,\ldots,A _ N) として与えられます。

A _ i\ (1\leq i\leq N) は次のような情報を表しています。

  • A _ i=-1 のとき、人 i は先頭に並んでいる。
  • A _ i\neq -1 のとき、人 i は人 A _ i のすぐ後ろに並んでいる。

列に並んでいる人の番号を先頭から順番に出力してください。

制約

  • 1\leq N\leq3\times10 ^ 5
  • A _ i=-1 もしくは 1\leq A _ i\leq N\ (1\leq i\leq N)
  • 情報と矛盾しないような N 人の並び方がただ 1 通り存在する
  • 入力はすべて整数

入力

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

N
A _ 1 A _ 2 \ldots A _ N

出力

人 s _ 1, 人 s _ 2,\ldots, 人 s _ N がこの順に列に並んでいるとき、s _ 1,s _ 2,\ldots,s _ N をこの順に空白を区切りとして出力せよ。


入力例 1

6
4 1 -1 5 3 2

出力例 1

3 5 4 1 2 6

先頭から、人 3, 人 5, 人 4, 人 1, 人 2, 人 6 がこの順に列に並んでいるとき、与えられた情報と一致しています。

実際、

  • 人 1 は人 4 のすぐ後ろに並んでいます。
  • 人 2 は人 1 のすぐ後ろに並んでいます。
  • 人 3 は先頭に並んでいます。
  • 人 4 は人 5 のすぐ後ろに並んでいます。
  • 人 5 は人 3 のすぐ後ろに並んでいます。
  • 人 6 は人 2 のすぐ後ろに並んでいます。

となり、与えられた情報と一致していることが確認できます。

よって、3,5,4,1,2,6 をこの順に空白区切りで出力してください。


入力例 2

10
-1 1 2 3 4 5 6 7 8 9

出力例 2

1 2 3 4 5 6 7 8 9 10

入力例 3

30
3 25 20 6 18 12 26 1 29 -1 21 17 23 9 8 30 10 15 22 27 4 13 5 11 16 24 28 2 19 7

出力例 3

10 17 12 6 4 21 11 24 26 7 30 16 25 2 28 27 20 3 1 8 15 18 5 23 13 22 19 29 9 14

Score: 300 points

Problem Statement

There are N people standing in a line: person 1, person 2, \ldots, person N.

You are given the arrangement of the people as a sequence A=(A _ 1,A _ 2,\ldots,A _ N) of length N.

A _ i\ (1\leq i\leq N) represents the following information:

  • if A _ i=-1, person i is at the front of the line;
  • if A _ i\neq -1, person i is right behind person A _ i.

Print the people's numbers in the line from front to back.

Constraints

  • 1\leq N\leq3\times10 ^ 5
  • A _ i=-1 or 1\leq A _ i\leq N\ (1\leq i\leq N)
  • There is exactly one way to arrange the N people consistent with the information given.
  • All input values are integers.

Input

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

N
A _ 1 A _ 2 \ldots A _ N

Output

If person s _ 1, person s _ 2, \ldots, person s _ N are standing in the line in this order, print s _ 1, s _ 2, \ldots, and s _ N in this order, separated by spaces.


Sample Input 1

6
4 1 -1 5 3 2

Sample Output 1

3 5 4 1 2 6

If person 3, person 5, person 4, person 1, person 2, and person 6 stand in line in this order from front to back, the arrangement matches the given information.

Indeed, it can be seen that:

  • person 1 is standing right behind person 4,
  • person 2 is standing right behind person 1,
  • person 3 is at the front of the line,
  • person 4 is standing right behind person 5,
  • person 5 is standing right behind person 3, and
  • person 6 is standing right behind person 2.

Thus, print 3, 5, 4, 1, 2, and 6 in this order, separated by spaces.


Sample Input 2

10
-1 1 2 3 4 5 6 7 8 9

Sample Output 2

1 2 3 4 5 6 7 8 9 10

Sample Input 3

30
3 25 20 6 18 12 26 1 29 -1 21 17 23 9 8 30 10 15 22 27 4 13 5 11 16 24 28 2 19 7

Sample Output 3

10 17 12 6 4 21 11 24 26 7 30 16 25 2 28 27 20 3 1 8 15 18 5 23 13 22 19 29 9 14
G - Clouds

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 425 点

問題文

空は 2000 \times 2000 のマス目で表されます。
空を見上げた時、上から r 行目、左から c 列目にあるマスを (r,c) と呼びます。

いま、この空には雲 1,2,\dots,N が浮かんでいます。
整数の組 (r,c) が U_i \le r \le D_i, L_i \le c \le R_i を満たすとき、またその時に限り、 (r,c) は雲 i で覆われています。

k=1,2,\dots,N について、以下の問いに答えてください。

  • N 個の雲のうち、雲 k のみを取り除く。この時点で空には N-1 個の雲が浮かんでいる。このとき、どの雲にも覆われていないマスがいくつあるか答えよ。

制約

  • 1 \le N \le 2 \times 10^5
  • 1 \le U_i \le D_i \le 2000
  • 1 \le L_i \le R_i \le 2000
  • 入力される値は全て整数

入力

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

N
U_1 D_1 L_1 R_1
U_2 D_2 L_2 R_2
\vdots
U_N D_N L_N R_N

出力

N 行出力せよ。
i 行目には、 k=i とした場合の問いの答えを出力せよ。


入力例 1

5
2 4 1 4
3 3 3 5
1 3 4 6
4 5 3 5
5 5 4 6

出力例 1

3999983
3999976
3999982
3999978
3999977

図は、空のうち左上 5 \times 6 の領域を抜き出したものです。

  • 雲 1 を取り除いた際、何らかの雲に覆われているマスは 17 マスなので、どの雲にも覆われていないマスは 3999983 マスです。
  • 雲 2 を取り除いた際、何らかの雲に覆われているマスは 24 マスなので、どの雲にも覆われていないマスは 3999976 マスです。
  • 雲 3 を取り除いた際、何らかの雲に覆われているマスは 18 マスなので、どの雲にも覆われていないマスは 3999982 マスです。
  • 雲 4 を取り除いた際、何らかの雲に覆われているマスは 22 マスなので、どの雲にも覆われていないマスは 3999978 マスです。
  • 雲 5 を取り除いた際、何らかの雲に覆われているマスは 23 マスなので、どの雲にも覆われていないマスは 3999977 マスです。

Score : 425 points

Problem Statement

The sky is represented by a 2000 \times 2000 grid.
When looking up at the sky, the cell at the r-th row from the top and c-th column from the left is called (r,c).

Currently, there are clouds 1,2,\dots,N floating in this sky.
The cell (r,c) is covered by cloud i if and only if it satisfies U_i \le r \le D_i and L_i \le c \le R_i.

For k=1,2,\dots,N, answer the following question:

  • Remove only cloud k from the N clouds. At this point, there are N-1 clouds floating in the sky. How many cells are not covered by any cloud?

Constraints

  • 1 \le N \le 2 \times 10^5
  • 1 \le U_i \le D_i \le 2000
  • 1 \le L_i \le R_i \le 2000
  • All input values are integers.

Input

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

N
U_1 D_1 L_1 R_1
U_2 D_2 L_2 R_2
\vdots
U_N D_N L_N R_N

Output

Output N lines.
The i-th line should contain the answer to the question when k=i.


Sample Input 1

5
2 4 1 4
3 3 3 5
1 3 4 6
4 5 3 5
5 5 4 6

Sample Output 1

3999983
3999976
3999982
3999978
3999977

The figure shows the top-left 5 \times 6 region of the sky.

  • When cloud 1 is removed, the number of cells covered by some cloud is 17, so the number of cells not covered by any cloud is 3999983.
  • When cloud 2 is removed, the number of cells covered by some cloud is 24, so the number of cells not covered by any cloud is 3999976.
  • When cloud 3 is removed, the number of cells covered by some cloud is 18, so the number of cells not covered by any cloud is 3999982.
  • When cloud 4 is removed, the number of cells covered by some cloud is 22, so the number of cells not covered by any cloud is 3999978.
  • When cloud 5 is removed, the number of cells covered by some cloud is 23, so the number of cells not covered by any cloud is 3999977.
H - Safety Journey

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 500 点

問題文

AtCoder国には N 個の都市があり、都市 1 , 都市 2 , \ldots , 都市 N と番号付けられています。 最初、どの 2 つの相異なる都市の間も双方向に通れる道で結ばれていましたが、老朽化が進み、これらのうち M 本の道が使えなくなってしまいました。具体的には 1\leq i \leq M について都市 U_i と都市 V_i を結ぶ道が使えなくなってしまいました。

いま、高橋君は都市 1 で始まり、都市 1 で終わる K 日間の旅をしようと考えました。都市 1 で始まり、都市 1 で終わる K 日間の旅とは、 K+1 個の都市の列 (A_0, A_1, \ldots, A_K) であって、A_0=A_K=1 をみたし、 0\leq i\leq K-1 について A_i と A_{i+1} が相異なり、かつ都市 A_i と都市 A_{i+1} が現在も使用可能な道で結ばれているものを指します。

都市 1 で始まり、都市 1 で終わる K 日間の相異なる旅の数を 998244353 で割った余りを出力してください。ただし、 2 つの K 日間の旅 (A_0, A_1, \ldots, A_K) と (B_0, B_1, \ldots, B_K) が相異なるとは、ある i が存在して A_i\neq B_i となることを言います。

制約

  • 2 \leq N \leq 5000
  • 0 \leq M \leq \min\left( \frac{N(N-1)}{2},5000 \right)
  • 2 \leq K \leq 5000
  • 1 \leq U_i<V_i \leq N
  • (U_i, V_i) は全て互いに相異なる。
  • 入力は全て整数である。

入力

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

N M K
U_1 V_1
:
U_M V_M

出力

答えを出力せよ。


入力例 1

3 1 4
2 3

出力例 1

4

次のような 4 種類の旅が存在します。

  • (1,2,1,2,1)
  • (1,2,1,3,1)
  • (1,3,1,2,1)
  • (1,3,1,3,1)

これ以外に条件をみたすようなものは無いため、 4 を出力します。


入力例 2

3 3 3
1 2
1 3
2 3

出力例 2

0

使える道が 1 本も残っておらず、条件をみたすような旅は存在しません。


入力例 3

5 3 100
1 2
4 5
2 3

出力例 3

428417047

Score : 500 points

Problem Statement

The Republic of AtCoder has N cities, called City 1, City 2, \ldots, City N. Initially, there was a bidirectional road between every pair of different cities, but M of these roads have become unusable due to deterioration over time. More specifically, for each 1\leq i \leq M, the road connecting City U_i and City V_i has become unusable.

Takahashi will go for a K-day trip that starts and ends in City 1. Formally speaking, a K-day trip that starts and ends in City 1 is a sequence of K+1 cities (A_0, A_1, \ldots, A_K) such that A_0=A_K=1 holds and for each 0\leq i\leq K-1, A_i and A_{i+1} are different and there is still a usable road connecting City A_i and City A_{i+1}.

Print the number of different K-day trips that start and end in City 1, modulo 998244353. Here, two K-day trips (A_0, A_1, \ldots, A_K) and (B_0, B_1, \ldots, B_K) are said to be different when there exists an i such that A_i\neq B_i.

Constraints

  • 2 \leq N \leq 5000
  • 0 \leq M \leq \min\left( \frac{N(N-1)}{2},5000 \right)
  • 2 \leq K \leq 5000
  • 1 \leq U_i<V_i \leq N
  • All pairs (U_i, V_i) are pairwise distinct.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M K
U_1 V_1
:
U_M V_M

Output

Print the answer.


Sample Input 1

3 1 4
2 3

Sample Output 1

4

There are four different trips as follows.

  • (1,2,1,2,1)
  • (1,2,1,3,1)
  • (1,3,1,2,1)
  • (1,3,1,3,1)

No other trip is valid, so we should print 4.


Sample Input 2

3 3 3
1 2
1 3
2 3

Sample Output 2

0

No road remains usable, so there is no valid trip.


Sample Input 3

5 3 100
1 2
4 5
2 3

Sample Output 3

428417047
I - Half and Median

Time Limit: 4 sec / Memory Limit: 1024 MiB

配点 : 550 点

問題文

N 本の棒があり、i 本目の棒の長さは A_i です。
以下の操作を M 回行います。

  • 長さが 2 以上の棒を 1 本選び、この棒の長さを l と置く。この棒を、長さが \left\lfloor\frac{l}{2}\right\rfloor と \left\lceil\frac{l}{2}\right\rceil の 2 本の棒に分割する。

制約から、操作を M 回行うことは可能であることが証明できます。
M 回の操作後、N+M 本の棒が残りますが、これらの棒の長さの中央値としてありうる値の最大値を求めてください。

1 つの入力につき、T 個のテストケースを解いてください。

中央値とは N が偶数であるとき、N+1 個の数の中央値とは、それらを昇順に並べたときに (1+\frac{N}{2}) 番目の値です。
例えば、(1,3,4,5,8) の中央値は 4、(2,2,2) の中央値は 2 です。
本問題において、長さの中央値を考える棒の本数は制約から常に奇数であることに注意してください。

制約

  • 1 \leq T \leq 10^5
  • 1 \leq N \leq 10^5
  • 1 \leq A_i \leq 10^9
  • 1 \leq M \leq \sum_{i=1}^{N}{A_i} - N
  • N+M は奇数
  • 全てのテストケースにおける N の総和は 10^5 以下
  • 入力される値は全て整数

入力

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

T
case_1
case_2
\vdots
case_T

各ケースは以下の形式で与えられる。

N M  
A_1 A_2 \ldots A_N

出力

答えを合計 T 行で出力せよ。 t 行目には、t 番目のテストケースの答えを出力せよ。


入力例 1

3
5 2
14 2 5 19 1
10 1
10 6 7 6 2 20 9 16 3 3
4 1
444 444 44 444

出力例 1

7
7
444

1 つ目のテストケースでは、1 回目の操作で長さ 14 の棒を選ぶとその棒は長さ 7 の棒 2 本に分割され、6 本の棒の長さは 7,7,2,5,19,1 になります。 2 回目の操作で長さ 19 の棒を選ぶとその棒は長さ 9,10 の棒 2 本に分割され、7 本の棒の長さは 7,7,2,5,9,10,1 になります。 このとき、棒の長さの中央値は 7 になります。

Score : 550 points

Problem Statement

There are N sticks, and the length of the i-th stick is A_i.
You will perform the following operation M times:

  • Choose one stick of length at least 2, and let l be the length of this stick. Divide this stick into two sticks of lengths \left\lfloor\frac{l}{2}\right\rfloor and \left\lceil\frac{l}{2}\right\rceil.

From the constraints, it can be proved that it is possible to perform the operation M times.
After M operations, N+M sticks will remain. Find the maximum possible value of the median of the lengths of these sticks.

Solve T test cases per input.

What is the median? When N is even, the median of N+1 numbers is the (1+\frac{N}{2})-th value when they are sorted in ascending order.
For example, the median of (1,3,4,5,8) is 4, and the median of (2,2,2) is 2.
Note that in this problem, from the constraints, the number of sticks to consider for the median of lengths is always odd.

Constraints

  • 1 \leq T \leq 10^5
  • 1 \leq N \leq 10^5
  • 1 \leq A_i \leq 10^9
  • 1 \leq M \leq \sum_{i=1}^{N}{A_i} - N
  • N+M is odd.
  • The sum of N over all test cases is at most 10^5.
  • All input values are integers.

Input

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

T
case_1
case_2
\vdots
case_T

Each case is given in the following format:

N M  
A_1 A_2 \ldots A_N

Output

Output the answers in T lines in total. The t-th line should contain the answer for the t-th test case.


Sample Input 1

3
5 2
14 2 5 19 1
10 1
10 6 7 6 2 20 9 16 3 3
4 1
444 444 44 444

Sample Output 1

7
7
444

In the first test case, if you choose the stick of length 14 in the first operation, it is divided into two sticks of length 7, and now you have six sticks of lengths 7,7,2,5,19,1. If you choose the stick of length 19 in the second operation, it is divided into two sticks of lengths 9,10, and now you have seven sticks of lengths 7,7,2,5,9,10,1. In this case, the median of the stick lengths is 7.