A - A Unique Letter

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

配点 : 100

問題文

長さ 3 の文字列 S が与えられます。
S1 度だけ含まれる文字を 1 つ出力してください。
但し、そのような文字が存在しない場合は代わりに -1 と出力してください。

制約

  • S は英小文字のみからなる 3 文字の文字列

入力

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

S

出力

答えを出力せよ。正解が複数ある場合、どれを出力してもよい。


入力例 1

pop

出力例 1

o

popo1 度だけ含まれます。


入力例 2

abc

出力例 2

a

abca, b, c はどれも 1 度だけ含まれるので、どれを出力しても構いません。


入力例 3

xxx

出力例 3

-1

xxx1 度だけ含まれる文字はありません。

Score : 100 points

Problem Statement

You are given a string S of length 3.
Print a character that occurs only once in S.
If there is no such character, print -1 instead.

Constraints

  • S is a string of length 3 consisting of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S

Output

Print the answer. If multiple solutions exist, you may print any of them.


Sample Input 1

pop

Sample Output 1

o

o occurs only once in pop.


Sample Input 2

abc

Sample Output 2

a

a, b, and c occur once each in abc, so you may print any of them.


Sample Input 3

xxx

Sample Output 3

-1

No character occurs only once in xxx.

B - Misdelivery

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

配点 : 100

問題文

AtCoder マンションには 1 号室から N 号室までの N 個の部屋があります。
i 号室には S_i さんが 1 人で住んでいます。

あなたは X 号室の Y さん宛に荷物を届けようとしています。宛先が正しいかどうかを判定してください。

制約

  • 1 \leq N \leq 100
  • 1 \leq X \leq N
  • N,X は整数
  • S_i および Y は英小文字のみからなる長さ 1 以上 10 以下の文字列

入力

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

N
S_1
S_2
\vdots
S_N
X Y

出力

X 号室に住んでいる人の名前が Y であるとき Yes、そうでないとき No と出力せよ。


入力例 1

3
sato
suzuki
takahashi
3 takahashi

出力例 1

Yes

3 号室に住んでいるのは takahashi さんであり、荷物の宛名と一致しています。


入力例 2

3
sato
suzuki
takahashi
1 aoki

出力例 2

No

1 号室に住んでいるのは sato さんであり、荷物の宛名である aoki と一致しません。


入力例 3

2
smith
smith
1 smith

出力例 3

Yes

AtCoder マンションには異なる部屋に同じ名前の人が住んでいることがあります。


入力例 4

2
wang
li
2 wang

出力例 4

No

Score : 100 points

Problem Statement

Mansion AtCoder has N rooms numbered from room 1 to room N.
Each room i is inhabited by one person named S_i.

You are to deliver a package addressed to Mr./Ms. Y in room X. Determine whether the destination is correct.

Constraints

  • 1 \leq N \leq 100
  • 1 \leq X \leq N
  • N and X are integers.
  • S_i and Y are strings consisting of lowercase English letters with length between 1 and 10, inclusive.

Input

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

N
S_1
S_2
\vdots
S_N
X Y

Output

Print Yes if the name of the person living in room X is Y, and No otherwise.


Sample Input 1

3
sato
suzuki
takahashi
3 takahashi

Sample Output 1

Yes

The person living in room 3 is takahashi, which matches the name on the package.


Sample Input 2

3
sato
suzuki
takahashi
1 aoki

Sample Output 2

No

The person living in room 1 is sato, which does not match the name on the package, aoki.


Sample Input 3

2
smith
smith
1 smith

Sample Output 3

Yes

Mansion AtCoder may have people with the same name living in different rooms.


Sample Input 4

2
wang
li
2 wang

Sample Output 4

No
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 - Longest Segment

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

配点 : 200

問題文

二次元平面上に N 個の点があります。i 個目の点の座標は (x_i,y_i) です。

この中から 2 個の点を選ぶとき、それらを結ぶ線分の長さの最大値を求めてください。

制約

  • 2 \leq N \leq 100
  • -1000 \leq x_i,y_i \leq 1000
  • (x_i,y_i) \neq (x_j,y_j)\ (i \neq j)
  • 入力はすべて整数

入力

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

N
x_1 y_1
x_2 y_2
\hspace{0.4cm} \vdots
x_N y_N

出力

2 点を結ぶ線分の長さの最大値を出力せよ。

想定解との絶対誤差または相対誤差が 10^{-6} 以下であれば正解とみなされる。


入力例 1

3
0 0
0 1
1 1

出力例 1

1.4142135624

1 個目の点と 3 個目の点を選んだときそれらを結ぶ線分の長さは \sqrt 2 = 1.41421356237\dots となり、これが最大です。


入力例 2

5
315 271
-2 -621
-205 -511
-952 482
165 463

出力例 2

1455.7159750446

Score : 200 points

Problem Statement

There are N points in a two-dimensional plane. The coordinates of the i-th point are (x_i,y_i).

Find the maximum length of a segment connecting two of these points.

Constraints

  • 2 \leq N \leq 100
  • -1000 \leq x_i,y_i \leq 1000
  • (x_i,y_i) \neq (x_j,y_j)\ (i \neq j)
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
x_1 y_1
x_2 y_2
\hspace{0.4cm} \vdots
x_N y_N

Output

Print the maximum length of a segment connecting two of the points.

Your answer will be considered correct when the absolute or relative error from the judge's answer is at most 10^{-6}.


Sample Input 1

3
0 0
0 1
1 1

Sample Output 1

1.4142135624

For the 1-st and 3-rd points, the length of the segment connecting them is \sqrt 2 = 1.41421356237\dots, which is the maximum length.


Sample Input 2

5
315 271
-2 -621
-205 -511
-952 482
165 463

Sample Output 2

1455.7159750446
E - Peer Review

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

配点 : 300

問題文

N 人の研究者がおり、研究者には 1, 2, \ldots, N の番号が付けられています。

研究者の間には M 個の利害関係があり、i = 1, 2, \ldots, M に対して研究者 A_i と研究者 B_i は互いに利害関係にあります。

論文の査読者は、その論文の著者とは異なり、著者と利害関係にない相異なる 3 人の研究者である必要があります。

i = 1, 2, \ldots, N について以下の問題を解いてください。

  • 研究者 i が著者である論文の査読者の 3 人組として考えられるものは何通りあるか求めよ。

ただし、すべての論文は単著であるものとします。

制約

  • 1 \leq N \leq 2 \times 10^5
  • 0 \leq M \leq 2 \times 10^5
  • 1 \leq A_i, B_i \leq N
  • A_i \neq B_i
  • i \neq j のとき (A_i, B_i) \neq (A_j, B_j)
  • i \neq j のとき (A_i, B_i) \neq (B_j, A_j)
  • 入力される値はすべて整数

入力

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

N M
A_1 B_1
A_2 B_2
\vdots
A_M B_M

出力

i = 1, 2, \ldots, N に対する答えをこの順に空白区切りで出力せよ。


入力例 1

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

出力例 1

0 1 0 4 4 10

以下、研究者の番号の集合により研究者の集合を表します。

  • 研究者 1 が著者である論文の査読者の 3 人組として考えられるものはありません。

  • 研究者 2 が著者である論文の査読者の 3 人組として考えられるものは \lbrace 4, 5, 6 \rbrace1 通りです。

  • 研究者 3 が著者である論文の査読者の 3 人組として考えられるものはありません。

  • 研究者 4 が著者である論文の査読者の 3 人組として考えられるものは \lbrace 2, 3, 5 \rbrace, \lbrace 2, 3, 6 \rbrace, \lbrace 2, 5, 6 \rbrace, \lbrace 3, 5, 6 \rbrace4 通りです。

  • 研究者 5 が著者である論文の査読者の 3 人組として考えられるものは \lbrace 1, 2, 4 \rbrace, \lbrace 1, 2, 6 \rbrace, \lbrace 1, 4, 6 \rbrace, \lbrace 2, 4, 6 \rbrace4 通りです。

  • 研究者 6 が著者である論文の査読者の 3 人組として考えられるものは \lbrace 1, 2, 3 \rbrace, \lbrace 1, 2, 4 \rbrace, \lbrace 1, 2, 5 \rbrace, \lbrace 1, 3, 4 \rbrace, \lbrace 1, 3, 5 \rbrace, \lbrace 1, 4, 5 \rbrace, \lbrace 2, 3, 4 \rbrace, \lbrace 2, 3, 5 \rbrace, \lbrace 2, 4, 5 \rbrace, \lbrace 3, 4, 5 \rbrace10 通りです。


入力例 2

7 3
1 2
3 4
5 6

出力例 2

10 10 10 10 10 10 20

入力例 3

6 9
3 6
2 5
2 3
4 3
1 5
6 2
3 1
5 3
2 4

出力例 3

1 0 0 1 0 1

Score : 300 points

Problem Statement

There are N researchers, numbered 1, 2, \ldots, N.

There are M conflicts of interest among the researchers; for i = 1, 2, \ldots, M, researchers A_i and B_i have a conflict of interest with each other.

The reviewers of a paper must be three distinct researchers who are different from the author of the paper and have no conflict of interest with the author.

For i = 1, 2, \ldots, N, solve the following problem:

  • Find the number of possible triples of reviewers for a paper authored by researcher i.

Assume that all papers are single-authored.

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 0 \leq M \leq 2 \times 10^5
  • 1 \leq A_i, B_i \leq N
  • A_i \neq B_i
  • (A_i, B_i) \neq (A_j, B_j) if i \neq j.
  • (A_i, B_i) \neq (B_j, A_j) if i \neq j.
  • 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_M B_M

Output

Print the answers for i = 1, 2, \ldots, N in this order, separated by spaces.


Sample Input 1

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

Sample Output 1

0 1 0 4 4 10

Below, we represent a set of researchers by the set of their numbers.

  • There are no possible triples of reviewers for a paper authored by researcher 1.

  • The possible triple of reviewers for a paper authored by researcher 2 is \lbrace 4, 5, 6 \rbrace, which is 1 triple.

  • There are no possible triples of reviewers for a paper authored by researcher 3.

  • The possible triples of reviewers for a paper authored by researcher 4 are \lbrace 2, 3, 5 \rbrace, \lbrace 2, 3, 6 \rbrace, \lbrace 2, 5, 6 \rbrace, \lbrace 3, 5, 6 \rbrace, which is 4 triples.

  • The possible triples of reviewers for a paper authored by researcher 5 are \lbrace 1, 2, 4 \rbrace, \lbrace 1, 2, 6 \rbrace, \lbrace 1, 4, 6 \rbrace, \lbrace 2, 4, 6 \rbrace, which is 4 triples.

  • The possible triples of reviewers for a paper authored by researcher 6 are \lbrace 1, 2, 3 \rbrace, \lbrace 1, 2, 4 \rbrace, \lbrace 1, 2, 5 \rbrace, \lbrace 1, 3, 4 \rbrace, \lbrace 1, 3, 5 \rbrace, \lbrace 1, 4, 5 \rbrace, \lbrace 2, 3, 4 \rbrace, \lbrace 2, 3, 5 \rbrace, \lbrace 2, 4, 5 \rbrace, \lbrace 3, 4, 5 \rbrace, which is 10 triples.


Sample Input 2

7 3
1 2
3 4
5 6

Sample Output 2

10 10 10 10 10 10 20

Sample Input 3

6 9
3 6
2 5
2 3
4 3
1 5
6 2
3 1
5 3
2 4

Sample Output 3

1 0 0 1 0 1