A - Apple

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

配点 : 100

問題文

果物屋さんでりんごが売られています。
あなたは次の操作を好きな順で好きなだけ繰り返すことができます。

  • X 円を払ってりんごを 1 個手に入れる。
  • Y 円を払ってりんごを 3 個手に入れる。

りんごをちょうど N 個手に入れるには最低何円必要ですか?

制約

  • 1 \leq X \leq Y \leq 100
  • 1 \leq N \leq 100
  • 入力される値はすべて整数

入力

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

X Y N

出力

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


入力例 1

10 25 10

出力例 1

85

25 円払って 3 個のりんごを手に入れる操作を 3 回繰り返した後、10 円払って 1 個のりんごを手に入れると丁度 10 個のりんごを手に入れられます。このときあなたは 85 円を消費します。
これより少ない金額でちょうど 10 個のりんごを手に入れることはできないので、答えは 85 円になります。


入力例 2

10 40 10

出力例 2

100

10 円払って 1 個のりんごを手に入れる操作を 10 回繰り返すのが最適です。


入力例 3

100 100 2

出力例 3

200

100 円を払って 1 個のりんごを手に入れる操作を 2 回繰り返す以外に ちょうど 2 個のりんごを手に入れる方法はありません。


入力例 4

100 100 100

出力例 4

3400

Score : 100 points

Problem Statement

A fruit store sells apples.
You may perform the following operations as many times as you want in any order:

  • Buy one apple for X yen (the currency in Japan).
  • Buy three apples for Y yen.

How much yen do you need to pay to obtain exactly N apples?

Constraints

  • 1 \leq X \leq Y \leq 100
  • 1 \leq N \leq 100
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

X Y N

Output

Print the answer as an integer.


Sample Input 1

10 25 10

Sample Output 1

85

Buy three apples for 25 yen three times and one apple for 10 yen, and you will obtain exactly 10 apples for a total of 85 yen.
You cannot obtain exactly 10 apples for a lower cost, so the answer is 85 yen.


Sample Input 2

10 40 10

Sample Output 2

100

It is optimal to buy an apple for 10 yen 10 times.


Sample Input 3

100 100 2

Sample Output 3

200

The only way to obtain exactly 2 apples is to buy an apple for 100 yen twice.


Sample Input 4

100 100 100

Sample Output 4

3400
B - Isosceles

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

配点 : 100

問題文

面積が正である三角形 ABC があります。
三角形 ABC の三辺の長さはそれぞれ a,b,c です。

三角形 ABC が二等辺三角形であるか判定してください。

制約

  • 1 \leq a,b,c \leq 10
  • 三辺の長さが a,b,c であるような三角形が存在し、その面積は正である。
  • a,b,c は整数

入力

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

a b c

出力

三角形 ABC が二等辺三角形であるならば Yes を、そうでないならば No を出力せよ。


入力例 1

4 2 4

出力例 1

Yes

a=c であるため、三角形 ABC は二等辺三角形です。
よって、Yes を出力します。


入力例 2

3 4 5

出力例 2

No

三角形 ABC の三辺の長さはすべて異なるため、二等辺三角形ではありません。
よって、No を出力します。


入力例 3

10 10 10

出力例 3

Yes

正三角形も二等辺三角形の一種であることに注意してください。

Score : 100 points

Problem Statement

There is a triangle ABC with positive area.
The lengths of the three sides of triangle ABC are a,b,c.

Determine whether triangle ABC is isosceles.

Constraints

  • 1 \leq a,b,c \leq 10
  • A triangle with side lengths a,b,c exists, and its area is positive.
  • a,b,c are integers.

Input

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

a b c

Output

If triangle ABC is isosceles, output Yes; otherwise, output No.


Sample Input 1

4 2 4

Sample Output 1

Yes

Since a=c, triangle ABC is isosceles. Thus, output Yes.


Sample Input 2

3 4 5

Sample Output 2

No

Since the three side lengths of triangle ABC are all different, it is not isosceles. Thus, output No.


Sample Input 3

10 10 10

Sample Output 3

Yes

Note that an equilateral triangle is a kind of isosceles triangle.

C - Nearest Taller

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

配点 : 200

問題文

N 人の人が左右一列に並んでいます。左から i 番目 (1\le i\le N) の人を人 i と呼びます。人 i (1\le i\le N) の身長は A_i です。

i=1,2,\ldots,N に対し、人 i より左にいる人であって人 i より身長の高い人が存在するか判定し、存在する場合はその中で番号が人 i に最も近い人を求めてください。

制約

  • 1\le N\le 100
  • 1\le A_i\le 100
  • 入力される値は全て整数

入力

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

N
A_1 A_2 \ldots A_N

出力

N 行出力せよ。

i 行目 (1\le i\le N) には、人 i より左にいる人であって人 i より身長の高い人が存在しない場合は -1 を、存在する場合はその中で番号が人 i に最も近い人の番号を出力せよ。


入力例 1

4
4 3 2 5

出力例 1

-1
1
2
-1
  • 1 より左側に人はいません。したがって、 1 行目には -1 を出力してください。
  • 2 より左側にいる人で人 2 より身長が高いのは人 1 のみです。したがって、 2 行目には 1 を出力してください。
  • 3 より左側にいる人で人 3 より身長が高いのは人 1,2 で、このうち番号が人 3 に最も近いのは人 2 です。したがって、 3 行目には 2 を出力してください。
  • 4 より左側に人 4 より身長が高い人はいません。したがって、 4 行目には -1 を出力してください。

入力例 2

3
7 7 7

出力例 2

-1
-1
-1

同じ身長の人が複数人いる場合もあります。


入力例 3

6
31 9 17 10 2 9

出力例 3

-1
1
1
3
4
4

Score : 200 points

Problem Statement

There are N people standing in a row from left to right. The i-th person from the left (1\le i\le N) is called person i. The height of person i (1\le i\le N) is A_i.

For each i=1,2,\ldots,N, determine whether there exists a person to the left of person i who is taller than person i, and if so, find the person standing closest to person i among them.

Constraints

  • 1\le N\le 100
  • 1\le A_i\le 100
  • 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

Output N lines.

The i-th line (1\le i\le N) should contain -1 if there is no person to the left of person i who is taller than person i, and otherwise, the number representing the person standing closest to person i among such people.


Sample Input 1

4
4 3 2 5

Sample Output 1

-1
1
2
-1
  • There is no person to the left of person 1. Thus, output -1 on the first line.
  • Among the people to the left of person 2, only person 1 is taller than person 2. Thus, output 1 on the second line.
  • Among the people to the left of person 3, persons 1,2 are taller than person 3, and the person standing closest to person 3 is person 2. Thus, output 2 on the third line.
  • There is no person to the left of person 4 who is taller than person 4. Thus, output -1 on the fourth line.

Sample Input 2

3
7 7 7

Sample Output 2

-1
-1
-1

There may be multiple people with the same height.


Sample Input 3

6
31 9 17 10 2 9

Sample Output 3

-1
1
1
3
4
4
D - Bird Watching

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

配点 : 200

問題文

空に M 種類の鳥が合わせて N 羽飛んでいます。
鳥の種類には 1,2,\dots,M の番号が付けられています。
N 羽の鳥には 1,2,\dots,N の番号が付けられており、鳥 i の種類は A_i で、大きさは B_i です。

全ての k=1,2,\dots,M について、飛んでいる種類 k の鳥の大きさの平均値を求めてください。
ただし、全ての k=1,2,\dots,M について、種類 k の鳥が 1 羽以上飛んでいることが保証されます。

制約

  • 1 \le M \le N \le 100
  • 1 \le A_i \le M
  • 1 \le B_i \le 100
  • 種類 k の鳥が少なくとも 1 羽存在する ( 1 \le k \le M )
  • 入力される値は全て整数

入力

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

N M
A_1 B_1
A_2 B_2
\vdots
A_N B_N

出力

M 行出力せよ。
k ( 1 \le k \le M ) 行目には、種類 k の鳥の大きさの平均値を出力せよ。
真の解との絶対誤差または相対誤差が 10^{-5} 以下であるとき、正解とみなされる。


入力例 1

10 5
4 92
1 16
3 77
4 99
2 89
3 8
1 40
5 56
1 40
4 77

出力例 1

32.00000000000000000000
89.00000000000000000000
42.50000000000000000000
89.33333333333333333333
56.00000000000000000000
  • 種類 1 の鳥の大きさの平均値は (16+40+40)/3 = 32 です。
  • 種類 2 の鳥の大きさの平均値は 89 です。
  • 種類 3 の鳥の大きさの平均値は (77+8)/2 = 42.5 です。
  • 種類 4 の鳥の大きさの平均値は (92+99+77)/3 \approx 89.3333 です。
  • 種類 5 の鳥の大きさの平均値は 56 です。

Score : 200 points

Problem Statement

There are N birds of M types flying in the sky.
The bird types are numbered 1,2,\dots,M.
The N birds are numbered 1,2,\dots,N, and bird i is of type A_i and has size B_i.

For every k=1,2,\dots,M, find the average size of the flying birds of type k.
It is guaranteed that for every k=1,2,\dots,M, there is at least one bird of type k flying.

Constraints

  • 1 \le M \le N \le 100
  • 1 \le A_i \le M
  • 1 \le B_i \le 100
  • There exists at least one bird of type k ( 1 \le k \le M ).
  • All input values are integers.

Input

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

N M
A_1 B_1
A_2 B_2
\vdots
A_N B_N

Output

Output M lines.
The k-th line ( 1 \le k \le M ) should contain the average size of birds of type k.
Your answer will be considered correct if the absolute or relative error from the true value is at most 10^{-5}.


Sample Input 1

10 5
4 92
1 16
3 77
4 99
2 89
3 8
1 40
5 56
1 40
4 77

Sample Output 1

32.00000000000000000000
89.00000000000000000000
42.50000000000000000000
89.33333333333333333333
56.00000000000000000000
  • The average size of birds of type 1 is (16+40+40)/3 = 32.
  • The average size of birds of type 2 is 89.
  • The average size of birds of type 3 is (77+8)/2 = 42.5.
  • The average size of birds of type 4 is (92+99+77)/3 \approx 89.3333.
  • The average size of birds of type 5 is 56.
E - Number Place

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

配点 : 250

問題文

9\times 9 のマス目 A があり、各マスには 1 以上 9 以下の整数が書き込まれています。
具体的には、 A の上から i 行目、左から j 列目のマスには A_{i,j} が書き込まれています。

A が次の条件をすべてみたしているならば Yes を、そうでないならば No を出力してください。

  • A の各行について、その行に含まれる 9 マスには 1 以上 9 以下の整数がちょうど 1 個ずつ書き込まれている。
  • A の各列について、その列に含まれる 9 マスには 1 以上 9 以下の整数がちょうど 1 個ずつ書き込まれている。
  • A の行を上から 3 行ずつ 3 つに分け、同様に列も左から 3 列ずつ 3 つに分ける。 これによって A9 つの 3\times 3 のマス目に分けたとき、それぞれの 3\times 3 のマス目には 1 以上 9 以下の整数がちょうど 1 個ずつ書き込まれている。

制約

  • 1\leq A_{i,j}\leq 9
  • 入力はすべて整数

入力

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

A_{1,1} A_{1,2} \ldots A_{1,9}
A_{2,1} A_{2,2} \ldots A_{2,9}
\vdots
A_{9,1} A_{9,2} \ldots A_{9,9}

出力

マス目 A が問題文の条件をすべてみたすならば Yes を、 そうでないならば No を出力せよ。


入力例 1

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

出力例 1

Yes

マス目 A は次のようになっています。

マス目 A3 つの条件をすべてみたしているため、Yes を出力します。


入力例 2

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

出力例 2

No

マス目 A は次のようになっています。

例えば左上の 3\times 3 のマス目に注目すると 3 つめの条件をみたしていないことが分かるため、No を出力します。


入力例 3

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

出力例 3

No

マス目 A は次のようになっています。

例えば一番左の列に注目すると 2 つめの条件をみたしていないことが分かるため、No を出力します。

Score : 250 points

Problem Statement

There is a 9\times 9 grid A, where each cell contains an integer between 1 and 9, inclusive.
Specifically, the cell at the i-th row from the top and j-th column from the left contains A_{i,j}.

If A satisfies all of the following conditions, print Yes. Otherwise, print No.

  • For each row of A, the nine cells in that row contain each integer from 1 to 9 exactly once.
  • For each column of A, the nine cells in that column contain each integer from 1 to 9 exactly once.
  • Divide the rows of A into three groups, each of three rows, from top to bottom, and similarly divide the columns into three groups, each of three columns, from left to right. Each 3\times 3 grid obtained from A in this way contains each integer from 1 to 9 exactly once.

Constraints

  • 1\leq A_{i,j}\leq 9
  • All input values are integers.

Input

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

A_{1,1} A_{1,2} \ldots A_{1,9}
A_{2,1} A_{2,2} \ldots A_{2,9}
\vdots
A_{9,1} A_{9,2} \ldots A_{9,9}

Output

If the grid A satisfies all the conditions in the problem statement, print Yes; otherwise, print No.


Sample Input 1

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

Sample Output 1

Yes

The grid A is shown below.

The grid A satisfies all three conditions, so print Yes.


Sample Input 2

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

Sample Output 2

No

The grid A is shown below.

For example, if you look at the top left 3\times 3 grid, you can see that the third condition is unsatisfied, so print No.


Sample Input 3

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

Sample Output 3

No

The grid A is shown below.

For example, if you look at the leftmost column, you can see that the second condition is unsatisfied, so print No.