A - Feet

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100

問題文

1 フィートは 12 インチです。

A フィート B インチは、インチ換算で何インチですか?

制約

  • 1 \leq A \leq 8
  • 0 \leq B \leq 11
  • 入力される値はすべて整数

入力

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

A B

出力

答えを 1 行に出力せよ。単位 (インチ) は省いて出力すること。


入力例 1

6 7

出力例 1

79

6 フィート 7 インチは、インチ換算で 6 \times 12 + 7 = 79 インチです。


入力例 2

4 11

出力例 2

59

4 フィート 11 インチは、インチ換算で 4 \times 12 + 11 = 59 インチです。


入力例 3

8 0

出力例 3

96

8 フィート 0 インチは、インチ換算で 8 \times 12 + 0 = 96 インチです。

Score : 100 points

Problem Statement

1 foot is 12 inches.

How many inches is A feet B inches?

Constraints

  • 1 \leq A \leq 8
  • 0 \leq B \leq 11
  • All input values are integers.

Input

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

A B

Output

Output the answer in one line. Omit the unit (inches).


Sample Input 1

6 7

Sample Output 1

79

6 feet 7 inches is 6 \times 12 + 7 = 79 inches.


Sample Input 2

4 11

Sample Output 2

59

4 feet 11 inches is 4 \times 12 + 11 = 59 inches.


Sample Input 3

8 0

Sample Output 3

96

8 feet 0 inches is 8 \times 12 + 0 = 96 inches.

B - Buildings

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100

問題文

N 個のビルが横一列に並んでいて、左から i 番目のビルの高さは H_i です。

左から 1 番目のビルより高いビルが存在するか判定し、存在する場合その内最も左のビルは左から何番目か求めてください。

制約

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

入力

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

N 
H_1 H_2 \ldots H_N

出力

左から 1 番目のビルより高いビルが存在しない場合 -1 を出力せよ。

存在する場合、その内最も左のビルは左から何番目か出力せよ。


入力例 1

4
3 2 5 2

出力例 1

3

左から 1 番目のビルより高いビルは、左から 3 番目のビルです。


入力例 2

3
4 3 2

出力例 2

-1

左から 1 番目のビルより高いビルは存在しません。


入力例 3

7
10 5 10 2 10 13 15

出力例 3

6

左から 1 番目のビルより高いビルは、左から 6 番目のビルと左から 7 番目のビルです。その内最も左のビルは左から 6 番目のビルです。

Score: 100 points

Problem Statement

There are N buildings aligned in a row. The i-th building from the left has a height of H_i.

Determine if there is a building taller than the first one from the left. If such a building exists, find the position of the leftmost such building from the left.

Constraints

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

Input

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

N
H_1 H_2 \ldots H_N

Output

If no building is taller than the first one from the left, print -1.

If such a building exists, print the position (index) of the leftmost such building from the left.


Sample Input 1

4
3 2 5 2

Sample Output 1

3

The building taller than the first one from the left is the third one from the left.


Sample Input 2

3
4 3 2

Sample Output 2

-1

No building is taller than the first one from the left.


Sample Input 3

7
10 5 10 2 10 13 15

Sample Output 3

6

The buildings taller than the first one from the left are the sixth and seventh ones. Among them, the leftmost is the sixth one.

C - Unique Nicknames

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

1, 人 2, \dotsNN 人の人がいます。人 i の姓は s_i、名は t_i です。

N 人の人すべてにあだ名をつけることを考えます。人 i のあだ名 a_i は以下の条件を満たす必要があります。

  • a_i は人 i の姓あるいは名と一致する。言い換えると、a_i = s_i または a_i = t_i の少なくとも一方が成り立つ。
  • a_i は自分以外の人の姓および名のどちらとも一致しない。言い換えると、1 \leq j \leq N, i \neq j を満たすすべての整数 j について a_i \neq s_j かつ a_i \neq t_j が成り立つ。

N 人全員に条件を満たすあだ名をつけることは可能でしょうか。可能ならば Yes を、そうでないならば No を出力してください。

制約

  • 2 \leq N \leq 100
  • N は整数である。
  • s_i,t_i は英小文字からなる 1 文字以上 10 文字以下の文字列である。

入力

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

N
s_1 t_1
s_2 t_2
\vdots
s_N t_N

出力

N 人すべてにあだ名をつけることが可能ならば Yes を、そうでないならば No を出力せよ。


入力例 1

3
tanaka taro
tanaka jiro
suzuki hanako

出力例 1

Yes

a_1 = taro, a_2 = jiro, a_3 = hanako とすれば、これは問題文にあるあだ名の条件を満たしています。(a_3suzuki でもよいです。)
ここで、a_1 = tanaka とはできないことに注意してください。なぜならば 人 2 の姓 s_2 もまた tanaka であるため、あだ名の条件の 2 つ目を満たさなくなるからです。


入力例 2

3
aaa bbb
xxx aaa
bbb yyy

出力例 2

No

問題文の条件を満たすあだ名のつけ方は存在しません。


入力例 3

2
tanaka taro
tanaka taro

出力例 3

No

同姓同名である人の組が存在する場合もあります。


入力例 4

3
takahashi chokudai
aoki kensho
snu ke

出力例 4

Yes

a_1 = chokudai, a_2 = kensho, a_3 = ke とすればよいです。

Score : 200 points

Problem Statement

There are N people numbered Person 1, Person 2, \dots, and Person N. Person i has a family name s_i and a given name t_i.

Consider giving a nickname to each of the N people. Person i's nickname a_i should satisfy all the conditions below.

  • a_i coincides with Person i's family name or given name. In other words, a_i = s_i and/or a_i = t_i holds.
  • a_i does not coincide with the family name and the given name of any other person. In other words, for all integer j such that 1 \leq j \leq N and i \neq j, it holds that a_i \neq s_j and a_i \neq t_j.

Is it possible to give nicknames to all the N people? If it is possible, print Yes; otherwise, print No.

Constraints

  • 2 \leq N \leq 100
  • N is an integer.
  • s_i and t_i are strings of lengths between 1 and 10 (inclusive) consisting of lowercase English alphabets.

Input

Input is given from Standard Input in the following format:

N
s_1 t_1
s_2 t_2
\vdots
s_N t_N

Output

If it is possible to give nicknames to all the N people, print Yes; otherwise, print No.


Sample Input 1

3
tanaka taro
tanaka jiro
suzuki hanako

Sample Output 1

Yes

The following assignment satisfies the conditions of nicknames described in the Problem Statement: a_1 = taro, a_2 = jiro, a_3 = hanako. (a_3 may be suzuki, too.)
However, note that we cannot let a_1 = tanaka, which violates the second condition of nicknames, since Person 2's family name s_2 is tanaka too.


Sample Input 2

3
aaa bbb
xxx aaa
bbb yyy

Sample Output 2

No

There is no way to give nicknames satisfying the conditions in the Problem Statement.


Sample Input 3

2
tanaka taro
tanaka taro

Sample Output 3

No

There may be a pair of people with the same family name and the same given name.


Sample Input 4

3
takahashi chokudai
aoki kensho
snu ke

Sample Output 4

Yes

We can let a_1 = chokudai, a_2 = kensho, and a_3 = ke.

D - Nice Grid

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

次の図に示す、各マスが黒または白に塗られた縦 15\times15 列のグリッドにおいて、 上から R 行目、左から C 列目のマスが何色かを出力して下さい。

制約

  • 1 \leq R, C \leq 15
  • R, C は整数

入力

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

R C

出力

図のグリッドにおいて上から R 行目、左から C 列目のマスが黒色の場合は black と、白色の場合は white と出力せよ。 ジャッジは英小文字と英大文字を厳密に区別することに注意せよ。


入力例 1

3 5

出力例 1

black

図のグリッドにおいて上から 3 行目、左から 5 列目のマスは黒色です。 よって、black と出力します。


入力例 2

4 5

出力例 2

white

図のグリッドにおいて上から 4 行目、左から 5 列目のマスは白色です。 よって、white と出力します。

Score : 200 points

Problem Statement

Print the color of the cell at the R-th row from the top and C-th column from the left in the following grid with 15 vertical rows and 15 horizontal columns.

Constraints

  • 1 \leq R, C \leq 15
  • R and C are integers.

Input

Input is given from Standard Input in the following format:

R C

Output

In the grid above, if the color of the cell at the R-th row from the top and C-th column from the left is black, then print black; if the cell is white, then print white. Note that the judge is case-sensitive.


Sample Input 1

3 5

Sample Output 1

black

In the grid above, the cell at the 3-rd row from the top and 5-th column from the left is black. Thus, black should be printed.


Sample Input 2

4 5

Sample Output 2

white

In the grid above, the cell at the 4-th row from the top and 5-th column from the left is white. Thus, white should be printed.

E - RANDOM

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

#. からなる HW 列の図形 S,T が与えられます。
図形 SH 個の文字列として与えられ、 S_ij 文字目は Sij 列にある要素を表します。 T についても同様です。

S の列を並べ替えて T と等しくできるか判定してください。

但し、図形 X の列を並べ替えるとは、以下の操作を言います。

  • (1,2,\dots,W) の順列 P=(P_1,P_2,\dots,P_W) をひとつ選択する。
  • その後、全ての 1 \le i \le H を満たす整数 i について、以下の操作を同時に行う。
    • 1 \le j \le W を満たす全ての整数 j について同時に、 Xij 列にある要素を iP_j 列にある要素に置き換える。

制約

  • H,W は整数
  • 1 \le H,W
  • 1 \le H \times W \le 4 \times 10^5
  • S_i,T_i#. からなる長さ W の文字列

入力

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

H W
S_1
S_2
\vdots
S_H
T_1
T_2
\vdots
T_H

出力

ST と等しくできるなら Yes 、 そうでないなら No と出力せよ。


入力例 1

3 4
##.#
##..
#...
.###
..##
...#

出力例 1

Yes

例えば S3,4,2,1 列目をこの順に左から並べ替えた場合、 ST と等しくできます。


入力例 2

3 3
#.#
.#.
#.#
##.
##.
.#.

出力例 2

No

この入力では、 ST と等しくすることができません。


入力例 3

2 1
#
.
#
.

出力例 3

Yes

S=T である場合もあります。


入力例 4

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

出力例 4

Yes

Score : 300 points

Problem Statement

You are given patterns S and T consisting of # and ., each with H rows and W columns.
The pattern S is given as H strings, and the j-th character of S_i represents the element at the i-th row and j-th column. The same goes for T.

Determine whether S can be made equal to T by rearranging the columns of S.

Here, rearranging the columns of a pattern X is done as follows.

  • Choose a permutation P=(P_1,P_2,\dots,P_W) of (1,2,\dots,W).
  • Then, for every integer i such that 1 \le i \le H, simultaneously do the following.
    • For every integer j such that 1 \le j \le W, simultaneously replace the element at the i-th row and j-th column of X with the element at the i-th row and P_j-th column.

Constraints

  • H and W are integers.
  • 1 \le H,W
  • 1 \le H \times W \le 4 \times 10^5
  • S_i and T_i are strings of length W consisting of # and ..

Input

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

H W
S_1
S_2
\vdots
S_H
T_1
T_2
\vdots
T_H

Output

If S can be made equal to T, print Yes; otherwise, print No.


Sample Input 1

3 4
##.#
##..
#...
.###
..##
...#

Sample Output 1

Yes

If you, for instance, arrange the 3-rd, 4-th, 2-nd, and 1-st columns of S in this order from left to right, S will be equal to T.


Sample Input 2

3 3
#.#
.#.
#.#
##.
##.
.#.

Sample Output 2

No

In this input, S cannot be made equal to T.


Sample Input 3

2 1
#
.
#
.

Sample Output 3

Yes

It is possible that S=T.


Sample Input 4

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

Sample Output 4

Yes