A - Round decimals

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100 点

問題文

小数第三位までで表すことのできる実数 X が、小数第三位まで入力されます。
X を小数第一位で四捨五入した結果として得られる整数を出力してください。

制約

  • 0 \leq X < 100
  • X は小数第三位までで表現可能である。
  • X は小数第三位まで与えられる。

入力

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

X

出力

X を小数第一位で四捨五入して得られる整数を出力せよ。


入力例 1

3.456

出力例 1

3

3.456 の小数第一位は 4 であるので、3.456 を小数第一位で四捨五入した値は 3 となります。


入力例 2

99.500

出力例 2

100

入力例 3

0.000

出力例 3

0

Score : 100 points

Problem Statement

You are given a real number X, which is representable using at most three decimal digits, with three decimal digits.
Round X to the nearest integer and print the result.

Constraints

  • 0 \leq X < 100
  • X is representable using at most three decimal digits.
  • X has three decimal digits in input.

Input

Input is given from Standard Input in the following format:

X

Output

Print the integer resulting from rounding X to the nearest integer.


Sample Input 1

3.456

Sample Output 1

3

The digit in the first decimal place of 3.456 is 4, so we should round it down to 3.


Sample Input 2

99.500

Sample Output 2

100

Sample Input 3

0.000

Sample Output 3

0
B - 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
C - Triangle (Easier)

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200 点

問題文

N 頂点 M 辺の単純無向グラフが与えられます。頂点には 1, \dots, N の番号が付けられており、i \, (1 \leq i \leq M) 番目の辺は頂点 U_i と頂点 V_i を結んでいます。

以下の条件を全て満たす整数 a, b, c の組の総数を求めてください。

  • 1 \leq a \lt b \lt c \leq N
  • 頂点 a と頂点 b を結ぶ辺が存在する。
  • 頂点 b と頂点 c を結ぶ辺が存在する。
  • 頂点 c と頂点 a を結ぶ辺が存在する。

制約

  • 3 \leq N \leq 100
  • 1 \leq M \leq \frac{N(N - 1)}{2}
  • 1 \leq U_i \lt V_i \leq N \, (1 \leq i \leq M)
  • (U_i, V_i) \neq (U_j, V_j) \, (i \neq j)
  • 入力は全て整数

入力

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

N M
U_1 V_1
\vdots
U_M V_M

出力

答えを出力せよ。


入力例 1

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

出力例 1

2

(a, b, c) = (1, 4, 5), (2, 3, 5) が条件を満たします。


入力例 2

3 1
1 2

出力例 2

0

入力例 3

7 10
1 7
5 7
2 5
3 6
4 7
1 5
2 4
1 3
1 6
2 7

出力例 3

4

Score : 200 points

Problem Statement

You are given a simple undirected graph with N vertices and M edges. The vertices are numbered 1, \dots, N, and the i-th (1 \leq i \leq M) edge connects Vertex U_i and Vertex V_i.

Find the number of tuples of integers a, b, c that satisfy all of the following conditions:

  • 1 \leq a \lt b \lt c \leq N
  • There is an edge connecting Vertex a and Vertex b.
  • There is an edge connecting Vertex b and Vertex c.
  • There is an edge connecting Vertex c and Vertex a.

Constraints

  • 3 \leq N \leq 100
  • 1 \leq M \leq \frac{N(N - 1)}{2}
  • 1 \leq U_i \lt V_i \leq N \, (1 \leq i \leq M)
  • (U_i, V_i) \neq (U_j, V_j) \, (i \neq j)
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
U_1 V_1
\vdots
U_M V_M

Output

Print the answer.


Sample Input 1

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

Sample Output 1

2

(a, b, c) = (1, 4, 5), (2, 3, 5) satisfy the conditions.


Sample Input 2

3 1
1 2

Sample Output 2

0

Sample Input 3

7 10
1 7
5 7
2 5
3 6
4 7
1 5
2 4
1 3
1 6
2 7

Sample Output 3

4
D - Fibonacci Reversed

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200 点

問題文

正整数 x に対し、f(x) を以下のように定義します。

  • x を(先頭に余分な 0 をつけずに)十進表記して得られる文字列を s_x、s_x を反転して得られる文字列を \text{rev}(s_x) とおく。 f(x) の値は、\text{rev}(s_x) を整数の十進表記としてみなすことで得られる整数である。

例えば、x=13 のとき \text{rev}(s_x)=\ 31 より f(x)=31 であり、x=10 のとき \text{rev}(s_x)=\ 01 より f(x)=1 です。 特に、どのような正整数 x に対しても f(x) の値は正整数です。

正整数 X,Y が与えられます。 正整数列 A=(a_1,a_2,\dots,a_{10}) を以下のように定義します。

  • a_1 = X
  • a_2 = Y
  • a_i = f(a_{i-1}+a_{i-2})\ (i\geq 3)

a_{10} の値を求めてください。

制約

  • 1\leq X,Y \leq 10^5
  • 入力は全て整数

入力

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

X Y

出力

a_{10} の値を出力せよ。


入力例 1

1 1

出力例 1

415

A の各要素の値は以下の通りです。

  • a_1=1
  • a_2=1
  • a_3=2
  • a_4=3
  • a_5=5
  • a_6=8
  • a_7=31
  • a_8=93
  • a_9=421
  • a_{10}=415

よって 415 を出力します。


入力例 2

3 7

出力例 2

895

入力例 3

90701 90204

出力例 3

9560800101

Score : 200 points

Problem Statement

For a positive integer x, define f(x) as follows:

  • Let s_x be the string obtained by representing x in decimal notation (without leading zeros), and let \text{rev}(s_x) be the string obtained by reversing s_x. The value of f(x) is the integer obtained by interpreting \text{rev}(s_x) as a decimal representation of an integer.

For example, when x=13, we have \text{rev}(s_x)= 31, so f(x)=31; when x=10, we have \text{rev}(s_x)= 01, so f(x)=1. Particularly, for any positive integer x, the value of f(x) is a positive integer.

You are given positive integers X and Y. Define a sequence of positive integers A=(a_1,a_2,\dots,a_{10}) as follows:

  • a_1 = X
  • a_2 = Y
  • a_i = f(a_{i-1}+a_{i-2})\ (i\geq 3)

Find the value of a_{10}.

Constraints

  • 1\leq X,Y \leq 10^5
  • All input values are integers.

Input

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

X Y

Output

Print the value of a_{10}.


Sample Input 1

1 1

Sample Output 1

415

The values of the elements of A are as follows:

  • a_1=1
  • a_2=1
  • a_3=2
  • a_4=3
  • a_5=5
  • a_6=8
  • a_7=31
  • a_8=93
  • a_9=421
  • a_{10}=415

Thus, print 415.


Sample Input 2

3 7

Sample Output 2

895

Sample Input 3

90701 90204

Sample Output 3

9560800101
E - Equilateral Triangle

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300 点

問題文

円周が L の円があり、この円周上に点 1,2,\ldots,N が配置されています。i=1,2,\ldots,N-1 に対し、点 i+1 は点 i から時計回りに円周上を d_i 進んだ位置にあります。

整数の組 (a,b,c)\ (1\leq a\lt b\lt c\leq N) であって、以下の 2 つをともに満たすものの個数を求めてください。

  • 3 点 a,b,c はすべて異なる位置にある。
  • 3 点 a,b,c を頂点とする三角形は正三角形である。

制約

  • 3\leq L,N\leq 3\times 10^5
  • 0\leq d_i\lt L
  • 入力は全て整数

入力

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

N L
d_1 d_2 \ldots d_{N-1}

出力

答えを出力せよ。


入力例 1

5 6
4 3 1 2

出力例 1

2

5 つの点の配置は以下のようになります。条件を満たすのは (a,b,c)=(1,2,4),(1,4,5) の 2 つです。


入力例 2

4 4
1 1 1

出力例 2

0

入力例 3

10 12
4 4 5 7 1 7 0 8 5

出力例 3

13

Score : 300 points

Problem Statement

There is a circle with circumference L, and points 1,2,\ldots,N are placed on this circle. For i=1,2,\ldots,N-1, point i+1 is located at a position that is d_i clockwise from point i on the circle.

Find the number of integer triples (a,b,c)\ (1\leq a\lt b\lt c\leq N) that satisfy both of the following conditions:

  • The three points a, b, and c are all at different positions.
  • The triangle with vertices at the three points a, b, and c is an equilateral triangle.

Constraints

  • 3\leq L,N\leq 3\times 10^5
  • 0\leq d_i\lt L
  • All input values are integers.

Input

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

N L
d_1 d_2 \ldots d_{N-1}

Output

Output the answer.


Sample Input 1

5 6
4 3 1 2

Sample Output 1

2

The arrangement of the five points is as follows. Two pairs satisfy the conditions: (a,b,c)=(1,2,4),(1,4,5).


Sample Input 2

4 4
1 1 1

Sample Output 2

0

Sample Input 3

10 12
4 4 5 7 1 7 0 8 5

Sample Output 3

13