A - OS Versions

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

配点 : 100

問題文

ある OS のバージョンは古い順に "Ocelot", "Serval", "Lynx" です。
バージョン X がバージョン Y 以降のバージョンであるか判定してください。
なお、バージョン X 自身もバージョン X 以降のバージョンであるものとします。

制約

  • X,Y は "Ocelot", "Serval", "Lynx" のいずれか (引用符を含まない)

入力

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

X Y

出力

バージョン X がバージョン Y 以降のバージョンであれば Yes 、そうでなければ No と出力せよ。


入力例 1

Serval Ocelot

出力例 1

Yes

バージョン Serval はバージョン Ocelot 以降のバージョンです。そのため、 Yes と出力します。


入力例 2

Serval Lynx

出力例 2

No

バージョン Serval はバージョン Lynx 以降のバージョンではありません。そのため、 No と出力します。


入力例 3

Ocelot Ocelot

出力例 3

Yes

バージョン Ocelot 自身もバージョン Ocelot 以降のバージョンです。そのため、 Yes と出力します。

Score : 100 points

Problem Statement

The versions of a certain OS in chronological order are "Ocelot", "Serval", "Lynx".
Determine whether version X is the same as or newer than version Y.

Constraints

  • Each of X and Y is one of "Ocelot", "Serval", "Lynx" (without quotation marks).

Input

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

X Y

Output

If version X is the same as or newer than version Y, print Yes; otherwise, print No.


Sample Input 1

Serval Ocelot

Sample Output 1

Yes

Version Serval is the same as or newer than version Ocelot. Therefore, print Yes.


Sample Input 2

Serval Lynx

Sample Output 2

No

Version Serval is not the same as nor newer than version Lynx. Therefore, print No.


Sample Input 3

Ocelot Ocelot

Sample Output 3

Yes

Version Ocelot itself is the same as or newer than version Ocelot. Therefore, print Yes.

B - New Scheme

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

配点 : 100

問題文

8 個の整数 S_1,S_2,\dots,S_8 が与えられます。 以下の 3 つの条件が全て満たされるならば Yes を、そうでないならば No を出力してください。

  • 数列 (S_1,S_2,\dots,S_8) は広義単調増加である。すなわち、S_1 \leq S_2 \leq \dots \leq S_8 である。
  • S_1,S_2,\dots,S_8 は全て 100 以上 675 以下である。
  • S_1,S_2,\dots,S_8 は全て 25 の倍数である。

制約

  • 0\leq S_i \leq 1000
  • 入力は全て整数

入力

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

S_1 S_2 \dots S_8

出力

答えを出力せよ。


入力例 1

125 175 250 300 400 525 600 650

出力例 1

Yes

3 つの条件を全て満たしています。


入力例 2

100 250 300 400 325 575 625 675

出力例 2

No

S_4 > S_5 であるため、1 つ目の条件を満たしていません。


入力例 3

0 23 24 145 301 413 631 632

出力例 3

No

2 つ目の条件と 3 つ目の条件を満たしていません。

Score : 100 points

Problem Statement

Given eight integers S_1,S_2,\dots, and S_8, print Yes if they satisfy all of the following three conditions, and No otherwise.

  • The sequence (S_1,S_2,\dots,S_8) is monotonically non-decreasing. In other words, S_1 \leq S_2 \leq \dots \leq S_8.
  • S_1,S_2,\dots, and S_8 are all between 100 and 675, inclusive.
  • S_1,S_2,\dots, and S_8 are all multiples of 25.

Constraints

  • 0\leq S_i \leq 1000
  • All input values are integers.

Input

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

S_1 S_2 \dots S_8

Output

Print the answer.


Sample Input 1

125 175 250 300 400 525 600 650

Sample Output 1

Yes

They satisfy all of the three conditions.


Sample Input 2

100 250 300 400 325 575 625 675

Sample Output 2

No

They violate the first condition because S_4 > S_5.


Sample Input 3

0 23 24 145 301 413 631 632

Sample Output 3

No

They violate the second and third conditions.

C - Tombola

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

配点 : 200

問題文

HW 列からなるグリッドがあります。各マスには整数が 1 つずつ書かれており、これらの整数は相異なります。グリッドの上から i 行目・左から j 行目のマスには整数 A_{i,j} が書かれています。

いま、司会が N 個の相異なる整数 B_1, \dots, B_N を叫びました。

それぞれの行に対して、司会の叫んだ整数がその行に何個含まれるかを求めたとき、それらの最大値はいくつになりますか?

制約

  • 1 \leq H \leq 3
  • 1 \leq W \leq 5
  • 1 \leq N \leq 90
  • 1 \leq A_{i,j} \leq 90
  • A_{i,j} は相異なる
  • 1 \leq B_i \leq 90
  • B_i は相異なる
  • 入力される値はすべて整数

入力

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

H W N
A_{1,1} \cdots A_{1,W}
\vdots
A_{H,1} \cdots A_{H,W}
B_1
\vdots
B_N

出力

答えを 1 行に出力せよ。


入力例 1

3 4 5
12 3 5 7
6 10 11 9
1 2 4 8
2
4
9
6
11

出力例 1

3
  • 上から 1 行目にある整数のうち、司会の叫んだ整数は 0 個です。
  • 上から 2 行目にある整数のうち、司会の叫んだ整数は 6,11,93 個です。
  • 上から 3 行目にある整数のうち、司会の叫んだ整数は 2,42 個です。

以上より、0,3,2 のうちの最大値である 3 が答えです。


入力例 2

3 5 2
81 63 31 16 15
30 3 6 54 24
26 41 48 64 66
44
79

出力例 2

0

入力例 3

3 5 12
78 19 70 58 83
12 30 80 20 27
48 71 8 43 82
82
30
43
8
80
70
20
78
12
71
19
48

出力例 3

5

Score : 200 points

Problem Statement

There is a grid with H rows and W columns. Each square has one integer written on it, and these integers are distinct. The square at the i-th row from the top and j-th column from the left has the integer A_{i,j} written on it.

Now, the host called out N distinct integers B_1, \dots, B_N.

If you find, for each row, how many of the integers called out by the host are contained in that row, what is the maximum value among these?

Constraints

  • 1 \leq H \leq 3
  • 1 \leq W \leq 5
  • 1 \leq N \leq 90
  • 1 \leq A_{i,j} \leq 90
  • A_{i,j} are distinct.
  • 1 \leq B_i \leq 90
  • B_i are distinct.
  • All input values are integers.

Input

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

H W N
A_{1,1} \cdots A_{1,W}
\vdots
A_{H,1} \cdots A_{H,W}
B_1
\vdots
B_N

Output

Output the answer in one line.


Sample Input 1

3 4 5
12 3 5 7
6 10 11 9
1 2 4 8
2
4
9
6
11

Sample Output 1

3
  • Among the integers in the 1-st row from the top, 0 integers were called out by the host.
  • Among the integers in the 2-nd row from the top, 3 integers 6,11,9 were called out by the host.
  • Among the integers in the 3-rd row from the top, 2 integers 2,4 were called out by the host.

Thus, the answer is the maximum value among 0,3,2, which is 3.


Sample Input 2

3 5 2
81 63 31 16 15
30 3 6 54 24
26 41 48 64 66
44
79

Sample Output 2

0

Sample Input 3

3 5 12
78 19 70 58 83
12 30 80 20 27
48 71 8 43 82
82
30
43
8
80
70
20
78
12
71
19
48

Sample Output 3

5
D - Round-Robin Tournament

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

配点 : 200

問題文

1 から N までの番号が付いた N 人のプレイヤーが総当たり戦をしました。この総当たり戦で行われた試合全てについて、二人の一方が勝ち、もう一方が負けました。

総当たり戦の結果は N 個の長さ N の文字列 S_1,S_2,\ldots,S_N によって以下の形式で与えられます。

  • i\neq j のとき、S_ij 文字目は o, x のいずれかであり、o のときプレイヤー i がプレイヤー j に勝ったことを、x のときプレイヤー i がプレイヤー j に負けたことを意味する。

  • i=j のとき、S_ij 文字目は - である。

総当たり戦で勝った試合数が多いほうが順位が上であり、勝った試合数が同じ場合は、プレイヤーの番号が小さいほうが順位が上となります。 N 人のプレイヤーの番号を順位が高い順に答えてください。

制約

  • 2\leq N\leq 100
  • N は整数
  • S_io, x, - からなる長さ N の文字列
  • S_1,\ldots,S_N は問題文中の形式を満たす

入力

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

N 
S_1
S_2
\vdots
S_N

出力

N 人のプレイヤーの番号を、順位が高い順に空白区切りで出力せよ。


入力例 1

3
-xx
o-x
oo-

出力例 1

3 2 1

プレイヤー 10 勝、プレイヤー 21 勝、プレイヤー 32 勝なので、プレイヤーの番号は順位が高い順に 3,2,1 です。


入力例 2

7
-oxoxox
x-xxxox
oo-xoox
xoo-ooo
ooxx-ox
xxxxx-x
oooxoo-

出力例 2

4 7 3 1 5 2 6

プレイヤー 4 とプレイヤー 7 はどちらも 5 勝ですが、プレイヤー番号が小さいプレイヤー 4 のほうが順位が上になります。

Score : 200 points

Problem Statement

There are N players numbered 1 to N, who have played a round-robin tournament. For every match in this tournament, one player won and the other lost.

The results of the matches are given as N strings S_1,S_2,\ldots,S_N of length N each, in the following format:

  • If i\neq j, the j-th character of S_i is o or x. o means that player i won against player j, and x means that player i lost to player j.

  • If i=j, the j-th character of S_i is -.

The player with more wins ranks higher. If two players have the same number of wins, the player with the smaller player number ranks higher. Report the player numbers of the N players in descending order of rank.

Constraints

  • 2\leq N\leq 100
  • N is an integer.
  • S_i is a string of length N consisting of o, x, and -.
  • S_1,\ldots,S_N conform to the format described in the problem statement.

Input

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

N 
S_1
S_2
\vdots
S_N

Output

Print the player numbers of the N players in descending order of rank.


Sample Input 1

3
-xx
o-x
oo-

Sample Output 1

3 2 1

Player 1 has 0 wins, player 2 has 1 win, and player 3 has 2 wins. Thus, the player numbers in descending order of rank are 3,2,1.


Sample Input 2

7
-oxoxox
x-xxxox
oo-xoox
xoo-ooo
ooxx-ox
xxxxx-x
oooxoo-

Sample Output 2

4 7 3 1 5 2 6

Both players 4 and 7 have 5 wins, but player 4 ranks higher because their player number is smaller.

E - Manga

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

配点 : 300

問題文

高橋君は全 10^9 巻の漫画『すぬけ君』を読むことにしました。
初め、高橋君は『すぬけ君』の単行本を N 冊持っています。i 番目の単行本は a_i 巻です。

高橋君は『すぬけ君』を読み始める前に限り次の操作を 0 回以上何度でも繰り返せます。

  • 現在持っている単行本が 1 冊以下の場合、何もしない。そうでない場合、現在持っている単行本から 2 冊を選んで売り、代わりに好きな巻を選んで 1 冊買う

その後、高橋君は『すぬけ君』を 1 巻、2 巻、3 巻、\ldots と順番に読みます。ただし、次に読むべき巻を持っていない状態になった場合、(他の巻を持っているかどうかに関わらず)その時点で『すぬけ君』を読むのをやめます。

高橋君が『すぬけ君』を最大で何巻まで読めるかを求めてください。ただし、1 巻を読めない場合の答えは 0 とします。

制約

  • 1 \leq N \leq 3 \times 10^5
  • 1 \leq a_i \leq 10^9
  • 入力はすべて整数

入力

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

N
a_1 \ldots a_N

出力

答えを出力せよ。


入力例 1

6
1 2 4 6 7 271

出力例 1

4

『すぬけ君』を読み始める前に「7 巻と 271 巻を選んで売り、代わりに 3 巻を選んで 1 冊買う」という内容で操作をすると、高橋君は 1 巻、2 巻、3 巻、4 巻、6 巻を 1 冊ずつ持っている状態になります。
この状態から『すぬけ君』を読み始めると、高橋君は 1 巻、2 巻、3 巻、4 巻を読み、続いて 5 巻を読もうとしますが持っていないためこの時点で『すぬけ君』を読むのをやめます。
操作の方法を変えても 5 巻を読むことは出来ないため、4 が答えです。


入力例 2

10
1 1 1 1 1 1 1 1 1 1

出力例 2

5

高橋君は同じ巻を 2 冊以上持っているかもしれません。
この入力に対しては以下のように 4 回操作をしてから『すぬけ君』を読み始めることで 5 巻まで読むことが出来、これが最大です。

  • 1 巻を 2 冊選んで売り、代わりに 2 巻を選んで 1 冊買う
  • 1 巻を 2 冊選んで売り、代わりに 3 巻を選んで 1 冊買う
  • 1 巻を 2 冊選んで売り、代わりに 4 巻を選んで 1 冊買う
  • 1 巻を 2 冊選んで売り、代わりに 5 巻を選んで 1 冊買う

入力例 3

1
5

出力例 3

0

高橋君は 1 巻を読めません。

Score : 300 points

Problem Statement

Takahashi is going to read a manga series "Snuke-kun" in 10^9 volumes.
Initially, Takahashi has N books of this series. The i-th book is Volume a_i.

Takahashi may repeat the following operation any number of (possibly zero) times only before he begins to read:

  • Do nothing if he has 1 or less books; otherwise, sell two of the books he has and buy one book of any volume instead.

Then, Takahashi reads Volume 1, Volume 2, Volume 3, \ldots, in order. However, when he does not have a book of the next volume to read, he stops reading the series (regardless of the other volumes he has).

Find the latest volume of the series that he can read up to. If he cannot read any, let the answer be 0.

Constraints

  • 1 \leq N \leq 3 \times 10^5
  • 1 \leq a_i \leq 10^9
  • All values in the input are integers.

Input

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

N
a_1 \ldots a_N

Output

Print the answer.


Sample Input 1

6
1 2 4 6 7 271

Sample Output 1

4

Before he begins to read the series, he may do the following operation: "sell books of Volumes 7 and 271 and buy one book of Volume 3 instead." Then, he has one book each of Volumes 1, 2, 3, 4, and 6.
If he then begins to read the series, he reads Volumes 1, 2, 3, and 4, then tries to read Volume 5. However, he does not have one, so he stops reading at this point.
Regardless of the choices in the operation, he cannot read Volume 5, so the answer is 4.


Sample Input 2

10
1 1 1 1 1 1 1 1 1 1

Sample Output 2

5

Takahashi may have multiple books of the same volume.
For this input, if he performs the following 4 operations before he begins to read the series, he can read up to Volume 5, which is the maximum:

  • Sell two books of Volume 1 and buy a book of Volume 2 instead.
  • Sell two books of Volume 1 and buy a book of Volume 3 instead.
  • Sell two books of Volume 1 and buy a book of Volume 4 instead.
  • Sell two books of Volume 1 and buy a book of Volume 5 instead.

Sample Input 3

1
5

Sample Output 3

0

Takahashi cannot read Volume 1.