A - Octave

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

配点 : 100 点

問題文

音の高さが 1 オクターヴ上がるごとに、音の周波数は 2 倍になります。

周波数 X ヘルツの音の高さを Y オクターヴ上げると、その周波数は何ヘルツになりますか?

制約

  • 1 \leq X \leq 444
  • 1 \leq Y \leq 3
  • 入力される値はすべて整数

入力

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

X Y

出力

答えを整数として 1 行に出力せよ。単位 (ヘルツ) は省いて出力すること。


入力例 1

110 2

出力例 1

440

周波数 110 ヘルツの音の 2 オクターヴ上の音について、その周波数は 110 \times 2 \times 2 = 440 ヘルツです。


入力例 2

233 3

出力例 2

1864

周波数 233 ヘルツの音の 3 オクターヴ上の音について、その周波数は 233 \times 2 \times 2 \times 2 = 1864 ヘルツです。


入力例 3

432 1

出力例 3

864

周波数 432 ヘルツの音の 1 オクターヴ上の音について、その周波数は 432 \times 2 = 864 ヘルツです。

Score : 100 points

Problem Statement

The frequency of a sound doubles for every increase of 1 octave in pitch.

If the pitch of a sound with frequency X hertz is raised by Y octaves, what will its frequency be in hertz?

Constraints

  • 1 \leq X \leq 444
  • 1 \leq Y \leq 3
  • All input values are integers.

Input

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

X Y

Output

Output the answer as an integer in one line. Omit the unit (hertz).


Sample Input 1

110 2

Sample Output 1

440

For a sound 2 octaves above a sound with frequency 110 hertz, its frequency is 110 \times 2 \times 2 = 440 hertz.


Sample Input 2

233 3

Sample Output 2

1864

For a sound 3 octaves above a sound with frequency 233 hertz, its frequency is 233 \times 2 \times 2 \times 2 = 1864 hertz.


Sample Input 3

432 1

Sample Output 3

864

For a sound 1 octave above a sound with frequency 432 hertz, its frequency is 432 \times 2 = 864 hertz.

B - OS Versions

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

配点 : 100 点

問題文

ある OS のバージョンは古い順に "Ocelot", "Serval", "Lynx" です。
バージョン X がバージョン Y 以降のバージョンであるか判定してください。
なお、バージョン X 自身もバージョン X 以降のバージョンであるものとします。

制約

  • X,Y は "Ocelot", "Serval", "Lynx" のいずれか (引用符を含まない)

入力

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

X Y

出力

バージョン X がバージョン Y 以降のバージョンであれば Yes 、そうでなければ No と出力せよ。


入力例 1

Serval Ocelot

出力例 1

Yes

バージョン Serval はバージョン Ocelot 以降のバージョンです。そのため、 Yes と出力します。


入力例 2

Serval Lynx

出力例 2

No

バージョン Serval はバージョン Lynx 以降のバージョンではありません。そのため、 No と出力します。


入力例 3

Ocelot Ocelot

出力例 3

Yes

バージョン Ocelot 自身もバージョン Ocelot 以降のバージョンです。そのため、 Yes と出力します。

Score : 100 points

Problem Statement

The versions of a certain OS in chronological order are "Ocelot", "Serval", "Lynx".
Determine whether version X is the same as or newer than version Y.

Constraints

  • Each of X and Y is one of "Ocelot", "Serval", "Lynx" (without quotation marks).

Input

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

X Y

Output

If version X is the same as or newer than version Y, print Yes; otherwise, print No.


Sample Input 1

Serval Ocelot

Sample Output 1

Yes

Version Serval is the same as or newer than version Ocelot. Therefore, print Yes.


Sample Input 2

Serval Lynx

Sample Output 2

No

Version Serval is not the same as nor newer than version Lynx. Therefore, print No.


Sample Input 3

Ocelot Ocelot

Sample Output 3

Yes

Version Ocelot itself is the same as or newer than version Ocelot. Therefore, print Yes.

C - Taro

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

配点 : 200 点

問題文

AtCoder 王国では、長男に必ず「太郎」という名前を付けます。長男以外には「太郎」という名前は付けません。 長男とは、各家で生まれた男の子のうち最も早く生まれた者を指します。

AtCoder 王国には N 戸の家があり、M 人の赤子が生まれました。また、M 人の赤子が生まれる前には、N 戸のどの家も赤子が生まれたことはありませんでした。

赤子の情報が生まれの時系列順に与えられます。

i 番目に生まれた赤子は、A_i 番目の家で生まれ、B_i が M のとき男の子、F のとき女の子です。

M 人の赤子それぞれについて、付けられた名前が「太郎」か判定してください。

制約

  • 1\leq N,M\leq 100
  • 1\leq A_i\leq N
  • B_i は M または F
  • 入力される数値は全て整数

入力

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

N M
A_1 B_1
\vdots
A_M B_M

出力

M 行出力せよ。

i\ (1\leq i \leq M) 行目には、i 番目に生まれた赤子の名前が「太郎」ならば Yes を、そうでない場合 No を出力せよ。


入力例 1

2 4
1 M
1 M
2 F
2 M

出力例 1

Yes
No
No
Yes

1 番目に生まれた赤子は、家 1 で生まれた男の子のうち最も早く生まれた者なので「太郎」です。

一方、2 番目に生まれた赤子は、家 1 で生まれた男の子のうち最も早く生まれた者ではないので「太郎」ではありません。

3 番目に生まれた赤子は、女の子なので「太郎」ではありません。

4 番目に生まれた赤子は、家 2 で生まれた男の子のうち最も早く生まれた者なので「太郎」です。3 番目に生まれた赤子も家 2 で生まれていますが、男の子のうち最も早く生まれた者を「太郎」と名付けることに注意してください。


入力例 2

4 7
2 M
3 M
1 F
4 F
4 F
1 F
2 M

出力例 2

Yes
Yes
No
No
No
No
No

Score : 200 points

Problem Statement

In the Kingdom of AtCoder, the eldest son is always given the name Taro. No one else is given the name Taro. The eldest son is the earliest born male child in each family.

There are N families in the Kingdom, and M babies were born. Before the M babies were born, none of the N families had had any babies.

Information about the babies is given in chronological order of their birth.

The i-th baby born was born in family A_i, and the baby is male if B_i is M, and female if it is F.

Determine for each of the M babies whether the name given is Taro.

Constraints

  • 1\leq N,M\leq 100
  • 1\leq A_i\leq N
  • B_i is M or F.
  • All numbers in the input are integers.

Input

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

N M
A_1 B_1
\vdots
A_M B_M

Output

Print M lines.

The i-th line (1\leq i \leq M) should contain Yes if the name given to the i-th baby is Taro, and No otherwise.


Sample Input 1

2 4
1 M
1 M
2 F
2 M

Sample Output 1

Yes
No
No
Yes

The first baby is the earliest born boy in family 1, so he is named Taro.

The second baby is not the earliest born boy in family 1, so he is not named Taro.

The third baby is a girl, so she is not named Taro.

The fourth baby is the earliest born boy in family 2, so he is named Taro. Note that the third baby is also born in family 2, but it is the earliest born boy who is named Taro.


Sample Input 2

4 7
2 M
3 M
1 F
4 F
4 F
1 F
2 M

Sample Output 2

Yes
Yes
No
No
No
No
No
D - Unauthorized

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

配点 : 200 点

問題文

ある日、高橋くんはあるウェブサイトに対して N 回の操作を行いました。

i 回目 (1\leq i\leq N) の操作は文字列 S _ i で表され、次の 4 つのうちいずれかです。

  • S _ i= login である。高橋くんはログイン操作を行い、高橋くんがウェブサイトにログインした状態になる。
  • S _ i= logout である。高橋くんはログアウト操作を行い、高橋くんがウェブサイトにログインしていない状態になる。
  • S _ i= public である。高橋くんはウェブサイトの公開ページにアクセスする。
  • S _ i= private である。高橋くんはウェブサイトの非公開ページにアクセスする。

高橋くんがログインしていない状態で非公開ページにアクセスした時、またその時に限り、ウェブサイトは認証エラーを返します。

ログインした状態でさらにログイン操作をしたり、ログインしていない状態でさらにログアウト操作をしてもエラーにはなりません。 また、認証エラーが返されたあとも、高橋くんは操作を続けることができます。

はじめ、高橋くんはログインしていない状態です。

N 回の操作のうち、高橋くんが認証エラーを受け取った回数を出力してください。

制約

  • 1\leq N\leq100
  • N は整数
  • S _ i は login, logout, public, private のいずれか (1\leq i\leq N)

入力

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

N
S _ 1
S _ 2
\vdots
S _ N

出力

高橋くんが認証エラーを受け取った回数を出力せよ。


入力例 1

6
login
private
public
logout
private
public

出力例 1

1

高橋くんが行うそれぞれの操作の結果は以下のようになります。

  • 高橋くんがウェブサイトにログインした状態になる。
  • 高橋くんは非公開ページにアクセスする。高橋くんは現在ログインしているので、エラーは返されない。
  • 高橋くんは公開ページにアクセスする。
  • 高橋くんがウェブサイトにログインしていない状態になる。
  • 高橋くんは非公開ページにアクセスする。高橋くんは現在ログインしていないので、認証エラーが返される。
  • 高橋くんは公開ページにアクセスする。

高橋くんが認証エラーを受け取るのは 5 回目の操作のみなので、1 を出力してください。


入力例 2

4
private
private
private
logout

出力例 2

3

連続で非公開ページにアクセスしようとした場合、操作のたびに認証エラーを受け取ります。

ログインしていない状態からさらにログアウト操作をした場合には認証エラーは返されないことに注意してください。


入力例 3

20
private
login
private
logout
public
logout
logout
logout
logout
private
login
login
private
login
private
login
public
private
logout
private

出力例 3

3

Score : 200 points

Problem Statement

One day, Takahashi performed N operations on a certain web site.

The i‑th operation (1 \le i \le N) is represented by a string S_i, which is one of the following:

  • S _ i= login: He performs a login operation and becomes logged in to the site.
  • S _ i= logout: He performs a logout operation and becomes not logged in to the site.
  • S _ i= public: He accesses a public page of the site.
  • S _ i= private: He accesses a private page of the site.

The site returns an authentication error if and only if he accesses a private page while he is not logged in.

Logging in again while already logged in, or logging out again while already logged out, does not cause an error. Even after an authentication error is returned, he continues performing the remaining operations.

Initially, he is not logged in.

Print the number of operations among the N operations at which he receives an authentication error.

Constraints

  • 1 \le N \le 100
  • N is an integer.
  • Each S_i is one of login, logout, public, private. (1 \le i \le N)

Input

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

N
S_1
S_2
\vdots
S_N

Output

Print the number of times Takahashi receives an authentication error.


Sample Input 1

6
login
private
public
logout
private
public

Sample Output 1

1

The result of each operation is as follows:

  • Takahashi becomes logged in.
  • He accesses a private page. He is logged in, so no error is returned.
  • He accesses a public page.
  • He becomes logged out.
  • He accesses a private page. He is not logged in, so an authentication error is returned.
  • He accesses a public page.

An authentication error occurs only at the 5th operation, so print 1.


Sample Input 2

4
private
private
private
logout

Sample Output 2

3

If he tries to access private pages consecutively while not logged in, he receives an authentication error for each such operation.

Note that logging out again while already logged out does not cause an authentication error.


Sample Input 3

20
private
login
private
logout
public
logout
logout
logout
logout
private
login
login
private
login
private
login
public
private
logout
private

Sample Output 3

3
E - Operate 1

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

配点 : 350 点

問題文

この問題は F 問題 (Operate K) の部分問題であり、 K=1 です。
F 問題に正解するコードをこの問題に提出することで、この問題に正解できます。

文字列 S に対して以下の操作を 0 回以上 K 回以下行って、文字列 T と一致させられるか判定してください。

  • 次の 3 種類の操作のうちひとつを選択し、実行する。
    • S 中の (先頭や末尾を含む) 任意の位置に、任意の文字を 1 つ挿入する。
    • S 中の文字を 1 つ選び、削除する。
    • S 中の文字を 1 つ選び、別の 1 つの文字に変更する。

制約

  • S,T は英小文字からなる長さ 1 以上 500000 以下の文字列
  • \color{red}{K=1}

入力

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

K
S
T

出力

K 回以下の操作で S を T に一致させられる時 Yes 、そうでない時 No と出力せよ。


入力例 1

1
abc
agc

出力例 1

Yes

abc の 2 文字目の b を g に置き換えることで、 abc を 1 回の操作で agc に変換できます。


入力例 2

1
abc
awtf

出力例 2

No

1 回の操作では abc を awtf に変換できません。


入力例 3

1
abc
ac

出力例 3

Yes

abc の 2 文字目の b を削除することで、 abc を 1 回の操作で ac に変換できます。


入力例 4

1
back
black

出力例 4

Yes

back の 1 文字目と 2 文字目の間に l を挿入することで、 back を 1 回の操作で black に変換できます。


入力例 5

1
same
same

出力例 5

Yes

初めから S=T である場合もあります。


入力例 6

1
leap
read

出力例 6

No

Score : 350 points

Problem Statement

This problem is a sub-problem of Problem F (Operate K), with K=1.
You can solve this problem by submitting a correct solution for Problem F to this problem.

Determine whether it is possible to perform the following operation on string S between 0 and K times, inclusive, to make it identical to string T.

  • Choose one of the following three operations and execute it.
    • Insert any one character at any position in S (possibly the beginning or end).
    • Delete one character from S.
    • Choose one character in S and replace it with another character.

Constraints

  • Each of S and T is a string of length between 1 and 500000, inclusive, consisting of lowercase English letters.
  • \color{red}{K=1}

Input

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

K
S
T

Output

If S can be made identical to T with at most K operations, print Yes; otherwise, print No.


Sample Input 1

1
abc
agc

Sample Output 1

Yes

Replacing the second character b of abc with g converts abc to agc in one operation.


Sample Input 2

1
abc
awtf

Sample Output 2

No

abc cannot be converted to awtf in one operation.


Sample Input 3

1
abc
ac

Sample Output 3

Yes

Deleting the second character b of abc converts abc to ac in one operation.


Sample Input 4

1
back
black

Sample Output 4

Yes

Inserting l between the first and second characters of back converts back to black in one operation.


Sample Input 5

1
same
same

Sample Output 5

Yes

It is also possible that S = T from the beginning.


Sample Input 6

1
leap
read

Sample Output 6

No
F - Sum of Product

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

配点 : 300 点

問題文

長さ N の整数列 A=(A_1,A_2,\dots,A_N) が与えられます。

\displaystyle \sum_{1\leq i< j\leq N} A_iA_j の値を求めてください。

制約

  • 2\leq N \leq 3\times 10^5
  • 1\leq A_i \leq 10^4
  • 入力は全て整数

入力

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

N
A_1 A_2 \dots A_N

出力

答えを出力せよ。


入力例 1

3
4 2 3

出力例 1

26

\displaystyle \sum_{1\leq i< j\leq N} A_iA_j=A_1A_2+A_1A_3+A_2A_3=4\cdot 2+4\cdot 3+2\cdot 3=26 です。


入力例 2

2
9 45

出力例 2

405

入力例 3

10
7781 8803 8630 9065 8831 9182 8593 7660 7548 8617

出力例 3

3227530139

Score : 300 points

Problem Statement

You are given a length-N integer sequence A = (A_1, A_2, \dots, A_N).

Compute the value of \displaystyle \sum_{1\leq i< j\leq N} A_iA_j.

Constraints

  • 2 \le N \le 3 \times 10^5
  • 1 \le A_i \le 10^4
  • All input values are integers.

Input

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

N
A_1 A_2 \dots A_N

Output

Output the answer.


Sample Input 1

3
4 2 3

Sample Output 1

26

We have \displaystyle \sum_{1\leq i< j\leq N} A_iA_j=A_1A_2+A_1A_3+A_2A_3=4\cdot 2+4\cdot 3+2\cdot 3=26.


Sample Input 2

2
9 45

Sample Output 2

405

Sample Input 3

10
7781 8803 8630 9065 8831 9182 8593 7660 7548 8617

Sample Output 3

3227530139
G - Neighbor Distance

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

配点 : 400 点

問題文

数直線があり、最初は座標 0 に人 0 がひとりで立っています。

これから、人 1,2,\dots,N がこの順に到着し、数直線上に立ちます。
人 i は座標 X_i に立ちます。なお、 X_i \ge 1 であり、全ての人について X_i は相異なります。

人が到着するたびに、以下の問いに答えてください。

  • 現在数直線に人 0,1,\dots,r の r+1 人が立っているとする。
  • このとき、 d_i を「人 i に最も近い別の人までの距離」と定義する。
    • より厳密には、 \displaystyle d_i = \min_{0 \le j \le r, j \neq i} \vert X_i - X_j \vert とする。
  • この d の総和、すなわち \displaystyle \sum_{i=0}^r d_i を求めよ。

制約

  • 入力は全て整数
  • 1 \le N \le 5 \times 10^5
  • 1 \le X_i \le 10^9
  • i \neq j ならば X_i \neq X_j

入力

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

N
X_1 X_2 \dots X_N

出力

N 行に出力せよ。
そのうち i ( 1 \le i \le N ) 行目には、人 i が到着した時点での問いの答えを出力せよ。


入力例 1

10
5 2 7 4 108728325 390529120 597713292 322456626 845148281 812604915

出力例 1

10
7
8
8
108728326
390529121
523096670
452057486
699492475
517144218

この入力では、人が 10 人到着します。
このうち最初の 4 人について説明します。

  • 人 1 が到着した時点で、座標 0,5 に人がいます。
    • 求める値は 5+5=10 です。
  • 人 2 が到着した時点で、座標 0,2,5 に人がいます。
    • 求める値は 2+2+3=7 です。
  • 人 3 が到着した時点で、座標 0,2,5,7 に人がいます。
    • 求める値は 2+2+2+2=8 です。
  • 人 4 が到着した時点で、座標 0,2,4,5,7 に人がいます。
    • 求める値は 2+2+1+1+2=8 です。

Score : 400 points

Problem Statement

There is a number line, and initially person 0 is standing alone at coordinate 0.

From now on, persons 1,2,\dots,N will arrive in this order and stand on the number line.
Person i stands at coordinate X_i. Here, X_i \ge 1, and X_i is distinct for all persons.

Each time a person arrives, answer the following question.

  • Suppose that currently r+1 persons 0,1,\dots,r are standing on the number line.
  • Here, define d_i as the distance to the nearest other person from person i.
    • More formally, \displaystyle d_i = \min_{0 \le j \le r, j \neq i} \vert X_i - X_j \vert.
  • Find the sum of this d, that is, \displaystyle \sum_{i=0}^r d_i.

Constraints

  • All input values are integers.
  • 1 \le N \le 5 \times 10^5
  • 1 \le X_i \le 10^9
  • X_i \neq X_j if i \neq j.

Input

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

N
X_1 X_2 \dots X_N

Output

Print N lines.
The i-th line ( 1 \le i \le N ) should contain the answer to the question when person i arrives.


Sample Input 1

10
5 2 7 4 108728325 390529120 597713292 322456626 845148281 812604915

Sample Output 1

10
7
8
8
108728326
390529121
523096670
452057486
699492475
517144218

In this input, 10 persons arrive.
The first four persons are explained below.

  • When person 1 arrives, there are persons at coordinates 0,5.
    • The required value is 5+5=10.
  • When person 2 arrives, there are persons at coordinates 0,2,5.
    • The required value is 2+2+3=7.
  • When person 3 arrives, there are persons at coordinates 0,2,5,7.
    • The required value is 2+2+2+2=8.
  • When person 4 arrives, there are persons at coordinates 0,2,4,5,7.
    • The required value is 2+2+1+1+2=8.
H - Putting Candies

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

配点 : 500 点

問題文

長さ N の数列 A=(A_0,A_1,\ldots,A_{N-1}) が与えられます。
最初の時点では空の皿があり、高橋君は次の操作を K 回繰り返します。

  • 皿の中のアメの個数を X とする。皿に A_{(X\bmod N)} 個のアメを追加する。 ただし、X\bmod N で X を N で割った余りを表す。

K 回の操作の後で、皿の中には何個のアメがあるか求めてください。

制約

  • 2 \leq N \leq 2\times 10^5
  • 1 \leq K \leq 10^{12}
  • 1 \leq A_i\leq 10^6
  • 入力はすべて整数である。

入力

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

N K
A_0 A_1 \ldots A_{N-1}

出力

答えを出力せよ。


入力例 1

5 3
2 1 6 3 1

出力例 1

11

皿の中のアメの個数は次のように変化します。

  • 1 回目の操作において、X=0 であるので、アメは A_{(0\mod 5)}=A_0=2 個追加されます。
  • 2 回目の操作において、X=2 であるので、アメは A_{(2\mod 5)}=A_2=6 個追加されます。
  • 3 回目の操作において、X=8 であるので、アメは A_{(8\mod 5)}=A_3=3 個追加されます。

よって、3 回の操作の後で、皿には 11 個のアメがあります。出力する値は N で割った余りではない事に注意してください。


入力例 2

10 1000000000000
260522 914575 436426 979445 648772 690081 933447 190629 703497 47202

出力例 2

826617499998784056

答えは 32 bit 整数型に収まらない場合があります。

Score : 500 points

Problem Statement

You are given a sequence A=(A_0,A_1,\ldots,A_{N-1}) of length N.
There is an initially empty dish. Takahashi is going to repeat the following operation K times.

  • Let X be the number of candies on the dish. He puts A_{(X\bmod N)} more candies on the dish. Here, X\bmod N denotes the remainder when X is divided by N.

Find how many candies are on the dish after the K operations.

Constraints

  • 2 \leq N \leq 2\times 10^5
  • 1 \leq K \leq 10^{12}
  • 1 \leq A_i\leq 10^6
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
A_0 A_1 \ldots A_{N-1}

Output

Print the answer.


Sample Input 1

5 3
2 1 6 3 1

Sample Output 1

11

The number of candies on the dish transitions as follows.

  • In the 1-st operation, we have X=0, so A_{(0\mod 5)}=A_0=2 more candies will be put on the dish.
  • In the 2-nd operation, we have X=2, so A_{(2\mod 5)}=A_2=6 more candies will be put on the dish.
  • In the 3-rd operation, we have X=8, so A_{(8\mod 5)}=A_3=3 more candies will be put on the dish.

Thus, after the 3 operations, there will be 11 candies on the dish. Note that you must not print the remainder divided by N.


Sample Input 2

10 1000000000000
260522 914575 436426 979445 648772 690081 933447 190629 703497 47202

Sample Output 2

826617499998784056

The answer may not fit into a 32-bit integer type.

I - typewriter

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

配点 : 500 点

問題文

N 段からなるタイプライターがあります。このうち、上から i 段目のキーでは文字列 S_i に含まれる文字が打てます。

このキーボードを使って、以下のルールで文字列をひとつ入力することを考えます。

  • まず、整数 1 \le k \le N を選択する。
  • その後、空文字列から始めて、上から k 段目にあるキーだけを使ってちょうど L 文字の文字列を入力する。

このルールに従って入力可能な L 文字の文字列は何通りありますか? 答えは非常に大きくなる場合があるので 998244353 で割った余りを出力してください。

制約

  • N,L は整数
  • 1 \le N \le 18
  • 1 \le L \le 10^9
  • S_i は abcdefghijklmnopqrstuvwxyz の(連続とは限らない)空でない部分列

入力

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

N L
S_1
S_2
\dots
S_N

出力

答えを出力せよ。


入力例 1

2 2
ab
ac

出力例 1

7

入力可能な文字列は aa, ab, ac, ba, bb, ca, cc の 7 つです。


入力例 2

4 3
abcdefg
hijklmnop
qrstuv
wxyz

出力例 2

1352

入力例 3

5 1000000000
abc
acde
cefg
abcfh
dghi

出力例 3

346462871

答えを 998244353 で割った余りを出力してください。

Score : 500 points

Problem Statement

We have a typewriter with N rows. The keys in the i-th row from the top can type the characters in a string S_i.

Let us use this keyboard to enter a string, as follows.

  • First, choose an integer 1 \le k \le N.
  • Then, start with an empty string and only use the keys in the k-th row from the top to enter a string of length exactly L.

How many strings of length L can be entered in this way? Since the answer can be enormous, print it modulo 998244353.

Constraints

  • N and L are integers.
  • 1 \le N \le 18
  • 1 \le L \le 10^9
  • S_i is a (not necessarily contiguous) non-empty subsequence of abcdefghijklmnopqrstuvwxyz.

Input

Input is given from Standard Input in the following format:

N L
S_1
S_2
\dots
S_N

Output

Print the answer.


Sample Input 1

2 2
ab
ac

Sample Output 1

7

We can enter seven strings: aa, ab, ac, ba, bb, ca, cc.


Sample Input 2

4 3
abcdefg
hijklmnop
qrstuv
wxyz

Sample Output 2

1352

Sample Input 3

5 1000000000
abc
acde
cefg
abcfh
dghi

Sample Output 3

346462871

Be sure to print the answer modulo 998244353.