A - Subsegment Reverse

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100

問題文

正整数 N,L,R が与えられます。
長さ N の数列 A=(1,2,\dots,N) に対し、 L 項目から R 項目までを逆順に並べ替えるという操作を一度行いました。
操作後の数列を出力してください。

制約

  • 入力は全て整数
  • 1 \le L \le R \le N \le 100

入力

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

N L R

出力

操作後の数列を A'=(A'_1,A'_2,\dots,A'_N) として、以下の形式で出力せよ。

A'_1 A'_2 \dots A'_N

入力例 1

5 2 3

出力例 1

1 3 2 4 5

最初、 A=(1,2,3,4,5) です。
2 項目から 3 項目までを逆順に並べ替えた後の数列は (1,3,2,4,5) なので、これを出力してください。


入力例 2

7 1 1

出力例 2

1 2 3 4 5 6 7

L=R である場合もあります。


入力例 3

10 1 10

出力例 3

10 9 8 7 6 5 4 3 2 1

L=1R=N である場合もあります。

Score : 100 points

Problem Statement

You are given positive integers N, L, and R.
For a sequence A = (1, 2, \dots, N) of length N, an operation of reversing the L-th through R-th elements was performed once.
Print the sequence after this operation.

Constraints

  • All input values are integers.
  • 1 \leq L \leq R \leq N \leq 100

Input

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

N L R

Output

Let A' = (A'_1, A'_2, \dots, A'_N) be the sequence after the operation. Print it in the following format:

A'_1 A'_2 \dots A'_N

Sample Input 1

5 2 3

Sample Output 1

1 3 2 4 5

Initially, A = (1, 2, 3, 4, 5).
After reversing the second through third elements, the sequence becomes (1, 3, 2, 4, 5), which should be printed.


Sample Input 2

7 1 1

Sample Output 2

1 2 3 4 5 6 7

It is possible that L = R.


Sample Input 3

10 1 10

Sample Output 3

10 9 8 7 6 5 4 3 2 1

It is possible that L = 1 or R = N.

B - Overall Winner

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100

問題文

高橋くんと青木くんが N 回の試合を行いました。 これらの試合の結果を表す長さ N の文字列 S が与えられます。 i 回目の試合の勝者は、Si 文字目が T ならば高橋くん、A ならば青木くんです。

高橋くんと青木くんのうち、勝った試合の数が多い方を総合勝者とします。 ただし、勝った試合の数が同じである場合は、先にその勝ち数に達した者を総合勝者とします。 高橋くんと青木くんのどちらが総合勝者であるか求めてください。

制約

  • 1\leq N \leq 100
  • N は整数
  • ST および A からなる長さ N の文字列

入力

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

N
S

出力

総合勝者が高橋くんならば T を、青木くんならば A を出力せよ。


入力例 1

5
TTAAT

出力例 1

T

高橋くんは 3 回の試合に勝ち、青木くんは 2 回の試合に勝ちました。 よって、勝った試合の数が多い高橋くんが総合勝者です。


入力例 2

6
ATTATA

出力例 2

T

高橋くんと青木くんのどちらも 3 回の試合に勝ちました。 また、高橋くんは 5 回目の試合で 3 勝目に達し、青木くんは 6 回目の試合で 3 勝目に達しました。 よって、先に 3 勝目に達した高橋くんが総合勝者です。


入力例 3

1
A

出力例 3

A

Score : 100 points

Problem Statement

Takahashi and Aoki played N games. You are given a string S of length N, representing the results of these games. Takahashi won the i-th game if the i-th character of S is T, and Aoki won that game if it is A.

The overall winner between Takahashi and Aoki is the one who won more games than the other. If they had the same number of wins, the overall winner is the one who reached that number of wins first. Find the overall winner: Takahashi or Aoki.

Constraints

  • 1\leq N \leq 100
  • N is an integer.
  • S is a string of length N consisting of T and A.

Input

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

N
S

Output

If the overall winner is Takahashi, print T; if it is Aoki, print A.


Sample Input 1

5
TTAAT

Sample Output 1

T

Takahashi won three games, and Aoki won two. Thus, the overall winner is Takahashi, who won more games.


Sample Input 2

6
ATTATA

Sample Output 2

T

Both Takahashi and Aoki won three games. Takahashi reached three wins in the fifth game, and Aoki in the sixth game. Thus, the overall winner is Takahashi, who reached three wins first.


Sample Input 3

1
A

Sample Output 3

A
C - chess960

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

高橋君は chess960 と呼ばれるゲームで遊んでいます。 高橋君はランダムに決めた初期配置が chess960 の条件を満たすか確認するプログラムを書くことにしました。

長さ 8 の文字列 S が与えられます。S には K, Q がちょうど 1 文字ずつ、R, B, N がちょうど 2 文字ずつ含まれます。 S が以下の条件を全て満たしているか判定してください。

  • S において左から x,y\ (x < y) 文字目が B であるとする。このとき xy の偶奇が異なる。

  • K2 つの R の間にある。より形式的には、S において左から x,y\ (x < y) 文字目が R であり、 z 文字目が K であるとする。このとき、 x< z < y が成り立つ。

制約

  • S は 長さ 8 の文字列であり、K, Q がちょうど 1 文字ずつ、R, B, N がちょうど 2 文字ずつ含まれる。

入力

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

S

出力

S が条件を満たす場合 Yes を、そうでない場合 No を出力せよ。


入力例 1

RNBQKBNR

出力例 1

Yes

B は左から 3 番目、6 番目にあり、36 は偶奇が異なります。 また、K2 つの R の間にあります。よって条件を満たします。


入力例 2

KRRBBNNQ

出力例 2

No

K2 つの R の間にありません。


入力例 3

BRKRBQNN

出力例 3

No

Score : 200 points

Problem Statement

Takahashi is playing a game called Chess960. He has decided to write a code that determines if a random initial state satisfies the conditions of Chess960.

You are given a string S of length eight. S has exactly one K and Q, and exactly two R's, B's , and N's. Determine if S satisfies all of the following conditions.

  • Suppose that the x-th and y-th (x < y) characters from the left of S are B; then, x and y have different parities.

  • K is between two R's. More formally, suppose that the x-th and y-th (x < y) characters from the left of S are R and the z-th is K; then x< z < y.

Constraints

  • S is a string of length 8 that contains exactly one K and Q, and exactly two R's, B's , and N's.

Input

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

S

Output

Print Yes if S satisfies the conditions; print No otherwise.


Sample Input 1

RNBQKBNR

Sample Output 1

Yes

The 3-rd and 6-th characters are B, and 3 and 6 have different parities. Also, K is between the two R's. Thus, the conditions are fulfilled.


Sample Input 2

KRRBBNNQ

Sample Output 2

No

K is not between the two R's.


Sample Input 3

BRKRBQNN

Sample Output 3

No
D - Number Box

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

正整数 N が与えられます。

NN 列のマス目があり、上から i 行目、左から j 列目のマスには数字 A_{i,j} が書かれています。

このマス目は上下および左右がつながっているものとします。つまり以下が全て成り立ちます。

  • (1,i) の上のマスは (N,i) であり、(N,i) の下のマスは (1,i) である。(1\le i\le N)
  • (i,1) の左のマスは (i,N) であり、(i,N) の右のマスは (i,1) である。(1\le i\le N)

高橋君は、上下左右および斜めの 8 方向のうちいずれかを初めに選びます。そして、好きなマスから決めた方向に 1 マス移動することを N-1 回繰り返します。

高橋君は N 個のマス上を移動することになりますが、高橋君が通ったマスに書かれている数字を左から通った順番に並べた整数としてあり得る最大のものを求めてください。

制約

  • 1 \le N \le 10
  • 1 \le A_{i,j} \le 9
  • 入力はすべて整数。

入力

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

N
A_{1,1}A_{1,2}\dots A_{1,N}
A_{2,1}A_{2,2}\dots A_{2,N}
\vdots
A_{N,1}A_{N,2}\dots A_{N,N}

出力

答えを出力せよ。


入力例 1

4
1161
1119
7111
1811

出力例 1

9786

高橋君が上から 2 行目、左から 4 列目のマスから出発し、右下に進むことで、通ったマスに書かれた数字を並べ 9786 を作ることができます。 9786 より大きい値を作ることはできないため、9786 が解です。


入力例 2

10
1111111111
1111111111
1111111111
1111111111
1111111111
1111111111
1111111111
1111111111
1111111111
1111111111

出力例 2

1111111111

32bit整数型に答えが収まるとは限らないことに注意してください。

Score : 200 points

Problem Statement

You are given a positive integer N.

We have a grid with N rows and N columns, where the square at the i-th row from the top and j-th column from the left has a digit A_{i,j} written on it.

Assume that the upper and lower edges of this grid are connected, as well as the left and right edges. In other words, all of the following holds.

  • (N,i) is just above (1,i), and (1,i) is just below (N,i). (1\le i\le N).
  • (i,N) is just to the left of (i,1), and (i,1) is just to the right of (i,N). (1\le i\le N).

Takahashi will first choose one of the following eight directions: up, down, left, right, and the four diagonal directions. Then, he will start on a square of his choice and repeat moving one square in the chosen direction N-1 times.

In this process, Takahashi visits N squares. Find the greatest possible value of the integer that is obtained by arranging the digits written on the squares visited by Takahashi from left to right in the order visited by him.

Constraints

  • 1 \le N \le 10
  • 1 \le A_{i,j} \le 9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_{1,1}A_{1,2}\dots A_{1,N}
A_{2,1}A_{2,2}\dots A_{2,N}
\vdots
A_{N,1}A_{N,2}\dots A_{N,N}

Output

Print the answer.


Sample Input 1

4
1161
1119
7111
1811

Sample Output 1

9786

If Takahashi starts on the square at the 2-nd row from the top and 4-th column from the left and goes down and to the right, the integer obtained by arranging the digits written on the visited squares will be 9786. It is impossible to make a value greater than 9786, so the answer is 9786.


Sample Input 2

10
1111111111
1111111111
1111111111
1111111111
1111111111
1111111111
1111111111
1111111111
1111111111
1111111111

Sample Output 2

1111111111

Note that the answer may not fit into a 32-bit integer.

E - Triple Attack

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

あなたはゲームをプレイしています。

N 人の敵が一列に並んでおり、前から i 番目の敵の体力は H_i です。

あなたは 0 で初期化された変数 T を使い、全ての敵の体力が 0 以下になるまで次の行動を繰り返します。

  • T1 増やす。その後、体力が 1 以上である最も前の敵を攻撃する。このとき、T3 の倍数ならばその敵の体力は 3 減り、そうでないなら 1 減る。

全ての敵の体力が 0 以下になったときの T の値を求めてください。

制約

  • 1 \leq N \leq 2\times 10^5
  • 1 \leq H_i \leq 10^9
  • 入力は全て整数

入力

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

N
H_1 H_2 \ldots H_N

出力

答えを出力せよ。


入力例 1

3
6 2 2

出力例 1

8

行動は次のように行われます。

  • T=1 になる。1 番目の敵を攻撃し、その敵の体力は 6-1=5 となる。
  • T=2 になる。1 番目の敵を攻撃し、その敵の体力は 5-1=4 となる。
  • T=3 になる。1 番目の敵を攻撃し、その敵の体力は 4-3=1 となる。
  • T=4 になる。1 番目の敵を攻撃し、その敵の体力は 1-1=0 となる。
  • T=5 になる。2 番目の敵を攻撃し、その敵の体力は 2-1=1 となる。
  • T=6 になる。2 番目の敵を攻撃し、その敵の体力は 1-3=-2 となる。
  • T=7 になる。3 番目の敵を攻撃し、その敵の体力は 2-1=1 となる。
  • T=8 になる。3 番目の敵を攻撃し、その敵の体力は 1-1=0 となる。

入力例 2

9
1 12 123 1234 12345 123456 1234567 12345678 123456789

出力例 2

82304529

入力例 3

5
1000000000 1000000000 1000000000 1000000000 1000000000

出力例 3

3000000000

オーバーフローに注意してください。

Score : 300 points

Problem Statement

You are playing a game.

There are N enemies lined up in a row, and the i-th enemy from the front has a health of H_i.

You will repeat the following action until the healths of all enemies become 0 or less, using a variable T initialized to 0.

  • Increase T by 1. Then, attack the frontmost enemy with health 1 or more. If T is a multiple of 3, the enemy's health decreases by 3; otherwise, it decreases by 1.

Find the value of T when the healths of all enemies become 0 or less.

Constraints

  • 1 \leq N \leq 2\times 10^5
  • 1 \leq H_i \leq 10^9
  • All input values are integers.

Input

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

N
H_1 H_2 \ldots H_N

Output

Print the answer.


Sample Input 1

3
6 2 2

Sample Output 1

8

The actions are performed as follows:

  • T becomes 1. Attack the 1st enemy, and its health becomes 6-1=5.
  • T becomes 2. Attack the 1st enemy, and its health becomes 5-1=4.
  • T becomes 3. Attack the 1st enemy, and its health becomes 4-3=1.
  • T becomes 4. Attack the 1st enemy, and its health becomes 1-1=0.
  • T becomes 5. Attack the 2nd enemy, and its health becomes 2-1=1.
  • T becomes 6. Attack the 2nd enemy, and its health becomes 1-3=-2.
  • T becomes 7. Attack the 3rd enemy, and its health becomes 2-1=1.
  • T becomes 8. Attack the 3rd enemy, and its health becomes 1-1=0.

Sample Input 2

9
1 12 123 1234 12345 123456 1234567 12345678 123456789

Sample Output 2

82304529

Sample Input 3

5
1000000000 1000000000 1000000000 1000000000 1000000000

Sample Output 3

3000000000

Beware of integer overflow.

F - Sum of Min Query

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

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

Q 個のクエリが与えられるので順に処理してください。 i 番目 (1\le i\le Q) のクエリは以下で説明されます。

文字 c_i と整数 X_i,V_i が与えられる。 c_i= A ならば A_{X_i} を、 c_i= B ならば B_{X_i}V_i に変更する。その後、 \displaystyle \sum_{k=1}^N \min(A_k,B_k) を出力する。

制約

  • 1\le N,Q \le 2 \times 10^5
  • 1\le A_i,B_i \le 10^9
  • c_iAB のいずれか
  • 1\le X_i \le N
  • 1\le V_i \le 10^9
  • 入力される数値は全て整数

入力

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

N Q
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_N
c_1 X_1 V_1
c_2 X_2 V_2
\vdots
c_Q X_Q V_Q

出力

Q 行出力せよ。 i 行目 (1\le i\le Q) には i 番目のクエリに対する答えを出力せよ。


入力例 1

4 3
3 1 4 1
2 7 1 8
A 2 3
B 3 3
A 1 7

出力例 1

7
9
9

1 番目のクエリでは A=(3,3,4,1),B=(2,7,1,8) となります。したがって、1 行目には \displaystyle \min(3,2)+\min(3,7) + \min(4 , 1)+\min(1,8) = 7 を出力してください。

2 番目のクエリでは A=(3,3,4,1),B=(2,7,3,8) となります。したがって、 2 行目には \displaystyle \min(3,2)+\min(3,7) + \min(4 , 3)+\min(1,8) = 9 を出力してください。

3 番目のクエリでは A=(7,3,4,1),B=(2,7,3,8) となります。したがって、 3 行目には \displaystyle \min(7,2)+\min(3,7) + \min(4 , 3)+\min(1,8) = 9 を出力してください。


入力例 2

1 3
1
1000000000
A 1 1
A 1 1
A 1 1

出力例 2

1
1
1

入力例 3

5 3
100 100 100 100 100
100 100 100 100 100
A 4 21
A 2 99
B 4 57

出力例 3

421
420
420

Score : 300 points

Problem Statement

You are given length-N integer sequences: A=(A_1,A_2,\ldots,A_N) and B=(B_1,B_2,\ldots,B_N).

You are given Q queries to process in order. The i-th query (1\le i\le Q) is described as follows:

You are given a character c_i and integers X_i,V_i. If c_i= A, change A_{X_i} to V_i; if c_i= B, change B_{X_i} to V_i. Then, output \displaystyle \sum_{k=1}^N \min(A_k,B_k).

Constraints

  • 1\le N,Q \le 2 \times 10^5
  • 1\le A_i,B_i \le 10^9
  • c_i is either A or B.
  • 1\le X_i \le N
  • 1\le V_i \le 10^9
  • All input values are integers.

Input

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

N Q
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_N
c_1 X_1 V_1
c_2 X_2 V_2
\vdots
c_Q X_Q V_Q

Output

Output Q lines. The i-th line (1\le i\le Q) should contain the answer to the i-th query.


Sample Input 1

4 3
3 1 4 1
2 7 1 8
A 2 3
B 3 3
A 1 7

Sample Output 1

7
9
9

After the 1st query, A=(3,3,4,1),B=(2,7,1,8). Therefore, output \displaystyle \min(3,2)+\min(3,7) + \min(4 , 1)+\min(1,8) = 7 on the 1st line.

After the 2nd query, A=(3,3,4,1),B=(2,7,3,8). Therefore, output \displaystyle \min(3,2)+\min(3,7) + \min(4 , 3)+\min(1,8) = 9 on the 2nd line.

After the 3rd query, A=(7,3,4,1),B=(2,7,3,8). Therefore, output \displaystyle \min(7,2)+\min(3,7) + \min(4 , 3)+\min(1,8) = 9 on the 3rd line.


Sample Input 2

1 3
1
1000000000
A 1 1
A 1 1
A 1 1

Sample Output 2

1
1
1

Sample Input 3

5 3
100 100 100 100 100
100 100 100 100 100
A 4 21
A 2 99
B 4 57

Sample Output 3

421
420
420
G - 250-like Number

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 400

問題文

以下の条件を満たす整数 k を「 250 に似た数」と呼びます。

  • k が素数 p<q を使って k=p \times q^3 と表される。

N 以下の「 250 に似た数」は全部でいくつありますか?

制約

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

入力

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

N

出力

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


入力例 1

250

出力例 1

2
  • 54 = 2 \times 3^3 なので、「 250 に似た数」です。
  • 250 = 2 \times 5^3 なので、「 250 に似た数」です。

250 以下の「 250 に似た数」は、以上の 2 つです。


入力例 2

1

出力例 2

0

入力例 3

123456789012345

出力例 3

226863

Score : 400 points

Problem Statement

Let us regard an integer k as "similar to 250" if the following condition is satisfied:

  • k is represented as k=p \times q^3 with primes p<q.

How many integers less than or equal to N are "similar to 250"?

Constraints

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

Input

Input is given from Standard Input in the following format:

N

Output

Print the answer as an integer.


Sample Input 1

250

Sample Output 1

2
  • 54 = 2 \times 3^3 is "similar to 250".
  • 250 = 2 \times 5^3 is "similar to 250".

The two integers above are all the integers "similar to 250".


Sample Input 2

1

Sample Output 2

0

Sample Input 3

123456789012345

Sample Output 3

226863
H - Blackout 2

Time Limit: 3 sec / Memory Limit: 1024 MiB

配点 : 500

問題文

ある国には N 個の都市と M 個の発電所があります。これらを総称して地点と呼びます。
地点には 1,2,\dots,N+M の番号がつけられており、そのうち都市は地点 1,2,\dots,N で発電所は地点 N+1,N+2,\dots,N+M です。

この国には電線が E 本あり、電線 i ( 1 \le i \le E ) は地点 U_i と地点 V_i を双方向に結びます。
また、ある都市に 電気が通っている とは、ある都市から電線をいくつか辿って少なくともひとつの発電所に辿り着くことができる状態を言います。

今、 Q 個のイベントが起こります。そのうち i ( 1 \le i \le Q ) 番目のイベントでは電線 X_i が切れ、その電線を辿ることができなくなります。一度切れた電線は、その後のイベントにおいても切れたままです。

全てのイベントについて、そのイベントが終わった直後に電気が通っている都市の数を求めてください。

制約

  • 入力は全て整数
  • 1 \le N,M
  • N+M \le 2 \times 10^5
  • 1 \le Q \le E \le 5 \times 10^5
  • 1 \le U_i < V_i \le N+M
  • i \neq j ならば、 U_i \neq U_j または V_i \neq V_j
  • 1 \le X_i \le E
  • X_i は相異なる

入力

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

N M E
U_1 V_1
U_2 V_2
\vdots
U_E V_E
Q
X_1
X_2
\vdots
X_Q

出力

Q 行出力せよ。
そのうち i ( 1 \le i \le Q ) 行目には i 番目のイベントが終わった直後に電気が通っている都市の数を出力せよ。


入力例 1

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

出力例 1

4
4
2
2
2
1

はじめ、全ての都市に電気が通っています。

  • 1 番目のイベントによって地点 5 と地点 10 を結ぶ電線 3 が切れます。
    • これにより、都市 5 に電気が通らなくなり、電気が通っている都市の数は 4 となります。
  • 2 番目のイベントによって地点 2 と地点 9 を結ぶ電線 5 が切れます。
  • 3 番目のイベントによって地点 3 と地点 6 を結ぶ電線 8 が切れます。
    • これにより、都市 2,3 に電気が通らなくなり、電気が通っている都市の数は 2 となります。
  • 4 番目のイベントによって地点 1 と地点 8 を結ぶ電線 10 が切れます。
  • 5 番目のイベントによって地点 4 と地点 10 を結ぶ電線 2 が切れます。
  • 6 番目のイベントによって地点 1 と地点 7 を結ぶ電線 7 が切れます。
    • これにより、都市 1 に電気が通らなくなり、電気が通っている都市の数は 1 となります。

Score : 500 points

Problem Statement

A country has N cities and M power plants, which we collectively call places.
The places are numbered 1,2,\dots,N+M, among which Places 1,2,\dots,N are the cities and Places N+1,N+2,\dots,N+M are the power plants.

This country has E power lines. Power Line i (1 \le i \le E) connects Place U_i and Place V_i bidirectionally.
A city is said to be electrified if one can reach at least one of the power plants from the city using some power lines.

Now, Q events will happen. In the i-th (1 \le i \le Q) event, Power Line X_i breaks, making it unusable. Once a power line breaks, it remains broken in the succeeding events.

Find the number of electrified cities right after each events.

Constraints

  • All values in input are integers.
  • 1 \le N,M
  • N+M \le 2 \times 10^5
  • 1 \le Q \le E \le 5 \times 10^5
  • 1 \le U_i < V_i \le N+M
  • If i \neq j, then U_i \neq U_j or V_i \neq V_j.
  • 1 \le X_i \le E
  • X_i are distinct.

Input

Input is given from Standard Input in the following format:

N M E
U_1 V_1
U_2 V_2
\vdots
U_E V_E
Q
X_1
X_2
\vdots
X_Q

Output

Print Q lines.
The i-th line should contain the number of electrified cities right after the i-th event.


Sample Input 1

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

Sample Output 1

4
4
2
2
2
1

Initially, all cities are electrified.

  • The 1-st event breaks Power Line 3 that connects Point 5 and Point 10.
    • Now City 5 is no longer electrified, while 4 cities remain electrified.
  • The 2-nd event breaks Power Line 5 that connects Point 2 and Point 9.
  • The 3-rd event breaks Power Line 8 that connects Point 3 and Point 6.
    • Now Cities 2 and 3 are no longer electrified, while 2 cities remain electrified.
  • The 4-th event breaks Power Line 10 that connects Point 1 and Point 8.
  • The 5-th event breaks Power Line 2 that connects Point 4 and Point 10.
  • The 6-th event breaks Power Line 7 that connects Point 1 and Point 7.
    • Now City 1 is no longer electrified, while 1 city remains electrified.
I - All Included

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 550

問題文

N 個の英小文字列 S_1,S_2,\ldots,S_N および整数 L が与えられます。

長さ L の英小文字列であって、S_1,S_2,\ldots,S_N をすべて部分文字列として含むものの個数を 998244353 で割った余りを求めてください。

部分文字列とは S部分文字列とは、S の先頭から 0 文字以上、末尾から 0 文字以上削除して得られる文字列のことをいいます。
例えば、ab, bc, bcdabcd の部分文字列ですが、ac, dc, eabcd の部分文字列ではありません。

制約

  • 1\leq N\leq 8
  • 1\leq L\leq 100
  • N,L は整数
  • S_i は長さが 1 以上 10 以下の英小文字からなる文字列
  • S_i\neq S_j\ (i\neq j)

入力

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

N L
S_1
S_2
\vdots
S_N

出力

答えを出力せよ。


入力例 1

2 4
ab
c

出力例 1

153

条件を満たす文字列として、たとえば abczcabc があります。acbdab を部分文字列として含まないため条件を満たしません。


入力例 2

2 6
abc
cde

出力例 2

54

入力例 3

5 50
bbfogggj
zkbach
eedirhyc
ffgd
oemmswj

出力例 3

689020583

Score : 550 points

Problem Statement

You are given N lowercase English strings S_1,S_2,\ldots,S_N, and an integer L.

Find the number, modulo 998244353, of length-L lowercase English strings that contain all of S_1,S_2,\ldots,S_N as substrings.

What is a substring? A substring of S is a string obtained by deleting zero or more characters from the beginning and zero or more characters from the end of S.
For example, ab, bc, and bcd are substrings of abcd, while ac, dc, and e are not substrings of abcd.

Constraints

  • 1\leq N\leq 8
  • 1\leq L\leq 100
  • N and L are integers.
  • Each S_i is a string of length 1 and 10, inclusive, consisting of lowercase English letters.
  • S_i\neq S_j\ (i\neq j)

Input

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

N L
S_1
S_2
\vdots
S_N

Output

Output the answer.


Sample Input 1

2 4
ab
c

Sample Output 1

153

Some of the strings that satisfy the condition are abcz and cabc. acbd does not contain ab as a substring, so it does not satisfy the condition.


Sample Input 2

2 6
abc
cde

Sample Output 2

54

Sample Input 3

5 50
bbfogggj
zkbach
eedirhyc
ffgd
oemmswj

Sample Output 3

689020583