alexjercan/bugnet huggingface dataset:
Problem I: Aaron と Bruce

Aaron は凶悪な犯罪者である．
彼は幾度も犯罪を繰り返しながら
（万引き2回，のぞき16回，下着泥棒256回，食い逃げ65,536回）
も，その人並み外れた身体能力を用いて
警察の手から逃れ続けてきた．
Bruce は警察官である．
彼は突出した運動能力は持っていないが，
写真撮影が趣味であり，
彼の撮った写真が雑誌に載るほどの腕前を持っている．

ある日，Bruce は山奥に写真撮影をしに来た．
すると偶然 Aaron のアジトを突き止めてしまった．
Bruce が逃げる Aaron を追っていくと，
彼らは落とし穴に落ちて古代遺跡の中に迷い込んでしまった．

古代遺跡の中はいくつかの部屋と，部屋どうしを結ぶ通路で構成されている．
古代遺跡に M 個の部屋があるとき，
遺跡内の部屋にはそれぞれ 0 から M−1 までの番号がつけられている．

Aaron は逃げている間に時効を迎えるかもしれないと考えたので，
Bruce が最適に移動したときに一番長い間逃げ続けられるように
遺跡の中を移動する．
Bruce は早く Aaron を写真に収めたいので，
Aaron が最適に移動したときに一番早く Bruce を写真に収められるように
遺跡の中を移動する．

Aaron と Bruce は順番に行動する．
最初は Aaron の番とする．
それぞれの順番のとき，隣接している部屋のどれか1つに移動，
もしくはその場にとどまることができる．
Aaron と Bruce が同じ部屋に入ったとき，
Bruce は Aaron を撮影するものとする．

Bruce が Aaron を撮影するのにどれくらいの時間がかかるかを求めて欲しい．
時間はターン数で表すこととし，
Aaron と Bruce がともに1回行動し終わったら1ターンと数える．

例えば，図5のような状況のとき，
Aaron は部屋5に逃げ込めば Bruce は4ターンでたどり着くが，
Aaron が部屋7に逃げ込めば Bruce はたどり着くのに5ターンかかる．
Aaron にとっては部屋7に逃げ込むことで一番長く逃げ続けられるので
答えは5ターンとなる．

図5: Aaron が5ターン逃げ続けられる例．

また，図6のような状況のとき，
Aaron が Bruce から遠ざかるように部屋を移動することで
いつまでも逃げ回ることができる．

図6: Aaron がいつまでも逃げ続けられる例．

Input

入力の最初の行にデータセット数を表す数 N
(0 < N ≤ 100) が与えられる．
次の行から N 個のデータセットが続く．

各データセットは古代遺跡の形状と Aaron と Bruce の初期位置からなる．
初めに，古代遺跡の部屋の数 M
(2 ≤ M ≤ 50) が与えられる．
次に要素数 M × M の行列が与えられる．
各行列の要素は 0 もしくは 1 であり，
i 行目の j 番目の数字が 1 ならば，
部屋 i と部屋 j
は通路でつながっているということを意味する
（ただし，行列の行番号と列番号は0から数える）．
行列の (i, j) 成分と
(j, i) 成分の値は必ず等しく，
(i, i) 成分の値は 0 である．
続いて，2つの整数 a, b が与えられる．
各整数はそれぞれ Aaron の初期位置の部屋番号
(0 ≤ a < M) と
Bruce の初期位置の部屋番号
(0 ≤ b < M) を示す．
a と b の値は必ず異なる．

Output

各データセットごとに，Bruce が Aaron を撮影するのに何ターンかかるかを
1行で出力せよ．
どれだけたっても撮影できない場合は
“infinity” と出力せよ．

Sample Input

6
8
0 1 0 0 0 0 0 0
1 0 1 0 0 0 0 0
0 1 0 1 1 0 0 0
0 0 1 0 0 0 0 0
0 0 1 0 0 1 1 0
0 0 0 0 1 0 0 0
0 0 0 0 1 0 0 1
0 0 0 0 0 0 1 0
3 0
4
0 1 1 0
1 0 0 1
1 0 0 1
0 1 1 0
1 0
5
0 1 0 1 0
1 0 0 1 0
0 0 0 0 1
1 1 0 0 0
0 0 1 0 0
2 0
5
0 1 0 0 1
1 0 1 1 1
0 1 0 1 0
0 1 1 0 1
1 1 0 1 0
2 4
5
0 1 0 1 0
1 0 1 1 0
0 1 0 0 1
1 1 0 0 1
0 0 1 1 0
3 0
5
0 1 0 1 1
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
1 1 0 1 0
0 4

Output for the Sample Input

5
infinity
infinity
2
infinity
1
Problem J: いにしえの数式

あなたの友人の考古学者が遺跡を発掘していた．
ある日，彼は怪しげな記号の羅列が刻まれている石盤を大量に発見した．
彼はこの大発見に大喜びし，すぐさま石盤に刻まれている記号の解読を始めた．
何週間にもわたる彼の解読の努力の結果，
どうやらこれらの石盤には変数・演算子・カッコの組み合わせで成り立っている
数式のようなものが刻まれていることがわかった．
発掘した石盤と遺跡に関わる文献を調べていくうちに彼はさらに，
それぞれの石盤で演算子の結合規則が異なっており，
それぞれの石盤の先頭に演算子の結合規則が記されているらしいことを突きとめた．
しかし，彼は数学が苦手であるため，演算子の結合規則を見ても
すぐには数式がどのように結合しているかがわからなかった．
そこで彼は，優れたコンピュータサイエンティストであるあなたに
「石盤に書かれている数式がどのように結合しているかを調べてほしい」
と依頼してきた．
あなたは，彼を手助けすることができるだろうか？

数式中に現れる演算子には優先順位が定められており，
優先順位の高い演算子から順に結合していく．
同一優先順位をもつ演算子にはそれぞれ結合方向が定められており，
左から右に結合する場合は左にある演算子から順に，
右から左に結合する場合は右にある演算子から順に結合していく．
例えば， + より * の方が優先順位が高く，
* が左から右に結合する場合，
式 a+b*c*d は (a+((b*c)*d)) のように結合する．
サンプル入力にも他の例がいくつか挙げられているので参照のこと．

Input

入力に与えられる数式は，以下の Expr
で定義されるような文字列である．
この定義において，Var は変数を表し，
Op は演算子を表す．

Expr
::=
Var

|
Expr Op Expr

|

“(”
Expr
“)”

Var
::=

“a” |
“b” |
... |
“z”

Op
::=

“+” |
“-” |
“*” |
“/” |
“<” |
“>” |
“=” |
“&” |
“|” |
“^”

演算子はすべて二項演算子であり，単項演算子やその他の演算子は存在しない．

入力は，いくつかのデータセットからなる．
入力の先頭行にデータセット数 D (D ≤ 100)
が与えられ，
以降の行に D 個のデータセットが続く．

それぞれのデータセットは，次のようなフォーマットで与えられる．

（演算子の結合規則の定義）

（クエリの定義）

演算子の結合規則の定義は，以下のようなフォーマットで与えられる．この定義において，G は演算子グループの数を表す数である．

G

（演算子グループ1 の定義）

（演算子グループ2 の定義）

...

（演算子グループG の定義）

演算子は，結合の優先順位ごとにグループに分けられている．
同一のグループに属する演算子は結合の優先順位が等しく，
グループの定義が後に現れる演算子の方が
前に現れる演算子より結合の優先順位が高い．

それぞれの演算子グループは，以下のように定義される．

A M p1
p2 ... pM

A は演算子の結合方向を表す文字で，
“L” か “R” の
いずれかである．
“L” は左から右に結合することを表し，
“R” は右から左に結合することを表す．
M (M > 0)
は演算子グループに含まれる演算子の数であり，
pi (1 ≤ i ≤ M)
はグループに含まれる演算子を表す文字である．
同じ演算子がグループ内に2度現れることはなく，また，
データセット内にグループをまたがって
同じ演算子が2度現れることもない．

演算子の定義には，上記の Op で定義された演算子のみが現れる．
1つのデータセットにおいて，必ず1つ以上の演算子が定義されると仮定してよい．

クエリの定義は以下のようなフォーマットで与えられる．

N

e1

e2

...

eN

N (0 < N ≤ 50) はクエリとして与えられる
数式の数である．
ei
(1 ≤ i ≤ N)
は上記の Expr の定義を満たすような
式を表す空でない文字列である．
ei の長さはたかだか100文字であり，
当該データセットで定義されていない演算子は出現しないものと仮定してよい．

Output

データセットごとに，
クエリとして与えられたそれぞれの式について，
式中の各演算子について必ず1つのカッコの組を用いて
すべての二項演算を正しく囲み，
演算子の結合を表現した文字列を出力せよ．
入力の式に現れる変数や演算子の順序を変更してはならない．

それぞれのデータセットの間には空行を出力せよ．
出力の末尾に空行を出力してはならない．

Sample Input

2
3
R 1 =
L 2 + -
L 2 * /
6
a+b*c-d
(p-q)/q/d
a+b*c=d-e
t+t+t+t+t
s=s=s=s=s
(((((z)))))
3
R 3 = < >
L 3 & | ^
L 4 + - * /
1
a>b*c=d<e|f+g^h&i<j>k

Output for the Sample Input

((a+(b*c))-d)
(((p-q)/q)/d)
((a+(b*c))=(d-e))
((((t+t)+t)+t)+t)
(s=(s=(s=(s=s))))
z

(a>((b*c)=(d<((((e|(f+g))^h)&i)<(j>k)))))
Problem K: 電波基地

20XX年，長年の研究が実を結び，
無線によるエネルギー送受信の技術が実用化された．
この技術を利用することで，
コストが見合わず今まで電力線を引くことができなかった過疎地にも
電力を供給することが可能となった．
この技術には少しくせがあって，
どこまでも遠くにエネルギーを送ることができるのだが，
特定の位置でしか電波の受信ができないという制約が存在する．
つまり，世界を2次元平面で表し，y軸正の方向を北，
x軸正の方向を東とすると，
x座標・y座標がともに整数の地点でしか
電波を受信することができない（位相の問題である）．
また，基地（電波の送受信が可能な設備）
から見て8方位（東・西・南・北・北東・北西・南東・南西）
の方向にしか電波を送信することができない．

この制約のために，目標の場所に電波を直接供給できない場合があるが，
これは中継基地を置くことで解決可能である．
例えば，座標 (0, 0) から (3, 7) へは直接エネルギーを送ることができないが，
(3, 3) に中継基地を置くことで解決できる．

あなたは電力会社のエンジニアで，
顧客からある場所に基地を用意してほしいと言われている．
ただし，ある箇所が故障しただけで電力が止まってしまうという問題を避けるため，
新たに基地を敷設する際には，既に建っている2箇所以上の基地から
エネルギーを受け取れなくてはいけない．
また，基地は同時には1つしか建てることができず，
同じ場所に基地を2つ置くことはできない．
既存の基地の位置が2つ与えられるので，
顧客の要望を満たすためには最低でもあと何件の基地を建てる必要があるかを
求めて欲しい．

Input

入力は複数のデータセットからなる．

入力の最初の行にデータセット数 N (0 < N ≤ 300)
が与えられる．
以降の N 行に，それぞれのデータセットが与えられる．

1つのデータセットは1行の文字列からなり，
以下のようにスペースで区切られた6つの整数が与えられる．

x1
y1
x2
y2
X Y

(x1, y1) と
(x2, y2)
は既存の2つの基地の座標であり，
(X, Y) は目的地の座標である．
入力で与えられる x, y 座標値は
−100000000 ≤ x, y ≤ 100000000 を満たす．
既存の2つの基地の座標は異なっていることが保証されている．

Output

データセットごとに，敷設する必要のある基地の数を1行で出力せよ．

Sample Input

4
0 1 3 2 0 1
1 1 2 2 9 9
0 0 1 4 5 5
0 0 1 4 5 10

Output for the Sample Input

0
1
2
3
Problem B: Electrophoretic

Scientist Frank, majoring in electrochemistry, has developed line-shaped strange electrodes called F-electrodes.
During being activated, each F-electrode causes a special potential on and between the two lines touching the
F-electrode’s endpoints at a right angle. Then electrically-charged particles located inside the potential area get
to move in the direction parallel to the potential boundary (i.e. perpendicular to the F-electrode), either toward or
against F-electrode. The moving direction can be easily controlled between the two possibles; it is also possible
to get particles to pass through F-electrodes. In addition, unlike ordinary electrodes, F-electrodes can affect
particles even infinitely far away, as long as those particles are located inside the potential area. On the other
hand, two different F-electrodes cannot be activated at a time, since their potentials conflict strongly.

We can move particles on our will by controlling F-electrodes. However, in some cases, we cannot lead them to
the desired positions due to the potential areas being limited. To evaluate usefulness of F-electrodes from some
aspect, Frank has asked you the following task: to write a program that finds the shortest distances from the
particles’ initial positions to their destinations with the given sets of F-electrodes.

Input

The input consists of multiple test cases. The first line of each case contains N (1 ≤ N ≤ 100) which represents
the number of F-electrodes. The second line contains four integers xs, ys, xt and yt, where (xs, ys) and (xt, yt)
indicate the particle’s initial position and destination. Then the description of N F-electrodes follow. Each line
contains four integers Fxs, Fys, Fxt and Fyt, where (Fxs, Fys) and (Fxt, Fyt ) indicate the two endpoints of an
F-electrode. All coordinate values range from 0 to 100 inclusive.

The input is terminated by a case with N = 0.

Output

Your program must output the case number followed by the shortest distance between the initial position to
the destination. Output “Impossible” (without quotes) as the distance if it is impossible to lead the elementary
particle to the destination. Your answers must be printed with five digits after the decimal point. No absolute
error in your answers may exceed 10-5.

Sample Input

2
2 1 2 2
0 0 1 0
0 1 0 2
0

Output for the Sample Input

Case 1: 3.00000
Problem C: Median Filter

The median filter is a nonlinear digital filter used to reduce noise in images, sounds, and other kinds of signals.
It examines each sample of the input through a window and then emits the median of the samples in the win-
dow. Roughly speaking, a window is an interval that contains a target sample and its preceding and succeeding
samples; the median of a series of values is given by the middle value of the series arranged in ascending (or
descending) order.

Let us focus on a typical median filter for black-and-white raster images. The typical filter uses a 3 × 3 window,
which contains a target pixel and the eight adjacent pixels. The filter examines each pixel in turn through this
3 × 3 window, and outputs the median of the nine pixel values, i.e. the fifth lowest (or highest) pixel value, to the
corresponding pixel. We should note that the output is just given by the pixel value in majority for black-and-
white images, since there are only two possible pixel values (i.e. black and white). The figure below illustrates
how the filter works.

Note: The colors of lightly-shaded pixels depend on outside of the region.

The edges of images need to be specially processed due to lack of the adjacent pixels. In this problem, we extends
the original images by repeating pixels on the edges as shown in the figure below. In other words, the lacked
pixels take the same values as the nearest available pixels in the original images.

Note: The letters ‘a’ through ‘f’ indicate pixel values.

You are requested to write a program that reads images to which the filter is applied, then finds the original
images containing the greatest and smallest number of black pixels among all possible ones, and reports the
difference in the numbers of black pixels.

Input

The input contains a series of test cases.

The first line of each test case contains two integers W and H (1 ≤ W, H ≤ 8), which indicates the width and
height of the image respectively. Then H lines follow to describe the filtered image. The i-th line represents
the i-th scan line and contains exactly W characters, each of which is either ‘#’ (representing black) or ‘.’
(representing white).

The input is terminated by a line with two zeros.

Output

For each test case, print a line that contains the case number followed by the difference of black pixels. If there
are no original images possible for the given filtered image, print “Impossible” instead.

Obey the format as shown in the sample output.

Sample Input

5 5
#####
#####
#####
#####
#####
4 4
####
####
####
####
4 4
#...
....
....
...#
4 4
.#.#
#.#.
.#.#
#.#.
0 0

Output for the Sample Input

Case 1: 10
Case 2: 6
Case 3: 2
Case 4: Impossible
Problem D: Life Game

You are working at a production plant of biological weapons. You are a maintainer of a terrible virus weapon
with very high reproductive power. The virus has a tendency to build up regular hexagonal colonies. So as a
whole, the virus weapon forms a hexagonal grid, each hexagon being a colony of the virus. The grid itself is in
the regular hexagonal form with N colonies on each edge.

The virus self-propagates at a constant speed. Self-propagation is performed simultaneously at all colonies.
When it is done, for each colony, the same number of viruses are born at every neighboring colony. Note that,
after the self-propagation, if the number of viruses in one colony is more than or equal to the limit density M,
then the viruses in the colony start self-attacking, and the number reduces modulo M.

Your task is to calculate the total number of viruses after L periods, given the size N of the hexagonal grid and
the initial number of viruses in each of the colonies.

Input

The input consists of multiple test cases.

Each case begins with a line containing three integers N (1 ≤ N ≤ 6), M (2 ≤ M ≤ 109 ), and L (1 ≤ L ≤ 109 ).
The following 2N - 1 lines are the description of the initial state. Each non-negative integer (smaller than M)
indicates the initial number of viruses in the colony. The first line contains the number of viruses in the N colonies
on the topmost row from left to right, and the second line contains those of N + 1 colonies in the next row, and
so on.

The end of the input is indicated by a line “0 0 0”.

Output

For each test case, output the test case number followed by the total number of viruses in all colonies after L
periods.

Sample Input

3 3 1
1 0 0
0 0 0 0
0 0 0 0 0
0 0 0 0
0 0 1
3 3 2
1 0 0
0 0 0 0
0 0 0 0 0
0 0 0 0
0 0 1
0 0 0

Output for the Sample Input

Case 1: 8
Case 2: 18
Problem E: Subdividing a Land

Indigo Real-estate Company is now planning to develop a new housing complex. The entire complex is a square,
all of whose edges are equally a meters. The complex contains n subdivided blocks, each of which is a b-meter
square. Here both a and b are positive integers.

However the project is facing a big problem. In this country, a percentage limit applies to the subdivision of a
land, under the pretext of environmental protection. When developing a complex, the total area of the subdivided
blocks must not exceed 50% of the area of the complex; in other words, more than or equal to 50% of the newly
developed housing complex must be kept for green space. As a business, a green space exceeding 50% of the
total area is a dead space. The primary concern of the project is to minimize it.

Of course purchasing and developing a land costs in proportion to its area, so the company also wants to minimize
the land area to develop as the secondary concern. You, a member of the project, were assigned this task, but can
no longer stand struggling against the problem with your pencil and paper. So you decided to write a program to
find the pair of minimum a and b among those which produce the minimum dead space for given n.

Input

The input consists of multiple test cases. Each test case comes in a line, which contains an integer n. You may
assume 1 ≤ n ≤ 10000.

The end of input is indicated by a line containing a single zero. This line is not a part of the input and should not
be processed.

Output

For each test case, output the case number starting from 1 and the pair of minimum a and b as in the sample
output.

You may assume both a and b fit into 64-bit signed integers.

Sample Input

1
2
0

Output for the Sample Input

Case 1: 3 2
Case 2: 2 1
Problem F: Connect Line Segments

Your dear son Arnie is addicted to a puzzle named Connect Line Segments.

In this puzzle, you are given several line segments placed on a two-dimensional area. You are allowed to add
some new line segments each connecting the end points of two existing line segments. The objective is to form a
single polyline, by connecting all given line segments, as short as possible. The resulting polyline is allowed to
intersect itself.

Arnie has solved many instances by his own way, but he is wondering if his solutions are the best one. He knows
you are a good programmer, so he asked you to write a computer program with which he can verify his solutions.

Please respond to your dear Arnie’s request.

Input

The input consists of multiple test cases.

Each test case begins with a line containing a single integer n (2 ≤ n ≤ 14), which is the number of the initial
line segments. The following n lines are the description of the line segments. The i-th line consists of four real
numbers: xi,1, yi,1, xi,2, and yi,2 (-100 ≤ xi,1, yi,1, xi,2, yi,2 ≤ 100). (xi,1, yi,1) and (xi,2, yi,2) are the coordinates of
the end points of the i-th line segment.

The end of the input is indicated by a line with single “0”.

Output

For each test case, output the case number followed by the minimum length in a line.

The output value should be printed with five digits after the decimal point, and should not contain an error greater
than 0.00001.

Sample Input

4
0 1 0 9
10 1 10 9
1 0 9 0
1 10 9 10
2
1.2 3.4 5.6 7.8
5.6 3.4 1.2 7.8
0

Output for the Sample Input

Case 1: 36.24264
Case 2: 16.84508
Problem G: Oil Company

Irving & Cohen Petroleum Corporation has decided to develop a new oil field in an area. A preliminary survey
has been done and they created a detailed grid map of the area which indicates the reserve of oil.

They are now planning to construct mining plants on several grid blocks according this map, but they decided
not to place any two plants on adjacent positions to avoid spreading of fire in case of blaze. Two blocks are
considered to be adjacent when they have a common edge. You are one of the programmers working for the
company and your task is to write a program which calculates the maximum amount of oil they can mine, given
the map of the reserve.

Input

The first line of the input specifies N, the number of test cases. Then N test cases follow, each of which looks
like the following:

W H
r1,1 r2,1 . . . rW,1
...
r1,H r2,H . . . rW,H

The first line of a test case contains two integers W and H (1 ≤ W, H ≤ 20). They specifies the dimension of
the area. The next H lines, each of which contains W integers, represent the map of the area. Each integer rx,y
(0 ≤ rx,y < 10000) indicates the oil reserve at the grid block (x, y).

Output

For each test case, output the case number (starting from 1) and the maximum possible amount of mining in a
line. Refer to the sample output section about the format.

Sample Input

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

Output for the Sample Input

Case 1: 7
Case 2: 8
Problem H: Finding the Top RPS Player

A company “ACM Foods” is preparing for opening its chain shop in a certain area, but another company “ICPC
Pizza” is also planning to set up its branch shop in the same area. In general, two competitive shops gain less
incomes if they are located so close to each other. Thus, if both “ACM Foods” and “ICPC Pizza” went on
opening, they would be damaged financially. So, they had a discussion on this matter and made the following
agreement: only one of them can branch its shop in the area. It is determined by Rock-Paper-Scissors (RPS)
which to branch the shop.

ACM Foods is facing financial difficulties and strongly desires to open their new shop in that area. The executives
have decided to make every effort for finding out a very strong RPS player. They believes that players who win
consecutive victories must be strong players. In order to find such a player for sure, they have decided their
simple strategy.

In this strategy, many players play games of RPS repeatedly, but the games are only played between players with
the same number of consecutive wins. At the beginning, all the players have no wins, so any pair of players
can play a game. The games can be played by an arbitrary number of pairs simultaneously. Let us call a set of
simultaneous games as a turn. After the first turn, some players will have one win, and the other players will
remain with no wins. In the second turn, some games will be played among players with one win, and some
other games among players with no wins. For the former games, the winners will have two consecutive wins,
and the losers will lose their first wins and have no consecutive wins. For the latter games, the winners will have
one win, and the losers will remain with no wins. Therefore, after the second turn, the players will be divided
into three groups: players with two consecutive wins, players with one win, and players with no wins. Again,
in the third turn, games will be played among players with two wins, among with one win, and among with no
wins. The following turns will be conducted so forth. After a sufficient number of turns, there should be a player
with the desired number of consecutive wins.

The strategy looks crazy? Oh well, maybe they are confused because of their financial difficulties.

Of course, this strategy requires an enormous amount of plays. The executives asked you, as an employee of
ACM Foods, to estimate how long the strategy takes. Your task is to write a program to count the minimum
number of turns required to find a player with M consecutive wins among N players.

Input

The input consists of multiple test cases. Each test case consists of two integers N (2 ≤ N ≤ 20) and M
(1 ≤ M < N) in one line.

The input is terminated by the line containing two zeroes.

Output

For each test case, your program must output the case number followed by one integer which indicates the
minimum number of turns required to find a person with M consecutive wins.

Sample Input

2 1
10 5
15 10
0 0

Output for the Sample Input

Case 1: 1
Case 2: 11
Case 3: 210
Problem I: Revenge of Voronoi

A discrete Voronoi diagram is a derivation of a Voronoi diagram. It is represented as a set of pixels. Each of the
generatrices lies on the center of some pixel. Each pixel belongs to the generatrix nearest from the center of the
pixel in the sense of Manhattan distance. The Manhattan distance d between two points (x1, y1) and (x2, y2) is given by the following formula:

d = |x1 - x2| + |y1 - y2|

Your task is to find a set of generatrices which generates a given discrete Voronoi diagram. In the given diagram,
each generatrix is given a unique lowercase letter as its identifier, and each pixel is represented by the identifier
of the generatrix the pixel belongs to. If a pixel has multiple generatrices at the same distance from its center, it
belongs to the generatrix with the most preceding identifier among them (i.e. the smallest character code).

Input

The input consists of multiple test cases.

Each test case begins with a line containing two integers W (1 ≤ W ≤ 32) and H (1 ≤ H ≤ 32), which denote the
width and height of the discrete Voronoi diagram.

The following H lines, each of which consists of W letters, give one discrete Voronoi diagram. Each letter
represents one pixel.

The end of input is indicated by a line with two zeros. This is not a part of any test cases.

Output

For each test case, print the case number and the coordinates of generatrices as shown in the sample output. Each
generatrix line should consist of its identifier, x-coordinate, and y-coordinate. Generatrices should be printed in
alphabetical order of the identifiers. Each coordinate is zero-based where (0, 0) indicates the center of the top-left
corner pixel of the diagram.

You may assume that every test case has at least one solution. If there are multiple solutions, any one is acceptable.

Print a blank line after every test case including the last one.

Sample Input

4 3
ooxx
ooxx
ooxx
4 1
null
4 4
aabb
aabb
ccdd
ccdd
0 0

Output for the Sample Input

Case 1:
o 0 0
x 2 0
Case 2:
l 2 0
n 0 0
u 1 0
Case 3:
a 0 0
b 2 0
c 0 2
d 2 2