A - 3.14

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100

問題文

円周率の小数第 100 位までの値は

3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679

です。

1 以上 100 以下の整数 N が与えられます。

円周率を小数第 N 位まで出力してください。

より厳密には、円周率を小数第 N+1 位で切り捨て、末尾の 0 を取り除かずに出力してください。

制約

  • 1\leq N\leq 100
  • N は整数

入力

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

N

出力

円周率を小数第 N 位まで 1 行で出力せよ。


入力例 1

2

出力例 1

3.14

円周率を小数第 2+1 位で切り捨てると値は 3.14 になります。 よって、3.14 を出力してください。


入力例 2

32

出力例 2

3.14159265358979323846264338327950

末尾の 0 は取り除かずに出力してください。


入力例 3

100

出力例 3

3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679

Score : 100 points

Problem Statement

The number pi to the 100-th decimal place is

3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679.

You are given an integer N between 1 and 100, inclusive.

Print the value of pi to the N-th decimal place.

More precisely, truncate the value of pi to N decimal places and print the result without removing the trailing 0s.

Constraints

  • 1\leq N\leq 100
  • N is an integer.

Input

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

N

Output

Print the value of pi to the N-th decimal place in a single line.


Sample Input 1

2

Sample Output 1

3.14

Truncating the value of pi to 2 decimal places results in 3.14. Thus, you should print 3.14.


Sample Input 2

32

Sample Output 2

3.14159265358979323846264338327950

Do not remove the trailing 0s.


Sample Input 3

100

Sample Output 3

3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
B - Count Down

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100

問題文

N 以下の非負整数を大きい方から順にすべて出力してください。

制約

  • 1 \leq N \leq 100
  • N は整数

入力

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

N

出力

N 以下の非負整数が X 個存在するとき、X 行出力せよ。
i=1,2,\ldots,X に対し、i 行目には N 以下の非負整数のうち大きい方から i 番目のものを出力せよ。


入力例 1

3

出力例 1

3
2
1
0

3 以下の非負整数は 0,1,2,34 個です。
1 行目に 3 を、2 行目に 2 を、3 行目に 1 を、4 行目に 0 を出力することでこれらを大きい方から順に出力したことになります。


入力例 2

22

出力例 2

22
21
20
19
18
17
16
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
0

Score : 100 points

Problem Statement

Print all non-negative integers less than or equal to N in descending order.

Constraints

  • 1 \leq N \leq 100
  • N is an integer.

Input

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

N

Output

Print X lines, where X is the number of non-negative integers less than or equal to N.
For each i=1, 2, \ldots, X, the i-th line should contain the i-th greatest non-negative integer less than or equal to N.


Sample Input 1

3

Sample Output 1

3
2
1
0

We have four non-negative integers less than or equal to 3, which are 0, 1, 2, and 3.
To print them in descending order, print 3 in the first line, 2 in the second, 1 in the third, and 0 in the fourth.


Sample Input 2

22

Sample Output 2

22
21
20
19
18
17
16
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
0
C - racecar

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

英小文字のみからなる N 個の文字列 S_1,S_2,\ldots,S_N が与えられます。
1 以上 N 以下の 相異なる 整数 i,j であって、S_iS_j をこの順に連結した文字列が回文となるようなものが存在するか判定してください。

ただし、長さ M の文字列 T が回文であるとは、任意の 1\leq i\leq M について、Ti 文字目と (M+1-i) 文字目が一致していることをいいます。

制約

  • 2\leq N\leq 100
  • 1\leq \lvert S_i\rvert \leq 50
  • N は整数
  • S_i は英小文字のみからなる文字列
  • S_i はすべて異なる。

入力

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

N
S_1
S_2
\vdots
S_N

出力

問題文の条件をみたす i,j が存在するならば Yes を、そうでないならば No を出力せよ。


入力例 1

5
ab
ccef
da
a
fe

出力例 1

Yes

(i,j)=(1,4) とすると、S_1=abS_4=a をこの順に連結した文字列は aba となり、 これは回文であるため条件をみたしています。
よって、Yes を出力します。

また、(i,j)=(5,2) としても、S_5=feS_2=ccef をこの順に連結した文字列は feccef となり、やはり条件をみたしています。


入力例 2

3
a
b
aba

出力例 2

No

S_1, S_2, S_3 のうち、どの相異なる 2 つの文字列を繋げても回文となりません。 よって、No を出力します。
問題文における i,j は相異なる必要があることに注意してください。


入力例 3

2
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

出力例 3

Yes

Score : 200 points

Problem Statement

You are given N strings S_1,S_2,\ldots,S_N consisting of lowercase English letters.
Determine if there are distinct integers i and j between 1 and N, inclusive, such that the concatenation of S_i and S_j in this order is a palindrome.

A string T of length M is a palindrome if and only if the i-th character and the (M+1-i)-th character of T are the same for every 1\leq i\leq M.

Constraints

  • 2\leq N\leq 100
  • 1\leq \lvert S_i\rvert \leq 50
  • N is an integer.
  • S_i is a string consisting of lowercase English letters.
  • All S_i are distinct.

Input

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

N
S_1
S_2
\vdots
S_N

Output

If there are i and j that satisfy the condition in the problem statement, print Yes; otherwise, print No.


Sample Input 1

5
ab
ccef
da
a
fe

Sample Output 1

Yes

If we take (i,j)=(1,4), the concatenation of S_1=ab and S_4=a in this order is aba, which is a palindrome, satisfying the condition.
Thus, print Yes.

Here, we can also take (i,j)=(5,2), for which the concatenation of S_5=fe and S_2=ccef in this order is feccef, satisfying the condition.


Sample Input 2

3
a
b
aba

Sample Output 2

No

No two distinct strings among S_1, S_2, and S_3 form a palindrome when concatenated. Thus, print No.
Note that the i and j in the statement must be distinct.


Sample Input 3

2
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

Sample Output 3

Yes
D - Base K

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

整数 A,BK 進法表記で与えられます。
A \times B10 進法表記で出力してください。

注記

K 進法表記については、Wikipedia「位取り記数法」 を参照してください。

制約

  • 2 \leq K \leq 10
  • 1 \leq A,B \leq 10^5
  • A,BK 進法表記で与えられる

入力

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

K
A B

出力

答えを出力せよ。


入力例 1

2
1011 10100

出力例 1

220

2 進法表記の 1011 を 、10 進法表記すると 11 です。
2 進法表記の 10100 を、 10 進法表記すると 20 です。
11 \times 20 = 220 なので 220 を出力します。


入力例 2

7
123 456

出力例 2

15642

7 進法表記の 123 を 、10 進法表記すると 66 です。
7 進法表記の 456 を、 10 進法表記すると 237 です。
66 \times 237 = 15642 なので 15642 を出力します。

Score : 200 points

Problem Statement

You are given integers A and B, in base K.
Print A \times B in decimal.

Notes

For base-K representation, see Wikipedia's article on Positional notation.

Constraints

  • 2 \leq K \leq 10
  • 1 \leq A,B \leq 10^5
  • A and B are in base-K representation.

Input

Input is given from Standard Input in the following format:

K
A B

Output

Print the answer.


Sample Input 1

2
1011 10100

Sample Output 1

220

1011 in base 2 corresponds to 11 in base 10.
10100 in base 2 corresponds to 20 in base 10.
We have 11 \times 20 = 220, so print 220.


Sample Input 2

7
123 456

Sample Output 2

15642

123 in base 7 corresponds to 66 in base 10.
456 in base 7 corresponds to 237 in base 10.
We have 66 \times 237 = 15642, so print 15642.

E - Gap Existence

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

長さ N の数列 A=(A_1,\ldots,A_N) が与えられます。

1\leq i,j \leq N である組 (i,j) であって、A_i-A_j=X となるものが存在するかどうか判定してください。

制約

  • 2 \leq N \leq 2\times 10^5
  • -10^9 \leq A_i \leq 10^9
  • -10^9 \leq X \leq 10^9
  • 入力は全て整数である

入力

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

N X
A_1 \ldots A_N

出力

1\leq i,j \leq N である組 (i,j) であって、A_i-A_j=X となるものが存在するとき Yes、存在しないとき No と出力せよ。


入力例 1

6 5
3 1 4 1 5 9

出力例 1

Yes

A_6-A_3=9-4=5 です。


入力例 2

6 -4
-2 -7 -1 -8 -2 -8

出力例 2

No

A_i-A_j=-4 となる組 (i,j) は存在しません。


入力例 3

2 0
141421356 17320508

出力例 3

Yes

A_1-A_1=0 です。

Score : 300 points

Problem Statement

You are given a sequence of N numbers: A=(A_1,\ldots,A_N).

Determine whether there is a pair (i,j) with 1\leq i,j \leq N such that A_i-A_j=X.

Constraints

  • 2 \leq N \leq 2\times 10^5
  • -10^9 \leq A_i \leq 10^9
  • -10^9 \leq X \leq 10^9
  • All values in the input are integers.

Input

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

N X
A_1 \ldots A_N

Output

Print Yes if there is a pair (i,j) with 1\leq i,j \leq N such that A_i-A_j=X, and No otherwise.


Sample Input 1

6 5
3 1 4 1 5 9

Sample Output 1

Yes

We have A_6-A_3=9-4=5.


Sample Input 2

6 -4
-2 -7 -1 -8 -2 -8

Sample Output 2

No

There is no pair (i,j) such that A_i-A_j=-4.


Sample Input 3

2 0
141421356 17320508

Sample Output 3

Yes

We have A_1-A_1=0.

F - kasaka

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

英小文字からなる文字列 S が与えられます。 S の先頭に a をいくつか( 0 個でも良い)つけ加えて回文にすることができるか判定してください。

ただし、長さ N の文字列 A=A_1A_2\ldots A_N が回文であるとは、すべての 1\leq i\leq N について A_i=A_{N+1-i} が成り立っていることをいいます。

制約

  • 1 \leq \lvert S \rvert \leq 10^6
  • S は英小文字のみからなる。

入力

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

S

出力

S の先頭に a をいくつかつけ加えて回文にすることができるならば Yes を、そうでないならば No を出力せよ。


入力例 1

kasaka

出力例 1

Yes

kasaka の先頭に a1 つ付け加えることによって、akasaka となり回文となるため Yes を出力します。


入力例 2

atcoder

出力例 2

No

atcoder の先頭に a をいくつ付け加えても回文となる事はありません。


入力例 3

php

出力例 3

Yes

php はそれ自体回文です。S の先頭に付け加える a0 個でも許されるため、Yes を出力します。

Score : 300 points

Problem Statement

Given is a string S consisting of lowercase English letters. Determine whether adding some number of a's (possibly zero) at the beginning of S can make it a palindrome.

Here, a string of length N, A=A_1A_2\ldots A_N, is said to be a palindrome when A_i=A_{N+1-i} for every 1\leq i\leq N.

Constraints

  • 1 \leq \lvert S \rvert \leq 10^6
  • S consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S

Output

If adding some number of a's (possibly zero) at the beginning of S can make it a palindrome, print Yes; otherwise, print No.


Sample Input 1

kasaka

Sample Output 1

Yes

By adding one a at the beginning of kasaka, we have akasaka, which is a palindrome, so Yes should be printed.


Sample Input 2

atcoder

Sample Output 2

No

Adding any number of a's at the beginning of atcoder does not make it a palindrome.


Sample Input 3

php

Sample Output 3

Yes

php itself is a palindrome. Adding zero a's at the beginning of S is allowed, so Yes should be printed.

G - Destroyer Takahashi

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 400

問題文

N10^9 列の格子状の区画に区切られた街に N 枚の壁があり、1 から N までの番号が割り振られています。
i は上から i 行目、左から L_i 列目から R_i 列目の範囲にあります。(入出力例 1 の図も参考にしてください。)

高橋君は N 枚の壁をすべて破壊することにしました。
超人的な腕力を持つ高橋君は、1 回のパンチで連続する D 列にまとめてダメージを与えることができます。

  • より厳密に言い換えると、1 以上 10^9 - D + 1 以下の 整数 x を選んで、x 列目から x + D - 1 列目に (一部でも) 存在するすべての破壊されていない壁にパンチによるダメージを与えることができます。

壁は一部分でもダメージを受けると、パンチの衝撃波により全体が木っ端みじんに破壊されてしまいます。
(入出力例 1 の説明も参考にしてください。)

高橋君がすべての壁を破壊するには、少なくとも何回のパンチを放つ必要がありますか?

制約

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq D \leq 10^9
  • 1 \leq L_i \leq R_i \leq 10^9
  • 入力はすべて整数である。

入力

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

N D
L_1 R_1
L_2 R_2
\vdots
L_N R_N

出力

すべての壁を破壊するのに必要なパンチの最少回数を出力せよ。


入力例 1

3 3
1 2
4 7
5 9

出力例 1

2

入力例 1 に対応する壁の配置を図示したものが下図です。

image

たとえば次のようにパンチを放つことで、 2 回のパンチですべての壁を破壊することができます。(以下の説明では、a 列目から b 列目までの範囲を \lbrack a, b \rbrack と表記します。)

  • まず、 \lbrack 2, 4 \rbrack にパンチを放つ。 \lbrack 2, 4 \rbrack に存在する壁である壁 1 と壁 2 はダメージを受け、破壊される。
  • 次に \lbrack 5, 7\rbrack にパンチを放つ。\lbrack 5, 7\rbrack に存在する壁 3 はダメージを受け、破壊される。

また、次の方法でもすべての壁を 2 回のパンチで破壊することができます。

  • まず、\lbrack 7, 9 \rbrack にパンチを放ち、壁 2 と壁 3 を破壊する。
  • 次に、\lbrack 1, 3 \rbrack にパンチを放ち、壁 1 を破壊する。

入力例 2

3 3
1 2
4 7
4 9

出力例 2

1

入出力例 1 と比べると、壁 3 の範囲が \lbrack 5, 9 \rbrack から \lbrack 4, 9 \rbrack に変わりました。
この場合は \lbrack 2, 4 \rbrack にパンチを放つことで 1 回ですべての壁を破壊できます。


入力例 3

5 2
1 100
1 1000000000
101 1000
9982 44353
1000000000 1000000000

出力例 3

3

Score : 400 points

Problem Statement

In a town divided into a grid with N rows and 10^9 columns, there are N walls, numbered 1 to N.
Wall i ranges from the L_i-th column to the R_i-th column from the left in the i-th row from the top. (See also the figure at Sample Input and Output 1.)

Takahashi has decided to destroy all N walls.
With his superhuman strength, his one punch can damage consecutive D columns at once.

  • More formally, he can choose an integer x between 1 and 10^9 - D + 1 (inclusive) to damage all walls that exist (or partly exist) in the x-th through (x + D - 1)-th columns and are not yet destroyed.

When a part of a wall is damaged, that whole wall will be destroyed by the impact of the punch.
(See also the figure at Sample Input and Output 1.)

At least how many times does Takahashi need to punch to destroy all walls?

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq D \leq 10^9
  • 1 \leq L_i \leq R_i \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N D
L_1 R_1
L_2 R_2
\vdots
L_N R_N

Output

Print the minimum number of punches needed to destroy all walls.


Sample Input 1

3 3
1 2
4 7
5 9

Sample Output 1

2

The figure below describes the arrangements of walls in Sample Input 1.

image

He can destroy all walls with two punches, such as the following. (Below, \lbrack a, b \rbrack denotes the range from the a-th through b-th columns.)

  • First, punch \lbrack 2, 4 \rbrack. The walls existing in \lbrack 2, 4 \rbrack ― Walls 1 and 2 ― are damaged and destroyed.
  • Second, punch \lbrack 5, 7 \rbrack. The wall existing in \lbrack 5, 7 \rbrack ― Wall 3 ― is damaged and destroyed.

It is also possible to destroy all walls with two punches in this way:

  • First, punch \lbrack 7, 9 \rbrack to destroy Walls 2 and 3.
  • Second, punch \lbrack 1, 3 \rbrack to destroy Wall 1.

Sample Input 2

3 3
1 2
4 7
4 9

Sample Output 2

1

The difference from Sample Input/Output 1 is that Wall 3 now covers \lbrack 4, 9 \rbrack, not \lbrack 5, 9 \rbrack.
In this case, he can punch \lbrack 2, 4 \rbrack to destroy all walls with one punch.


Sample Input 3

5 2
1 100
1 1000000000
101 1000
9982 44353
1000000000 1000000000

Sample Output 3

3
H - K-colinear Line

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 500

問題文

座標平面上の N 個の点が与えられます。 1\leq i\leq N について、i 番目の点の座標は (X_i, Y_i) です。

座標平面上の直線であって、N 個の点のうち K 個以上の点を通るものの個数を求めてください。
ただし、そのようなものが無数に存在する場合は Infinity を出力してください。

制約

  • 1 \leq K \leq N \leq 300
  • \lvert X_i \rvert, \lvert Y_i \rvert \leq 10^9
  • i\neq j ならば X_i\neq X_j または Y_i\neq Y_j
  • 入力はすべて整数

入力

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

N K
X_1 Y_1
X_2 Y_2
\vdots
X_N Y_N

出力

与えられた N 個の点のうち K 個以上の点を通る直線の数を出力せよ。ただし、そのようなものが無数に存在する場合は Infinity を出力せよ。


入力例 1

5 2
0 0
1 0
0 1
-1 0
0 -1

出力例 1

6

x=0, y=0, y=x\pm 1, y=-x\pm 16 本の直線が条件をみたします。
例えば、x=0 は、1, 3, 5 番目の 3 個の点を通ります。

よって、6 を出力します。


入力例 2

1 1
0 0

出力例 2

Infinity

原点を通る直線は無数に存在します。 よって、Infinity を出力します。

Score : 500 points

Problem Statement

You are given N points in the coordinate plane. For each 1\leq i\leq N, the i-th point is at the coordinates (X_i, Y_i).

Find the number of lines in the plane that pass K or more of the N points.
If there are infinitely many such lines, print Infinity.

Constraints

  • 1 \leq K \leq N \leq 300
  • \lvert X_i \rvert, \lvert Y_i \rvert \leq 10^9
  • X_i\neq X_j or Y_i\neq Y_j, if i\neq j.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
X_1 Y_1
X_2 Y_2
\vdots
X_N Y_N

Output

Print the number of lines in the plane that pass K or more of the N points, or Infinity if there are infinitely many such lines.


Sample Input 1

5 2
0 0
1 0
0 1
-1 0
0 -1

Sample Output 1

6

The six lines x=0, y=0, y=x\pm 1, and y=-x\pm 1 satisfy the requirement.
For example, x=0 passes the first, third, and fifth points.

Thus, 6 should be printed.


Sample Input 2

1 1
0 0

Sample Output 2

Infinity

Infinitely many lines pass the origin.

Thus, Infinity should be printed.

I - Regular Triangle Inside a Rectangle

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 500

問題文

縦の長さが A、横の長さが B の長方形の内部に描ける正三角形の一辺の長さの最大値を求めてください。

制約

  • 1 \leq A,B \leq 1000
  • A,B は整数

入力

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

A B

出力

答えを出力せよ。
なお、真の値との絶対誤差または相対誤差が 10^{-9} 以下であれば正解として扱われる。


入力例 1

1 1

出力例 1

1.03527618041008295791

下図のように描くのが最適で、一辺の長さが \sqrt{6} - \sqrt{2} になります。

image

なお、この出力例の値は \sqrt{6}- \sqrt{2} と厳密には一致しませんが、誤差が 10^{-9} 以下なので正解として扱われます。

Score : 500 points

Problem Statement

Find the maximum side length of a regular triangle that can be drawn within a rectangle whose side lengths are A and B.

Constraints

  • 1 \leq A,B \leq 1000
  • A and B are integers.

Input

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

A B

Output

Print the answer.
Your output is considered correct if the absolute or relative error from the true answer is at most 10^{-9}.


Sample Input 1

1 1

Sample Output 1

1.03527618041008295791

The following figure shows an optimal drawing, with the side length of \sqrt{6} - \sqrt{2}.

image

Note that the sample output does not strictly match \sqrt{6}- \sqrt{2}, but the error is within 10^{-9}, so it is considered correct.