A - Octave

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 100

問題文

音の高さが 1 オクターヴ上がるごとに、音の周波数は 2 倍になります。

周波数 X ヘルツの音の高さを Y オクターヴ上げると、その周波数は何ヘルツになりますか?

制約

  • 1 \leq X \leq 444
  • 1 \leq Y \leq 3
  • 入力される値はすべて整数

入力

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

X Y

出力

答えを整数として 1 行に出力せよ。単位 (ヘルツ) は省いて出力すること。


入力例 1

110 2

出力例 1

440

周波数 110 ヘルツの音の 2 オクターヴ上の音について、その周波数は 110 \times 2 \times 2 = 440 ヘルツです。


入力例 2

233 3

出力例 2

1864

周波数 233 ヘルツの音の 3 オクターヴ上の音について、その周波数は 233 \times 2 \times 2 \times 2 = 1864 ヘルツです。


入力例 3

432 1

出力例 3

864

周波数 432 ヘルツの音の 1 オクターヴ上の音について、その周波数は 432 \times 2 = 864 ヘルツです。

Score : 100 points

Problem Statement

The frequency of a sound doubles for every increase of 1 octave in pitch.

If the pitch of a sound with frequency X hertz is raised by Y octaves, what will its frequency be in hertz?

Constraints

  • 1 \leq X \leq 444
  • 1 \leq Y \leq 3
  • All input values are integers.

Input

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

X Y

Output

Output the answer as an integer in one line. Omit the unit (hertz).


Sample Input 1

110 2

Sample Output 1

440

For a sound 2 octaves above a sound with frequency 110 hertz, its frequency is 110 \times 2 \times 2 = 440 hertz.


Sample Input 2

233 3

Sample Output 2

1864

For a sound 3 octaves above a sound with frequency 233 hertz, its frequency is 233 \times 2 \times 2 \times 2 = 1864 hertz.


Sample Input 3

432 1

Sample Output 3

864

For a sound 1 octave above a sound with frequency 432 hertz, its frequency is 432 \times 2 = 864 hertz.

B - 10yen Stamp

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 100

問題文

サンタさんに手紙を出したい高橋くんは、 X 円切手が 1 枚だけ貼られた封筒を用意しました。
サンタさんに手紙を届けるためには、貼られている切手の総額が Y 円以上である必要があります。
高橋くんは、この封筒に 10 円切手を何枚か貼り足すことで、貼られている切手の総額を Y 円以上にしたいです。
高橋くんはこの封筒に、最小で何枚の 10 円切手を貼り足す必要がありますか?

制約

  • X,Y は整数
  • 1 \le X,Y \le 1000

入力

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

X Y

出力

答えを整数として出力せよ。


入力例 1

80 94

出力例 1

2
  • 80 円切手に 0 枚の 10 円切手を貼り足せば総額が 80 円となり、これは手紙を届けるのに必要な 94 円未満です。
  • 80 円切手に 1 枚の 10 円切手を貼り足せば総額が 90 円となり、これは手紙を届けるのに必要な 94 円未満です。
  • 80 円切手に 2 枚の 10 円切手を貼り足せば総額が 100 円となり、これは手紙を届けるのに必要な 94 円以上です。

入力例 2

1000 63

出力例 2

0

もともと貼られている切手だけで金額が十分である可能性もあります。


入力例 3

270 750

出力例 3

48

Score : 100 points

Problem Statement

Takahashi wants to send a letter to Santa Claus. He has an envelope with an X-yen (Japanese currency) stamp stuck on it.
To be delivered to Santa Claus, the envelope must have stamps in a total value of at least Y yen.
Takahashi will put some more 10-yen stamps so that the envelope will have stamps worth at least Y yen in total.
At least how many more 10-yen stamps does Takahashi need to put on the envelope?

Constraints

  • X and Y are integers.
  • 1 \le X,Y \le 1000

Input

Input is given from Standard Input in the following format:

X Y

Output

Print the answer as an integer.


Sample Input 1

80 94

Sample Output 1

2
  • After adding zero 10-yen stamps to the 80-yen stamp, the total is 80 yen, which is less than the required amount of 94 yen.
  • After adding one 10-yen stamp to the 80-yen stamp, the total is 90 yen, which is less than the required amount of 94 yen.
  • After adding two 10-yen stamps to the 80-yen stamp, the total is 100 yen, which is not less than the required amount of 94 yen.

Sample Input 2

1000 63

Sample Output 2

0

The envelope may already have a stamp with enough value.


Sample Input 3

270 750

Sample Output 3

48
C - Vacation Together

実行時間制限: 2 sec / メモリ制限: 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 - Integer Division Returns

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 200

問題文

-10^{18} 以上 10^{18} 以下の整数 X が与えられるので、\left\lceil \dfrac{X}{10} \right\rceil を出力してください。
ここで、\left\lceil a \right\rceila 以上の整数のうち最小のものを意味します。

制約

  • -10^{18} \leq X \leq 10^{18}
  • X は整数

入力

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

X

出力

\left\lceil \dfrac{X}{10} \right\rceil を整数として出力せよ。


入力例 1

27

出力例 1

3

\frac{27}{10} = 2.7 以上の整数は 3, 4, 5, \dots です。この中で一番小さい整数は 3 なので、\left \lceil \frac{27}{10} \right \rceil = 3 となります。


入力例 2

-13

出力例 2

-1

\frac{-13}{10} = -1.3 以上の整数は、全ての正整数および 0, -1 です。この中で一番小さい整数は -1 なので、\left \lceil \frac{-13}{10} \right \rceil = -1 となります。


入力例 3

40

出力例 3

4

\frac{40}{10} = 4 以上の整数で一番小さい整数は 4 自身です。


入力例 4

-20

出力例 4

-2

入力例 5

123456789123456789

出力例 5

12345678912345679

Score: 200 points

Problem Statement

Given an integer X between -10^{18} and 10^{18}, inclusive, print \left\lceil \dfrac{X}{10} \right\rceil.
Here, \left\lceil a \right\rceil denotes the smallest integer not less than a.

Constraints

  • -10^{18} \leq X \leq 10^{18}
  • X is an integer.

Input

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

X

Output

Print \left\lceil \dfrac{X}{10} \right\rceil as an integer.


Sample Input 1

27

Sample Output 1

3

The integers not less than \frac{27}{10} = 2.7 are 3, 4, 5, \dots. Among these, the smallest is 3, so \left \lceil \frac{27}{10} \right \rceil = 3.


Sample Input 2

-13

Sample Output 2

-1

The integers not less than \frac{-13}{10} = -1.3 are all positive integers, 0, and -1. Among these, the smallest is -1, so \left \lceil \frac{-13}{10} \right \rceil = -1.


Sample Input 3

40

Sample Output 3

4

The smallest integer not less than \frac{40}{10} = 4 is 4 itself.


Sample Input 4

-20

Sample Output 4

-2

Sample Input 5

123456789123456789

Sample Output 5

12345678912345679
E - Lock All Doors

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 300

問題文

N + 1 個の部屋が一列に並んでおり、順に 0, 1, \ldots, N の番号が付けられています。

部屋の間には N 個のドアがあり、1, 2, \ldots, N の番号が付けられています。ドア i は部屋 i - 1 と部屋 i の間にあります。

各ドアについて鍵の状態を表す値 L_i が与えられ、L_i = 0 のときドア i の鍵は開いており、L_i = 1 のときドア i の鍵は閉まっています。

高橋君ははじめ部屋 R におり、ドア i の鍵が開いているときに限り、部屋 i - 1 と部屋 i の間を移動することができます。また、高橋君は部屋 i - 1 または部屋 i にいるときに限り、ドア i の鍵に対して 開閉操作 を行うことができます。ドア i の鍵に対して開閉操作を行ったとき、その鍵が開いているときは閉まり、閉まっているときは開きます。

すべてのドアの鍵が閉まった状態にするために行う鍵の開閉操作の回数として考えられる最小値を求めてください。

制約

  • 2 \leq N \leq 2 \times 10^5
  • 0 \leq R \leq N
  • L_i \in \lbrace 0, 1 \rbrace
  • 入力される値はすべて整数

入力

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

N R
L_1 L_2 \ldots L_N

出力

答えを出力せよ。


入力例 1

6 3
1 0 0 1 0 0

出力例 1

6

高橋君は以下のように行動することで 6 回の開閉操作ですべてのドアの鍵が閉まった状態にすることができます。

  • 部屋 2 に移動する。
  • ドア 2 に対して開閉操作を行い、ドア 2 の鍵を閉める。
  • 部屋 3 に移動する。
  • ドア 4 に対して開閉操作を行い、ドア 4 の鍵を開ける。
  • ドア 3 に対して開閉操作を行い、ドア 3 の鍵を閉める。
  • 部屋 4 に移動する。
  • ドア 4 に対して開閉操作を行い、ドア 4 の鍵を閉める。
  • 部屋 5 に移動する。
  • ドア 5 に対して開閉操作を行い、ドア 5 の鍵を閉める。
  • ドア 6 に対して開閉操作を行い、ドア 6 の鍵を閉める。

入力例 2

2 1
0 0

出力例 2

2

入力例 3

8 2
0 1 0 0 1 0 1 1

出力例 3

8

Score : 300 points

Problem Statement

There are N + 1 rooms arranged in a line, numbered 0, 1, \ldots, N in order.

Between the rooms, there are N doors numbered 1, 2, \ldots, N. Door i is between rooms i - 1 and i.

For each door, a value L_i representing the lock state is given. When L_i = 0, door i is unlocked, and when L_i = 1, door i is locked.

Takahashi is initially in room R, and can move between rooms i - 1 and i only when door i is unlocked. Also, he can perform a switching operation on door i only when he is in room i - 1 or room i. When a switching operation is performed on door i, if the door is unlocked, it becomes locked, and if it is locked, it becomes unlocked.

Find the minimum number of switching operations needed to make all doors locked.

Constraints

  • 2 \leq N \leq 2 \times 10^5
  • 0 \leq R \leq N
  • L_i \in \lbrace 0, 1 \rbrace
  • All input values are integers.

Input

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

N R
L_1 L_2 \ldots L_N

Output

Output the answer.


Sample Input 1

6 3
1 0 0 1 0 0

Sample Output 1

6

Takahashi can make all doors locked with six switching operations by acting as follows:

  • Move to room 2.
  • Perform a switching operation on door 2 to lock door 2.
  • Move to room 3.
  • Perform a switching operation on door 4 to unlock door 4.
  • Perform a switching operation on door 3 to lock door 3.
  • Move to room 4.
  • Perform a switching operation on door 4 to lock door 4.
  • Move to room 5.
  • Perform a switching operation on door 5 to lock door 5.
  • Perform a switching operation on door 6 to lock door 6.

Sample Input 2

2 1
0 0

Sample Output 2

2

Sample Input 3

8 2
0 1 0 0 1 0 1 1

Sample Output 3

8