A - Six Characters

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100 点

問題文

英小文字からなる文字列 S が与えられます。 S の長さは 1 以上かつ 3 以下です。

S を繰り返して得られる文字列であって、長さが 6 のものを出力してください。

本問題の制約下で、そのような文字列はただ一つ存在することが示せます。

制約

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

入力

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

S

出力

答えとなる長さ 6 の文字列を出力せよ。


入力例 1

abc

出力例 1

abcabc

S = abc を繰り返してできる文字列として、abc 、abcabc 、abcabcabc 、abcabcabcabc などがあります。 そのうち、長さが 6 のものは abcabc です。よって、abcabc と出力します。


入力例 2

zz

出力例 2

zzzzzz

Score : 100 points

Problem Statement

You are given a string S consisting of lowercase English characters. The length of S is between 1 and 3, inclusive.

Print the string of length 6 that is a repetition of S.

It can be shown that there uniquely exists such a string under the Constraints of this problem.

Constraints

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

Input

Input is given from Standard Input in the following format:

S

Output

Print the answer string, which is of length 6.


Sample Input 1

abc

Sample Output 1

abcabc

These are strings that are repetitions of S = abc: abc, abcabc, abcabcabc, abcabcabcabc, and so on. Among them, abcabc has the length of 6, so abcabc should be printed.


Sample Input 2

zz

Sample Output 2

zzzzzz
B - A Substring

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100 点

問題文

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

S の先頭から A 文字、末尾から B 文字取り除いた N-A-B 文字の文字列を出力してください。

制約

  • 1\le N\le20
  • 0\le A
  • 0\le B
  • A+B\lt N
  • S は英小文字からなる N 文字の文字列
  • N,A,B はすべて整数

入力

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

N A B
S

出力

S の先頭から A 文字、末尾から B 文字取り除いた文字列を出力せよ。


入力例 1

7 1 3
atcoder

出力例 1

tco

atcoder の先頭から 1 文字、末尾から 3 文字取り除くと tco になります。


入力例 2

1 0 0
a

出力例 2

a

出力すべき文字列が S と等しい場合もあります。


入力例 3

20 4 8
abcdefghijklmnopqrst

出力例 3

efghijkl

Score : 100 points

Problem Statement

You are given an N-character string S consisting of lowercase English letters.

Output the string of N-A-B characters obtained by removing the first A characters and the last B characters from S.

Constraints

  • 1\le N\le20
  • 0\le A
  • 0\le B
  • A+B\lt N
  • S is a string of N characters consisting of lowercase English letters.
  • N, A, and B are all integers.

Input

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

N A B
S

Output

Output the string obtained by removing the first A characters and the last B characters from S.


Sample Input 1

7 1 3
atcoder

Sample Output 1

tco

Removing the first one character and the last three characters from atcoder gives tco.


Sample Input 2

1 0 0
a

Sample Output 2

a

The string to be output may be equal to S.


Sample Input 3

20 4 8
abcdefghijklmnopqrst

Sample Output 3

efghijkl
C - Vacation Together

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200 点

問題文

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

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

制約

  • 1 \leq N \leq 100
  • 1 \leq D \leq 100
  • N, D は整数
  • S_i は o と x からなる長さ 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 - Pasta

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200 点

問題文

高橋君の家には N 本の麺からなるパスタがあり、i 本目の麺の長さは A_i です。
高橋君はこれから M 日間の食事計画を立てており、 i 日目にはパスタの麺のうち長さがちょうど B_i であるようなものを 1 本選び、食べようと考えています。 もし、1 日目から M 日目の間に 1 日でもそのような麺が無い日があれば、食事計画は失敗となります。 また、同じ麺を複数の日に食べることはできません。

高橋君が食事計画を最後まで実行することは可能ですか?

制約

  • 1 \leq M \leq N \leq 1000
  • 1 \leq A_i \leq 10^9
  • 1 \leq B_i \leq 10^9
  • 入力はすべて整数である。

入力

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

N M
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_M

出力

高橋君が食事計画を最後まで実行できる場合は Yes を、そうでない場合は No を出力せよ。


入力例 1

3 2
1 1 3
3 1

出力例 1

Yes

1 日目に 3 本目の麺を、2 日目に 1 本目の麺を食べれば良いので、高橋君の食事計画は実行可能です。


入力例 2

1 1
1000000000
1

出力例 2

No

長さがちょうど 1 の麺が存在する必要があります。


入力例 3

5 2
1 2 3 4 5
5 5

出力例 3

No

長さが 5 の麺は 1 本しか存在しないため、2 日目に食事をとる事が出来ません。

Score : 200 points

Problem Statement

There is pasta consisting of N noodles at Takahashi's home. The length of the i-th noodle is A_i.
Takahashi has a meal plan for the next M days. On the i-th day, he is going to choose a pasta noodle of length exactly B_i and eat it. If no such noodle is available on any day, his plan fails. Additionally, he cannot eat the same noodle on multiple days.

Can Takahashi accomplish his meal plan?

Constraints

  • 1 \leq M \leq N \leq 1000
  • 1 \leq A_i \leq 10^9
  • 1 \leq B_i \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_M

Output

If Takahashi can accomplish his meal plan, print Yes; otherwise, print No.


Sample Input 1

3 2
1 1 3
3 1

Sample Output 1

Yes

He can eat the 3-rd noodle on the 1-st day and the 1-st noodle on the 2-nd day, so his meal plan is feasible.


Sample Input 2

1 1
1000000000
1

Sample Output 2

No

A noodle of length exactly 1 is needed.


Sample Input 3

5 2
1 2 3 4 5
5 5

Sample Output 3

No

Since there are only 1 noodle of length 5, he cannot have a meal on the 2-nd day.

E - Adjacent Sums (easy)

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300 点

問題文

※ C 問題の問題文は E 問題と同じです。赤字で示された制約のみが異なります。

0 以上 M-1 以下の整数からなる整数列 A=(A_1,A_2,\dots,A_N),B=(B_1,B_2,\dots,B_{N-1}) が与えられます。 A,B の長さはそれぞれ N,N-1 です。
A に対して以下の操作を好きな回数行うことができます。

  • 1 以上 N 以下の整数 i を 1 つ選び、A_i に 1 を加える。

以下の条件を満たすようにするために必要な操作回数の最小値を求めてください。
なお、問題の制約下では、必ず条件を満たすようにできることが証明できます。

  • i=1,2,\dots,N-1 について、A_i+A_{i+1} を M で割った余りは B_i に等しい。

制約

  • 2 \leq N \leq 2 \times 10^5
  • M=2
  • 0 \leq A_i \leq M-1
  • 0 \leq B_i \leq M-1
  • 入力される値はすべて整数

入力

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

N M  
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_{N-1}

出力

答えを 1 行で出力せよ。


入力例 1

3 2
1 1 1
1 1

出力例 1

1

1 回目の操作で i=2 を選ぶと、A=(1,2,1) となります。
A_1+A_2=1+2=3,\;A_2+A_3=2+1=3 なので、条件を満たします。
また、A=(1,1,1) は条件を満たさないため、答えは 1 です。


入力例 2

2 2
1 1
0

出力例 2

0

入力例 3

10 2
0 0 0 1 1 0 1 0 1 0
0 1 0 1 0 1 0 1 0

出力例 3

4

Score : 300 points

Problem Statement

The problem statement of Problem C is the same as Problem E. Only the constraint shown in red differ.

You are given integer sequences A=(A_1,A_2,\dots,A_N),B=(B_1,B_2,\dots,B_{N-1}) consisting of integers between 0 and M-1, inclusive. The lengths of A and B are N and N-1, respectively.
You can perform the following operation on A any number of times.

  • Choose an integer i with 1 \leq i \leq N, and add 1 to A_i.

Find the minimum number of operations required to satisfy the following condition.
It can be proved that the condition can always be satisfied under the constraints of this problem.

  • For i=1,2,\dots,N-1, the remainder when A_i+A_{i+1} is divided by M equals B_i.

Constraints

  • 2 \leq N \leq 2 \times 10^5
  • M=2
  • 0 \leq A_i \leq M-1
  • 0 \leq B_i \leq M-1
  • All input values are integers.

Input

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

N M  
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_{N-1}

Output

Output the answer on one line.


Sample Input 1

3 2
1 1 1
1 1

Sample Output 1

1

If we choose i=2 for the first operation, we get A=(1,2,1).
Since A_1+A_2=1+2=3 and A_2+A_3=2+1=3, the condition is satisfied.
A=(1,1,1) does not satisfy the condition, so the answer is 1.


Sample Input 2

2 2
1 1
0

Sample Output 2

0

Sample Input 3

10 2
0 0 0 1 1 0 1 0 1 0
0 1 0 1 0 1 0 1 0

Sample Output 3

4