実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
100 以上 999 以下の整数 S が与えられます。
S が 200 以上 299 以下のとき Success
、そうでないとき Failure
と出力してください。
制約
- 100\leq S\leq999
- S は整数
入力
入力は以下の形式で標準入力から与えられる。
S
出力
答えを出力せよ。
入力例 1
200
出力例 1
Success
200 は 200 以上 299 以下なので、Success
と出力してください。
入力例 2
401
出力例 2
Failure
401 は 200 以上 299 以下ではないので、Failure
と出力してください。
入力例 3
999
出力例 3
Failure
Score : 100 points
Problem Statement
You are given an integer S between 100 and 999 (inclusive).
If S is between 200 and 299 (inclusive), print Success
; otherwise, print Failure
.
Constraints
- 100 \le S \le 999
- S is an integer.
Input
The input is given from Standard Input in the following format:
S
Output
Print the answer.
Sample Input 1
200
Sample Output 1
Success
200 is between 200 and 299, so print Success
.
Sample Input 2
401
Sample Output 2
Failure
401 is not between 200 and 299, so print Failure
.
Sample Input 3
999
Sample Output 3
Failure
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
ある日、高橋くんはあるウェブサイトに対して N 回の操作を行いました。
i 回目 (1\leq i\leq N) の操作は文字列 S _ i で表され、次の 4 つのうちいずれかです。
- S _ i=
login
である。高橋くんはログイン操作を行い、高橋くんがウェブサイトにログインした状態になる。 - S _ i=
logout
である。高橋くんはログアウト操作を行い、高橋くんがウェブサイトにログインしていない状態になる。 - S _ i=
public
である。高橋くんはウェブサイトの公開ページにアクセスする。 - S _ i=
private
である。高橋くんはウェブサイトの非公開ページにアクセスする。
高橋くんがログインしていない状態で非公開ページにアクセスした時、またその時に限り、ウェブサイトは認証エラーを返します。
ログインした状態でさらにログイン操作をしたり、ログインしていない状態でさらにログアウト操作をしてもエラーにはなりません。 また、認証エラーが返されたあとも、高橋くんは操作を続けることができます。
はじめ、高橋くんはログインしていない状態です。
N 回の操作のうち、高橋くんが認証エラーを受け取った回数を出力してください。
制約
- 1\leq N\leq100
- N は整数
- S _ i は
login
,logout
,public
,private
のいずれか (1\leq i\leq N)
入力
入力は以下の形式で標準入力から与えられる。
N S _ 1 S _ 2 \vdots S _ N
出力
高橋くんが認証エラーを受け取った回数を出力せよ。
入力例 1
6 login private public logout private public
出力例 1
1
高橋くんが行うそれぞれの操作の結果は以下のようになります。
- 高橋くんがウェブサイトにログインした状態になる。
- 高橋くんは非公開ページにアクセスする。高橋くんは現在ログインしているので、エラーは返されない。
- 高橋くんは公開ページにアクセスする。
- 高橋くんがウェブサイトにログインしていない状態になる。
- 高橋くんは非公開ページにアクセスする。高橋くんは現在ログインしていないので、認証エラーが返される。
- 高橋くんは公開ページにアクセスする。
高橋くんが認証エラーを受け取るのは 5 回目の操作のみなので、1
を出力してください。
入力例 2
4 private private private logout
出力例 2
3
連続で非公開ページにアクセスしようとした場合、操作のたびに認証エラーを受け取ります。
ログインしていない状態からさらにログアウト操作をした場合には認証エラーは返されないことに注意してください。
入力例 3
20 private login private logout public logout logout logout logout private login login private login private login public private logout private
出力例 3
3
Score : 200 points
Problem Statement
One day, Takahashi performed N operations on a certain web site.
The i‑th operation (1 \le i \le N) is represented by a string S_i, which is one of the following:
- S _ i=
login
: He performs a login operation and becomes logged in to the site. - S _ i=
logout
: He performs a logout operation and becomes not logged in to the site. - S _ i=
public
: He accesses a public page of the site. - S _ i=
private
: He accesses a private page of the site.
The site returns an authentication error if and only if he accesses a private page while he is not logged in.
Logging in again while already logged in, or logging out again while already logged out, does not cause an error. Even after an authentication error is returned, he continues performing the remaining operations.
Initially, he is not logged in.
Print the number of operations among the N operations at which he receives an authentication error.
Constraints
- 1 \le N \le 100
- N is an integer.
- Each S_i is one of
login
,logout
,public
,private
. (1 \le i \le N)
Input
The input is given from Standard Input in the following format:
N S_1 S_2 \vdots S_N
Output
Print the number of times Takahashi receives an authentication error.
Sample Input 1
6 login private public logout private public
Sample Output 1
1
The result of each operation is as follows:
- Takahashi becomes logged in.
- He accesses a private page. He is logged in, so no error is returned.
- He accesses a public page.
- He becomes logged out.
- He accesses a private page. He is not logged in, so an authentication error is returned.
- He accesses a public page.
An authentication error occurs only at the 5th operation, so print 1
.
Sample Input 2
4 private private private logout
Sample Output 2
3
If he tries to access private pages consecutively while not logged in, he receives an authentication error for each such operation.
Note that logging out again while already logged out does not cause an authentication error.
Sample Input 3
20 private login private logout public logout logout logout logout private login login private login private login public private logout private
Sample Output 3
3
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
正整数 N,K が与えられます。長さ N+1 の数列 A=(A_0,A_1,\ldots,A_N) の各要素の値を、以下の方法で定義します。
- 0\leq i<K のとき、 A_i=1
- K\leq i のとき、 A_i=A_{i-K}+A_{i-K+1}+\ldots+A_{i-1}
A_N を 10^9 で割ったあまりを求めてください。
制約
- 1\leq N, K\leq 10^{6}
- 入力される数値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N K
出力
答えを出力せよ。
入力例 1
4 2
出力例 1
5
A_0=A_1=1 であり、A_2=A_0+A_1=2,A_3=A_1+A_2=3,A_4=A_2+A_3=5 となります。
入力例 2
10 20
出力例 2
1
入力例 3
1000000 500000
出力例 3
420890625
A_N を 10^9 で割ったあまりを出力することに注意してください。
Score : 300 points
Problem Statement
You are given positive integers N and K. Define a sequence A = (A_0, A_1, \ldots, A_N) of length N+1 as follows:
- A_i = 1 for 0 \le i < K;
- A_i=A_{i-K}+A_{i-K+1}+\ldots+A_{i-1} for K \le i.
Find A_N modulo 10^9.
Constraints
- 1 \le N, K \le 10^{6}
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N K
Output
Print the answer.
Sample Input 1
4 2
Sample Output 1
5
We have A_0 = A_1 = 1, and A_2=A_0+A_1=2,A_3=A_1+A_2=3,A_4=A_2+A_3=5.
Sample Input 2
10 20
Sample Output 2
1
Sample Input 3
1000000 500000
Sample Output 3
420890625
Remember to print A_N modulo 10^9.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 400 点
問題文
.
, o
, ?
のみからなる長さ N の文字列 S が与えられます。
全ての ?
をそれぞれ .
または o
で置き換えて得られる文字列のうち、以下の条件を全て満たすものの集合を X とします。
o
の個数がちょうど K個o
が連続しない
X が空集合でないことは保証されます。
以下を満たす、長さ N の文字列 T を出力して下さい。ここで、T の左から i 番目の文字を T_i と表記します。
- X に含まれる全ての文字列の i 文字目が
.
である場合: T_i=.
- X に含まれる全ての文字列の i 文字目が
o
である場合: T_i=o
- i 文字目が
.
である文字列もo
である文字列も X に含まれている場合: T_i=?
制約
- 1\leq N\leq 2\times 10^5
- 0\leq K
- S は
.
,o
,?
のみからなる長さ N の文字列 - X は空集合ではない
- 入力される数値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N K S
出力
答えを出力せよ。
入力例 1
4 2 o???
出力例 1
o.??
o.o.
と o..o
の二つの文字列から X はなります。
X に含まれる全ての文字列の 1 文字目は o
なので、 T_1 は o
です。
X に含まれる全ての文字列の 2 文字目は .
なので、 T_2 は .
です。
X に含まれる文字列の 3 文字目としては .
も o
も考えられるので、 T_3 は ?
です。
入力例 2
5 2 ?????
出力例 2
?????
入力例 3
7 3 .o???o.
出力例 3
.o.o.o.
Score : 400 points
Problem Statement
You are given a string S of length N consisting of the characters .
, o
, and ?
.
Among the strings that can be obtained by replacing every ?
in S independently with either .
or o
, let X be the set of strings that satisfy all of the following conditions:
- The number of
o
s is exactly K. - No two
o
s are adjacent.
It is guaranteed that X is non‑empty.
Print a string T of length N that satisfies the following (let T_i denote the i‑th character of T):
- If the i‑th character of every string in X is
.
, then T_i=.
. - If the i‑th character of every string in X is
o
, then T_i=o
. - If X contains both a string whose i‑th character is
.
and a string whose i‑th character iso
, then T_i=?
.
Constraints
- 1 \le N \le 2 \times 10^{5}
- 0 \le K
- S is a string of length N consisting of
.
,o
,?
. - X is non‑empty.
- All given numerical values are integers.
Input
The input is given from Standard Input in the following format:
N K S
Output
Print the answer.
Sample Input 1
4 2 o???
Sample Output 1
o.??
The set X consists of the two strings o.o.
and o..o
.
- The 1st character of every string in X is
o
, so T_1 iso
. - The 2nd character of every string in X is
.
, so T_2 is.
. - The 3rd character of a string in X can be either
.
oro
, so T_3 is?
.
Sample Input 2
5 2 ?????
Sample Output 2
?????
Sample Input 3
7 3 .o???o.
Sample Output 3
.o.o.o.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 450 点
問題文
N 頂点 M 辺からなる無向グラフがあります。 頂点には 1,2,\ldots,N の番号がついており、i 番目 (1\leq i\leq M) の辺は頂点 u _ i と頂点 v _ i を結んでいます。
k=1,2,\ldots,N について、次の問題を解いてください。
次の操作について考える。
- 頂点を一つ選ぶ。選んだ頂点と、選んだ頂点に接続する全ての辺をグラフから削除する。
上の操作を繰り返すことで、次の条件を満たすことができるか判定せよ。
- 頂点 1 から辺をたどって到達できる頂点の集合が、頂点 1, 頂点 2,\ldots, 頂点 k のちょうど k 個からなる。
可能な場合、条件を満たすために少なくとも何回操作を行う必要があるか求めよ。
制約
- 1\leq N\leq2\times10 ^ 5
- 0\leq M\leq3\times10 ^ 5
- 1\leq u _ i\lt v _ i\leq N\ (1\leq i\leq M)
- (u _ i,v _ i)\neq(u _ j,v _ j)\ (1\leq i\lt j\leq M)
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N M u _ 1 v _ 1 u _ 2 v _ 2 \vdots u _ M v _ M
出力
N 行にわたって出力せよ。
i 行目 (1\leq i\leq N) には、k=i としたときの条件を満たすことができないなら -1
を、満たすことができるなら条件を満たすために行う必要がある操作の回数を出力せよ。
入力例 1
6 7 1 2 1 5 2 3 2 4 2 5 3 6 5 6
出力例 1
2 3 3 2 1 0
たとえば、k=2 としたときの問題では、頂点 3, 頂点 4, 頂点 5 の 3 つの頂点を選んで削除することで、頂点 1 から到達できる頂点を頂点 1, 頂点 2 の 2 つだけにすることができます。
頂点を 2 つ以下だけ削除して条件を満たすことはできないため、2 行目には 3
を出力してください。
また、k=6 としたときの問題では、頂点をひとつも削除しないことで頂点 1 から到達できる頂点を頂点 1, 頂点 2,\ldots, 頂点 6 の 6 つにすることができます。
なので、6 行目には 0
を出力してください。
入力例 2
5 4 1 5 2 3 3 4 4 5
出力例 2
1 -1 -1 -1 0
入力例 3
2 0
出力例 3
0 -1
辺が 1 つもない場合もあります。
入力例 4
11 25 6 9 5 9 2 3 1 9 10 11 4 5 9 10 8 9 7 8 3 5 1 7 6 10 4 7 7 9 1 10 4 11 3 8 2 7 3 4 1 8 2 8 3 7 2 10 1 6 6 11
出力例 4
5 -1 -1 -1 -1 -1 4 3 2 1 0
Score : 450 points
Problem Statement
You are given an undirected graph with N vertices and M edges. The vertices are numbered 1,2,\ldots,N, and the i‑th edge (1 \le i \le M) connects vertices u_i and v_i.
For each k = 1,2,\ldots,N, solve the following problem:
Consider the following operation.
- Choose one vertex, and delete that vertex together with all edges incident to it.
Determine whether one can repeat this operation to satisfy the following condition:
- The set of vertices reachable from vertex 1 by traversing edges consists exactly of the k vertices 1,2,\ldots,k.
If it is possible, find the minimum number of operations required to do so.
Constraints
- 1 \le N \le 2 \times 10^{5}
- 0 \le M \le 3 \times 10^{5}
- 1 \le u_i < v_i \le N\ (1 \le i \le M)
- (u_i,v_i) \ne (u_j,v_j)\ (1 \le i < j \le M)
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M u_1 v_1 u_2 v_2 \vdots u_M v_M
Output
Print N lines. On the i-th line (1 \le i \le N), if one cannot satisfy the condition for k=i, print -1
; otherwise, print the minimum number of operations required to satisfy the condition.
Sample Input 1
6 7 1 2 1 5 2 3 2 4 2 5 3 6 5 6
Sample Output 1
2 3 3 2 1 0
For example, for k = 2, deleting the three vertices 3, 4, 5 makes the set of vertices reachable from vertex 1 equal to the two vertices 1, 2.
It is impossible with two or fewer deletions, so print 3
on the 2nd line.
For k = 6, deleting zero vertices makes the set of vertices reachable from vertex 1 equal to the six vertices 1,2,\ldots,6, so print 0
on the 6th line.
Sample Input 2
5 4 1 5 2 3 3 4 4 5
Sample Output 2
1 -1 -1 -1 0
Sample Input 3
2 0
Sample Output 3
0 -1
There may be no edges.
Sample Input 4
11 25 6 9 5 9 2 3 1 9 10 11 4 5 9 10 8 9 7 8 3 5 1 7 6 10 4 7 7 9 1 10 4 11 3 8 2 7 3 4 1 8 2 8 3 7 2 10 1 6 6 11
Sample Output 4
5 -1 -1 -1 -1 -1 4 3 2 1 0
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 500 点
問題文
頂点に 1 から N_1 までの番号が付いた N_1 頂点の木 1 と、頂点に 1 から N_2 までの番号が付いた N_2 頂点の木 2 が与えられます。木 1 の i 番目の辺は木 1 の頂点 u_{1,i} と v_{1,i} を双方向に結び、木 2 の i 番目の辺は木 2 の頂点 u_{2,i} と v_{2,i} を双方向に結んでいます。
木 1 の頂点 i と、木 2 の頂点 j を双方向に結ぶ辺を追加すると一つの木が得られます。この木の直径を f(i,j) と定めます。
\displaystyle \sum_{i=1}^{N_1}\sum_{j=1}^{N_2} f(i,j) を求めてください。
ただし、木の 2 頂点の間の距離は一方から他方へ移動するときに用いる辺の本数の最小値であり、 木の直径は任意の 2 頂点の間の距離の最大値として定められます。
制約
- 1\leq N_1,N_2\leq 2\times 10^{5}
- 1\leq u_{1,i},v_{1,i}\leq N_1
- 1\leq u_{2,i},v_{2,i}\leq N_2
- 入力されるグラフは共に木
- 入力される数値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N_1 u_{1,1} v_{1,1} \vdots u_{1,N_1-1} v_{1,N_1-1} N_2 u_{2,1} v_{2,1} \vdots u_{2,N_2-1} v_{2,N_2-1}
出力
答えを出力せよ。
入力例 1
3 1 3 1 2 3 1 2 3 1
出力例 1
39
例えば木 1 の頂点 2 と木 2 の頂点 3 を結んで得られる木の直径は 5 です。よって f(2,3) は 5 となります。
f(i,j) の総和は 39 です。
入力例 2
7 5 6 1 3 5 7 4 5 1 6 1 2 5 5 3 2 4 2 3 5 1
出力例 2
267
Score : 500 points
Problem Statement
You are given two trees: tree 1 with N_1 vertices numbered 1 to N_1, and tree 2 with N_2 vertices numbered 1 to N_2. The i-th edge of tree 1 connects vertices u_{1,i} and v_{1,i} bidirectionally, and the i-th edge of tree 2 connects vertices u_{2,i} and v_{2,i} bidirectionally.
One can add a bidirectional edge between vertex i of tree 1 and vertex j of tree 2 to obtain a single tree. Let f(i,j) be the diameter of this tree.
Find \displaystyle \sum_{i=1}^{N_1}\sum_{j=1}^{N_2} f(i,j).
Here, the distance between two vertices of a tree is the minimum number of edges that must be used to move between them, and the diameter of a tree is the maximum distance between two vertices.
Constraints
- 1 \le N_1, N_2 \le 2 \times 10^{5}
- 1 \le u_{1,i}, v_{1,i} \le N_1
- 1 \le u_{2,i}, v_{2,i} \le N_2
- Both given graphs are trees.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N_1 u_{1,1} v_{1,1} \vdots u_{1,N_1-1} v_{1,N_1-1} N_2 u_{2,1} v_{2,1} \vdots u_{2,N_2-1} v_{2,N_2-1}
Output
Print the answer.
Sample Input 1
3 1 3 1 2 3 1 2 3 1
Sample Output 1
39
For example, one can connect vertex 2 of tree 1 and vertex 3 of tree 2 to obtain a tree of diameter 5. Thus, f(2,3) is 5.
The sum of f(i,j) is 39.
Sample Input 2
7 5 6 1 3 5 7 4 5 1 6 1 2 5 5 3 2 4 2 3 5 1
Sample Output 2
267
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 575 点
問題文
平面上に N 人の高橋くんと N 個のボタンがあります。 平面上には原点があり、原点から東に x メートル進み、北に y メートル進んだ位置を座標 (x,y) で表すこととします。 i 番目 (1\leq i\leq N) の高橋くんははじめ座標 (\mathit{sx} _ i,\mathit{sy} _ i) にいます。 i 番目 (1\leq i\leq N) のボタンは座標 (\mathit{gx} _ i,\mathit{gy} _ i) にあります。
高橋くんたちはそれぞれ移動をした後、この N 個のボタンを一斉に押したいです。 各ボタンは、そのボタンがある座標にいる高橋くんだけが押すことができます。 ボタンが存在する座標に到達してからボタンを押すのに必要な時間は 0 秒です。
それぞれの高橋くんは秒速 1 メートル以下の速さで好きな方向に進むことができます。 より厳密には、i 番目の高橋くんがスタートから t 秒後にいる座標を (x _ i(t),y _ i(t)) としたとき、次の条件がすべて成り立っている必要があります。
- x _ i(0)=\mathit{sx} _ i
- y _ i(0)=\mathit{sy} _ i
- すべての非負実数 t _ 0,t _ 1 について、点 (x _ i(t _ 0),y _ i(t _ 0)) と点 (x _ i(t _ 1),y _ i(t _ 1)) の距離は |t _ 0-t _ 1| 以下
高橋くんたちが目標を達成するために必要な時間を求めてください。 厳密には、次の条件を満たすことができる t の最小値を求めてください。
- x _ i,y _ i を上の条件を満たすように適切に定めたとき、すべての整数 j\ (1\leq j\leq N) および実数 t ^ \prime\ (t ^ \prime\gt t) に対して、ある整数 i\ (1\leq i\leq N) が存在して (x _ i(t ^ \prime),y _ i(t ^ \prime))=(\mathit{gx} _ j,\mathit{gy} _ j) が成り立つ。
制約
- 1\leq N\leq 300
- 0\leq\mathit{sx} _ i\leq10 ^ {18}\ (1\leq i\leq N)
- 0\leq\mathit{sy} _ i\leq10 ^ {18}\ (1\leq i\leq N)
- 0\leq\mathit{gx} _ i\leq10 ^ {18}\ (1\leq i\leq N)
- 0\leq\mathit{gy} _ i\leq10 ^ {18}\ (1\leq i\leq N)
- (\mathit{sx} _ i,\mathit{sy} _ i)\neq(\mathit{sx} _ j,\mathit{sy} _ j)\ (1\leq i\lt j\leq N)
- (\mathit{gx} _ i,\mathit{gy} _ i)\neq(\mathit{gx} _ j,\mathit{gy} _ j)\ (1\leq i\lt j\leq N)
- (\mathit{sx} _ i,\mathit{sy} _ i)\neq(\mathit{gx} _ j,\mathit{gy} _ j)\ (1\leq i\leq N,1\leq j\leq N)
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N \mathit{sx} _ 1 \mathit{sy} _ 1 \mathit{sx} _ 2 \mathit{sy} _ 2 \vdots \mathit{sx} _ N \mathit{sy} _ N \mathit{gx} _ 1 \mathit{gy} _ 1 \mathit{gx} _ 2 \mathit{gy} _ 2 \vdots \mathit{gx} _ N \mathit{gy} _ N
出力
N 人の高橋くんが N 個のボタンを同時に押すのに必要な時間を出力せよ。 真の値と出力との相対誤差が 10 ^ {-6} 以下のとき、正解と判定される。
入力例 1
4 0 0 0 1 2 0 3 1 0 2 1 0 1 2 2 2
出力例 1
2
はじめ、高橋くんとボタンの位置関係は以下のようになっています。
1,2,3,4 番目の高橋くんが、それぞれ 1,3,2,4 番目のボタンに向かってまっすぐ動くことを考えます。
すると、高橋くんたちはそれぞれスタートから 2 秒後、\sqrt2 秒後、1 秒後、\sqrt2 秒後には対応するボタンがある座標に到着しています。
よって、スタートから 2 秒後にすべてのボタンを一斉に押すことができます。
逆に、スタートから 2 秒経つより前にすべてのボタンを一斉に押すことはできないので、2
を出力してください。
答えの真の値と出力との相対誤差が 10 ^ {-6} 以下であれば正解と判定されるため、1.999998
や 2.00000014
などを出力してもこのケースに対する正答と判定されます。
入力例 2
3 1 4 1 5 9 2 653589793238462643 383279502884197169 399375105820974944 592307816406286208 99862803482534211 706798214808651328
出力例 2
757682516069002110.04581169374262658710741005525
入力される座標が 32\operatorname{bit} 整数におさまらない場合があることに注意してください。
入力例 3
12 4459915897 5789359311 4393259463 4247016333 4827828467 4179021045 2654035685 3406423989 1790405301 4886103164 2978675817 4818583236 5912369644 5824121992 6016882384 4165667191 4305949638 3454894060 6545166942 5390976281 4043403253 4019611554 3462096432 4117859301 3528911877 4631601790 4627979431 4814676729 3810130146 5728760563 5586470124 3310360339 3664130072 4525834271 1710246881 3750440871 3143440609 5038869551 2294021341 3965849888 6189106395 4499485672 4799619607 5151972020 6905793542 3976136296 1764267574 4525373194
出力例 3
1299999319.116399442508650717909981965254
Score : 575 points
Problem Statement
There are N people and N buttons on a plane. The plane has an origin, and the coordinates (x, y) represents the position that is x meters east and y meters north of the origin. The i‑th person (1 \le i \le N) starts at (\mathit{sx}_i,\mathit{sy}_i). The i‑th button (1 \le i \le N) is located at (\mathit{gx}_i,\mathit{gy}_i).
The people want to move and press these N buttons simultaneously. A button can be pressed only by a person who is at the same coordinate as that button. The time required to press a button after reaching its coordinate is 0 seconds.
Each person can move in any direction with speed at most 1 meter per second. More formally, if the position of the i‑th person t seconds after the start is (x_i(t), y_i(t)), all of the following must hold:
- x_i(0) = \mathit{sx}_i;
- y_i(0) = \mathit{sy}_i;
- For all non‑negative real numbers t_0, t_1, the distance between (x_i(t_0), y_i(t_0)) and (x_i(t_1), y_i(t_1)) is at most |t_0 - t_1|.
Find the time required for the people to achieve the goal. Formally, find the minimum t that satisfies the following condition:
- It is possible to set x_i and y_i under the above conditions so that, for every integer j\ (1\leq j\leq N) and every real number t ^ \prime\ (t ^ \prime\gt t), there exists an integer i\ (1\leq i\leq N) with (x _ i(t ^ \prime),y _ i(t ^ \prime))=(\mathit{gx} _ j,\mathit{gy} _ j).
Constraints
- 1\leq N\leq 300
- 0\leq\mathit{sx} _ i\leq10 ^ {18}\ (1\leq i\leq N)
- 0\leq\mathit{sy} _ i\leq10 ^ {18}\ (1\leq i\leq N)
- 0\leq\mathit{gx} _ i\leq10 ^ {18}\ (1\leq i\leq N)
- 0\leq\mathit{gy} _ i\leq10 ^ {18}\ (1\leq i\leq N)
- (\mathit{sx} _ i,\mathit{sy} _ i)\neq(\mathit{sx} _ j,\mathit{sy} _ j)\ (1\leq i\lt j\leq N)
- (\mathit{gx} _ i,\mathit{gy} _ i)\neq(\mathit{gx} _ j,\mathit{gy} _ j)\ (1\leq i\lt j\leq N)
- (\mathit{sx} _ i,\mathit{sy} _ i)\neq(\mathit{gx} _ j,\mathit{gy} _ j)\ (1\leq i\leq N,1\leq j\leq N)
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N \mathit{sx}_1 \mathit{sy}_1 \mathit{sx}_2 \mathit{sy}_2 \vdots \mathit{sx}_N \mathit{sy}_N \mathit{gx}_1 \mathit{gy}_1 \mathit{gx}_2 \mathit{gy}_2 \vdots \mathit{gx}_N \mathit{gy}_N
Output
Print the time required for the N people to press the N buttons simultaneously. Your output is considered correct if the relative error from the true value is at most 10^{-6}.
Sample Input 1
4 0 0 0 1 2 0 3 1 0 2 1 0 1 2 2 2
Sample Output 1
2
Initially, the positions of the people and buttons are as shown below.
Suppose persons 1,2,3,4 move straight toward buttons 1,3,2,4, respectively.
They reach their respective buttons after 2, \sqrt2, 1, and \sqrt2 seconds.
Thus, all buttons can be pressed simultaneously 2 seconds after the start.
Conversely, they cannot press all buttons simultaneously earlier than 2 seconds, so print 2
.
Because an output is accepted if its relative error from the true value is at most 10^{-6}, outputs such as 1.999998
or 2.00000014
are also considered correct for this test case.
Sample Input 2
3 1 4 1 5 9 2 653589793238462643 383279502884197169 399375105820974944 592307816406286208 99862803482534211 706798214808651328
Sample Output 2
757682516069002110.04581169374262658710741005525
Note that the input coordinates may not fit in 32‑bit integers.
Sample Input 3
12 4459915897 5789359311 4393259463 4247016333 4827828467 4179021045 2654035685 3406423989 1790405301 4886103164 2978675817 4818583236 5912369644 5824121992 6016882384 4165667191 4305949638 3454894060 6545166942 5390976281 4043403253 4019611554 3462096432 4117859301 3528911877 4631601790 4627979431 4814676729 3810130146 5728760563 5586470124 3310360339 3664130072 4525834271 1710246881 3750440871 3143440609 5038869551 2294021341 3965849888 6189106395 4499485672 4799619607 5151972020 6905793542 3976136296 1764267574 4525373194
Sample Output 3
1299999319.116399442508650717909981965254