A - 2^N

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100

問題文

N が与えられます。2^N を出力してください。

制約

  • 0 \leq N \leq 30
  • N は整数である

入力

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

N

出力

答えを出力せよ。


入力例 1

3

出力例 1

8

2^3=8 です。


入力例 2

30

出力例 2

1073741824

Score : 100 points

Problem Statement

Given N, print 2^N.

Constraints

  • 0 \leq N \leq 30
  • N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

Print the answer.


Sample Input 1

3

Sample Output 1

8

We have 2^3=8.


Sample Input 2

30

Sample Output 2

1073741824
B - Majority

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100

問題文

ある提案に対し、N 人の人が賛成か反対かを表明しています。なお、N は奇数です。

i \, (i = 1, 2, \dots, N) 番目の人の意見は文字列 S_i で表され、S_i = For のとき賛成しており、S_i = Against のとき反対しています。

過半数の人がこの提案に賛成しているかどうかを判定してください。

制約

  • N1 以上 99 以下の奇数
  • 全ての i = 1, 2, \dots, N に対し、S_i = For または S_i = Against

入力

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

N
S_1
S_2
\vdots
S_N

出力

N 人のうち過半数が提案に賛成しているならば Yes、そうでなければ No と出力せよ。


入力例 1

3
For
Against
For

出力例 1

Yes

提案に賛成している人数は 2 人であり、これは半数を超えているので Yes と出力します。


入力例 2

5
Against
Against
For
Against
For

出力例 2

No

提案に賛成している人数は 2 人であり、これは半数以下なので No と出力します。


入力例 3

1
For

出力例 3

Yes

Score : 100 points

Problem Statement

There are N people. Each of them agrees or disagrees with a proposal. Here, N is an odd number.

The i-th (i = 1, 2, \dots, N) person's opinion is represented by a string S_i: the person agrees if S_i = For and disagrees if S_i = Against.

Determine whether the majority agrees with the proposal.

Constraints

  • N is an odd number between 1 and 99, inclusive.
  • S_i = For or S_i = Against, for all i = 1, 2, \dots, N.

Input

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

N
S_1
S_2
\vdots
S_N

Output

Print Yes if the majority of the N people agree with the proposal; print No otherwise.


Sample Input 1

3
For
Against
For

Sample Output 1

Yes

The proposal is supported by two people, which is the majority, so Yes should be printed.


Sample Input 2

5
Against
Against
For
Against
For

Sample Output 2

No

The proposal is supported by two people, which is not the majority, so No should be printed.


Sample Input 3

1
For

Sample Output 3

Yes
C - Chessboard

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

チェス盤のどこにコマが置かれているか答えてください。

8 マス、横 8 マスのグリッドがあります。グリッドの各マスには、次のルールで定められる長さ 2 の文字列の名前がついています。

  • 左から 1 列目にあるマスの名前の 1 文字目は a である。同様に、左から 2,3,\ldots,8 列目にあるマスの名前の 1 文字目は b, c, d, e, f, g, h である。
  • 下から 1 行目にあるマスの名前の 2 文字目は 1 である。同様に、下から 2,3,\ldots,8 行目にあるマスの名前の 2 文字目は 2, 3, 4, 5, 6, 7, 8 である。

例えば、グリッドの左下のマスの名前は a1、右下のマスの名前は h1、右上のマスの名前は h8 です。

グリッドの状態を表す長さ 88 つの文字列 S_1,\ldots,S_8 が与えられます。
S_ij 文字目は、グリッドの上から i 行目 左から j 列目のマスにコマが置かれているとき *、置かれていないとき . であり、S_1,\ldots,S_8 の中に文字 * はちょうど 1 つ存在します。
コマが置かれているマスの名前を求めてください。

制約

  • S_i. および * のみからなる長さ 8 の文字列である
  • S_1,\ldots,S_8 の中に文字 * はちょうど 1 つ存在する。

入力

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

S_1
S_2
S_3
S_4
S_5
S_6
S_7
S_8

出力

答えを出力せよ。


入力例 1

........
........
........
........
........
........
........
*.......

出力例 1

a1

問題文中で説明したとおり、グリッドの左下のマスの名前は a1 です。


入力例 2

........
........
........
........
........
.*......
........
........

出力例 2

b3

Score : 200 points

Problem Statement

Locate a piece on a chessboard.

We have a grid with 8 rows and 8 columns of squares. Each of the squares has a 2-character name determined as follows.

  • The first character of the name of a square in the 1-st column from the left is a. Similarly, the first character of the name of a square in the 2-nd, 3-rd, \ldots, 8-th column from the left is b, c, d, e, f, g, h, respectively.
  • The second character of the name of a square in the 1-st row from the bottom is 1. Similarly, the second character of the name of a square in the 2-nd, 3-rd, \ldots, 8-th row from the bottom is 2, 3, 4, 5, 6, 7, 8, respectively.

For instance, the bottom-left square is named a1, the bottom-right square is named h1, and the top-right square is named h8.

You are given 8 strings S_1,\ldots,S_8, each of length 8, representing the state of the grid.
The j-th character of S_i is * if the square at the i-th row from the top and j-th column from the left has a piece on it, and . otherwise. The character * occurs exactly once among S_1,\ldots,S_8. Find the name of the square that has a piece on it.

Constraints

  • S_i is a string of length 8 consisting of . and*.
  • The character * occurs exactly once among S_1,\ldots,S_8.

Input

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

S_1
S_2
S_3
S_4
S_5
S_6
S_7
S_8

Output

Print the answer.


Sample Input 1

........
........
........
........
........
........
........
*.......

Sample Output 1

a1

As explained in the problem statement, the bottom-left square is named a1.


Sample Input 2

........
........
........
........
........
.*......
........
........

Sample Output 2

b3
D - ABCDEFG

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

直線上に 7 個の点 A, B, C, D, E, F, G がこの順に並んでいます。(下の図も参考にしてください)
隣り合う点の距離は次の通りです。

  • A と点 B の距離は 3
  • B と点 C の距離は 1
  • C と点 D の距離は 4
  • D と点 E の距離は 1
  • E と点 F の距離は 5
  • F と点 G の距離は 9

image

2 つの英大文字 p, q が与えられます。p, qA,B,C,D,E,F,G のいずれかで、 p \neq q が成り立ちます。
p と点 q の間の距離を答えてください。

制約

  • p, qA,B,C,D,E,F,G のいずれか
  • p \neq q

入力

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

p q

出力

p と点 q の間の距離を出力せよ。


入力例 1

A C

出力例 1

4

A と点 C の距離は 3 + 1 = 4 です。


入力例 2

G B

出力例 2

20

G と点 B の距離は 9 + 5 + 1 + 4 + 1 = 20 です。


入力例 3

C F

出力例 3

10

Score : 200 points

Problem Statement

There are 7 points A, B, C, D, E, F, and G on a straight line, in this order. (See also the figure below.)
The distances between adjacent points are as follows.

  • Between A and B: 3
  • Between B and C: 1
  • Between C and D: 4
  • Between D and E: 1
  • Between E and F: 5
  • Between F and G: 9

image

You are given two uppercase English letters p and q. Each of p and q is A, B, C, D, E, F, or G, and it holds that p \neq q.
Find the distance between the points p and q.

Constraints

  • Each of p and q is A,B,C,D,E,F, or G.
  • p \neq q

Input

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

p q

Output

Print the distance between the points p and q.


Sample Input 1

A C

Sample Output 1

4

The distance between the points A and C is 3 + 1 = 4.


Sample Input 2

G B

Sample Output 2

20

The distance between the points G and B is 9 + 5 + 1 + 4 + 1 = 20.


Sample Input 3

C F

Sample Output 3

10
E - Almost Equal

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 250

問題文

英小文字からなる長さ M の文字列 NS_1,S_2,\dots,S_N が与えられます。ここで、S_i は互いに異なります。

これらを並び替えた文字列の列 T_1,T_2,\dots,T_N であって、以下の条件を満たすものが存在するか判定してください。

  • 1 \le i \le N-1 を満たす全ての整数 i に対して、T_i1 文字だけ別の英小文字に変えて T_{i+1} にすることが出来る。

制約

  • 2 \le N \le 8
  • 1 \le M \le 5
  • S_i は英小文字からなる長さ M の文字列である。(1 \le i \le N)
  • S_i は互いに異なる。

入力

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

N M
S_1
S_2
\vdots
S_N

出力

問題文の条件を満たす列が存在するならば Yes を、そうでないならば No を出力せよ。


入力例 1

4 4
bbed
abcd
abed
fbed

出力例 1

Yes

abcd , abed , bbed , fbed の順に並び替えると条件を満たします。


入力例 2

2 5
abcde
abced

出力例 2

No

どのように並び替えても条件を満たすことは出来ません。


入力例 3

8 4
fast
face
cast
race
fact
rice
nice
case

出力例 3

Yes

Score : 250 points

Problem Statement

You are given N strings S_1,S_2,\dots,S_N, each of length M, consisting of lowercase English letter. Here, S_i are pairwise distinct.

Determine if one can rearrange these strings to obtain a new sequence of strings T_1,T_2,\dots,T_N such that:

  • for all integers i such that 1 \le i \le N-1, one can alter exactly one character of T_i to another lowercase English letter to make it equal to T_{i+1}.

Constraints

  • 2 \le N \le 8
  • 1 \le M \le 5
  • S_i is a string of length M consisting of lowercase English letters. (1 \le i \le N)
  • S_i are pairwise distinct.

Input

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

N M
S_1
S_2
\vdots
S_N

Output

Print Yes if one can obtain a conforming sequence; print No otherwise.


Sample Input 1

4 4
bbed
abcd
abed
fbed

Sample Output 1

Yes

One can rearrange them in this order: abcd, abed, bbed, fbed. This sequence satisfies the condition.


Sample Input 2

2 5
abcde
abced

Sample Output 2

No

No matter how the strings are rearranged, the condition is never satisfied.


Sample Input 3

8 4
fast
face
cast
race
fact
rice
nice
case

Sample Output 3

Yes
F - Happy New Year!

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

10 進法で表記したときに 0,2 のみからなる正整数のうち、 K 番目に小さいものを求めてください。

制約

  • K1 以上 10^{18} 以下の整数

入力

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

K

出力

答えを整数として出力せよ。
ただし、たとえ答えが大きな整数であっても、求める答えを正確に整数として出力する必要がある。たとえば、 2.34e+22 のような指数表記や、 0523 のような先頭に不要な 0 を付けたような表記は許されない。


入力例 1

3

出力例 1

22

10 進法で表記した時に 0,2 のみからなる正整数を小さい方から並べると、 2,20,22,\dots となります。
このうち K=3 番目である 22 を出力してください。


入力例 2

11

出力例 2

2022

入力例 3

923423423420220108

出力例 3

220022020000202020002022022000002020002222002200002022002200

たとえ答えが大きな整数であっても、求める答えを正確に整数として出力する必要があることに注意してください。

Score : 300 points

Problem Statement

Among the positive integers that consist of 0's and 2's when written in base 10, find the K-th smallest integer.

Constraints

  • K is an integer between 1 and 10^{18} (inclusive).

Input

Input is given from Standard Input in the following format:

K

Output

Print the answer as an integer.
Here, the exact value must be printed as an integer, even if it is big. Exponential notations such as 2.34e+22, for example, or unnecessary leading zeros such as 0523 are not allowed.


Sample Input 1

3

Sample Output 1

22

The positive integers that consist of 0's and 2's when written in base 10 are 2,20,22,\dots in ascending order.
The (K=) 3-rd of them, which is 22, should be printed.


Sample Input 2

11

Sample Output 2

2022

Sample Input 3

923423423420220108

Sample Output 3

220022020000202020002022022000002020002222002200002022002200

Note that the exact value of the answer must be printed as an integer, even if it is big.

G - Polynomial division

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 400

問題文

N 次多項式 A(x)=A_Nx^N+A_{N-1}x^{N-1}+\cdots +A_1x+A_0
M 次多項式 B(x)=B_Mx^M+B_{M-1}x^{M-1}+\cdots +B_1x+B_0 があります。
ここで、A(x), B(x) の各係数は絶対値が 100 以下の整数であり、最高次の係数は 0 ではありません。

また、それらの積を C(x)=A(x)B(x)=C_{N+M}x^{N+M}+C_{N+M-1}x^{N+M-1}+\cdots +C_1x+C_0 とします。

A_0,A_1,\ldots, A_N および C_0,C_1,\ldots, C_{N+M} が与えられるので、B_0,B_1,\ldots, B_M を求めてください。
ただし、与えられる入力に対して、条件をみたす B_0,B_1,\ldots, B_M がただ一つ存在することが保証されます。

制約

  • 1 \leq N < 100
  • 1 \leq M < 100
  • |A_i| \leq 100
  • |C_i| \leq 10^6
  • A_N \neq 0
  • C_{N+M} \neq 0
  • 条件をみたす B_0,B_1,\ldots, B_M がただ一つ存在する。

入力

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

N M
A_0 A_1 \ldots A_{N-1} A_N
C_0 C_1 \ldots C_{N+M-1} C_{N+M}

出力

M+1 個の整数 B_0,B_1,\ldots, B_M を空白区切りで一行に出力せよ。


入力例 1

1 2
2 1
12 14 8 2

出力例 1

6 4 2

A(x)=x+2, B(x)=2x^2+4x+6 のとき、C(x)=A(x)B(x)=(x+2)(2x^2+4x+6)=2x^3+8x^2+14x+12 であるので、 B(x)=2x^2+4x+6 が条件をみたします。 よって、B_0=6, B_1=4, B_2=2 をこの順に空白区切りで出力します。


入力例 2

1 1
100 1
10000 0 -1

出力例 2

100 -1

A(x)=x+100, C(x)=-x^2+10000 であり、B(x)=-x+100 が条件をみたします。 よって、100, -1 をこの順に空白区切りで出力します。

Score : 400 points

Problem Statement

We have a polynomial of degree N, A(x)=A_Nx^N+A_{N-1}x^{N-1}+\cdots +A_1x+A_0,
and another of degree M, B(x)=B_Mx^M+B_{M-1}x^{M-1}+\cdots +B_1x+B_0.
Here, each coefficient of A(x) and B(x) is an integer whose absolute value is at most 100, and the leading coefficients are not 0.

Also, let the product of them be C(x)=A(x)B(x)=C_{N+M}x^{N+M}+C_{N+M-1}x^{N+M-1}+\cdots +C_1x+C_0.

Given A_0,A_1,\ldots, A_N and C_0,C_1,\ldots, C_{N+M}, find B_0,B_1,\ldots, B_M.
Here, the given inputs guarantee that there is a unique sequence B_0, B_1, \ldots, B_M that satisfies the given conditions.

Constraints

  • 1 \leq N < 100
  • 1 \leq M < 100
  • |A_i| \leq 100
  • |C_i| \leq 10^6
  • A_N \neq 0
  • C_{N+M} \neq 0
  • There is a unique sequence B_0, B_1, \ldots, B_M that satisfies the conditions given in the statement.

Input

Input is given from Standard Input in the following format:

N M
A_0 A_1 \ldots A_{N-1} A_N
C_0 C_1 \ldots C_{N+M-1} C_{N+M}

Output

Print the M+1 integers B_0,B_1,\ldots, B_M in one line, with spaces in between.


Sample Input 1

1 2
2 1
12 14 8 2

Sample Output 1

6 4 2

For A(x)=x+2 and B(x)=2x^2+4x+6, we have C(x)=A(x)B(x)=(x+2)(2x^2+4x+6)=2x^3+8x^2+14x+12, so B(x)=2x^2+4x+6 satisfies the given conditions. Thus, B_0=6, B_1=4, B_2=2 should be printed in this order, with spaces in between.


Sample Input 2

1 1
100 1
10000 0 -1

Sample Output 2

100 -1

We have A(x)=x+100, C(x)=-x^2+10000, for which B(x)=-x+100 satisfies the given conditions. Thus, 100, -1 should be printed in this order, with spaces in between.

H - MST + 1

Time Limit: 4 sec / Memory Limit: 1024 MiB

配点 : 500

問題文

N 頂点 M 辺の重み付き無向連結グラフ G が与えられます。G には自己ループや多重辺が含まれている可能性があります。
頂点には頂点 1, 頂点 2, \dots, 頂点 N と番号がついています。
辺には辺 1, 辺 2, \dots, 辺 M と番号がついています。辺 i は頂点 a_i と頂点 b_i を結ぶ重み c_i の辺です。ここで、1 \leq i \lt j \leq M を満たすすべての整数の組 (i, j) について c_i \neq c_j が成り立ちます。

以下で説明される Q 個のクエリに答えてください。
i 番目のクエリでは整数の組 (u_i, v_i, w_i) が与えられます。ここで、1 \leq j \leq M を満たすすべての整数 j について w_i \neq c_j が成り立ちます。
頂点 u_i と頂点 v_i を結ぶ重み w_i の無向辺を e_i として、Ge_i を追加してできるグラフ G_i を考えます。 このとき G_i の最小全域木 T_i は一意に定まることが証明できますが、T_ie_i は含まれるでしょうか?答えを Yes あるいは No で出力してください。

ここで、クエリの前後で G は変化しないことに注意してください。言い換えると、クエリ iGe_i を追加したグラフを考えたとしても、他のクエリで出てくる Ge_i が追加されていることはありません。

最小全域木とは? G全域木 とは、G に含まれるすべての頂点と G に含まれる辺の一部からなる木のことを言います。
G最小全域木 とは、G の全域木の中で辺の重みの和が最小である木のことを言います。

制約

  • 2 \leq N \leq 2 \times 10^5
  • N - 1 \leq M \leq 2 \times 10^5
  • 1 \leq a_i \leq N (1 \leq i \leq M)
  • 1 \leq b_i \leq N (1 \leq i \leq M)
  • 1 \leq c_i \leq 10^9 (1 \leq i \leq M)
  • c_i \neq c_j (1 \leq i \lt j \leq M)
  • グラフ G は連結である。
  • 1 \leq Q \leq 2 \times 10^5
  • 1 \leq u_i \leq N (1 \leq i \leq Q)
  • 1 \leq v_i \leq N (1 \leq i \leq Q)
  • 1 \leq w_i \leq 10^9 (1 \leq i \leq Q)
  • w_i \neq c_j (1 \leq i \leq Q, 1 \leq j \leq M)
  • 入力はすべて整数である。

入力

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

N M Q
a_1 b_1 c_1
a_2 b_2 c_2
\vdots
a_M b_M c_M
u_1 v_1 w_1
u_2 v_2 w_2
\vdots
u_Q v_Q w_Q

出力

Q 行出力せよ。i 行目ではクエリ i への答えを Yes または No で出力せよ。


入力例 1

5 6 3
1 2 2
2 3 3
1 3 6
2 4 5
4 5 9
3 5 8
1 3 1
3 4 7
3 5 7

出力例 1

Yes
No
Yes

以下では頂点 u と頂点 v を結ぶ重み w の無向辺を (u,v,w) と表します。 G を図に表したものを以下に挙げます。

image

たとえばクエリ 1 では Ge_1 = (1,3,1) を追加したグラフ G_1 を考えます。G_1 の最小全域木 T_1 の辺集合は \lbrace (1,2,2),(1,3,1),(2,4,5),(3,5,8) \rbrace であり e_1 を含みます。よって Yes を出力します。


入力例 2

2 3 2
1 2 100
1 2 1000000000
1 1 1
1 2 2
1 1 5

出力例 2

Yes
No

Score : 500 points

Problem Statement

Given is a weighted undirected connected graph G with N vertices and M edges, which may contain self-loops and multi-edges.
The vertices are labeled as Vertex 1, Vertex 2, \dots, Vertex N.
The edges are labeled as Edge 1, Edge 2, \ldots, Edge M. Edge i connects Vertex a_i and Vertex b_i and has a weight of c_i. Here, for every pair of integers (i, j) such that 1 \leq i \lt j \leq M, c_i \neq c_j holds.

Process the Q queries explained below.
The i-th query gives a triple of integers (u_i, v_i, w_i). Here, for every integer j such that 1 \leq j \leq M, w_i \neq c_j holds.
Let e_i be an undirected edge that connects Vertex u_i and Vertex v_i and has a weight of w_i. Consider the graph G_i obtained by adding e_i to G. It can be proved that the minimum spanning tree T_i of G_i is uniquely determined. Does T_i contain e_i? Print the answer as Yes or No.

Note that the queries do not change T. In other words, even though Query i considers the graph obtained by adding e_i to G, the G in other queries does not have e_i.

What is minimum spanning tree? The spanning tree of G is a tree with all of the vertices in G and some of the edges in G.
The minimum spanning tree of G is the tree with the minimum total weight of edges among the spanning trees of G.

Constraints

  • 2 \leq N \leq 2 \times 10^5
  • N - 1 \leq M \leq 2 \times 10^5
  • 1 \leq a_i \leq N (1 \leq i \leq M)
  • 1 \leq b_i \leq N (1 \leq i \leq M)
  • 1 \leq c_i \leq 10^9 (1 \leq i \leq M)
  • c_i \neq c_j (1 \leq i \lt j \leq M)
  • The graph G is connected.
  • 1 \leq Q \leq 2 \times 10^5
  • 1 \leq u_i \leq N (1 \leq i \leq Q)
  • 1 \leq v_i \leq N (1 \leq i \leq Q)
  • 1 \leq w_i \leq 10^9 (1 \leq i \leq Q)
  • w_i \neq c_j (1 \leq i \leq Q, 1 \leq j \leq M)
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M Q
a_1 b_1 c_1
a_2 b_2 c_2
\vdots
a_M b_M c_M
u_1 v_1 w_1
u_2 v_2 w_2
\vdots
u_Q v_Q w_Q

Output

Print Q lines. The i-th line should contain the answer to Query i: Yes or No.


Sample Input 1

5 6 3
1 2 2
2 3 3
1 3 6
2 4 5
4 5 9
3 5 8
1 3 1
3 4 7
3 5 7

Sample Output 1

Yes
No
Yes

Below, let (u,v,w) denote an undirected edge that connects Vertex u and Vertex v and has the weight of w. Here is an illustration of G:

image

For example, Query 1 considers the graph G_1 obtained by adding e_1 = (1,3,1) to G. The minimum spanning tree T_1 of G_1 has the edge set \lbrace (1,2,2),(1,3,1),(2,4,5),(3,5,8) \rbrace, which contains e_1, so Yes should be printed.


Sample Input 2

2 3 2
1 2 100
1 2 1000000000
1 1 1
1 2 2
1 1 5

Sample Output 2

Yes
No
I - Erase Subarrays

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 500

問題文

正整数列 A=(a_1,a_2,\ldots,a_N) が与えられます。
あなたは次の操作を 0 回以上何度でも繰り返せます。

  • A から(空でない)連続する部分列を選び、削除する。

x=1,2,\ldots,M に対し、次の問題を解いてください。

  • A の要素の総和をちょうど x にするために必要な操作回数の最小値を求めてください。ただし、どのように操作を行っても A の要素の総和をちょうど x にできない場合は代わりに -1 と出力してください。

なお、A が空である時、A の要素の総和は 0 であるとします。

制約

  • 1 \leq N,M \leq 3000
  • 1 \leq a_i \leq 3000
  • 入力はすべて整数

入力

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

N M
a_1 \ldots a_N

出力

M 行出力せよ。i 行目には x=i に対する答えを出力せよ。


入力例 1

4 5
1 2 3 4

出力例 1

1
2
1
1
1

操作回数が最小である操作の例を以下に示します。

  • x=1 について、a_2,a_3,a_4 に対して操作をすることで A の要素の総和が x になります。
  • x=2 について、a_3,a_4 に対して操作をした後、a_1 に対して操作をすることで A の要素の総和が x になります。
  • x=3 について、a_3,a_4 に対して操作をすることで A の要素の総和が x になります。
  • x=4 について、a_1,a_2,a_3 に対して操作をすることで A の要素の総和が x になります。
  • x=5 について、a_2,a_3 に対して操作をすることで A の要素の総和が x になります。

入力例 2

1 5
3

出力例 2

-1
-1
0
-1
-1

入力例 3

12 20
2 5 6 5 2 1 7 9 7 2 5 5

出力例 3

2
1
2
2
1
2
1
2
2
1
2
1
1
1
2
2
1
1
1
1

Score : 500 points

Problem Statement

You are given an integer array A=(a_1,a_2,\ldots,a_N).
You may perform the following operation any number of times (possibly zero).

  • Choose a nonempty contiguous subarray of A, and delete it from the array.

For each x=1,2,\ldots,M, solve the following problem:

  • Find the minimum possible number of operations to make the sum of elements of A equal x. If it is impossible to make the sum of elements of A equal x, print -1 instead.

Note that the sum of elements of an empty array is 0.

Constraints

  • 1 \leq N,M \leq 3000
  • 1 \leq a_i \leq 3000
  • All values in the input are integers.

Input

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

N M
a_1 \ldots a_N

Output

Print M lines. The i-th line should contain the answer for x=i.


Sample Input 1

4 5
1 2 3 4

Sample Output 1

1
2
1
1
1

The followings are examples of minimum number of operations that achieve the goal.

  • For x=1, delete a_2,a_3,a_4, and the sum of elements of A becomes x.
  • For x=2, delete a_3,a_4, then delete a_1, and the sum of elements of A becomes x.
  • For x=3, delete a_3,a_4, and the sum of elements of A becomes x.
  • For x=4, delete a_1,a_2,a_3, and the sum of elements of A becomes x.
  • For x=5, delete a_2,a_3, and the sum of elements of A becomes x.

Sample Input 2

1 5
3

Sample Output 2

-1
-1
0
-1
-1

Sample Input 3

12 20
2 5 6 5 2 1 7 9 7 2 5 5

Sample Output 3

2
1
2
2
1
2
1
2
2
1
2
1
1
1
2
2
1
1
1
1