A - Exact Price

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100

問題文

高橋君の財布の中には 100 円硬貨が 1 枚以上入っており、それ以外には何も入っていません。

高橋君の財布の中の合計金額が X 円である可能性はありますか?

制約

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

入力

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

X

出力

高橋君の財布の中の合計金額が X 円である可能性がある場合は Yes、そうでない場合は No と出力せよ。


入力例 1

500

出力例 1

Yes

財布に 100 円硬貨が 5 枚入っているとき、合計金額は 500 円になります。故に財布の中の合計金額は X=500 円になりうるため、Yes を出力します。


入力例 2

40

出力例 2

No

入力例 3

0

出力例 3

No

財布の中には 100 円硬貨が 1 枚以上入っていることに注意してください。

Score : 100 points

Problem Statement

Takahashi's purse has one or more 100-yen coins in it and nothing else. (Yen is the Japanese currency.)

Is it possible that the total amount of money in the purse is X yen?

Constraints

  • 0 \leq X \leq 1000
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

X

Output

If it is possible that the total amount of money in Takahashi's purse is X yen, print Yes; otherwise, print No.


Sample Input 1

500

Sample Output 1

Yes

If the purse has five 100-yen coins, the total amount of money is 500 yen. Thus, it is possible that the total amount is X=500 yen, so we should print Yes.


Sample Input 2

40

Sample Output 2

No

Sample Input 3

0

Sample Output 3

No

Note that the purse has at least one 100-yen coin.

B - Last Two Digits

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100

問題文

100 以上の整数 N が与えられます。N の下 2 桁を出力してください。

ただし、N の下 2 桁とは十の位と一の位をこの順に並べたものを言います。

制約

  • 100 \le N \le 999
  • N は整数である。

入力

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

N

出力

答えを出力せよ。


入力例 1

254

出力例 1

54

254 の下 2 桁は 54 であるため、54 を出力します。


入力例 2

101

出力例 2

01

101 の下 2 桁は 01 であるため、01 を出力します。

Score : 100 points

Problem Statement

You are given an integer N at least 100. Print the last two digits of N.

Strictly speaking, print the tens and ones digits of N in this order.

Constraints

  • 100 \le N \le 999
  • N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

Print the answer.


Sample Input 1

254

Sample Output 1

54

The last two digits of 254 are 54, which should be printed.


Sample Input 2

101

Sample Output 2

01

The last two digits of 101 are 01, which should be printed.

C - A^A

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

整数 B が与えられます。
A^A = B であるような正の整数 A が存在するならばその値を、存在しないならば -1 を出力してください。

制約

  • 1 \leq B \leq 10^{18}
  • B は整数

入力

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

B

出力

A^A = B であるような正の整数 A が存在するならばその値を、存在しないならば -1 を出力せよ。
A^A = B を満たす正の整数 A が複数ある場合は、どれを出力しても正解とみなされる。


入力例 1

27

出力例 1

3

3^3 = 27 なので 3 を出力します。


入力例 2

100

出力例 2

-1

A^A = B を満たす A は存在しません。


入力例 3

10000000000

出力例 3

10

Score : 200 points

Problem Statement

You are given an integer B.
If there exists a positive integer A such that A^A = B, print its value; otherwise, output -1.

Constraints

  • 1 \leq B \leq 10^{18}
  • B is an integer.

Input

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

B

Output

If there exists a positive integer A such that A^A = B, print its value; otherwise, print -1.
If there are multiple positive integers A such that A^A = B, any of them will be accepted.


Sample Input 1

27

Sample Output 1

3

3^3 = 27, so print 3.


Sample Input 2

100

Sample Output 2

-1

There is no A such that A^A = B.


Sample Input 3

10000000000

Sample Output 3

10
D - Yellow and Red Card

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

1 から N までの番号がついた N 人の選手がサッカーの試合をします。
選手が反則を犯したとき、その選手には イエローカードレッドカード のどちらかが提示されます。
以下の条件のうち一方を満たした選手は 退場処分 と呼ばれるペナルティを受けます。

  • イエローカードを累計 2 回提示される。
  • レッドカードを提示される。

なお、退場処分を受けた選手にそれ以降カードが提示されることはありません。

あなたはこの試合を観戦します。はじめ、すべての選手はカードを 1 回も提示されていません。
Q 個のイベントが発生するので、イベントで聞かれる質問に正しく答えてください。
イベントは 3 種類あり、c x (c1, 2, 3 のいずれか) という形式で入力から与えられます。イベントの説明は次の通りです。

  • 1 x : 選手 x にイエローカードが提示される。
  • 2 x : 選手 x にレッドカードが提示される。
  • 3 x : あなたは選手 x が退場処分を受けたかを質問される。選手 x が退場処分を受けていれば Yes と、そうでなければ No と答える。

制約

  • 1 \leq N \leq 100
  • 1 \leq Q \leq 100
  • 全てのイベントにおいて 1 \leq x \leq N
  • 3 種類目のイベントは少なくとも 1 個以上存在する
  • すでに退場処分を受けた選手にカードが提示されることはない
  • 入力される値はすべて整数

入力

入力は以下の形式で標準入力から与えられる。ただし、\text{event}_ii 番目に発生するイベントを意味する。

N Q
\text{event}_1
\text{event}_2
\vdots
\text{event}_Q

イベントは次の 3 つのいずれかの形式で入力される。

1 x
2 x
3 x

出力

入力で与えられる 3 種類目のイベントの個数を X として、X 行出力せよ。
i 行目には、3 種類目のイベントのうち i 番目のもので聞かれる質問について、選手 x が退場処分を受けていれば Yes を、そうでなければ No を出力せよ。


入力例 1

3 9
3 1
3 2
1 2
2 1
3 1
3 2
1 2
3 2
3 3

出力例 1

No
No
Yes
No
Yes
No

イベントを時系列順にすべて説明すると次の通りです。

1 番目のイベントでは、あなたは選手 1 が退場処分を受けたかを質問されます。選手 1 は退場処分を受けていないので No を出力します。
2 番目のイベントでは、あなたは選手 2 が退場処分を受けたかを質問されます。選手 2 は退場処分を受けていないので No を出力します。
3 番目のイベントでは、選手 2 にイエローカードが提示されます。
4 番目のイベントでは、選手 1 にレッドカードが提示されます。選手 1 は退場処分を受けます。
5 番目のイベントでは、あなたは選手 1 が退場処分を受けたかを質問されます。選手 1 は退場処分を受けたので Yes を出力します。
6 番目のイベントでは、あなたは選手 2 が退場処分を受けたかを質問されます。選手 2 は退場処分を受けていないので No を出力します。
7 番目のイベントでは、選手 2 にイエローカードが提示されます。選手 2 は退場処分を受けます。
8 番目のイベントでは、あなたは選手 2 が退場処分を受けたかを質問されます。選手 2 は退場処分を受けたので Yes を出力します。
9 番目のイベントでは、あなたは選手 3 が退場処分を受けたかを質問されます。選手 3 は退場処分を受けていないので No を出力します。

Score : 200 points

Problem Statement

N players numbered 1 to N will play a soccer game.
When a player commits an offense, that player will receive a yellow card or a red card.
A player who satisfies one of the following conditions will be removed from the game.

  • Accumulates two yellow cards.
  • Receives a red card.

Once a player is removed, that player will no longer receive any cards.

You will watch this game. Initially, the players have not received any cards.
There will be Q events. Correctly answer the questions asked in the events.
There are three kinds of events, which are given in the format c x from the input, where c is 1, 2, or 3. The events are as follows.

  • 1 x: Player x receives a yellow card.
  • 2 x: Player x receives a red card.
  • 3 x: You are asked whether player x has been removed from the game. Answer Yes or No.

Constraints

  • 1 \leq N \leq 100
  • 1 \leq Q \leq 100
  • 1 \leq x \leq N in all events.
  • There is at least one event of the third kind.
  • A player who has been removed will no longer receive any cards.
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format, where \text{event}_i denotes the i-th event.

N Q
\text{event}_1
\text{event}_2
\vdots
\text{event}_Q

Each event is in one of the following formats:

1 x
2 x
3 x

Output

Print X lines, where X is the number of events of the third kind in the input.
The i-th line should contain Yes if, for the i-th event of the third kind, player x has been removed from the game, and No otherwise.


Sample Input 1

3 9
3 1
3 2
1 2
2 1
3 1
3 2
1 2
3 2
3 3

Sample Output 1

No
No
Yes
No
Yes
No

Here are all the events in chronological order.

In the 1-st event, you are asked whether player 1 has been removed from the game. Player 1 has not been removed, so you should print No.
In the 2-nd event, you are asked whether player 2 has been removed from the game. Player 2 has not been removed, so you should print No.
In the 3-rd event, player 2 receives a yellow card.
In the 4-th event, player 1 receives a red card and is removed from the game.
In the 5-th event, you are asked whether player 1 has been removed from the game. Player 1 has been removed, so you should print Yes.
In the 6-th event, you are asked whether player 2 has been removed from the game. Player 2 has not been removed, so you should print No.
In the 7-th event, player 2 receives a yellow card and is removed from the game.
In the 8-th event, you are asked whether player 2 has been removed from the game. Player 2 has been removed, so you should print Yes.
In the 9-th event, you are asked whether player 3 has been removed from the game. Player 3 has not been removed, so you should print No.

E - PC on the Table

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

高橋君は部屋に PC を沢山置こうとしています。そこで最大何台の PC を部屋に置けるか調べるプログラムを書くことにしました。

H 個の長さ W., T からなる文字列 S_1,S_2,\ldots,S_H が与えられます。

高橋君は以下の操作を 0 回以上何回でも行うことができます。

  • 1\leq i \leq H, 1 \leq j \leq W-1 を満たす整数であって、 S_ij 番目の文字も j+1 番目の文字も T であるようなものを選ぶ。 S_ij 番目の文字を P で置き換え、S_ij+1 番目の文字を C で置き換える。

高橋君が操作回数の最大化を目指すとき、操作終了後の S_1,S_2,\ldots,S_H としてあり得るものの一例を出力してください。

制約

  • 1\leq H \leq 100
  • 2\leq W \leq 100
  • HW は整数である
  • S_i., T からなる長さ W の文字列

入力

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

H W 
S_1
S_2
\vdots
S_H

出力

高橋君が操作回数の最大化を目指すとき、操作終了後の S_1,S_2,\ldots,S_H としてあり得るものの一例を改行区切りで出力せよ。

解が複数存在する場合、どれを出力しても正答とみなされる。


入力例 1

2 3
TTT
T.T

出力例 1

PCT
T.T

可能な操作回数の最大値は 1 です。

例えば、 (i,j)=(1,1) として操作を行うと、S_1PCT に変化します。


入力例 2

3 5
TTT..
.TTT.
TTTTT

出力例 2

PCT..
.PCT.
PCTPC

Score : 300 points

Problem Statement

Planning to place many PCs in his room, Takahashi has decided to write a code that finds how many PCs he can place in his room.

You are given H strings S_1,S_2,\ldots,S_H, each of length W, consisting of . and T.

Takahashi may perform the following operation any number of times (possibly zero):

  • Choose integers satisfying 1\leq i \leq H and 1 \leq j \leq W-1 such that the j-th and (j+1)-th characters of S_i are both T. Replace the j-th character of S_i with P, and (j+1)-th with C.

He tries to maximize the number of times he performs the operation. Find possible resulting S_1,S_2,\ldots,S_H.

Constraints

  • 1\leq H \leq 100
  • 2\leq W \leq 100
  • H and W are integers.
  • S_i is a string of length W consisting of . and T.

Input

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

H W 
S_1
S_2
\vdots
S_H

Output

Print a sequence of strings, S_1,S_2,\ldots,S_H, separated by newlines, possibly resulting from maximizing the number of times he performs the operation.

If multiple solutions exist, print any of them.


Sample Input 1

2 3
TTT
T.T

Sample Output 1

PCT
T.T

He can perform the operation at most once.

For example, an operation with (i,j)=(1,1) makes S_1 PCT.


Sample Input 2

3 5
TTT..
.TTT.
TTTTT

Sample Output 2

PCT..
.PCT.
PCTPC
F - Shapes

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

2 次元グリッド上に 2 つの図形 ST があります。グリッドは正方形のマスからなります。

SNN 列のグリッド内にあり、S_{i,j}# であるようなマス全体からなります。
TNN 列のグリッド内にあり、T_{i,j}# であるようなマス全体からなります。

ST90 度回転及び平行移動の繰り返しによって一致させることができるか判定してください。

制約

  • 1 \leq N \leq 200
  • S,T#. のみからなる
  • S,T1 つ以上 # を含む

入力

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

N
S_{1,1}S_{1,2}\ldots S_{1,N}
\vdots
S_{N,1}S_{N,2}\ldots S_{N,N}
T_{1,1}T_{1,2}\ldots T_{1,N}
\vdots
T_{N,1}T_{N,2}\ldots T_{N,N}

出力

ST90 度回転及び平行移動の繰り返しによって一致させることができるとき Yes を、そうでないとき No を出力せよ。


入力例 1

5
.....
..#..
.###.
.....
.....
.....
.....
....#
...##
....#

出力例 1

Yes

S を左回りに 90 度回転させ、平行移動することで T に一致させることができます。


入力例 2

5
#####
##..#
#..##
#####
.....
#####
#..##
##..#
#####
.....

出力例 2

No

90 度回転と平行移動の繰り返しによって一致させることはできません。


入力例 3

4
#...
..#.
..#.
....
#...
#...
..#.
....

出力例 3

Yes

S 及び T は連結とは限りません。


入力例 4

4
#...
.##.
..#.
....
##..
#...
..#.
....

出力例 4

No

回転や移動の操作は連結成分ごとにできるわけではなく、S,T 全体に対して行うことに注意してください。

Score : 300 points

Problem Statement

We have two figures S and T on a two-dimensional grid with square cells.

S lies within a grid with N rows and N columns, and consists of the cells where S_{i,j} is #.
T lies within the same grid with N rows and N columns, and consists of the cells where T_{i,j} is #.

Determine whether it is possible to exactly match S and T by 90-degree rotations and translations.

Constraints

  • 1 \leq N \leq 200
  • Each of S and T consists of # and ..
  • Each of S and T contains at least one #.

Input

Input is given from Standard Input in the following format:

N
S_{1,1}S_{1,2}\ldots S_{1,N}
\vdots
S_{N,1}S_{N,2}\ldots S_{N,N}
T_{1,1}T_{1,2}\ldots T_{1,N}
\vdots
T_{N,1}T_{N,2}\ldots T_{N,N}

Output

Print Yes if it is possible to exactly match S and T by 90-degree rotations and translations, and No otherwise.


Sample Input 1

5
.....
..#..
.###.
.....
.....
.....
.....
....#
...##
....#

Sample Output 1

Yes

We can match S to T by rotating it 90-degrees counter-clockwise and translating it.


Sample Input 2

5
#####
##..#
#..##
#####
.....
#####
#..##
##..#
#####
.....

Sample Output 2

No

It is impossible to match them by 90-degree rotations and translations.


Sample Input 3

4
#...
..#.
..#.
....
#...
#...
..#.
....

Sample Output 3

Yes

Each of S and T may not be connected.


Sample Input 4

4
#...
.##.
..#.
....
##..
#...
..#.
....

Sample Output 4

No

Note that it is not allowed to rotate or translate just a part of a figure; it is only allowed to rotate or translate a whole figure.

G - Bank

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 400

問題文

銀行に人 1, 人 2, \dots, 人 N が並んでいます。
Q 個のイベントが発生します。イベントは次の 3 種類のいずれかです。

  • 1 : 受付に呼ばれていない人のうち、最も小さい番号の人が受付に呼ばれる。
  • 2 x : 人 x が初めて受付に行く。(ここで、人 x はすでに 1 回以上受付に呼ばれている。)
  • 3 : すでに受付に呼ばれているが受付に行っていない人のうち、最も小さい番号の人が再度呼ばれる。

3 種類目のイベントで受付に呼ばれる人の番号を呼ばれた順に出力してください。

制約

  • 1 \leq N \leq 5 \times 10^5
  • 2 \leq Q \leq 5 \times 10^5
  • 全ての人が 1 回以上呼ばれているときに 1 種類目のイベントが発生することはない
  • 2 種類目のイベントについて、人 x はすでに 1 回以上受付に呼ばれている
  • 2 種類目のイベントについて、人 x が 2 回以上受付に行くことはない
  • 呼ばれている人が全員すでに受付に行っているときに 3 種類目のイベントが発生することはない
  • 3 種類目のイベントは少なくとも 1 回発生する
  • 入力される値はすべて整数

入力

入力は以下の形式で標準入力から与えられる。ここで \text{event}_ii 番目のイベントを意味する。

N Q
\text{event}_1
\text{event}_2
\vdots
\text{event}_Q

イベントは次の 3 つのいずれかの形式で入力される。

1
2 x
3

出力

入力で与えられる 3 種類目のイベントの個数を X として、X 行出力せよ。
i 行目には、3 種類目のイベントのうち i 番目のもので呼ばれた人の番号を出力せよ。


入力例 1

4 10
1
1
3
2 1
1
2 3
3
1
2 2
3

出力例 1

1
2
4

i = 1, 2, \dots, Q について、i 番目のイベントが起こる前の時点での、受付に呼ばれたが受付に行っていない人の集合を列挙すると次のようになります。

  • i=1 : \lbrace \rbrace
  • i=2 : \lbrace 1\rbrace
  • i=3 : \lbrace 1,2\rbrace
  • i=4 : \lbrace 1,2\rbrace
  • i=5 : \lbrace 2\rbrace
  • i=6 : \lbrace 2,3\rbrace
  • i=7 : \lbrace 2\rbrace
  • i=8 : \lbrace 2\rbrace
  • i=9 : \lbrace 2,4\rbrace
  • i=10 : \lbrace 4\rbrace

3 種類目のイベントは i=3,7,10 のときに発生しているので、その時点での集合のうち番号が最小の人である 1, 2, 4 を出力します。

Score : 400 points

Problem Statement

N people, with ID numbers 1, 2, \dots, N, are lining up in front of a bank.
There will be Q events. The following three kinds of events can happen.

  • 1 : The teller calls the person with the smallest ID number who has not been called.
  • 2 x : The person with the ID number x comes to the teller for the first time. (Here, person x has already been called by the teller at least once.)
  • 3 : The teller again calls the person with the smallest ID number who has already been called but has not come.

Print the ID numbers of the people called by the teller in events of the third kind.

Constraints

  • 1 \leq N \leq 5 \times 10^5
  • 2 \leq Q \leq 5 \times 10^5
  • There will not be an event of the first kind when all people have already been called at least once.
  • For each event of the second kind, the person with the ID number x has already been called by the teller at least once.
  • For each event of the second kind, the person with the ID number x will not come to the teller more than once.
  • There will not be an event of the third kind when all people who have already been called have come to the teller.
  • There is at least one event of the third kind.
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format, where \text{event}_i denotes the i-th event:

N Q
\text{event}_1
\text{event}_2
\vdots
\text{event}_Q

The description of each event is in one of the following formats:

1
2 x
3

Output

Print X lines, where X is the number of events of the third kind.
The i-th line should contain the ID number of the person called in the i-th event of the third kind.


Sample Input 1

4 10
1
1
3
2 1
1
2 3
3
1
2 2
3

Sample Output 1

1
2
4

For each i = 1, 2, \dots, Q, shown below is the set of people who have already been called but have not come just before the i-th event.

  • i=1 : \lbrace \rbrace
  • i=2 : \lbrace 1\rbrace
  • i=3 : \lbrace 1,2\rbrace
  • i=4 : \lbrace 1,2\rbrace
  • i=5 : \lbrace 2\rbrace
  • i=6 : \lbrace 2,3\rbrace
  • i=7 : \lbrace 2\rbrace
  • i=8 : \lbrace 2\rbrace
  • i=9 : \lbrace 2,4\rbrace
  • i=10 : \lbrace 4\rbrace

The events for i=3,7,10 are of the third kind, so you should print the persons with the smallest ID numbers in the sets for those events: 1, 2, 4.

H - Fraction Floor Sum

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 500

問題文

正の整数 N が与えられます。 \displaystyle\sum_{i=1}^N \left[ \frac{N}{i} \right] の値を求めてください。

ただし、実数 x に対して [x]x 以下の最大の整数を表します。

制約

  • 1 \leq N \leq 10^{12}
  • N は整数である。

入力

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

N

出力

答えを出力せよ。


入力例 1

3

出力例 1

5

\left[ \frac{3}{1} \right]+\left[ \frac{3}{2} \right]+\left[ \frac{3}{3} \right]=3+1+1=5 です。


入力例 2

10000000000

出力例 2

231802823220

入力や出力が 32 bit 整数型に収まらないことがあることに注意してください。

Score : 500 points

Problem Statement

Given is a positive integer N. Find the value \displaystyle\sum_{i=1}^N \left[ \frac{N}{i} \right].

Here, for a real number x, [x] denotes the largest integer not exceeding x.

Constraints

  • 1 \leq N \leq 10^{12}
  • N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

Print the answer.


Sample Input 1

3

Sample Output 1

5

We have \left[ \frac{3}{1} \right]+\left[ \frac{3}{2} \right]+\left[ \frac{3}{3} \right]=3+1+1=5.


Sample Input 2

10000000000

Sample Output 2

231802823220

Note that the input and output may not fit into a 32-bit integer type.

I - Find 4-cycle

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 500

問題文

S+T 頂点 M 辺の単純無向グラフ G があります。頂点には 1 から S+T の番号が、辺には 1 から M の番号が割り振られています。辺 i は頂点 u_i と頂点 v_i を結んでいます。
また、頂点集合 V_1 = \lbrace 1, 2,\dots, S\rbrace および V_2 = \lbrace S+1, S+2, \dots, S+T \rbrace はともに独立集合です。

長さ 4 のサイクルを 4-cycle と呼びます。
G が 4-cycle を含む場合、4-cycle をどれか 1 つ選び、選んだサイクルに含まれる頂点を出力してください。頂点を出力する順番は自由です。
G が 4-cycle を含まない場合、 -1 を出力してください。

独立集合とは? グラフ G の独立集合とは、G に含まれるいくつかの頂点からなる集合 V' であって、V' に含まれる任意の 2 つの頂点の間に辺がないものを言います。

制約

  • 2 \leq S \leq 3 \times 10^5
  • 2 \leq T \leq 3000
  • 4 \leq M \leq \min(S \times T,3 \times 10^5)
  • 1 \leq u_i \leq S
  • S + 1 \leq v_i \leq S + T
  • i \neq j ならば (u_i, v_i) \neq (u_j, v_j)
  • 入力される値はすべて整数

入力

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

S T M
u_1 v_1
u_2 v_2
\vdots
u_M v_M

出力

G が 4-cycle を含む場合は、任意の 4-cycle を 1 つ選び、選んだサイクルに含まれている相異なる 4 個の頂点の番号を出力せよ。(頂点の順番は問わない。)
G が 4-cycle を含まない場合は -1 を出力せよ。


入力例 1

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

出力例 1

1 2 4 5

頂点 14422551 の間に辺があるので 頂点 1,2,4,5 は 4-cycle をなします。よって 1, 2, 4, 5 を出力すればよいです。
頂点を出力する順番は自由で、出力例のほかにも例えば 2 5 1 4 のような出力も正答となります。


入力例 2

3 2 4
1 4
1 5
2 5
3 5

出力例 2

-1

G が 4-cycle を含まない入力もあります。


入力例 3

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

出力例 3

1 7 2 9

Score : 500 points

Problem Statement

We have a simple undirected graph G with (S+T) vertices and M edges. The vertices are numbered 1 through (S+T), and the edges are numbered 1 through M. Edge i connects Vertices u_i and v_i.
Here, vertex sets V_1 = \lbrace 1, 2,\dots, S\rbrace and V_2 = \lbrace S+1, S+2, \dots, S+T \rbrace are both independent sets.

A cycle of length 4 is called a 4-cycle.
If G contains a 4-cycle, choose any of them and print the vertices in the cycle. You may print the vertices in any order.
If G does not contain a 4-cycle, print -1.

What is an independent set? An independent set of a graph G is a set V' of some of the vertices in G such that no two vertices of V' have an edge between them.

Constraints

  • 2 \leq S \leq 3 \times 10^5
  • 2 \leq T \leq 3000
  • 4 \leq M \leq \min(S \times T,3 \times 10^5)
  • 1 \leq u_i \leq S
  • S + 1 \leq v_i \leq S + T
  • If i \neq j, then (u_i, v_i) \neq (u_j, v_j).
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

S T M
u_1 v_1
u_2 v_2
\vdots
u_M v_M

Output

If G contains a 4-cycle, choose any of them, and print the indices of the four distinct vertices in the cycle. (The order of the vertices does not matter.)
If G does not contain a 4-cycle, print -1.


Sample Input 1

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

Sample Output 1

1 2 4 5

There are edges between Vertices 1 and 4, 4 and 2, 2 and 5, and 5 and 1, so Vertices 1, 2, 4, and 5 form a 4-cycle. Thus, 1, 2, 4, and 5 should be printed.
The vertices may be printed in any order. Besides the Sample Output, 2 5 1 4 is also considered correct, for example.


Sample Input 2

3 2 4
1 4
1 5
2 5
3 5

Sample Output 2

-1

Some inputs may give G without a 4-cycle.


Sample Input 3

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

Sample Output 3

1 7 2 9