A - Append s

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100

問題文

英小文字からなる文字列 S が与えられます。

文字列 S の末尾に s を追加した文字列を出力してください。

制約

  • S は英小文字からなる長さ 1 以上 10 以下の文字列

入力

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

S

出力

答えを出力せよ。


入力例 1

http

出力例 1

https

http の末尾に s を追加すると https になります。したがって、 https を出力してください。


入力例 2

append

出力例 2

appends

入力例 3

beginner

出力例 3

beginners

Score : 100 points

Problem Statement

You are given a string S consisting of lowercase English letters.

Output the string obtained by appending s to the end of the string S.

Constraints

  • S is a string of length between 1 and 10, inclusive, consisting of lowercase English letters.

Input

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

S

Output

Output the answer.


Sample Input 1

http

Sample Output 1

https

Appending s to the end of http results in https, so print https.


Sample Input 2

append

Sample Output 2

appends

Sample Input 3

beginner

Sample Output 3

beginners
B - Horizon

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100

問題文

地上 x メートルの高さから見える水平線は \sqrt{x(12800000+x)} メートル先にあるとするとき、 地上 H メートルの高さから見える水平線が何メートル先にあるか求めてください。

制約

  • 1 \leq H \leq 10^5
  • H は整数である

入力

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

H

出力

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


入力例 1

333

出力例 1

65287.907678222

\sqrt{333(12800000+333)} = 65287.9076782\ldots です。65287.91 などの出力でも正解となります。


入力例 2

634

出力例 2

90086.635834623

\sqrt{634(12800000+634)} = 90086.6358346\ldots です。

Score : 100 points

Problem Statement

Assuming that the horizon seen from a place x meters above the ground is \sqrt{x(12800000+x)} meters away, find how many meters away the horizon seen from a place H meters above the ground is.

Constraints

  • 1 \leq H \leq 10^5
  • H is an integer.

Input

Input is given from Standard Input in the following format:

H

Output

Print the answer.
Your answer will be considered correct when the absolute or relative error from the judge's answer is at most 10^{-6}.


Sample Input 1

333

Sample Output 1

65287.907678222

We have \sqrt{333(12800000+333)} = 65287.9076782\ldots. Outputs such as 65287.91 would also be accepted.


Sample Input 2

634

Sample Output 2

90086.635834623

We have \sqrt{634(12800000+634)} = 90086.6358346\ldots.

C - Vacation Together

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

1 から N までの番号がついた N 人の人がいます。
N 人の人の今後 D 日間の予定が与えられます。人 i の予定は長さ D の文字列 S_i で表されて、S_ij 文字目が o ならば j 日目は暇であることを、x ならばそうでないことを意味します。

D 日間のうち全員が暇であるような 連続する 何日かを選ぶことを考えます。
選べる日数は最大で何日ですか?ただし、選べる日が存在しない場合は 0 日と答えてください。

制約

  • 1 \leq N \leq 100
  • 1 \leq D \leq 100
  • N, D は整数
  • S_iox からなる長さ D の文字列

入力

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

N D
S_1
S_2
\vdots
S_N

出力

選べる日数の最大値を出力せよ。選べる日が存在しない場合は 0 を出力せよ。


入力例 1

3 5
xooox
oooxx
oooxo

出力例 1

2

2 日目と 3 日目は全員が暇な日なので選ぶことができます。
この 2 日間を選ぶと、連続する日にちを選ぶ方法の中で日数を最大にすることができます。


入力例 2

3 3
oxo
oxo
oxo

出力例 2

1

選ぶ日にちは連続している必要があるのに注意してください。(1 日目と 3 日目は全員が暇な日なので選ぶことができますが、この 2 つを同時に選ぶことはできません)


入力例 3

3 3
oox
oxo
xoo

出力例 3

0

選べる日が存在しない場合は 0 を出力してください。


入力例 4

1 7
ooooooo

出力例 4

7

入力例 5

5 15
oxooooooooooooo
oxooxooooooooox
oxoooooooooooox
oxxxooooooxooox
oxooooooooxooox

出力例 5

5

Score : 200 points

Problem Statement

There are N people numbered 1 to N.
You are given their schedule for the following D days. The schedule for person i is represented by a string S_i of length D. If the j-th character of S_i is o, person i is free on the j-th day; if it is x, they are occupied that day.

From these D days, consider choosing some consecutive days when all the people are free.
How many days can be chosen at most? If no day can be chosen, report 0.

Constraints

  • 1 \leq N \leq 100
  • 1 \leq D \leq 100
  • N and D are integers.
  • S_i is a string of length D consisting of o and x.

Input

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

N D
S_1
S_2
\vdots
S_N

Output

Print the maximum number of days that can be chosen, or 0 if no day can be chosen.


Sample Input 1

3 5
xooox
oooxx
oooxo

Sample Output 1

2

All the people are free on the second and third days, so we can choose them.
Choosing these two days will maximize the number of days among all possible choices.


Sample Input 2

3 3
oxo
oxo
oxo

Sample Output 2

1

Note that the chosen days must be consecutive. (All the people are free on the first and third days, so we can choose either of them, but not both.)


Sample Input 3

3 3
oox
oxo
xoo

Sample Output 3

0

Print 0 if no day can be chosen.


Sample Input 4

1 7
ooooooo

Sample Output 4

7

Sample Input 5

5 15
oxooooooooooooo
oxooxooooooooox
oxoooooooooooox
oxxxooooooxooox
oxooooooooxooox

Sample Output 5

5
D - 9x9 Sum

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 150

問題文

九九の表に現れる 81 個の整数のうち、X でないものの総和を求めてください。

9 マス、横 9 マスのグリッドがあります。
グリッドの各マスには整数が書きこまれていて、グリッドの上から i 行目、左から j 列目のマスには i \times j が書きこまれています。
整数 X が与えられます。グリッドに書きこまれた 81 個の整数のうち X でないものの総和を求めてください。値の等しい整数が異なるマスに書きこまれている場合は別々に加算する点に注意してください。

制約

  • X1 以上 81 以下の整数

入力

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

X

出力

グリッドに書きこまれた 81 個の整数のうち X でないものの総和を出力せよ。


入力例 1

1

出力例 1

2024

グリッドに 1 が書きこまれたマスは上から 1 行目、左から 1 列目のマスのみです。1 でない整数を全て足し合わせると総和は 2024 になります。


入力例 2

11

出力例 2

2025

グリッドに 11 が書きこまれたマスは存在しません。よって 81 個の整数全てを足し合わせた総和である 2025 が答えとなります。


入力例 3

24

出力例 3

1929

Score : 150 points

Problem Statement

Among the 81 integers that appear in the 9-by-9 multiplication table, find the sum of those that are not X.

There is a grid of size 9 by 9.
Each cell of the grid contains an integer: the cell at the i-th row from the top and the j-th column from the left contains i \times j.
You are given an integer X. Among the 81 integers written in this grid, find the sum of those that are not X. If the same value appears in multiple cells, add it for each cell.

Constraints

  • X is an integer between 1 and 81, inclusive.

Input

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

X

Output

Print the sum of the integers that are not X among the 81 integers written in the grid.


Sample Input 1

1

Sample Output 1

2024

The only cell with 1 in the grid is the cell at the 1st row from the top and 1st column from the left. Summing all integers that are not 1 yields 2024.


Sample Input 2

11

Sample Output 2

2025

There is no cell containing 11 in the grid. Thus, the answer is 2025, the sum of all 81 integers.


Sample Input 3

24

Sample Output 3

1929
E - Omelette Restaurant

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

AtCoder レストランは開店してから N 日間営業しました。

開店してから i 日目 (1\leq i\leq N) には次の行動が行われました。

  • i 日目の朝に、A_i 個の卵を仕入れる。
  • i 日目の昼に、B_i 個の卵を使用する。このとき、卵は 在庫にある卵の中で仕入れた順に使用される
  • i 日目の夜に、仕入れてから D 日間以上経過した卵をすべて処分する。

なお、1 日目の朝の前の時点で卵の在庫は無く、それぞれの日の昼に卵が足りなくなることはありませんでした。

N 日目の夜の行動の後で、レストランに何個の卵が残っているか求めてください。

T 個のテストケースが与えられるので、それぞれについて答えを求めてください。

制約

  • 1 \leq T\leq 2\times 10^5
  • 1 \leq D \leq N \leq 2\times 10^5
  • 1 \leq A_i,B_i \leq 10
  • N 日間のそれぞれの昼において、卵が足りなくなることはない。
  • それぞれの入力において、各テストケースにおける N の総和は 2\times 10^5 以下である。
  • 入力はすべて整数

入力

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

T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_T

\mathrm{case}_ii 個目のテストケースを表す。
各テストケースは以下の形式で与えられる。

N D
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_N

出力

T 行出力せよ。
i 行目 (1\leq i\leq T) には、i 個目のテストケースに対する答えを出力せよ。


入力例 1

3
3 1
7 2 3
1 3 2
3 2
7 2 3
1 3 2
2 1
2 1
1 2

出力例 1

3
5
0

1 個目のテストケースにおいて次の行動が行われます。

  • 最初、AtCoder レストランには卵がありません。
  • 1 日目の朝に卵を 7 個仕入れます。レストランには 1 日目に仕入れた卵が 7 個あります。
  • 1 日目の昼に卵を 1 個使用します。レストランには 1 日目に仕入れた卵が 6 個残っています。
  • 1 日目の夜に処分する卵はありません。レストランには 1 日目に仕入れた卵が 6 個残っています。
  • 2 日目の朝に卵を 2 個仕入れます。レストランには 1 日目に仕入れた卵が 6 個、2 日目に仕入れた卵が 2 個あります。
  • 2 日目の昼に卵を 3 個使用します。レストランには 1 日目に仕入れた卵が 3 個、2 日目に仕入れた卵が 2 個残っています。
  • 2 日目の夜に、1 日目に仕入れた卵を処分します。レストランには 2 日目に仕入れた卵が 2 個残っています。
  • 3 日目の朝に卵を 3 個仕入れます。レストランには 2 日目に仕入れた卵が 2 個、3 日目に仕入れた卵が 3 個あります。
  • 3 日目の昼に卵を 2 個使用します。レストランには 3 日目に仕入れた卵が 3 個残っています。
  • 3 日目の夜に処分する卵はありません。(2 日目に仕入れた卵は全て使用されているためです。)レストランには 3 日目に仕入れた卵が 3 個残っています。

よって、3 日目の夜の行動の後で、卵は 3 個残っているため、1 行目には 3 を出力します。

2 個目のテストケースにおいては、3 日目の夜に 1 日目に仕入れた卵を処分した後の個数を出力することに注意してください。

Score : 300 points

Problem Statement

AtCoder Restaurant was open for N days after opening.

On day i (1\leq i\leq N) after opening, the following actions were performed.

  • In the morning of day i, A_i eggs are purchased.
  • At noon on day i, B_i eggs are used. Here, eggs in stock are used in the order they were purchased.
  • In the evening of day i, all eggs that have been stocked for D or more days are discarded.

There were no eggs in stock before the morning of day 1, and eggs never ran out at noon on any day.

Find how many eggs remain in the restaurant after the evening action on day N.

T test cases are given; solve each.

Constraints

  • 1 \leq T\leq 2\times 10^5
  • 1 \leq D \leq N \leq 2\times 10^5
  • 1 \leq A_i,B_i \leq 10
  • Eggs never run out at noon on any of the N days.
  • For each input, the sum of N over all test cases is at most 2\times 10^5.
  • All input values are integers.

Input

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

T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_T

\mathrm{case}_i represents the i-th test case.
Each test case is given in the following format:

N D
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_N

Output

Output T lines.
The i-th line (1\leq i\leq T) should contain the answer for the i-th test case.


Sample Input 1

3
3 1
7 2 3
1 3 2
3 2
7 2 3
1 3 2
2 1
2 1
1 2

Sample Output 1

3
5
0

In the first test case, the following actions are performed.

  • Initially, AtCoder Restaurant has no eggs.
  • In the morning of day 1, 7 eggs are purchased. The restaurant has 7 eggs stocked on day 1.
  • At noon on day 1, 1 egg is used. The restaurant has 6 eggs stocked on day 1 remaining.
  • In the evening of day 1, no eggs are discarded. The restaurant has 6 eggs stocked on day 1 remaining.
  • In the morning of day 2, 2 eggs are purchased. The restaurant has 6 eggs stocked on day 1 and 2 eggs stocked on day 2.
  • At noon on day 2, 3 eggs are used. The restaurant has 3 eggs stocked on day 1 and 2 eggs stocked on day 2 remaining.
  • In the evening of day 2, the eggs stocked on day 1 are discarded. The restaurant has 2 eggs stocked on day 2 remaining.
  • In the morning of day 3, 3 eggs are purchased. The restaurant has 2 eggs stocked on day 2 and 3 eggs stocked on day 3.
  • At noon on day 3, 2 eggs are used. The restaurant has 3 eggs stocked on day 3 remaining.
  • In the evening of day 3, no eggs are discarded. (This is because all eggs stocked on day 2 have already been used.) The restaurant has 3 eggs stocked on day 3 remaining.

Thus, 3 eggs remain after the evening action on day 3, so output 3 on the first line.

For the second test case, remember to output the number of eggs after discarding the eggs stocked on day 1 in the evening of day 3.