A - chukodai

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 100

問題文

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

S の先頭から a 文字目と b 文字目を入れ替えて得られる文字列を出力してください。

制約

  • S は英小文字からなる文字列
  • S の長さ |S| は、 2 \leq |S| \leq 10 を満たす
  • 1 \leq a < b \leq |S|
  • a, b は整数

入力

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

S
a b

出力

答えを出力せよ。


入力例 1

chokudai
3 5

出力例 1

chukodai

chokudai3 文字目 o5 文字目 u を入れ替えると chukodai となります。


入力例 2

aa
1 2

出力例 2

aa

この入力例では、S1 文字目と 2 文字目を入れ替えて得られる文字列は、元の S と同じになります。


入力例 3

aaaabbbb
1 8

出力例 3

baaabbba

Score : 100 points

Problem Statement

You are given a string S consisting of lowercase English letters.

Swap the a-th and b-th characters from the beginning of S and print the resulting string.

Constraints

  • S is a string consisting of lowercase English letters.
  • The length of S, |S|, satisfies 2 \leq |S| \leq 10.
  • 1 \leq a < b \leq |S|
  • a and b are integers.

Input

Input is given from Standard Input in the following format:

S
a b

Output

Print the answer.


Sample Input 1

chokudai
3 5

Sample Output 1

chukodai

After swapping the 3-rd character o and 5-th character u of chokudai, we have chukodai.


Sample Input 2

aa
1 2

Sample Output 2

aa

In this sample, after swapping the 1-st and 2-nd characters of S, we have the same string as S.


Sample Input 3

aaaabbbb
1 8

Sample Output 3

baaabbba
B - Who is missing?

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 200

問題文

整数 1, 2, \dots, N が書かれたカードが 4 枚ずつ、合計 4N 枚あります。

高橋君は、これらのカードをシャッフルしたのち 1 枚のカードを選んで抜き取り、残りの 4N - 1 枚を束にしてあなたに渡しました。渡された束の i \, (1 \leq i \leq 4N - 1) 枚目のカードには、整数 A_i が書かれています。

高橋君が抜き取ったカードに書かれていた整数を求めてください。

制約

  • 1 \leq N \leq 10^5
  • 1 \leq A_i \leq N \, (1 \leq i \leq 4N - 1)
  • k \, (1 \leq k \leq N) に対し、A_i = k となる i4 個以下である。
  • 入力は全て整数である。

入力

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

N
A_1 A_2 \ldots A_{4N - 1}

出力

答えを出力せよ。


入力例 1

3
1 3 2 3 3 2 2 1 1 1 2

出力例 1

3

高橋君が抜き取ったカードには 3 が書かれています。


入力例 2

1
1 1 1

出力例 2

1

入力例 3

4
3 2 1 1 2 4 4 4 4 3 1 3 2 1 3

出力例 3

2

Score : 200 points

Problem Statement

We have 4 cards with an integer 1 written on it, 4 cards with 2, \ldots, 4 cards with N, for a total of 4N cards.

Takahashi shuffled these cards, removed one of them, and gave you a pile of the remaining 4N-1 cards. The i-th card (1 \leq i \leq 4N - 1) of the pile has an integer A_i written on it.

Find the integer written on the card removed by Takahashi.

Constraints

  • 1 \leq N \leq 10^5
  • 1 \leq A_i \leq N \, (1 \leq i \leq 4N - 1)
  • For each k \, (1 \leq k \leq N), there are at most 4 indices i such that A_i = k.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 \ldots A_{4N - 1}

Output

Print the answer.


Sample Input 1

3
1 3 2 3 3 2 2 1 1 1 2

Sample Output 1

3

Takahashi removed a card with 3 written on it.


Sample Input 2

1
1 1 1

Sample Output 2

1

Sample Input 3

4
3 2 1 1 2 4 4 4 4 3 1 3 2 1 3

Sample Output 3

2
C - Route Map

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 300

問題文

AtCoder 鉄道のとある路線には N 個の駅が存在し、始点から終点に向かって i \, (1 \leq i \leq N) 番目の駅の名前は S_i です。

普通列車は全ての駅に止まりますが、急行列車は全ての駅に止まるとは限りません。具体的には、急行列車は M \, (M \leq N) 個の駅にのみ止まり、j \, (1 \leq j \leq M) 番目に止まる駅の名前は T_j です。
ただし、T_1 = S_1 かつ T_M = S_N、すなわち急行列車は始点と終点の両方に止まることが保証されます。

N 個の駅それぞれについて、その駅に急行列車が止まるかどうか判定してください。

制約

  • 2 \leq M \leq N \leq 10^5
  • N, M は整数
  • S_i \, (1 \leq i \leq N) は英小文字のみからなる 1 文字以上 10 文字以下の文字列
  • S_i \neq S_j \, (i \neq j)
  • T_1 = S_1 かつ T_M = S_N
  • (T_1, \dots, T_M)(S_1, \dots, S_N) から 0 個以上の文字列を選んで取り除き、残った文字列を元の順序で並べることで得られる

入力

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

N M
S_1 \ldots S_N
T_1 \ldots T_M

出力

N 行出力せよ。i \, (1 \leq i \leq N) 行目には、始点から終点に向かって i 番目の駅に急行列車が止まるなら Yes、そうでないなら No と出力せよ。


入力例 1

5 3
tokyo kanda akiba okachi ueno
tokyo akiba ueno

出力例 1

Yes
No
Yes
No
Yes

入力例 2

7 7
a t c o d e r
a t c o d e r

出力例 2

Yes
Yes
Yes
Yes
Yes
Yes
Yes

急行列車が全ての駅に止まることもあります。

Score : 300 points

Problem Statement

There are N stations on a certain line operated by AtCoder Railway. The i-th station (1 \leq i \leq N) from the starting station is named S_i.

Local trains stop at all stations, while express trains may not. Specifically, express trains stop at only M \, (M \leq N) stations, and the j-th stop (1 \leq j \leq M) is the station named T_j.
Here, it is guaranteed that T_1 = S_1 and T_M = S_N, that is, express trains stop at both starting and terminal stations.

For each of the N stations, determine whether express trains stop at that station.

Constrains

  • 2 \leq M \leq N \leq 10^5
  • N and M are integers.
  • S_i (1 \leq i \leq N) is a string of length between 1 and 10 (inclusive) consisting of lowercase English letters.
  • S_i \neq S_j \, (i \neq j)
  • T_1 = S_1 and T_M = S_N.
  • (T_1, \dots, T_M) is obtained by removing zero or more strings from (S_1, \dots, S_N) and lining up the remaining strings without changing the order.

Input

Input is given from Standard Input in the following format:

N M
S_1 \ldots S_N
T_1 \ldots T_M

Output

Print N lines. The i-th line (1 \leq i \leq N) should contain Yes if express trains stop at the i-th station from the starting station, and No otherwise.


Sample Input 1

5 3
tokyo kanda akiba okachi ueno
tokyo akiba ueno

Sample Output 1

Yes
No
Yes
No
Yes

Sample Input 2

7 7
a t c o d e r
a t c o d e r

Sample Output 2

Yes
Yes
Yes
Yes
Yes
Yes
Yes

Express trains may stop at all stations.

D - Dance

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 400

問題文

1, 2, \ldots, 2N と番号づけられた 2N 人の人が舞踏会に参加します。 彼らは N 個の 2 人組にわかれてダンスを踊ります。

2 人組を構成する人のうち、番号の小さい方の人が人 i 、番号の大きい方の人が人 j のとき、 その 2 人組の「相性」は A_{i, j} です。
N 個の 2 人組の相性がそれぞれ B_1, B_2, \ldots, B_N であるとき、 「舞踏会全体の楽しさ」はそれらのビットごとの排他的論理和である B_1 \oplus B_2 \oplus \cdots \oplus B_N です。

2N 人の参加者が N 個の 2 人組に分かれる方法」を自由に選べるとき、「舞踏会全体の楽しさ」としてあり得る最大値を出力してください。

制約

  • 1 \leq N \leq 8
  • 0 \leq A_{i, j} < 2^{30}
  • 入力はすべて整数

入力

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

N
A_{1, 2} A_{1, 3} A_{1, 4} \cdots A_{1, 2N}
A_{2, 3} A_{2, 4} \cdots A_{2, 2N}
A_{3, 4} \cdots A_{3, 2N}
\vdots
A_{2N-1, 2N}

出力

舞踏会全体の楽しさとしてあり得る最大値を出力せよ。


入力例 1

2
4 0 1
5 3
2

出力例 1

6

i と人 j からなる 2 人組を \lbrace i, j\rbrace で表します。 4 人が 2 個の 2 人組にわかれる方法は下記の 3 通りです。

  • \lbrace 1, 2\rbrace, \lbrace 3, 4\rbrace という 2 組にわかれる。 このとき、舞踏会全体の楽しさは A_{1, 2} \oplus A_{3, 4} = 4 \oplus 2 = 6 です。
  • \lbrace 1, 3\rbrace, \lbrace 2, 4\rbrace という 2 組にわかれる。 このとき、舞踏会全体の楽しさは A_{1, 3} \oplus A_{2, 4} = 0 \oplus 3 = 3 です。
  • \lbrace 1, 4\rbrace, \lbrace 2, 3\rbrace という 2 組にわかれる。 このとき、舞踏会全体の楽しさは A_{1, 4} \oplus A_{2, 3} = 1 \oplus 5 = 4 です。

よって、舞踏会全体の楽しさとしてあり得る最大値は 6 です。


入力例 2

1
5

出力例 2

5

1 と人 2 からなる 2 人組のみが作られ、このときの舞踏会全体の楽しさは 5 です。


入力例 3

5
900606388 317329110 665451442 1045743214 260775845 726039763 57365372 741277060 944347467
369646735 642395945 599952146 86221147 523579390 591944369 911198494 695097136
138172503 571268336 111747377 595746631 934427285 840101927 757856472
655483844 580613112 445614713 607825444 252585196 725229185
827291247 105489451 58628521 1032791417 152042357
919691140 703307785 100772330 370415195
666350287 691977663 987658020
1039679956 218233643
70938785

出力例 3

1073289207

Score : 400 points

Problem Statement

2N people numbered 1, 2, \ldots, 2N attend a ball. They will group into N pairs and have a dance.

If Person i and Person j pair up, where i is smaller than j, the affinity of that pair is A_{i, j}.
If the N pairs have the affinity of B_1, B_2, \ldots, B_N, the total fun of the ball is the bitwise XOR of them: B_1 \oplus B_2 \oplus \cdots \oplus B_N.

Print the maximum possible total fun of the ball when the 2N people can freely group into N pairs.

Constraints

  • 1 \leq N \leq 8
  • 0 \leq A_{i, j} < 2^{30}
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_{1, 2} A_{1, 3} A_{1, 4} \cdots A_{1, 2N}
A_{2, 3} A_{2, 4} \cdots A_{2, 2N}
A_{3, 4} \cdots A_{3, 2N}
\vdots
A_{2N-1, 2N}

Output

Print the maximum possible total fun of the ball.


Sample Input 1

2
4 0 1
5 3
2

Sample Output 1

6

Let \lbrace i, j\rbrace denote a pair of Person i and Person j. There are three ways for the four people to group into two pairs, as follows.

  • Group into \lbrace 1, 2\rbrace, \lbrace 3, 4\rbrace. The total fun of the ball here is A_{1, 2} \oplus A_{3, 4} = 4 \oplus 2 = 6.
  • Group into \lbrace 1, 3\rbrace, \lbrace 2, 4\rbrace. The total fun of the ball here is A_{1, 3} \oplus A_{2, 4} = 0 \oplus 3 = 3.
  • Group into \lbrace 1, 4\rbrace, \lbrace 2, 3\rbrace. The total fun of the ball here is A_{1, 4} \oplus A_{2, 3} = 1 \oplus 5 = 4.

Therefore, the maximum possible total fun of the ball is 6.


Sample Input 2

1
5

Sample Output 2

5

There will be just a pair of Person 1 and Person 2, where the total fun of the ball is 5.


Sample Input 3

5
900606388 317329110 665451442 1045743214 260775845 726039763 57365372 741277060 944347467
369646735 642395945 599952146 86221147 523579390 591944369 911198494 695097136
138172503 571268336 111747377 595746631 934427285 840101927 757856472
655483844 580613112 445614713 607825444 252585196 725229185
827291247 105489451 58628521 1032791417 152042357
919691140 703307785 100772330 370415195
666350287 691977663 987658020
1039679956 218233643
70938785

Sample Output 3

1073289207
E - Average and Median

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 500

問題文

N 枚のカードがあり、i \, (1 \leq i \leq N) 番目のカードには整数 A_i が書かれています。

高橋君は、これらのカードから好きな枚数選びます。ただし、各 i \, (1 \leq i \leq N - 1) について、i 番目のカードと i + 1 番目のカードの少なくとも一方を選ぶ必要があります。

以下の値を求めてください。

  • 選んだカードに書かれた整数の平均値としてあり得る最大値
  • 選んだカードに書かれた整数の中央値としてあり得る最大値

ただし、n 個の整数の中央値は、それらのうち小さい方から数えて \lceil \frac{n}{2} \rceil 番目であるものとします。ここで、\lceil x \rceilx 以上の最小の整数を表します。

制約

  • 2 \leq N \leq 10^5
  • 1 \leq A_i \leq 10^{9}
  • 入力は全て整数である。

入力

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

N
A_1 \ldots A_N

出力

2 行出力せよ。1 行目には選んだカードに書かれた整数の平均値としてあり得る最大値を、2 行目には選んだカードに書かれた整数の中央値としてあり得る最大値を出力せよ。 平均値の出力については、正しい値との相対誤差または絶対誤差が 10^{-3} 以下であれば正答とみなされる。


入力例 1

6
2 1 2 1 1 10

出力例 1

4
2

2 番目、4 番目、6 番目のカードを選ぶと、書かれた整数の平均は \frac{12}{3} = 4 となり、これが最大です。

1 番目、3 番目、5 番目、6 番目のカードを選ぶと、書かれた整数の中央値は 2 となり、これが最大です。


入力例 2

7
3 1 4 1 5 9 2

出力例 2

5.250000000
4

平均値の出力については誤差が認められるので、例えば 5.2491 と出力しても正答とみなされます。ただし、中央値は正確な値を出力しなければなりません。

Score : 500 points

Problem Statement

We have N cards. The i-th card (1 \leq i \leq N) has an integer A_i written on it.

Takahashi will choose any number of cards from these. However, for each i (1 \leq i \leq N - 1), at least one of the i-th and (i+1)-th cards must be chosen.

Find the following values.

  • The maximum possible average of the integers written on the chosen cards
  • The maximum possible median of the integers written on the chosen cards

Here, the median of the n integers is defined to be the \lceil \frac{n}{2} \rceil-th smallest of them, where \lceil x \rceil is the smallest integer not less than x.

Constraints

  • 2 \leq N \leq 10^5
  • 1 \leq A_i \leq 10^{9}
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 \ldots A_N

Output

Print two lines. The first and second lines should contain the maximum possible average and maximum possible median of the integers written on the chosen cards, respectively. For the average, your output will be considered correct when its relative or absolute error from the exact answer is at most 10^{-3}.


Sample Input 1

6
2 1 2 1 1 10

Sample Output 1

4
2

Choosing the 2-nd, 4-th, and 6-th cards makes the average of the written integers \frac{12}{3} = 4, which is the maximum possible.

Choosing the 1-st, 3-rd, 5-th, and 6-th cards makes the median of the written integers 2, which is the maximum possible.


Sample Input 2

7
3 1 4 1 5 9 2

Sample Output 2

5.250000000
4

For the average, your output may contain some degree of error: for example, the output 5.2491 is still considered correct. For the median, however, the exact value must be printed.

F - Spices

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 500

問題文

スパイス屋には、スパイス 1 、スパイス 2\ldots 、スパイス 2^N-12^N-1 種類のスパイスがそれぞれ 1 個ずつ売られています。 i = 1, 2, \ldots, 2^N-1 について、スパイス i の値段は c_i 円です。 高橋君はそれらを好きなだけ買うことができます。

高橋君は帰宅後、買ったスパイスのうち 1 つ以上を選び、それらを組み合わせてカレーを作る予定です。
高橋君がスパイス A_1 、スパイス A_2\ldots、スパイス A_kk 個のスパイスを組み合わせると、完成するカレーの辛さは A_1 \oplus A_2 \oplus \cdots \oplus A_k になります。 ここで、\oplus はビットごとの排他的論理和を表します。

高橋君は、作るカレーの辛さを帰宅後の気分で決めたいので、とりあえず 1 以上 2^N-1 以下の任意の整数の辛さのカレーを作れるように、購入するスパイスの組み合わせを決定します。高橋君が支払う金額としてあり得る最小値を出力してください。

制約

  • 2 \leq N \leq 16
  • 1 \leq c_i \leq 10^9
  • 入力はすべて整数

入力

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

N
c_1 c_2 \ldots c_{2^N-1}

出力

高橋君が支払う金額としてあり得る最小値を出力せよ。


入力例 1

2
4 5 3

出力例 1

7

高橋君がスパイス 1 とスパイス 3 を買うと、下記の通り、1 以上 3 以下の任意の整数の辛さのカレーを作ることができます。

  • 辛さ 1 のカレーを作るには、スパイス 1 のみを使い、
  • 辛さ 2 のカレーを作るには、スパイス 1 とスパイス 3 を組み合わせ、
  • 辛さ 3 のカレーを作るには、スパイス 3 のみを使えば良いです。

このとき高橋君が支払う金額は c_1 + c_3 = 4 + 3 = 7 円であり、これが高橋君が支払う金額としてあり得る最小値です。


入力例 2

4
9 7 9 7 10 4 3 9 4 8 10 5 6 3 8

出力例 2

15

Score : 500 points

Problem Statement

The shop supaisu-ya sells 2^N-1 kinds of spices: Spice 1, Spice 2, \ldots, Spice 2^N-1. One pack of each spice is in stock. For each i = 1, 2, \ldots, 2^N-1, Spice i costs c_i yen. Takahashi can buy any of these spices.

He plans to make curry after getting home by choosing one or more of the bought spices and mixing them.
If k spices, Spice A_1, Spice A_2, \ldots, Spice A_k, are mixed, the hotness of the resulting curry is A_1 \oplus A_2 \oplus \cdots \oplus A_k, where \oplus denotes the bitwise XOR.

Takahashi wants to decide the hotness of the curry based on his feeling after getting home. For now, he will buy a set of spices that allows him to make curry of any hotness from 1 through 2^N-1. Print the minimum possible amount of money Takahashi pays.

Constraints

  • 2 \leq N \leq 16
  • 1 \leq c_i \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
c_1 c_2 \ldots c_{2^N-1}

Output

Print the minimum possible amount of money Takahashi pays.


Sample Input 1

2
4 5 3

Sample Output 1

7

If Takahashi buys Spice 1 and 3, he can make curry of any hotness from 1 through 3, as follows.

  • To make curry of hotness 1, use just Spice 1.
  • To make curry of hotness 2, mix Spice 1 and Spice 3.
  • To make curry of hotness 3, use just Spice 3.

Here, Takahashi pays c_1 + c_3 = 4 + 3 = 7 yen, which is the minimum possible amount he pays.


Sample Input 2

4
9 7 9 7 10 4 3 9 4 8 10 5 6 3 8

Sample Output 2

15
G - Good Vertices

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 600

問題文

N 頂点の有向グラフがあります。N 個の頂点はそれぞれ頂点 1 、頂点 2\ldots、頂点 N と呼ばれます。 時刻 0 には、このグラフには辺がありません。

t = 1, 2, \ldots, T について、時刻 t に頂点 u_t から頂点 v_t への有向辺が追加されます。 (追加される辺が自己ループである場合、すなわち u_t = v_t の場合もあります。)

頂点 1 から始め「現在いる頂点からちょうど 1 本の有向辺をたどって到達できる頂点を 1 つ選び、選んだ頂点に移動する」ことをちょうど L 回繰り返して到達できる頂点を「良い頂点」と呼びます。

i = 1, 2, \ldots, N について、頂点 i が良い頂点となる最小の時刻を出力してください。ただし、頂点 i が良い頂点となる時刻が存在しない場合は、代わりに -1 を出力してください。

制約

  • 2 \leq N \leq 100
  • 1 \leq T \leq N^2
  • 1 \leq L \leq 10^9
  • 1 \leq u_t, v_t \leq N
  • i \neq j \Rightarrow (u_i, v_i) \neq (u_j, v_j)
  • 入力はすべて整数

入力

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

N T L
u_1 v_1
u_2 v_2
\vdots
u_T v_T

出力

下記の形式の通り、i = 1, 2, \ldots, N について、頂点 i が良い頂点となる最小の時刻 X_i を出力せよ。ただし、頂点 i が良い頂点となる時刻が存在しない場合は、X_i = -1 とせよ。

X_1 X_2 \ldots X_N

入力例 1

4 5 3
2 3
3 4
1 2
3 2
2 2

出力例 1

-1 4 5 3

時刻 0 ではグラフは辺を持ちません。その後、以下の通りに辺の追加が行われます。

  • 時刻 1 に、頂点 2 から頂点 3 への有向辺が追加されます。
  • 時刻 2 に、頂点 3 から頂点 4 への有向辺が追加されます。
  • 時刻 3 に、頂点 1 から頂点 2 への有向辺が追加されます。これによって、頂点 1 から頂点 41 \rightarrow 2 \rightarrow 3 \rightarrow 4 とちょうど 3 回の移動で到達できるようになり、頂点 4 は良い頂点に変わります。
  • 時刻 4 に、頂点 3 から頂点 2 への有向辺が追加されます。これによって、頂点 1 から頂点 21 \rightarrow 2 \rightarrow 3 \rightarrow 2 とちょうど 3 回の移動で到達できるようになり、頂点 2 は良い頂点に変わります。
  • 時刻 5 に、頂点 2 から頂点 2 への有向辺(自己ループ)が追加されます。これによって、頂点 1 から頂点 31 \rightarrow 2 \rightarrow 2 \rightarrow 3 とちょうど 3 回の移動で到達できるようになり、頂点 3 は良い頂点に変わります。

頂点 1 が良い頂点となることはありません。


入力例 2

2 1 1000000000
1 2

出力例 2

-1 -1

Score : 600 points

Problem Statement

We have a directed graph with N vertices. The N vertices are called Vertex 1, Vertex 2, \ldots, Vertex N. At time 0, the graph has no edge.

For each t = 1, 2, \ldots, T, at time t, a directed edge from Vertex u_t to Vertex v_t will be added. (The edge may be a self-loop, that is, u_t = v_t may hold.)

A vertex is called good when it can be reached by starting at Vertex 1 and traversing an edge exactly L times.

For each i = 1, 2, \ldots, N, print the earliest time when Vertex i is good. If there is no time when Vertex i is good, print -1 instead.

Constraints

  • 2 \leq N \leq 100
  • 1 \leq T \leq N^2
  • 1 \leq L \leq 10^9
  • 1 \leq u_t, v_t \leq N
  • i \neq j \Rightarrow (u_i, v_i) \neq (u_j, v_j)
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N T L
u_1 v_1
u_2 v_2
\vdots
u_T v_T

Output

In the following format, for each i = 1, 2, \ldots, N, print the earliest time X_i when Vertex i is good. If there is no time when Vertex i is good, X_i should be -1.

X_1 X_2 \ldots X_N

Sample Input 1

4 5 3
2 3
3 4
1 2
3 2
2 2

Sample Output 1

-1 4 5 3

At time 0, the graph has no edge. Afterward, edges are added as follows.

  • At time 1, a directed edge from Vertex 2 to Vertex 3 is added.
  • At time 2, a directed edge from Vertex 3 to Vertex 4 is added.
  • At time 3, a directed edge from Vertex 1 to Vertex 2 is added. Now, Vertex 4 can be reached from Vertex 1 in exactly three moves: 1 \rightarrow 2 \rightarrow 3 \rightarrow 4, making Vertex 4 good.
  • At time 4, a directed edge from Vertex 3 to Vertex 2 is added. Now, Vertex 2 can be reached from Vertex 1 in exactly three moves: 1 \rightarrow 2 \rightarrow 3 \rightarrow 2, making Vertex 2 good.
  • At time 5, a directed edge (self-loop) from Vertex 2 to Vertex 2 is added. Now, Vertex 3 can be reached from Vertex 1 in exactly three moves: 1 \rightarrow 2 \rightarrow 2 \rightarrow 3, making Vertex 3 good.

Vertex 1 will never be good.


Sample Input 2

2 1 1000000000
1 2

Sample Output 2

-1 -1
Ex - Distinct Multiples

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 600

問題文

正整数 N, M および正整数列 D = (D_1, \dots, D_N) が与えられます。

以下の条件を満たす正整数列 A = (A_1, \dots, A_N) の総数を 998244353 で割った余りを求めてください。

  • 1 \leq A_i \leq M \, (1 \leq i \leq N)
  • A_i \neq A_j \, (1 \leq i \lt j \leq N)
  • i \, (1 \leq i \leq N) について、A_iD_i の倍数

制約

  • 2 \leq N \leq 16
  • 1 \leq M \leq 10^{18}
  • 1 \leq D_i \leq M \, (1 \leq i \leq N)
  • 入力は全て整数である。

入力

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

N M
D_1 \ldots D_N

出力

答えを出力せよ。


入力例 1

3 7
2 3 4

出力例 1

3

条件を満たす A(2, 3, 4), (2, 6, 4), (6, 3, 4)3 通りです。


入力例 2

3 3
1 2 2

出力例 2

0

条件を満たす A は存在しません。


入力例 3

6 1000000000000000000
380214083 420492929 929717250 666796775 209977152 770361643

出力例 3

325683519

998244353 で割った余りを求めることに注意してください。

Score : 600 points

Problem Statement

Given are positive integers N, M, and a sequence of positive integers D = (D_1, \dots, D_N).

Find the number of sequences of positive integers A = (A_1, \dots, A_N) that satisfy the following conditions, modulo 998244353.

  • 1 \leq A_i \leq M \, (1 \leq i \leq N)
  • A_i \neq A_j \, (1 \leq i \lt j \leq N)
  • For each i \, (1 \leq i \leq N), A_i is a multiple of D_i.

Constraints

  • 2 \leq N \leq 16
  • 1 \leq M \leq 10^{18}
  • 1 \leq D_i \leq M \, (1 \leq i \leq N)
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
D_1 \ldots D_N

Output

Print the answer.


Sample Input 1

3 7
2 3 4

Sample Output 1

3

The three sequences A that satisfy the conditions are (2, 3, 4), (2, 6, 4), (6, 3, 4).


Sample Input 2

3 3
1 2 2

Sample Output 2

0

No sequence A satisfies the conditions.


Sample Input 3

6 1000000000000000000
380214083 420492929 929717250 666796775 209977152 770361643

Sample Output 3

325683519

Be sure to find the count modulo 998244353.