A - Edge Checker 2

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 100

問題文

下の画像で示す図において、a 番の点と b 番の点が線で直接結ばれているかを答えてください。

制約

  • 1 \leq a \lt b \leq 15
  • a,b は整数

入力

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

a b

出力

a 番の点と b 番の点が線で直接結ばれているなら Yes、結ばれていないなら No を出力せよ。


入力例 1

1 2

出力例 1

Yes

問題文で示した図において、1 番の点と 2 番の点は線で直接結ばれています。 よって、Yes を出力します。


入力例 2

2 8

出力例 2

No

問題文で示した図において、2 番の点と 8 番の点は線で直接結ばれていません。 よって、No を出力します。


入力例 3

14 15

出力例 3

No

Score : 100 points

Problem Statement

Determine if there is a segment that directly connects the points numbered a and b in the figure below.

Constraints

  • 1 \leq a \lt b \leq 15
  • a and b are integers.

Input

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

a b

Output

Print Yes if there is a segment that directly connects the points numbered a and b; print No otherwise.


Sample Input 1

1 2

Sample Output 1

Yes

In the figure in the Problem Statement, there is a segment that directly connects the points numbered 1 and 2, so Yes should be printed.


Sample Input 2

2 8

Sample Output 2

No

In the figure in the Problem Statement, there is no segment that directly connects the points numbered 2 and 8, so No should be printed.


Sample Input 3

14 15

Sample Output 3

No
B - Longest Uncommon Prefix

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 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.
C - abc285_brutmhyhiizp

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 300

問題文

別世界の AtCoder で開催されている AtCoder Big Contest では、 10^{16} 問の問題が一度に出題されます。
問題の ID は 1 問目から順に A, B, ..., Z, AA, AB, ..., ZZ, AAA, ... と付けられています。

つまり、 ID は以下の順番で付けられています。

  • 長さ 1 の英大文字からなる文字列を辞書順に並べたもの
  • 長さ 2 の英大文字からなる文字列を辞書順に並べたもの
  • 長さ 3 の英大文字からなる文字列を辞書順に並べたもの
  • ...

このコンテストに含まれる問題の ID である文字列 S が与えられるので、それが何問目か答えてください。

制約

  • S は AtCoder Big Contest に含まれる問題の ID として正しい

入力

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

S

出力

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


入力例 1

AB

出力例 1

28

ID が AB である問題は、 AtCoder Big Contest の 28 問目です。


入力例 2

C

出力例 2

3

ID が C である問題は、 AtCoder Big Contest の 3 問目です。


入力例 3

BRUTMHYHIIZP

出力例 3

10000000000000000

ID が BRUTMHYHIIZP である問題は、 AtCoder Big Contest の 10^{16} 問目、すなわち最終問題です。

Score : 300 points

Problem Statement

In a parallel universe, AtCoder holds AtCoder Big Contest, where 10^{16} problems are given at once.
The IDs of the problems are as follows, from the 1-st problem in order: A, B, ..., Z, AA, AB, ..., ZZ, AAA, ...

In other words, the IDs are given in the following order:

  • the strings of length 1 consisting of uppercase English letters, in lexicographical order;
  • the strings of length 2 consisting of uppercase English letters, in lexicographical order;
  • the strings of length 3 consisting of uppercase English letters, in lexicographical order;
  • ...

Given a string S that is an ID of a problem given in this contest, find the index of the problem. (See also Samples.)

Constraints

  • S is a valid ID of a problem given in AtCoder Big Contest.

Input

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

S

Output

Print the answer as an integer.


Sample Input 1

AB

Sample Output 1

28

The problem whose ID is AB is the 28-th problem of AtCoder Big Contest, so 28 should be printed.


Sample Input 2

C

Sample Output 2

3

The problem whose ID is C is the 3-rd problem of AtCoder Big Contest, so 3 should be printed.


Sample Input 3

BRUTMHYHIIZP

Sample Output 3

10000000000000000

The problem whose ID is BRUTMHYHIIZP is the 10^{16}-th (last) problem of AtCoder Big Contest, so 10^{16} should be printed as an integer.

D - Change Usernames

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 400

問題文

あなたの運営する Web サービスには N 人のユーザがいます。

i 番目のユーザの現在のユーザ名は S_i ですが、T_i への変更を希望しています。
ここで、S_1,\ldots,S_N は相異なり、T_1,\ldots,T_N も相異なります。

ユーザ名を変更する順序を適切に定めることで、以下の条件を全て満たすように、全てのユーザのユーザ名を希望通り変更することができるか判定してください。

  • ユーザ名の変更は 1 人ずつ行う
  • どのユーザもユーザ名の変更は一度だけ行う
  • ユーザ名の変更を試みる時点で他のユーザが使っているユーザ名に変更することはできない

制約

  • 1 \leq N \leq 10^5
  • S_i,T_i は英小文字からなる 1 文字以上 8 文字以下の文字列
  • S_i \neq T_i
  • S_i は相異なる
  • T_i は相異なる

入力

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

N
S_1 T_1
S_2 T_2
\vdots
S_N T_N

出力

条件を全て満たすように全てのユーザのユーザ名を希望通り変更することができるとき Yes、できないとき No と出力せよ。


入力例 1

2
b m
m d

出力例 1

Yes

1 番目のユーザの現在のユーザ名は b であり、m への変更を希望しています。
2 番目のユーザの現在のユーザ名は m であり、d への変更を希望しています。

まず、2 番目のユーザのユーザ名を m から d に変更し、 その後 1 番目のユーザのユーザ名を b から m に変更することで、条件を満たしながら変更することができます。

最初の時点では 2 番目のユーザのユーザ名が m なので、1 番目のユーザのユーザ名を同じ m に変更することはできません。


入力例 2

3
a b
b c
c a

出力例 2

No

1 番目のユーザの現在のユーザ名は a であり、b への変更を希望しています。
2 番目のユーザの現在のユーザ名は b であり、c への変更を希望しています。
3 番目のユーザの現在のユーザ名は c であり、a への変更を希望しています。

条件を満たしながらユーザ名の変更を行うことはできません。


入力例 3

5
aaa bbb
yyy zzz
ccc ddd
xxx yyy
bbb ccc

出力例 3

Yes

Score : 400 points

Problem Statement

You run a web service with N users.

The i-th user with a current handle S_i wants to change it to T_i.
Here, S_1,\ldots, and S_N are pairwise distinct, and so are T_1,\ldots, and T_N.

Determine if there is an appropriate order to change their handles to fulfill all of their requests subject to the following conditions:

  • you change only one user's handle at a time;
  • you change each user's handle only once;
  • when changing the handle, the new handle should not be used by other users at that point.

Constraints

  • 1 \leq N \leq 10^5
  • S_i and T_i are strings of length between 1 and 8 (inclusive) consisting of lowercase English letters.
  • S_i \neq T_i
  • S_i are pairwise distinct.
  • T_i are pairwise distinct.

Input

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

N
S_1 T_1
S_2 T_2
\vdots
S_N T_N

Output

Print Yes if they can change their handles to fulfill all of their requests subject to the conditions; print No otherwise.


Sample Input 1

2
b m
m d

Sample Output 1

Yes

The 1-st user with a current handle b wants to change it to m.
The 2-nd user with a current handle m wants to change it to d.

First, you change the 2-nd user's handle from m to d; then you change the 1-st user's handle from b to m. This way, you can achieve the objective.

Note that you cannot change the 1-st user's handle to m at first, because it is used by the 2-nd user at that point.


Sample Input 2

3
a b
b c
c a

Sample Output 2

No

The 1-st user with a current handle a wants to change it to b.
The 2-nd user with a current handle b wants to change it to c.
The 3-rd user with a current handle c wants to change it to a.

We cannot change their handles subject to the conditions.


Sample Input 3

5
aaa bbb
yyy zzz
ccc ddd
xxx yyy
bbb ccc

Sample Output 3

Yes
E - Work or Rest

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 500

問題文

高橋君が住む世界の一週間は N 日からなります。
一週間は曜日 1,2,\dots,N と進んでいき、曜日 N が終わると次の週の曜日 1 が始まります。

ABC 国の国王である高橋君は、各曜日に「平日」「休日」のどちらかを割り当てます。この割り当ては毎週同じでなければなりません。また、少なくとも 1 つの曜日を「休日」に割り当てなければなりません。

この条件の下で、曜日 i の生産量は長さ N の数列 A を用いて以下のように定義されます。

  • 曜日 i が「休日」である場合は 0
  • 曜日 i が「平日」のとき、直前の休日が x 日前、直後の休日が y 日後である場合は A_{\min(x,y)}
    • 割り当ては毎週繰り返されるため、 直前 / 直後 の「休日」が当日とは別の週に属する可能性があることに注意してください。詳しくはサンプルを参照してください。

上手く割り当てを決めたときの一週間当たりの生産量の最大値を答えてください。
但し、一週間当たりの生産量とは曜日 1,2,\dots,N の生産量の総和を指します。

制約

  • 入力はすべて整数
  • 1 \le N \le 5000
  • 1 \le A_i \le 10^9

入力

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

N
A_1 A_2 \dots A_N

出力

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


入力例 1

7
10 10 1 1 1 1 1

出力例 1

50

例えば曜日 2,4 を「休日」、残りを「平日」に割り当てることで、以下のように一週間当たりの生産量 50 を達成できます。

  • 曜日 1 ... x=4,y=1 なので、この曜日の生産量は A_1 = 10 である。
  • 曜日 2 ... 「休日」であるので、この曜日の生産量は 0 である。
  • 曜日 3 ... x=1,y=1 なので、この曜日の生産量は A_1 = 10 である。
  • 曜日 4 ... 「休日」であるので、この曜日の生産量は 0 である。
  • 曜日 5 ... x=1,y=4 なので、この曜日の生産量は A_1 = 10 である。
  • 曜日 6 ... x=2,y=3 なので、この曜日の生産量は A_2 = 10 である。
  • 曜日 7 ... x=3,y=2 なので、この曜日の生産量は A_2 = 10 である。

一週間当たりの生産量を 51 以上にすることはできません。


入力例 2

10
200000000 500000000 1000000000 800000000 100000000 80000000 600000 900000000 1 20

出力例 2

5100000000

入力例 3

20
38 7719 21238 2437 8855 11797 8365 32285 10450 30612 5853 28100 1142 281 20537 15921 8945 26285 2997 14680

出力例 3

236980

Score : 500 points

Problem Statement

In the world where Takahashi lives, a week has N days.

Takahashi, the king of the Kingdom of AtCoder, assigns "weekday" or "holiday" to each day of week. The assignments should be the same for all weeks. At least one day of week should be assigned "holiday".

Under such conditions, the productivity of the i-th day of week is defined by a sequence A of length N as follows:

  • if the i-th day of week is "holiday", its productivity is 0;
  • if the i-th day of week is "weekday", its productivity is A_{\min(x,y)}, if the last holiday is x days before and the next one is y days after.
    • Note that the last/next holiday may belong to a different week due to the periodic assignments. For details, see the Samples.

Find the maximum productivity per week when the assignments are chosen optimally.
Here, the productivity per week refers to the sum of the productivities of the 1-st, 2-nd, \dots, and N-th day of week.

Constraints

  • All values in the input are integers.
  • 1 \le N \le 5000
  • 1 \le A_i \le 10^9

Input

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

N
A_1 A_2 \dots A_N

Output

Print the answer as an integer.


Sample Input 1

7
10 10 1 1 1 1 1

Sample Output 1

50

For example, we can assign "holiday" to the 2-nd and 4-th day of week and "weekday" to the rest to achieve a productivity of 50 per week:

  • the 1-st day of week ... x=4 and y=1, so its productivity is A_1 = 10.
  • the 2-nd day of week ... it is holiday, so its productivity is 0.
  • the 3-st day of week ... x=1 and y=1, so its productivity is A_1 = 10.
  • the 4-th day of week ... it is holiday, so its productivity is 0.
  • the 5-th day of week ... x=1 and y=4, so its productivity is A_1 = 10.
  • the 6-th day of week ... x=2 and y=3, so its productivity is A_2 = 10.
  • the 7-th day of week ... x=3 and y=2, so its productivity is A_2 = 10.

It is impossible to make the productivity per week 51 or greater.


Sample Input 2

10
200000000 500000000 1000000000 800000000 100000000 80000000 600000 900000000 1 20

Sample Output 2

5100000000

Sample Input 3

20
38 7719 21238 2437 8855 11797 8365 32285 10450 30612 5853 28100 1142 281 20537 15921 8945 26285 2997 14680

Sample Output 3

236980
F - Substring of Sorted String

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 500

問題文

英小文字からなる長さ N の文字列 SQ 個のクエリが与えられます。クエリを順に処理してください。

クエリは以下の 2 種類です。

  • 1 x cSx 文字目を文字 c に置き換える
  • 2 l rS を文字の昇順に並び替えて得られる文字列を T とする。Sl 文字目から r 文字目までからなる文字列が T の部分文字列であるとき Yes、部分文字列でないとき No を出力する
部分文字列とは? S部分文字列とは、S の先頭から 0 文字以上、末尾から 0 文字以上削除して得られる文字列のことをいいます。 例えば、ababc の部分文字列ですが、acabc の部分文字列ではありません。

制約

  • 1\leq N \leq 10^5
  • S は英小文字からなる長さ N の文字列
  • 1 \leq Q \leq 10^5
  • 1 種類目のクエリにおいて、1 \leq x \leq N
  • 1 種類目のクエリにおいて、c は英小文字
  • 2 種類目のクエリにおいて、1 \leq l \leq r \leq N

入力

入力は以下の形式で標準入力から与えられる。ただし、\text{query}_ii 番目のクエリを表す。

N
S
Q
\text{query}_1
\text{query}_2
\vdots
\text{query}_Q

出力

問題文中の指示に従ってクエリを処理せよ。


入力例 1

6
abcdcf
4
2 1 3
2 2 6
1 5 e
2 2 6

出力例 1

Yes
No
Yes
  • 1 番目のクエリにおいて、S を文字の昇順に並び替えて得られる文字列 Tabccdf です。 S1 文字目から 3 文字目までからなる文字列は abc であり T の部分文字列です。よって Yes を出力します。
  • 2 番目のクエリにおいて、S を文字の昇順に並び替えて得られる文字列 Tabccdf です。 S2 文字目から 6 文字目までからなる文字列は bcdcf であり T の部分文字列ではありません。よって No を出力します。
  • 3 番目のクエリにより、S5 文字目が e に置き換えられ、Sabcdef となります。
  • 4 番目のクエリにおいて、S を文字の昇順に並び替えて得られる文字列 Tabcdef です。 S2 文字目から 6 文字目までからなる文字列は bcdef であり T の部分文字列です。よって Yes を出力します。

Score : 500 points

Problem Statement

You are given a string S of length N consisting of lowercase English letters, and Q queries. Process the queries in order.

Each query is of one of the following two kinds:

  • 1 x c : replace the x-th character of S by the character c.
  • 2 l r : let T be the string obtained by sorting the characters of S in ascending order. Print Yes if the string consisting of the l-th through r-th characters of S is a substring of T; print No otherwise.
What is a substring? A substring of S is a string obtained by removing 0 or more initial characters and 0 or more final characters of S. For example, ab is a substring of abc, while ac is not a substring of abc.

Constraints

  • 1\leq N \leq 10^5
  • S is a string of length N consisting of lowercase English letters.
  • 1 \leq Q \leq 10^5
  • For each query of the first kind, 1 \leq x \leq N.
  • For each query of the first kind, c is a lowercase English letter.
  • For each query of the second kind, 1 \leq l \leq r \leq N.

Input

The input is given from Standard Input in the following format, where \text{query}_i denotes the i-th query:

N
S
Q
\text{query}_1
\text{query}_2
\vdots
\text{query}_Q

Output

Process the queries as instructed in the Problem Statement.


Sample Input 1

6
abcdcf
4
2 1 3
2 2 6
1 5 e
2 2 6

Sample Output 1

Yes
No
Yes
  • In the 1-st query, abccdf is the string T obtained by sorting the characters of S in ascending order. The string abc, consisting of the 1-st through 3-rd characters of S, is a substring of T, so Yes should be printed.
  • In the 2-nd query, abccdf is the string T obtained by sorting the characters of S in ascending order. The string bcdcf, consisting of the 2-nd through 6-th characters of S, is not a substring of T, so No should be printed.
  • The 3-rd query sets the 5-th character of S to e, making S abcdef.
  • In the 4-th query, abcdef is the string T obtained by sorting the characters of S in ascending order. The string bcdef, consisting of the 2-nd through 6-th characters of S, is a substring of T, so Yes should be printed.
G - Tatami

Time Limit: 3 sec / Memory Limit: 1024 MB

配点 : 600

問題文

H マス、横 W マスのグリッドがあります。上から i 行目、左から j 列目のマスをマス (i,j) と呼びます。

このグリッドを縦 1 マス \times1 マスのタイルと縦 1 マス \times2 マスのタイルで、重ならないように、隙間ができないように覆います(タイルは回転してもよい)。

各マスには 1, 2, ? のいずれかが書かれています。マス (i,j) に書かれている文字は c_{i,j} です。
1 が書かれたマスは 1\times 1 のタイルで、2 が書かれたマスは 1\times 2 のタイルで覆わなければなりません。? が書かれたマスはどちらのタイルで覆っても構いません。

そのようなタイルの置き方があるかどうか判定してください。

制約

  • 1 \leq H,W \leq 300
  • H,W は整数
  • c_{i,j}1, 2, ? のいずれか

入力

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

H W
c_{1,1}c_{1,2}\ldots c_{1,W}
\vdots
c_{H,1}c_{H,2}\ldots c_{H,W}

出力

問題文中の条件を満たすタイルの置き方が存在するなら Yes、存在しないなら No と出力せよ。


入力例 1

3 4
2221
?1??
2?21

出力例 1

Yes

例えば以下のようなタイルの置き方で条件を満たすことができます。


入力例 2

3 4
2?21
??1?
2?21

出力例 2

No

条件を満たすようなタイルの置き方は存在しません。


入力例 3

5 5
11111
11111
11211
11111
11111

出力例 3

No

Score : 600 points

Problem Statement

We have a grid with H horizontal rows and W vertical columns. We denote by square (i,j) the square at the i-th row from the top and j-th column from the left.

We want to cover this grid with 1 \times 1 tiles and 1 \times 2 tiles so that no tiles overlap and everywhere is covered by a tile. (A tile can be rotated.)

Each square has 1, 2, or ? written on it. The character written on square (i, j) is c_{i,j}.
A square with 1 written on it must be covered by a 1 \times 1 tile, and a square with 2 by a 1 \times 2 tile. A square with ? may be covered by any kind of tile.

Determine if there is such a placement of tiles.

Constraints

  • 1 \leq H,W \leq 300
  • H and W are integers.
  • c_{i,j} is one of 1, 2, and ?.

Input

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

H W
c_{1,1}c_{1,2}\ldots c_{1,W}
\vdots
c_{H,1}c_{H,2}\ldots c_{H,W}

Output

Print Yes if there is a placement of tiles to satisfy the conditions in the Problem Statement; print No otherwise.


Sample Input 1

3 4
2221
?1??
2?21

Sample Output 1

Yes

For example, the following placement satisfies the conditions.


Sample Input 2

3 4
2?21
??1?
2?21

Sample Output 2

No

There is no placement that satisfies the conditions.


Sample Input 3

5 5
11111
11111
11211
11111
11111

Sample Output 3

No
Ex - Avoid Square Number

Time Limit: 3 sec / Memory Limit: 1024 MB

配点 : 600

問題文

整数 N,K と長さ K の数列 E が与えられます。
長さ N の正整数列であって、以下の条件を全て満たすものの総数を \color{red}{10^9+7} で割った余りを求めてください。

  • どの要素も平方数でない
  • 全要素の積が \displaystyle \prod_{i=1}^{K} p_i^{E_i} である

但し、

  • p_i は小さい方から i 番目の素数を指すものとします。
  • ある 2 つの長さが等しい正整数列 A,B について、 Ai 項目と Bi 項目が異なるような整数 i が存在する時に限り、 AB は異なる列であるとします。

制約

  • 入力は全て整数
  • 1 \le N,K,E_i \le 10000

入力

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

N K
E_1 E_2 \dots E_K

出力

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


入力例 1

3 2
3 2

出力例 1

15

全要素の積が 72=2^3 \times 3^2 となる長さ 3 の数列は以下です。

  • (1,1,72) とその並べ替え ( 3 通り ) ... 1 が平方数なので、条件を満たしません。
  • (1,2,36) とその並べ替え ( 6 通り ) ... 1,36 が平方数なので、条件を満たしません。
  • (1,3,24) とその並べ替え ( 6 通り ) ... 1 が平方数なので、条件を満たしません。
  • (1,4,18) とその並べ替え ( 6 通り ) ... 1,4 が平方数なので、条件を満たしません。
  • (1,6,12) とその並べ替え ( 6 通り ) ... 1 が平方数なので、条件を満たしません。
  • (1,8,9) とその並べ替え ( 6 通り ) ... 1,9 が平方数なので、条件を満たしません。
  • (2,2,18) とその並べ替え ( 3 通り ) ... 条件を満たします。
  • (2,3,12) とその並べ替え ( 6 通り ) ... 条件を満たします。
  • (2,4,9) とその並べ替え ( 6 通り ) ... 4,9 が平方数なので、条件を満たしません。
  • (2,6,6) とその並べ替え ( 3 通り ) ... 条件を満たします。
  • (3,3,8) とその並べ替え ( 3 通り ) ... 条件を満たします。
  • (3,4,6) とその並べ替え ( 6 通り ) ... 4 が平方数なので、条件を満たしません。

よって、条件を満たす数列は 15 個です。


入力例 2

285 10
3141 5926 5358 9793 2384 6264 3383 279 5028 8419

出力例 2

672860525

\color{red}{10^9+7} で割った余りを求めることに注意してください。

Score : 600 points

Problem Statement

You are given integers N and K, and a sequence E of length K.
Find the number, modulo \color{red}{10^9+7}, of sequences of length N consisting of positive integers that satisfy the following conditions:

  • no element is a square number;
  • the product of all elements is \displaystyle \prod_{i=1}^{K} p_i^{E_i}.

Here,

  • p_i denotes the i-th smallest prime.
  • Two sequences A and B of the same length consisting of positive integers are considered different if and only if there exists an integer i such that the i-th terms of A and B are different.

Constraints

  • All values in the input are integers.
  • 1 \le N,K,E_i \le 10000

Input

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

N K
E_1 E_2 \dots E_K

Output

Print the answer as an integer.


Sample Input 1

3 2
3 2

Sample Output 1

15

The sequences of length 3 whose total product is 72=2^3 \times 3^2 are listed below.

  • (1,1,72) and its permutations (3 instances) are inappropriate because 1 is a square number.
  • (1,2,36) and its permutations (6 instances) are inappropriate because 1 and 36 are square numbers.
  • (1,3,24) and its permutations (6 instances) are inappropriate because 1 is a square number.
  • (1,4,18) and its permutations (6 instances) are inappropriate because 1 and 4 are square numbers.
  • (1,6,12) and its permutations (6 instances) are inappropriate because 1 is a square number.
  • (1,8,9) and its permutations (6 instances) are inappropriate because 1 and 9 are square numbers.
  • (2,2,18) and its permutations (3 instances) are appropriate.
  • (2,3,12) and its permutations (6 instances) are appropriate.
  • (2,4,9) and its permutations (6 instances) are inappropriate because 4 and 9 are square numbers.
  • (2,6,6) and its permutations (3 instances) are appropriate.
  • (3,3,8) and its permutations (3 instances) are appropriate.
  • (3,4,6) and its permutations (6 instances) are inappropriate because 4 is a square number.

Therefore, 15 sequences satisfy the conditions.


Sample Input 2

285 10
3141 5926 5358 9793 2384 6264 3383 279 5028 8419

Sample Output 2

672860525

Be sure to find the count modulo \color{red}{10^9+7}.