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 - World Cup

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100

問題文

あるスポーツ大会は西暦年を 4 で割った余りが 2 である年の 6 月に開催されます。
現在が西暦 Y 年の 1 月である時、このスポーツ大会が次に開催されるのは西暦何年になるかを求めてください。

制約

  • 2000 \leq Y \leq 3000
  • Y は整数

入力

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

Y

出力

答えを出力せよ。


入力例 1

2022

出力例 1

2022

20224 で割った余りが 2 なので、現在が西暦 2022 年の 1 月である時、次の開催は同年の 6 月です。


入力例 2

2023

出力例 2

2026

入力例 3

3000

出力例 3

3002

Score : 100 points

Problem Statement

A sport event is held in June of every year whose remainder when divided by 4 is 2.
Suppose that it is now January of the year Y. In what year will this sport event be held next time?

Constraints

  • 2000 \leq Y \leq 3000
  • Y is an integer.

Input

Input is given from Standard Input in the following format:

Y

Output

Print the answer.


Sample Input 1

2022

Sample Output 1

2022

The remainder when 2022 is divided by 4 is 2, so if it is now January of 2022, the next games will be held in June of the same year.


Sample Input 2

2023

Sample Output 2

2026

Sample Input 3

3000

Sample Output 3

3002
C - Hurdle Parsing

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

いろはちゃんは長さ N ( N \ge 1 ) の正整数列 A=(A_1,A_2,\dots,A_N) を持っています。
いろはちゃんは A を使って、次のように文字列 S を生成しました。

  • S= | から始める。
  • i=1,2,\dots,N の順に、次の操作を行う。
    • S の末尾に -A_i 個追加する。
    • その後、 S の末尾に |1 個追加する。

生成された文字列 S が与えられるので、正整数列 A を復元してください。

制約

  • S は問題文中の方法で生成された長さ 3 以上 100 以下の文字列
  • A は長さ 1 以上の正整数列

入力

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

S

出力

答えを以下の形式で、 1 行に空白区切りで出力せよ。

A_1 A_2 \dots A_N

入力例 1

|---|-|----|-|-----|

出力例 1

3 1 4 1 5

S= |---|-|----|-|-----| が生成されるような A(3,1,4,1,5) です。


入力例 2

|----------|

出力例 2

10

入力例 3

|-|-|-|------|

出力例 3

1 1 1 6

Score : 200 points

Problem Statement

Iroha has a sequence of positive integers A = (A_1, A_2, \dots, A_N) of length N (N \ge 1).
She generated a string S using A as follows:

  • Start with S = |.
  • For i = 1, 2, \dots, N, perform the following operations in order:
    • Append A_i copies of - to the end of S.
    • Then, append one | to the end of S.

Given the generated string S, reconstruct the sequence A.

Constraints

  • S is a string of length between 3 and 100, inclusive, generated by the method in the problem statement.
  • A is a sequence of positive integers of length at least 1.

Input

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

S

Output

Print the answer in the following format, with elements separated by spaces in a single line:

A_1 A_2 \dots A_N

Sample Input 1

|---|-|----|-|-----|

Sample Output 1

3 1 4 1 5

S = |---|-|----|-|-----| is generated by A = (3, 1, 4, 1, 5).


Sample Input 2

|----------|

Sample Output 2

10

Sample Input 3

|-|-|-|------|

Sample Output 3

1 1 1 6
D - Decrease 2 max elements

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

長さ N の正整数列 A = (A_1, A_2, \dots ,A_N) が与えられます。高橋くんは、以下の操作を A に含まれる正の要素の個数が 1 つ以下になるまで繰り返します。

  • A を要素の降順に並び替える。それから、 A_1, A_21 減らす。

高橋くんが操作をする回数を求めてください。

制約

  • 2 \leq N \leq 100
  • 1 \leq A_i \leq 100
  • 入力はすべて整数

入力

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

N
A_1 A_2 \cdots A_N

出力

答えを出力せよ。


入力例 1

4
1 2 3 3

出力例 1

4

操作は以下のように進みます。

  • 1 回目の操作で A = (2, 2, 2, 1) となる。
  • 2 回目の操作で A = (1, 1, 2, 1) となる。
  • 3 回目の操作で A = (1, 0, 1, 1) となる。
  • 4 回目の操作で A = (0, 0, 1, 0) となる。A に含まれる正の要素の個数が 1 つ以下になったので、ここで操作を終了する。

入力例 2

3
1 1 100

出力例 2

2

Score : 200 points

Problem Statement

You are given a sequence of N positive integers A = (A_1, A_2, \dots ,A_N). Takahashi repeats the following operation until A contains one or fewer positive elements:

  • Sort A in descending order. Then, decrease both A_1 and A_2 by 1.

Find the number of times he performs this operation.

Constraints

  • 2 \leq N \leq 100
  • 1 \leq A_i \leq 100
  • All input values are integers.

Input

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

N
A_1 A_2 \cdots A_N

Output

Print the answer.


Sample Input 1

4
1 2 3 3

Sample Output 1

4

The process goes as follows:

  • After the 1st operation, A is (2, 2, 2, 1).
  • After the 2nd operation, A is (1, 1, 2, 1).
  • After the 3rd operation, A is (1, 0, 1, 1).
  • After the 4th operation, A is (0, 0, 1, 0). A no longer contains more than one positive elements, so the process ends here.

Sample Input 2

3
1 1 100

Sample Output 2

2
E - Festival

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 250

問題文

AtCoder 王国では、これから N 日間のお祭りが開催されます。そのうち、A_1 日目、A_2 日目、\dotsA_M 日目の M 日では花火が上がります。ここで、お祭りの最終日には花火が上がることが保証されます。(つまり、A_M=N が保証されます。)

i=1,2,\dots,N に対して、以下の問題を解いてください。

  • i 日目以降で初めて花火が上がるのは、i 日目から数えて何日後か?ただし、i 日目に花火が上がる場合 0 日後とする。

制約

  • 1 \le M \le N \le 2 \times 10^5
  • 1 \le A_1 < A_2 < \dots < A_M = N
  • 入力は全て整数

入力

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

N M
A_1 A_2 \dots A_M

出力

N 行出力せよ。

i(1 \le i \le N) 行目には、i 日目以降で初めて花火が上がるのは、i 日目から数えて何日後かを整数として出力せよ。


入力例 1

3 2
2 3

出力例 1

1
0
0

AtCoder 王国ではお祭りを 3 日間開催し、2,3 日目に花火が上がります。

  • 1 日目以降で初めて花火が上がるのは 2 日目なので、1 日目から数えて 1 日後です。
  • 2 日目以降で初めて花火が上がるのは 2 日目なので、2 日目から数えて 0 日後です。
  • 3 日目以降で初めて花火が上がるのは 3 日目なので、3 日目から数えて 0 日後です。

入力例 2

8 5
1 3 4 7 8

出力例 2

0
1
0
0
2
1
0
0

Score : 250 points

Problem Statement

The AtCoder Kingdom holds a festival for N days. On M of these days, namely on the A_1-th, A_2-th, \dots, A_M-th days, fireworks will be launched. It is guaranteed that fireworks will be launched on the last day of the festival. (In other words, A_M=N is guaranteed.)

For each i=1,2,\dots,N, solve the following problem.

  • How many days later from the i-th day will fireworks be launched for the first time on or after the i-th day? If fireworks are launched on the i-th day, it is considered to be 0 days later.

Constraints

  • 1 \le M \le N \le 2 \times 10^5
  • 1 \le A_1 < A_2 < \dots < A_M = N
  • All input values are integers.

Input

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

N M
A_1 A_2 \dots A_M

Output

Print N lines.

The i-th line (1 \le i \le N) should contain an integer representing the number of days from the i-th day until fireworks are launched for the first time on or after the i-th day.


Sample Input 1

3 2
2 3

Sample Output 1

1
0
0

The kingdom holds a festival for 3 days, and fireworks are launched on the 2-nd and 3-rd days.

  • From the 1-st day, the first time fireworks are launched is the 2-nd day of the festival, which is 1 day later.
  • From the 2-nd day, the first time fireworks are launched is the 2-nd day of the festival, which is 0 days later.
  • From the 3-rd day, the first time fireworks are launched is the 3-rd day of the festival, which is 0 days later.

Sample Input 2

8 5
1 3 4 7 8

Sample Output 2

0
1
0
0
2
1
0
0