A - Three Threes

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

配点 : 100

問題文

1 以上 9 以下の整数 N が入力として与えられます。

数字 NN 個繋げて得られる文字列を出力してください。

制約

  • N1 以上 9 以下の整数

入力

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

N

出力

答えを出力せよ。


入力例 1

3

出力例 1

333

33 個繋げて得られる文字列は 333 です。


入力例 2

9

出力例 2

999999999

Score : 100 points

Problem Statement

You are given an integer N between 1 and 9, inclusive, as input.

Concatenate N copies of the digit N and print the resulting string.

Constraints

  • N is an integer between 1 and 9, inclusive.

Input

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

N

Output

Print the answer.


Sample Input 1

3

Sample Output 1

333

Concatenate three copies of the digit 3 to yield the string 333.


Sample Input 2

9

Sample Output 2

999999999
B - ABC400 Party

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

配点 : 100

問題文

ABC400 を記念した式典において、400 人の高橋君を AB 列の長方形状に隙間なく並べようとしています。

正整数 A が与えられるので、このような並べ方ができるような正整数 B の値を出力してください。ただし、そのような正整数 B が存在しない場合には -1 を出力してください。

制約

  • A1 以上 400 以下の整数

入力

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

A

出力

問題文の指示に従って B の値あるいは -1 を出力せよ。


入力例 1

10

出力例 1

40

400 人の高橋君を 1040 列の長方形状に並べることができます。


入力例 2

11

出力例 2

-1

入力例 3

400

出力例 3

1

Score : 100 points

Problem Statement

In the ceremony commemorating ABC400, we want to arrange 400 people in a rectangular formation of A rows and B columns without any gaps.

You are given a positive integer A. Print the value of a positive integer B for which such an arrangement is possible. If there is no such positive integer B, print -1.

Constraints

  • A is an integer between 1 and 400, inclusive.

Input

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

A

Output

Print the value of B or -1 as specified by the problem statement.


Sample Input 1

10

Sample Output 1

40

We can arrange 400 people in 10 rows and 40 columns.


Sample Input 2

11

Sample Output 2

-1

Sample Input 3

400

Sample Output 3

1
C - Longest Uncommon Prefix

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

配点 : 200

問題文

英小文字からなる長さ N の文字列 S が与えられます。 Sx 文字目 (1 \le x \le N)S_x です。

i=1,2,\dots,N-1 それぞれについて、以下の条件を全て満たす最大の非負整数 l を求めてください。

  • l+i \le N である。
  • 全ての 1 \le k \le l を満たす整数 k について、 S_{k} \neq S_{k+i} を満たす。

なお、 l=0 は常に条件を満たすことに注意してください。

制約

  • N2 \le N \le 5000 を満たす整数
  • S は英小文字からなる長さ N の文字列

入力

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

N
S

出力

N-1 行にわたって出力せよ。そのうち x 行目 (1 \le x < N) には i=x とした場合の答えを整数として出力せよ。


入力例 1

6
abcbac

出力例 1

5
1
2
0
1

この入力では、 S= abcbac です。

  • i=1 のとき、 S_1 \neq S_2, S_2 \neq S_3, \dots ,S_5 \neq S_6 であるため、 最大値は l=5 です。
  • i=2 のとき、 S_1 \neq S_3 ですが S_2 = S_4 であるため、 最大値は l=1 です。
  • i=3 のとき、 S_1 \neq S_4, S_2 \neq S_5 ですが S_3 = S_6 であるため、 最大値は l=2 です。
  • i=4 のとき、 S_1 = S_5 であるため、 最大値は l=0 です。
  • i=5 のとき、 S_1 \neq S_6 であるため、 最大値は l=1 です。

Score : 200 points

Problem Statement

You are given a string S of length N consisting of lowercase English letters. The x-th (1 \le x \le N) character of S is S_x.

For each i=1,2,\dots,N-1, find the maximum non-negative integer l that satisfies all of the following conditions:

  • l+i \le N, and
  • for all integers k such that 1 \le k \le l, it holds that S_{k} \neq S_{k+i}.

Note that l=0 always satisfies the conditions.

Constraints

  • N is an integer such that 2 \le N \le 5000.
  • S is a string of length N consisting of lowercase English letters.

Input

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

N
S

Output

Print (N-1) lines. The x-th (1 \le x < N) line should contain the answer as an integer when i=x.


Sample Input 1

6
abcbac

Sample Output 1

5
1
2
0
1

In this input, S= abcbac.

  • When i=1, we have S_1 \neq S_2, S_2 \neq S_3, \dots, and S_5 \neq S_6, so the maximum value is l=5.
  • When i=2, we have S_1 \neq S_3 but S_2 = S_4, so the maximum value is l=1.
  • When i=3, we have S_1 \neq S_4 and S_2 \neq S_5 but S_3 = S_6, so the maximum value is l=2.
  • When i=4, we have S_1 = S_5, so the maximum value is l=0.
  • When i=5, we have S_1 \neq S_6, so the maximum value is l=1.
D - Dentist Aoki

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

配点 : 200

問題文

高橋君には、穴 1,2,\dots,N1 本ずつ、全部で N 本の歯が生えています。
歯医者の青木君は、これらの歯と穴に対して、 Q 回の治療を行います。
i 回目の治療では、穴 T_i を治療します。治療内容は次の通りです。

  • T_i に歯が生えている場合、穴 T_i から歯を抜く。
  • そうでない ( 穴 T_i に歯が生えていない) 場合、穴 T_i に歯を生やす。

全ての治療が終わった後、高橋君に生えている歯の本数は何本ですか?

制約

  • 入力は全て整数
  • 1 \le N,Q \le 1000
  • 1 \le T_i \le N

入力

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

N Q
T_1 T_2 \dots T_Q

出力

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


入力例 1

30 6
2 9 18 27 18 9

出力例 1

28

高橋君には最初 30 本の歯が生えており、青木君は 6 回の治療を行います。

  • 1 回目の治療では穴 2 を治療します。 穴 2 に歯が生えているため、歯を抜きます。
  • 2 回目の治療では穴 9 を治療します。 穴 9 に歯が生えているため、歯を抜きます。
  • 3 回目の治療では穴 18 を治療します。 穴 18 に歯が生えているため、歯を抜きます。
  • 4 回目の治療では穴 27 を治療します。 穴 27 に歯が生えているため、歯を抜きます。
  • 5 回目の治療では穴 18 を治療します。 穴 18 に歯が生えていないため、歯を生やします。
  • 6 回目の治療では穴 9 を治療します。 穴 9 に歯が生えていないため、歯を生やします。

最終的な歯の本数は 28 本です。


入力例 2

1 7
1 1 1 1 1 1 1

出力例 2

0

入力例 3

9 20
9 5 1 2 2 2 8 9 2 1 6 2 6 5 8 7 8 5 9 8

出力例 3

5

Score: 200 points

Problem Statement

Takahashi has N teeth, one in each of the holes numbered 1, 2, \dots, N.
Dentist Aoki will perform Q treatments on these teeth and holes.
In the i-th treatment, hole T_i is treated as follows:

  • If there is a tooth in hole T_i, remove the tooth from hole T_i.
  • If there is no tooth in hole T_i (i.e., the hole is empty), grow a tooth in hole T_i.

After all treatments are completed, how many teeth does Takahashi have?

Constraints

  • All input values are integers.
  • 1 \le N, Q \le 1000
  • 1 \le T_i \le N

Input

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

N Q
T_1 T_2 \dots T_Q

Output

Print the number of teeth as an integer.


Sample Input 1

30 6
2 9 18 27 18 9

Sample Output 1

28

Initially, Takahashi has 30 teeth, and Aoki performs six treatments.

  • In the first treatment, hole 2 is treated. There is a tooth in hole 2, so it is removed.
  • In the second treatment, hole 9 is treated. There is a tooth in hole 9, so it is removed.
  • In the third treatment, hole 18 is treated. There is a tooth in hole 18, so it is removed.
  • In the fourth treatment, hole 27 is treated. There is a tooth in hole 27, so it is removed.
  • In the fifth treatment, hole 18 is treated. There is no tooth in hole 18, so a tooth is grown.
  • In the sixth treatment, hole 9 is treated. There is no tooth in hole 9, so a tooth is grown.

The final count of teeth is 28.


Sample Input 2

1 7
1 1 1 1 1 1 1

Sample Output 2

0

Sample Input 3

9 20
9 5 1 2 2 2 8 9 2 1 6 2 6 5 8 7 8 5 9 8

Sample Output 3

5
E - Paint to make a rectangle

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

配点 : 300

問題文

HW 列のマス目が与えられます。
以下、上から i 行目 (1\leq i\leq H) かつ左から j 列目 (1\leq j\leq W) のマスをマス (i,j) で表します。
マス目の状態は H 個の長さ W の文字列 S_1,S_2, \ldots, S_H によって以下のように表されます。

  • S_ij 文字目が # のとき、マス (i,j) は黒く塗られている。
  • S_ij 文字目が . のとき、マス (i,j) は白く塗られている。
  • S_ij 文字目が ? のとき、マス (i,j) は塗られていない。

高橋君はまだ塗られていないマスをそれぞれ白または黒で塗ることで、黒マス全体が長方形をなすようにしたいです。
より具体的には、ある 4 つの整数の組 (a,b,c,d) (1\leq a\leq b\leq H, 1\leq c\leq d\leq W) が存在して、次が成り立つようにしたいです。

マス (i,j) (1\leq i\leq H, 1\leq j\leq W) は、 a\leq i\leq b かつ c\leq j\leq d をみたすとき、黒く塗られている。
そうでないとき、白く塗られている。

そのようなことが可能か判定してください。

制約

  • 1\leq H,W\leq 1000
  • H, W は整数
  • S_i#, ., ? のみからなる長さ W の文字列
  • 黒く塗られたマスが 1 つ以上存在する。

入力

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

H W
S_1
S_2
\vdots
S_H

出力

まだ塗られていないマスをそれぞれ白または黒で塗ることで、黒マス全体が長方形をなすようにできるならば Yes を、そうでないならば No を出力せよ。


入力例 1

3 5
.#?#.
.?#?.
?...?

出力例 1

Yes

マス目は以下の状態になっています。? のマスがまだ塗られていないマスです。

マス (1,3), (2,2), (2,4) を黒く塗り、マス (3,1), (3,5) を白く塗ることで、 以下のように黒マス全体が長方形をなすようにできます。

よって、Yes を出力します。


入力例 2

3 3
?##
#.#
##?

出力例 2

No

黒マス全体が長方形をなすためには、少なくともマス (2,2) を黒く塗る必要がありますがすでに白く塗られています。
よって、黒マス全体が長方形をなすようにマス目を塗ることはできないため、No を出力します。


入力例 3

1 1
#

出力例 3

Yes

Score : 300 points

Problem Statement

You are given a grid of H rows and W columns.
Let (i,j) denote the cell at row i (1 \leq i \leq H) from the top and column j (1 \leq j \leq W) from the left.
The state of the grid is represented by H strings S_1, S_2, \ldots, S_H, each of length W, as follows:

  • If the j-th character of S_i is #, cell (i,j) is painted black.
  • If the j-th character of S_i is ., cell (i,j) is painted white.
  • If the j-th character of S_i is ?, cell (i,j) is not yet painted.

Takahashi wants to paint each not-yet-painted cell white or black so that all the black cells form a rectangle.
More precisely, he wants there to exist a quadruple of integers (a,b,c,d) (1 \leq a \leq b \leq H, 1 \leq c \leq d \leq W) such that:

For each cell (i,j) (1 \leq i \leq H, 1 \leq j \leq W), if a \leq i \leq b and c \leq j \leq d, the cell is black;
otherwise, the cell is white.

Determine whether this is possible.

Constraints

  • 1 \leq H, W \leq 1000
  • H and W are integers.
  • Each S_i is a string of length W consisting of #, ., ?.
  • There is at least one cell that is already painted black.

Input

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

H W
S_1
S_2
\vdots
S_H

Output

If it is possible to paint all the not-yet-painted cells so that the black cells form a rectangle, print Yes; otherwise, print No.


Sample Input 1

3 5
.#?#.
.?#?.
?...?

Sample Output 1

Yes

The grid is in the following state. ? indicates a cell that are not yet painted.

By painting cells (1,3), (2,2), and (2,4) black and cells (3,1) and (3,5) white, the black cells can form a rectangle as follows:

Therefore, print Yes.


Sample Input 2

3 3
?##
#.#
##?

Sample Output 2

No

To form a rectangle with all black cells, you would need to paint cell (2,2) black, but it is already painted white.
Therefore, it is impossible to make all black cells form a rectangle, so print No.


Sample Input 3

1 1
#

Sample Output 3

Yes