A - ABC400 Party

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

配点 : 100 点

問題文

ABC400 を記念した式典において、400 人の高橋君を A 行 B 列の長方形状に隙間なく並べようとしています。

正整数 A が与えられるので、このような並べ方ができるような正整数 B の値を出力してください。ただし、そのような正整数 B が存在しない場合には -1 を出力してください。

制約

  • A は 1 以上 400 以下の整数

入力

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

A

出力

問題文の指示に従って B の値あるいは -1 を出力せよ。


入力例 1

10

出力例 1

40

400 人の高橋君を 10 行 40 列の長方形状に並べることができます。


入力例 2

11

出力例 2

-1

入力例 3

400

出力例 3

1

Score : 100 points

Problem Statement

In the ceremony commemorating ABC400, we want to arrange 400 people in a rectangular formation of A rows and B columns without any gaps.

You are given a positive integer A. Print the value of a positive integer B for which such an arrangement is possible. If there is no such positive integer B, print -1.

Constraints

  • A is an integer between 1 and 400, inclusive.

Input

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

A

Output

Print the value of B or -1 as specified by the problem statement.


Sample Input 1

10

Sample Output 1

40

We can arrange 400 people in 10 rows and 40 columns.


Sample Input 2

11

Sample Output 2

-1

Sample Input 3

400

Sample Output 3

1
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 - Postal Card

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

配点 : 200 点

問題文

数字のみからなる長さ 6 の文字列が N 個与えられます。i \, (i = 1, 2, \dots, N) 番目のものを S_i と表します。

さらに、数字のみからなる長さ 3 の文字列が M 個与えられます。j \, (j = 1, 2, \dots, M) 番目のものを T_j と表します。

S_1, S_2, \dots, S_N のうち、末尾 3 文字が T_1, T_2, \dots, T_M のいずれかに一致するものの個数を求めてください。

制約

  • 1 \leq N, M \leq 1000
  • N, M は整数
  • 全ての i = 1, 2, \dots, N に対し、S_i は数字のみからなる長さ 6 の文字列
  • 全ての j = 1, 2, \dots, M に対し、T_j は数字のみからなる長さ 3 の文字列

入力

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

N M
S_1
S_2
\vdots
S_N
T_1
T_2
\vdots
T_M

出力

答えを出力せよ。


入力例 1

3 3
142857
004159
071028
159
287
857

出力例 1

2

S_1 の末尾 3 文字は 857 であり、これは T_3 に一致します。
S_2 の末尾 3 文字は 159 であり、これは T_1 に一致します。
S_3 の末尾 3 文字は 028 であり、これは T_1, T_2, T_3 のいずれにも一致しません。

以上から、答えは 2 です。


入力例 2

5 4
235983
109467
823476
592801
000333
333
108
467
983

出力例 2

3

入力例 3

4 4
000000
123456
987111
000000
000
111
999
111

出力例 3

3

Score : 200 points

Problem Statement

You are given N strings of length six each, consisting of digits. Let S_i be the i-th (i = 1, 2, \dots, N) of them.

You are also given M strings of length three each, consisting of digits. Let T_j be the j-th (j = 1, 2, \dots, M) of them.

Find the number of strings among S_1, S_2, \dots, S_N whose last three characters coincide with one or more of T_1, T_2, \dots, T_M.

Constraints

  • 1 \leq N, M \leq 1000
  • N and M are integers.
  • S_i is a string of length 6 consisting of digits, for all i = 1, 2, \dots, N.
  • T_j is a string of length 3 consisting of digits, for all j = 1, 2, \dots, M.

Input

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

N M
S_1
S_2
\vdots
S_N
T_1
T_2
\vdots
T_M

Output

Print the answer.


Sample Input 1

3 3
142857
004159
071028
159
287
857

Sample Output 1

2

The last three characters of S_1 are 857, which coincide with T_3.
The last three characters of S_2 are 159, which coincide with T_1.
The last three characters of S_3 are 028, which do not coincide with T_1, T_2, or T_3.

Thus, the answer is 2.


Sample Input 2

5 4
235983
109467
823476
592801
000333
333
108
467
983

Sample Output 2

3

Sample Input 3

4 4
000000
123456
987111
000000
000
111
999
111

Sample Output 3

3
D - Looped Rope

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

配点 : 200 点

問題文

縦 H マス、横 W マスのマス目があります。 上から i 行目 (1\le i\le H) 、左から j 列目 (1\le j\le W) のマスをマス (i,j) と呼ぶことにします。

それぞれのマスは白もしくは黒のどちらか 1 色で塗られています。 マスに塗られている色は H 個の文字列 S _ 1,S _ 2,\ldots,S _ H で表され、S _ i\ (1\le i\le H) の j 文字目 (1\le j\le W) が . のとき、マス (i,j) は白で塗られており、S _ i\ (1\le i\le H) の j 文字目 (1\le j\le W) が # のとき、マス (i,j) は黒で塗られています。

マス目が以下の条件を満たすか判定してください。

  • どの黒で塗られたマスについても、上下左右で隣り合うマスのうち黒く塗られているものは 2 つもしくは 4 つである。

ただし、マス (i,j)\ (1\le i\le H,1\le j\le W) とマス (k,l)\ (1\le k\le H,1\le l\le W) は、|i-k|+|j-l|=1 であるとき、かつそのときに限り上下左右で隣り合っているとします。

制約

  • 1\le H\le 20
  • 1\le W\le 20
  • H,W は整数
  • S _ i は . および # からなる長さ W の文字列 (1\le i\le H)

入力

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

H W
S _ 1
S _ 2
\vdots
S _ H

出力

与えられたマス目が条件を満たしているとき Yes を、条件を満たしていないとき No を出力せよ。


入力例 1

8 7
.######
##....#
#.###.#
#.#.#.#
#.#.#.#
#.#####
#...#..
#####..

出力例 1

Yes

例えば、マス (6,3) は黒で塗られており、隣り合っているマス (5,3),(6,2),(6,4),(7,3) のうち、マス (5,3) およびマス (6,4) の 2 マスが黒で塗られているため、条件を満たしています。

他の黒で塗られたどのマスについても条件を満たしているため、Yes を出力してください。


入力例 2

1 2
##

出力例 2

No

マス (1,1) は黒で塗られていますが、隣り合っているマスは 1 つしかないため、条件を満たしていません。

よって、No を出力して下さい。


入力例 3

4 3
...
...
...
...

出力例 3

Yes

黒で塗られているマスがないため、条件を満たしています。

よって、Yes を出力してください。


入力例 4

15 18
##.###..##.##..##.
##.#.##.##.##.####
...##.#.......####
###.###....###.##.
#.##.......#.#....
#..#.##.##.#.#....
#.########.####.##
#.##.##.#....##.##
#......##.........
##.##..#..##..####
.#.#####..#####..#
.#..#...##.#.....#
.#..#.####.#.....#
.##.#.#.#..##..###
..###.###...####..

出力例 4

Yes

Score : 200 points

Problem Statement

There is a grid with H rows and W columns. Let (i,j) denote the cell at the i-th row (1\le i\le H) from the top and the j-th column (1\le j\le W) from the left.

Each cell is painted with one color, white or black. The color painted on the cells is represented by H strings S _ 1,S _ 2,\ldots,S _ H. When the j-th character (1\le j\le W) of S _ i\ (1\le i\le H) is ., cell (i,j) is painted white, and when the j-th character (1\le j\le W) of S _ i\ (1\le i\le H) is #, cell (i,j) is painted black.

Determine whether the grid satisfies the following condition:

  • For every black cell, the number of horizontally or vertically adjacent cells that are painted black is 2 or 4.

Here, cells (i,j)\ (1\le i\le H,1\le j\le W) and (k,l)\ (1\le k\le H,1\le l\le W) are horizontally or vertically adjacent if and only if |i-k|+|j-l|=1.

Constraints

  • 1\le H\le 20
  • 1\le W\le 20
  • H and W are integers.
  • S _ i is a string of length W consisting of . and # (1\le i\le H).

Input

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

H W
S _ 1
S _ 2
\vdots
S _ H

Output

Output Yes if the given grid satisfies the condition, and No if it does not satisfy the condition.


Sample Input 1

8 7
.######
##....#
#.###.#
#.#.#.#
#.#.#.#
#.#####
#...#..
#####..

Sample Output 1

Yes

For example, cell (6,3) is painted black, and among the adjacent cells (5,3),(6,2),(6,4),(7,3), cells (5,3) and (6,4) are painted black, which is 2 cells, so it satisfies the condition.

Every other black cell also satisfies the condition, so output Yes.


Sample Input 2

1 2
##

Sample Output 2

No

Cell (1,1) is painted black, but it has only one adjacent cell, so it does not satisfy the condition.

Therefore, output No.


Sample Input 3

4 3
...
...
...
...

Sample Output 3

Yes

There are no black cells, so the condition is satisfied.

Therefore, output Yes.


Sample Input 4

15 18
##.###..##.##..##.
##.#.##.##.##.####
...##.#.......####
###.###....###.##.
#.##.......#.#....
#..#.##.##.#.#....
#.########.####.##
#.##.##.#....##.##
#......##.........
##.##..#..##..####
.#.#####..#####..#
.#..#...##.#.....#
.#..#.####.#.....#
.##.#.#.#..##..###
..###.###...####..

Sample Output 4

Yes
E - Count Close Pairs

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

配点 : 300 点

問題文

この問題は インタラクティブな問題(あなたが作成したプログラムとジャッジプログラムが標準入出力を介して対話を行う形式の問題)です。

数直線上に、点 1, 2, \ldots, N が この順に 左から右に並んでいます。

最初、あなたには整数 N のみが与えられます。

その後、あなたはジャッジに以下の質問を \bm{2N} 回まで行うことができます。

  • 1 \leq i < j \leq N を満たす整数 i,j を選び、点 i と点 j の距離が 1 以下であるか質問する。

距離が 1 以下の 2 点組の個数、すなわち 1\leq i<j\leq N をみたす整数の組 (i,j) であって、点 i と点 j の距離が 1 以下であるようなものの個数を出力してください。

制約

  • 2 \leq N \leq 10^3
  • N は整数

入出力

最初に、点の個数を表す整数 N を標準入力から受け取ってください。

N

次に、あなたはジャッジに対して問題文中の質問を 2N 回まで繰り返すことができます。

質問は、以下の形式で標準出力に出力してください。 ここで、i,j は 1 \leq i<j \leq N を満たす整数である必要があります。

? i j

これに対する応答として、以下のどちらかが標準入力から与えられます。

Yes
No

ここで、Yes ならば点 i と点 j の距離が 1 以下であることを、No ならば点 i と点 j の距離が 1 より大きいことを表します。

問題の答え X が求まったら、解答を以下の形式で出力してください。 その後、ただちにプログラムを終了してください。

! X

注意点

  • 出力を行うたびに、末尾に改行を入れて標準出力を flush してください。そうしなかった場合、ジャッジ結果が TLE となる可能性があります。
  • 対話の途中で不正な出力を行った、あるいはプログラムが途中で終了した場合のジャッジ結果は不定です。
  • 解答を出力したらただちにプログラムを終了してください。そうしない場合、ジャッジ結果は不定です。
  • 点の配置および答えはあなたとジャッジの対話の開始時に固定され、あなたが行った質問などに応じて変更されることはありません。

入出力例

以下は、N = 3、点 1,2,3 の座標がそれぞれ 0,0.7,1.5 の場合の入出力例です。(点 1,2,3 の座標は入力として与えられません。)

入力 出力 説明
3 N が与えられます。
? 1 2 点 1,2 の間の距離が 1 以下かをジャッジに質問します。
Yes ジャッジから、点 1,2 の間の距離が 1 以下であるという返答を得ます。
? 1 3 点 1,3 の間の距離が 1 以下かをジャッジに質問します。
No ジャッジから、点 1,3 の間の距離が 1 以下でないという返答を得ます。
? 2 3 点 2,3 の間の距離が 1 以下かをジャッジに質問します。
Yes ジャッジから、点 2,3 の間の距離が 1 以下であるという返答を得ます。
! 2 条件をみたす組の数として 2 を解答します。

質問回数は 3 回であり、特に 2N=6 回以下です。
解答した組の数も正しいため、この後ただちにプログラムを終了することで、正解と判定されます。

Score : 300 points

Problem Statement

This is an interactive problem (in which your program and the judge program communicate via Standard Input and Output).

On a number line, points 1, 2, \ldots, N are arranged from left to right in that order.

Initially, you are given only the integer N.

Then, you can ask the judge the following question at most \bm{2N} times.

  • Choose integers i and j satisfying 1 \leq i < j \leq N, and ask whether the distance between points i and j is at most 1.

Output the number of pairs of points whose distance is at most 1, that is, the number of pairs of integers (i,j) satisfying 1 \leq i < j \leq N such that the distance between points i and j is at most 1.

Constraints

  • 2 \leq N \leq 10^3
  • N is an integer.

Interaction

First, receive the integer N representing the number of points from Standard Input:

N

Then, you can repeat the question described in the problem statement to the judge at most 2N times.

Output the question to Standard Output in the following format, where i and j must be integers satisfying 1 \leq i<j \leq N:

? i j

As a response to this, one of the following will be given from Standard Input:

Yes
No

Here, Yes indicates that the distance between points i and j is at most 1, and No indicates that the distance between points i and j is greater than 1.

Once you have found the answer X to the problem, output your answer in the following format, and then terminate the program immediately:

! X

Notes

  • Each time you output something, insert a newline at the end and flush Standard Output. Otherwise, the judge result may be TLE.
  • The judge result is indeterminate if you output something invalid during the interaction, or if the program terminates prematurely.
  • Terminate the program immediately after outputting your answer. Otherwise, the judge result is indeterminate.
  • The arrangement of the points and the answer are fixed at the start of the interaction between you and the judge, and do not change depending on, for example, the questions you make.

Sample Interaction

Below is an example of interaction where N = 3 and the coordinates of points 1,2,3 are 0, 0.7, 1.5, respectively. (The coordinates of points 1,2,3 are not given as input.)

Input Output Explanation
3 N is given.
? 1 2 Ask the judge whether the distance between points 1 and 2 is at most 1.
Yes Obtain the response from the judge that the distance between points 1 and 2 is at most 1.
? 1 3 Ask the judge whether the distance between points 1 and 3 is at most 1.
No Obtain the response from the judge that the distance between points 1 and 3 is not at most 1.
? 2 3 Ask the judge whether the distance between points 2 and 3 is at most 1.
Yes Obtain the response from the judge that the distance between points 2 and 3 is at most 1.
! 2 Answer 2 as the number of pairs satisfying the condition.

The number of questions is 3, which is in particular at most 2N=6.
Since the answered number of pairs is also correct, the program will be judged as correct if it terminates immediately after this.

F - Jumping Takahashi

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

配点 : 300 点

問題文

高橋君は数直線上の座標 0 の位置にいます。

これから高橋君は N 回のジャンプを行います。i \, (1 \leq i \leq N) 回目のジャンプでは、正の方向に a_i または b_i 移動します。

N 回のジャンプの後に座標 X の位置にいるようにすることはできますか?

制約

  • 1 \leq N \leq 100
  • 1 \leq a_i \lt b_i \leq 100 \, (1 \leq i \leq N)
  • 1 \leq X \leq 10000
  • 入力は全て整数

入力

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

N X
a_1 b_1
\vdots
a_N b_N

出力

N 回のジャンプの後に座標 X の位置にいるようにすることができるならば Yes と、そうでないなら No と出力せよ。


入力例 1

2 10
3 6
4 5

出力例 1

Yes

1 回目のジャンプでは b_1 (= 6) 移動し、2 回目のジャンプでは a_2 (= 4) 移動することで、座標 X (= 10) の位置にいるようにすることができます。


入力例 2

2 10
10 100
10 100

出力例 2

No

1 回目のジャンプの後に座標 X (= 10) の位置にいるようにすることはできますが、全てのジャンプの後に座標 X (= 10) の位置にいるようにすることはできません。


入力例 3

4 12
1 8
5 7
3 4
2 6

出力例 3

Yes

Score : 300 points

Problem Statement

Takahashi is standing at the coordinate 0 on a number line.

He will now perform N jumps. In the i-th jump (1 \leq i \leq N), he moves a_i or b_i in the positive direction.

Is it possible for him to be at the coordinate X after N jumps?

Constraints

  • 1 \leq N \leq 100
  • 1 \leq a_i \lt b_i \leq 100 \, (1 \leq i \leq N)
  • 1 \leq X \leq 10000
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N X
a_1 b_1
\vdots
a_N b_N

Output

If it is possible for Takahashi to be at the coordinate X after N jumps, print Yes; otherwise, print No.


Sample Input 1

2 10
3 6
4 5

Sample Output 1

Yes

By moving b_1 (= 6) in the first jump and a_2 (= 4) in the second jump, he can be at the coordinate X (= 10).


Sample Input 2

2 10
10 100
10 100

Sample Output 2

No

He can be at the coordinate X (= 10) after the first jump, but not after all jumps.


Sample Input 3

4 12
1 8
5 7
3 4
2 6

Sample Output 3

Yes
G - Intersecting Intervals

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

配点 : 400 点

問題文

N 個の実数の区間が与えられます。i\,(1 \leq i \leq N) 番目の区間は [l_i,r_i] です。i 番目の区間と j 番目の区間が共通部分を持つような組 (i,j)\,(1\leq i < j \leq N) の個数を求めてください。

制約

  • 2 \leq N \leq 5 \times 10^5
  • 0 \leq l_i < r_i \leq 10^9
  • 入力はすべて整数

入力

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

N
l_1 r_1
l_2 r_2
\vdots
l_N r_N

出力

答えを出力せよ。


入力例 1

3
1 5
7 8
3 7

出力例 1

2

与えられた区間は [1,5], [7,8], [3,7] です。このうち,1 番目と 3 番目、 2 番目と 3 番目の区間が共通部分を持つため、答えは 2 です。


入力例 2

3
3 4
2 5
1 6

出力例 2

3

入力例 3

2
1 2
3 4

出力例 3

0

Score : 400 points

Problem Statement

You are given N intervals of real numbers. The i-th (1 \leq i \leq N) interval is [l_i, r_i]. Find the number of pairs (i, j)\,(1 \leq i < j \leq N) such that the i-th and j-th intervals intersect.

Constraints

  • 2 \leq N \leq 5 \times 10^5
  • 0 \leq l_i < r_i \leq 10^9
  • All input values are integers.

Input

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

N
l_1 r_1
l_2 r_2
\vdots
l_N r_N

Output

Print the answer.


Sample Input 1

3
1 5
7 8
3 7

Sample Output 1

2

The given intervals are [1,5], [7,8], [3,7]. Among these, the 1-st and 3-rd intervals intersect, as well as the 2-nd and 3-rd intervals, so the answer is 2.


Sample Input 2

3
3 4
2 5
1 6

Sample Output 2

3

Sample Input 3

2
1 2
3 4

Sample Output 3

0
H - Takahashi is Slime 2

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

配点 : 450 点

問題文

縦 H 行横 W 列のマス目があります。 上から i 行目 (1\leq i\leq H)、左から j 列目 (1\leq j\leq W) のマスをマス (i,j) と呼ぶことにします。

はじめ、マス (i,j) には強さ S _ {i,j} のスライムがおり、マス (P,Q) にいるスライムが高橋くんです。

高橋くんが以下の行動を好きな回数(0 回でもよい)行ったあとの、高橋くんの強さとしてありえる最大値を求めてください。

  • 高橋くんに隣接するスライムのうち、強さが高橋くんの強さの \dfrac1X 倍未満のものを選んで吸収する。 その結果、吸収されたスライムは消滅し、高橋君の強さは吸収したスライムの強さだけ増加する。

上記の行動の際、スライムが吸収され消滅したことで生じた隙間は直ちに高橋くんによって埋められ、消滅したスライムに隣接していたスライム(それらが存在すれば)は新たに高橋くんと隣接します(入出力例1の説明も参照してください)。

制約

  • 1\leq H,W\leq500
  • 1\leq P\leq H
  • 1\leq Q\leq W
  • 1\leq X\leq10^9
  • 1\leq S _ {i,j}\leq10^{12}
  • 入力はすべて整数

入力

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

H W X 
P Q
S _ {1,1} S _ {1,2} \ldots S _ {1,W}
S _ {2,1} S _ {2,2} \ldots S _ {2,W}
\vdots
S _ {H,1} S _ {H,2} \ldots S _ {H,W}

出力

高橋くんが行動を行ったあとの高橋くんの強さとしてありえる最大値を出力せよ。


入力例 1

3 3 2
2 2
14 6 9
4 9 20
17 15 7

出力例 1

28

はじめ、それぞれのマスにいるスライムの強さは以下の図のようになっています。

例えば、高橋くんは次のように行動を行うことができます。

  • マス (2,1) にいるスライムを吸収する。高橋くんの強さは 9+4=13 となり、新たにマス (1,1) のスライムとマス (3,1) のスライムが高橋くんと隣接する。
  • マス (1,2) にいるスライムを吸収する。高橋くんの強さは 13+6=19 となり、新たにマス (1,3) のスライムが高橋くんと隣接する。
  • マス (1,3) にいるスライムを吸収する。高橋くんの強さは 19+9=28 となる。

以上の行動を行ったあと、高橋くんの強さは 28 となります。

高橋くんがどのように行動を行っても、高橋くんの強さを 28 より大きくすることはできないため、28 を出力してください。

高橋くんの強さの \dfrac12 倍未満のスライムしか吸収できないことに注意してください。 例えば、上図の右側の状態からマス (1,1) にいるスライムを吸収することはできません。


入力例 2

3 4 1
1 1
5 10 1 1
10 1 1 1
1 1 1 1

出力例 2

5

高橋くんはどのスライムも吸収できません。


入力例 3

8 10 2
1 5
388 130 971 202 487 924 247 286 237 316
117 166 918 106 336 928 493 391 235 398
124 280 425 955 212 988 227 222 307 226
336 302 478 246 950 368 291 236 170 101
370 200 204 141 287 410 388 314 205 460
291 104 348 337 404 399 416 263 415 339
105 420 302 334 231 481 466 366 401 452
119 432 292 403 371 417 351 231 482 184

出力例 3

1343

Score : 450 points

Problem Statement

There is a grid with H horizontal rows and W vertical columns. Let (i, j) denote the cell at the i-th row (1\leq i\leq H) from the top and j-th column (1\leq j\leq W) from the left.

Initially, there is a slime with strength S _ {i,j} in cell (i,j), and Takahashi is the slime in the cell (P,Q).

Find the maximum possible strength of Takahashi after performing the following action any number of times (possibly zero):

  • Among the slimes adjacent to him, choose one whose strength is strictly less than \dfrac{1}{X} times his strength and absorb it. As a result, the absorbed slime disappears, and Takahashi's strength increases by the strength of the absorbed slime.

When performing the above action, the gap left by the disappeared slime is immediately filled by Takahashi, and the slimes that were adjacent to the disappeared one (if any) become newly adjacent to Takahashi (refer to the explanation in sample 1).

Constraints

  • 1\leq H,W\leq500
  • 1\leq P\leq H
  • 1\leq Q\leq W
  • 1\leq X\leq10^9
  • 1\leq S _ {i,j}\leq10^{12}
  • All input values are integers.

Input

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

H W X 
P Q
S _ {1,1} S _ {1,2} \ldots S _ {1,W}
S _ {2,1} S _ {2,2} \ldots S _ {2,W}
\vdots
S _ {H,1} S _ {H,2} \ldots S _ {H,W}

Output

Print the maximum possible strength of Takahashi after performing the action.


Sample Input 1

3 3 2
2 2
14 6 9
4 9 20
17 15 7

Sample Output 1

28

Initially, the strength of the slime in each cell is as follows:

For example, Takahashi can act as follows:

  • Absorb the slime in cell (2,1). His strength becomes 9+4=13, and the slimes in cells (1,1) and (3,1) become newly adjacent to him.
  • Absorb the slime in cell (1,2). His strength becomes 13+6=19, and the slime in cell (1,3) becomes newly adjacent to him.
  • Absorb the slime in cell (1,3). His strength becomes 19+9=28.

After these actions, his strength is 28.

No matter how he acts, it is impossible to get a strength greater than 28, so print 28.

Note that Takahashi can only absorb slimes whose strength is strictly less than half of his strength. For example, in the figure on the right above, he cannot absorb the slime in cell (1,1).


Sample Input 2

3 4 1
1 1
5 10 1 1
10 1 1 1
1 1 1 1

Sample Output 2

5

He cannot absorb any slimes.


Sample Input 3

8 10 2
1 5
388 130 971 202 487 924 247 286 237 316
117 166 918 106 336 928 493 391 235 398
124 280 425 955 212 988 227 222 307 226
336 302 478 246 950 368 291 236 170 101
370 200 204 141 287 410 388 314 205 460
291 104 348 337 404 399 416 263 415 339
105 420 302 334 231 481 466 366 401 452
119 432 292 403 371 417 351 231 482 184

Sample Output 3

1343
I - Many Lamps

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

配点 : 550 点

問題文

頂点に 1 から N の、辺に 1 から M の番号がついた N 頂点 M 辺の単純グラフがあります。辺 i は頂点 u_i と頂点 v_i を結んでいます。
各頂点にはランプが 1 個ずつ載っています。はじめ、全てのランプは消えています。

以下の操作を 0 回以上 M 回以下行うことで、ランプがちょうど K 個ついた状態にできるかどうかを判定してください。

  • 辺を 1 本選ぶ。辺の両端点を u, v とする。u, v に載っているランプの状態を反転させる。つまり、ランプがついていたら消して、消えていたらつける。

また、ちょうど K 個のランプがついた状態にすることが可能な場合は、そのような操作の手順を出力してください。

制約

  • 1 \leq N \leq 2 \times 10^5
  • 0 \leq M \leq \min\left( 2 \times 10^5, \frac{N(N-1)}{2} \right)
  • 0 \leq K \leq N
  • 1 \leq u_i \lt v_i \leq N
  • 入力で与えられるグラフは単純
  • 入力される値は全て整数

入力

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

N M K
u_1 v_1
u_2 v_2
\vdots
u_M v_M

出力

ちょうど K 個のランプがついた状態にすることが不可能な場合は No を出力せよ。
可能な場合はまず Yes を出力して、その後に操作の手順を以下の形式で出力せよ。

X
e_1 e_2 \dots e_X

ここで、X は操作回数を、e_i は i 番目の操作で選ぶ辺の番号を意味する。これらは次を満たす必要がある。

  • 0 \leq X \leq M
  • 1 \leq e_i \leq M

条件を満たす操作の手順が複数ある場合は、どれを出力しても正解とみなされる。


入力例 1

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

出力例 1

Yes
3
3 4 5

出力例に従って操作を行うと次のようになります。

  • 辺 3 を選ぶ。頂点 2 と頂点 4 に載っているランプをつける。
  • 辺 4 を選ぶ。頂点 3 と頂点 5 に載っているランプをつける。
  • 辺 5 を選ぶ。頂点 1 に載っているランプをつけて、頂点 5 に載っているランプを消す。

操作を全て終了した時点で頂点 1,2,3,4 に載っているランプがついています。よってこの操作の手順は条件を満たしています。

条件を満たす操作の手順としては他に X = 4, (e_1,e_2,e_3,e_4) = (3,4,3,1) などが挙げられます。(同じ辺を 2 回以上選んでもよいです。)


入力例 2

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

出力例 2

No

入力例 3

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

出力例 3

Yes
3
10 9 6

Score: 550 points

Problem Statement

There is a simple graph with N vertices numbered 1 to N and M edges numbered 1 to M. Edge i connects vertices u_i and v_i.
Each vertex has one lamp on it. Initially, all the lamps are off.

Determine whether it is possible to turn exactly K lamps on by performing the following operation between 0 and M times, inclusive.

  • Choose one edge. Let u and v be the endpoints of the edge. Toggle the states of the lamps on u and v. That is, if the lamp is on, turn it off, and vice versa.

If it is possible to turn exactly K lamps on, print a sequence of operations that achieves this state.

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 0 \leq M \leq \min\left( 2 \times 10^5, \frac{N(N-1)}{2} \right)
  • 0 \leq K \leq N
  • 1 \leq u_i < v_i \leq N
  • The given graph is simple.
  • All input values are integers.

Input

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

N M K
u_1 v_1
u_2 v_2
\vdots
u_M v_M

Output

If it is impossible to turn exactly K lamps on, print No.
Otherwise, first print Yes, and then print a sequence of operations in the following format:

X
e_1 e_2 \dots e_X

Here, X is the number of operations, and e_i is the number of the edge chosen in the i-th operation. These must satisfy the following:

  • 0 \leq X \leq M
  • 1 \leq e_i \leq M

If multiple sequences of operations satisfy the conditions, any of them will be considered correct.


Sample Input 1

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

Sample Output 1

Yes
3
3 4 5

If we operate according to the sample output, it will go as follows:

  • Choose edge 3. Turn on the lamps on vertex 2 and vertex 4.
  • Choose edge 4. Turn on the lamps on vertex 3 and vertex 5.
  • Choose edge 5. Turn on the lamp on vertex 1 and turn off the lamp on vertex 5.

After completing all operations, the lamps on vertices 1, 2, 3, and 4 are on. Therefore, this sequence of operations satisfies the conditions.

Other possible sequences of operations that satisfy the conditions include X = 4, (e_1,e_2,e_3,e_4) = (3,4,3,1). (It is allowed to choose the same edge more than once.)


Sample Input 2

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

Sample Output 2

No

Sample Input 3

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

Sample Output 3

Yes
3
10 9 6