A - Your First Judge

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 100

問題文

文字列 S が与えられるので、この文字列が Hello,World! と完全に一致するなら AC 、そうでないなら WA と出力してください。

「完全に一致する」とは?文字列 AB が完全に一致するとは、文字列 AB の長さが等しく、かつ全ての 1 \le i \le |A| を満たす整数 i について A の先頭から i 文字目と B の先頭から i 文字目とが(英大文字か小文字かも含めて)一致することを指します。

制約

  • 1 \le |S| \le 15
  • S は英大小文字, ,, ! のみからなる

入力

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

S

出力

答えを出力せよ。


入力例 1

Hello,World!

出力例 1

AC

文字列 SHello,World! と完全に一致します。


入力例 2

Hello,world!

出力例 2

WA

先頭から 7 文字目の W が、 Hello,World! では大文字ですが S では小文字です。よって SHello,World! と一致しません。


入力例 3

Hello!World!

出力例 3

WA

Score : 100 points

Problem Statement

Given a string S, print AC if it perfectly matches Hello,World!; otherwise, print WA.

What is a perfect match?Strings A is said to perfectly match B when the length of A is equal to that of B, and the i-th character of A is the same as the i-th character of B for every integer i such that 1 \le i \le |A|.

Constraints

  • 1 \le |S| \le 15
  • S consists of English lowercase letters, English uppercase letters, ,, and !.

Input

Input is given from Standard Input in the following format:

S

Output

Print the answer.


Sample Input 1

Hello,World!

Sample Output 1

AC

The string S perfectly matches Hello,World!.


Sample Input 2

Hello,world!

Sample Output 2

WA

The seventh character from the beginning should be an uppercase W in Hello,World!, but S has a lowercase w in that position. Thus, S does not match Hello,World!.


Sample Input 3

Hello!World!

Sample Output 3

WA
B - log2(N)

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 200

問題文

正整数 N が与えられるので、 2^k \le N となる最大の整数 k を求めてください。

制約

  • N1 \le N \le 10^{18} を満たす整数である

入力

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

N

出力

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


入力例 1

6

出力例 1

2
  • k=22^2=4 \le 6 を満たします。
  • k \ge 3 である全ての整数 k について 2^k > 6 となります。

以上より、答えは k=2 となります。


入力例 2

1

出力例 2

0

2^0=1 であることに注意してください。


入力例 3

1000000000000000000

出力例 3

59

入力が 32 bit 整数に収まらない場合があります。

Score : 200 points

Problem Statement

Given a positive integer N, find the maximum integer k such that 2^k \le N.

Constraints

  • N is an integer satisfying 1 \le N \le 10^{18}.

Input

Input is given from Standard Input in the following format:

N

Output

Print the answer as an integer.


Sample Input 1

6

Sample Output 1

2
  • k=2 satisfies 2^2=4 \le 6.
  • For every integer k such that k \ge 3, 2^k > 6 holds.

Therefore, the answer is k=2.


Sample Input 2

1

Sample Output 2

0

Note that 2^0=1.


Sample Input 3

1000000000000000000

Sample Output 3

59

The input value may not fit into a 32-bit integer.

C - One More aab aba baa

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 300

問題文

文字列 S の各文字を並べ替えて作ることが可能な文字列を辞書順にすべて列挙したとき、前から K 番目にくる文字列を求めてください。

「各文字を並べ替えて作ることが可能な文字列」とは? 「文字列 A が文字列 B の各文字を並べ替えて作ることが可能な文字列である」とは、任意の文字が文字列 A と文字列 B に同数含まれるということを指します。

制約

  • 1 \le |S| \le 8
  • S は英小文字のみからなる
  • S の各文字を並べ替えてできる文字列は K 種類以上存在する

入力

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

S K

出力

答えを出力せよ。


入力例 1

aab 2

出力例 1

aba

文字列 aab の各文字を並べ替えて作ることが可能な文字列は \{ aab, aba, baa \}3 つですが、このうち辞書順で前から 2 番目にくるものは aba です。


入力例 2

baba 4

出力例 2

baab

入力例 3

ydxwacbz 40320

出力例 3

zyxwdcba

Score : 300 points

Problem Statement

Find the K-th lexicographically smallest string among the strings that are permutations of a string S.

What is a permutation of a string?A string A is said to be a permutation of a string B when any character occurs the same number of times in A and B.

Constraints

  • 1 \le |S| \le 8
  • S consists of lowercase English letters.
  • There are at least K distinct strings that are permutations of S.

Input

Input is given from Standard Input in the following format:

S K

Output

Print the answer.


Sample Input 1

aab 2

Sample Output 1

aba

There are three permutations of a string aab: \{ aab, aba, baa \}. The 2-nd lexicographically smallest of them is aba.


Sample Input 2

baba 4

Sample Output 2

baab

Sample Input 3

ydxwacbz 40320

Sample Output 3

zyxwdcba
D - Coprime 2

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 400

問題文

長さ N の正整数列 A=(A_1,A_2,\dots,A_N) が与えられるので、以下の条件を満たす 1 以上 M 以下の整数 k を全て求めてください。

  • 全ての 1 \le i \le N を満たす整数 i について、 \gcd(A_i,k)=1 である。

制約

  • 入力は全て整数
  • 1 \le N,M \le 10^5
  • 1 \le A_i \le 10^5

入力

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

N M
A_1 A_2 \dots A_N

出力

1 行目に、出力する整数の数 x を出力せよ。
続く x 行に、答えとなる整数を小さい方から順に 1 行に 1 つずつ出力せよ。


入力例 1

3 12
6 1 5

出力例 1

3
1
7
11

例えば、 7\gcd(6,7)=1,\gcd(1,7)=1,\gcd(5,7)=1 を満たすので答えとなる整数の集合に含まれます。
一方、 9\gcd(6,9)=3 となるため、答えとなる整数の集合に含まれません。
条件を満たす 1 以上 12 以下の整数は 1,7,113 つです。これらを小さい方から出力することに注意してください。

Score : 400 points

Problem Statement

Given a sequence of N positive integers A=(A_1,A_2,\dots,A_N), find every integer k between 1 and M (inclusive) that satisfies the following condition:

  • \gcd(A_i,k)=1 for every integer i such that 1 \le i \le N.

Constraints

  • All values in input are integers.
  • 1 \le N,M \le 10^5
  • 1 \le A_i \le 10^5

Input

Input is given from Standard Input in the following format:

N M
A_1 A_2 \dots A_N

Output

In the first line, print x: the number of integers satisfying the requirement.
In the following x lines, print the integers satisfying the requirement, in ascending order, each in its own line.


Sample Input 1

3 12
6 1 5

Sample Output 1

3
1
7
11

For example, 7 has the properties \gcd(6,7)=1,\gcd(1,7)=1,\gcd(5,7)=1, so it is included in the set of integers satisfying the requirement.
On the other hand, 9 has the property \gcd(6,9)=3, so it is not included in that set.
We have three integers between 1 and 12 that satisfy the condition: 1, 7, and 11. Be sure to print them in ascending order.

E - Chain Contestant

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 500

問題文

別世界の AtCoder では現在、 AAC, ..., AJC の 10 種類のコンテストが開催されており、これから N 回のコンテストが開催されます。
各コンテストの種類は文字列 S として与えられ、 Si 文字目が x なら i 回目には AxC が開催されます。
シカの AtCoDeer くんは、 N 個のコンテストから 1 個以上いくつか選んで、以下の条件を満たすように選んで出場します。

  • 出るコンテストを順番を保ったまま抜き出したとき、コンテストの種類ごとにひとかたまりとなっている。
    • 厳密には、 AtCoDeer くんが x 個のコンテストに出場し、そのうち i 回目のコンテストの種類が T_i であるとき、全ての 1 \le i < j < k \le x を満たす整数組 (i,j,k) に対して、 T_i=T_k であるならば T_i=T_j でなければならない。

AtCoDeer くんが出場するコンテストの選び方として考えられるものの総数を 998244353 で割った余りを求めてください。
ただし、 2 つのコンテストの選び方が異なるとは、あるコンテスト c が存在して、片方の選び方では c に出場するがもう片方の選び方では出場しないということを指します。

制約

  • 1 \le N \le 1000
  • |S|=N
  • SA から J までの英大文字のみからなる

入力

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

N
S

出力

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


入力例 1

4
BGBH

出力例 1

13

例えば、 1,3 回目のコンテストに出場する、 2,4 回目のコンテストに出場するという選び方は条件を満たします。
一方、 1,2,3,4 回目のコンテストに出場する場合、 ABC への出場がひとかたまりになっておらず、整数組 (i,j,k)=(1,2,3) について条件に違反します。
また、全てのコンテストに出場しないということも認められません。
問題文の条件に適する出場するコンテストの選び方は 13 通りあります。


入力例 2

100
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBIEIJEIJIJCGCCFGIEBIHFCGFBFAEJIEJAJJHHEBBBJJJGJJJCCCBAAADCEHIIFEHHBGF

出力例 2

330219020

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

Score : 500 points

Problem Statement

AtCoder in another world holds 10 types of contests called AAC, ..., AJC. There will be N contests from now on.
The types of these N contests are given to you as a string S: if the i-th character of S is x, the i-th contest will be AxC.
AtCoDeer will choose and participate in one or more contests from the N so that the following condition is satisfied.

  • In the sequence of contests he will participate in, the contests of the same type are consecutive.
    • Formally, when AtCoDeer participates in x contests and the i-th of them is of type T_i, for every triple of integers (i,j,k) such that 1 \le i < j < k \le x, T_i=T_j must hold if T_i=T_k.

Find the number of ways for AtCoDeer to choose contests to participate in, modulo 998244353.
Two ways to choose contests are considered different when there is a contest c such that AtCoDeer participates in c in one way but not in the other.

Constraints

  • 1 \le N \le 1000
  • |S|=N
  • S consists of uppercase English letters from A through J.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print the answer as an integer.


Sample Input 1

4
BGBH

Sample Output 1

13

For example, participating in the 1-st and 3-rd contests is valid, and so is participating in the 2-nd and 4-th contests.
On the other hand, participating in the 1-st, 2-nd, 3-rd, and 4-th contests is invalid, since the participations in ABCs are not consecutive, violating the condition for the triple (i,j,k)=(1,2,3).
Additionally, it is not allowed to participate in zero contests.
In total, there are 13 valid ways to participate in some contests.


Sample Input 2

100
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBIEIJEIJIJCGCCFGIEBIHFCGFBFAEJIEJAJJHHEBBBJJJGJJJCCCBAAADCEHIIFEHHBGF

Sample Output 2

330219020

Be sure to find the count modulo 998244353.

F - Dist Max 2

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 500

問題文

2 次元平面上の N 個の相異なる点が与えられます。点 i\, (1 \leq i \leq N) の座標は (x_i,y_i) です。

2 つの点 i,j\, (1 \leq i,j \leq N) の距離を \mathrm{min} (|x_i-x_j|,|y_i-y_j|) 、すなわち x 座標の差と y 座標の差の小さい方と定義します。

異なる 2 つの点の距離の最大値を求めてください。

制約

  • 2 \leq N \leq 200000
  • 0 \leq x_i,y_i \leq 10^9
  • (x_i,y_i) \neq (x_j,y_j) (i \neq j)
  • 入力は全て整数である。

入力

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

N
x_1 y_1
x_2 y_2
\vdots
x_N y_N

出力

異なる 2 つの点の距離の最大値を出力せよ。


入力例 1

3
0 3
3 1
4 10

出力例 1

4

1 と点 2 の距離は 2 、点 1 と点 3 の距離は 4 、点 2 と点 3 の距離は 1 です。よって 4 を出力してください。


入力例 2

4
0 1
0 4
0 10
0 6

出力例 2

0

入力例 3

8
897 729
802 969
765 184
992 887
1 104
521 641
220 909
380 378

出力例 3

801

Score : 500 points

Problem Statement

Given are N distinct points in a two-dimensional plane. Point i (1 \leq i \leq N) has the coordinates (x_i,y_i).

Let us define the distance between two points i and j be \mathrm{min} (|x_i-x_j|,|y_i-y_j|): the smaller of the difference in the x-coordinates and the difference in the y-coordinates.

Find the maximum distance between two different points.

Constraints

  • 2 \leq N \leq 200000
  • 0 \leq x_i,y_i \leq 10^9
  • (x_i,y_i) \neq (x_j,y_j) (i \neq j)
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
x_1 y_1
x_2 y_2
\vdots
x_N y_N

Output

Print the maximum distance between two different points.


Sample Input 1

3
0 3
3 1
4 10

Sample Output 1

4

The distances between Points 1 and 2, between Points 1 and 3, and between Points 2 and 3 are 2, 4, and 1, respectively, so your output should be 4.


Sample Input 2

4
0 1
0 4
0 10
0 6

Sample Output 2

0

Sample Input 3

8
897 729
802 969
765 184
992 887
1 104
521 641
220 909
380 378

Sample Output 3

801
G - Colorful Candies 2

Time Limit: 4 sec / Memory Limit: 1024 MB

配点 : 600

問題文

N 個のキャンディが左右一列に並んでいます。
それぞれのキャンディは、色 1、色 2\ldots 、色 10^9 の、10^9 種類の色のうちいずれかの色をしています。
i = 1, 2, \ldots, N について、左から i 番目のキャンディの色は色 c_i です。

高橋君は並んでいる N 個のキャンディのうち K 個を選び、選んだ K 個のキャンディをすべてもらいます。
ここで、N 個のキャンディから K 個を選ぶ組み合わせの個数は二項係数を用いて \binom{N}{K} 個と表せますが、 高橋君は \binom{N}{K} 通りの選び方のうちいずれか一つを等確率でランダムに選びます。

高橋君はいろいろな色のキャンディを食べたいので、もらうキャンディに含まれる色の種類数が多いほどうれしい気持ちになります。
K = 1, 2, \ldots, N のそれぞれの場合について、高橋君がもらうキャンディに含まれる色の種類数の期待値を求めてください。
ここで、求める答えは有理数となることが証明できます。答えとなる有理数を注記で述べるように \bmod 998244353 で出力してください。

注記

有理数を出力する際は、まずその有理数を分数 \frac{y}{x} として表してください。ここで、x, y は整数であり、x998244353 で割り切れてはなりません(この問題の制約下で、そのような表現は必ず可能です)。そして、xz \equiv y \pmod{998244353} を満たすような 0 以上 998244352 以下の唯一の整数 z を出力してください。

制約

  • 1 \leq N \leq 5 \times 10^4
  • 1 \leq c_i \leq 10^9
  • 入力はすべて整数

入力

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

N
c_1 c_2 \ldots c_N

出力

N 行出力せよ。i 行目には K = i の場合における高橋君がもらうキャンディに含まれる色の種類数の期待値を、注記に述べるように \bmod 998244353で出力せよ。


入力例 1

3
1 2 2

出力例 1

1
665496237
2

K = 1 のとき、高橋君がもらうキャンディの組み合わせは、「 1 番目のみ」「 2 番目のみ」「 3 番目のみ」の 3 通りがあります。
いずれの場合も、含まれる色は 1 種類です。よって、含まれる色の種類数の期待値は 1 となります。

K = 2 のとき、高橋君がもらうキャンディの組み合わせは、「 1 番目と 2 番目」「 2 番目と 3 番目」「 1 番目と 3 番目」の 3 通りがあります。

  • 1 番目と 2 番目」をもらう場合、含まれる色は 2 種類
  • 2 番目と 3 番目」をもらう場合、含まれる色は 1 種類
  • 1 番目と 3 番目」をもらう場合、含まれる色は 2 種類

となりますから、含まれる色の種類数の期待値は、\frac{1}{3} \cdot 2 + \frac{1}{3} \cdot 1 + \frac{1}{3} \cdot 2 = \frac{5}{3} です。
注記に述べたように、\bmod 998244353 で出力することに注意してください。

K = 3 のとき、高橋君がもらうキャンディの組み合わせは、「 1, 2, 3 番目のすべて」の 1 通りのみであり、含まれる色は 2 種類です。
よって、含まれる色の種類数の期待値は 2 となります。


入力例 2

11
3 1 4 1 5 9 2 6 5 3 5

出力例 2

1
725995895
532396991
768345657
786495555
937744700
574746754
48399732
707846002
907494873
7

Score : 600 points

Problem Statement

There are N candies arranged in a row from left to right.
Each candy has one of the following 10^9 colors: Color 1, Color 2, \ldots, Color 10^9.
For each i = 1, 2, \ldots, N, the i-th candy from the left has Color c_i.

Takahashi will choose K from the N candies and get those K candies.
There are \binom{N}{K} ways to choose K from the N candies, where \binom{N}{K} is a binomial coefficient. Takahashi will randomly select one of these \binom{N}{K} ways with equal probability.

Because Takahashi wants to eat colorful candies, the more variety of colors his candies have, the happier he will be.
For each scenario K = 1, 2, \ldots, N, find the expected value of the number of different colors Takahashi's candies will have.
We can prove that the sought value is a rational number. Print this rational number modulo 998244353, as described in Notes.

Notes

When you print a rational number, first write it as a fraction \frac{y}{x}, where x, y are integers and x is not divisible by 998244353 (under the constraints of the problem, such representation is always possible). Then, you need to print the only integer z between 0 and P - 1, inclusive, that satisfies xz \equiv y \pmod{998244353}.

Constraints

  • 1 \leq N \leq 5 \times 10^4
  • 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_N

Output

Print N lines. The i-th line should contain the expected value of the number of different colors Takahashi's candies will have for the scenario K = i, modulo 998244353 as described in Notes.


Sample Input 1

3
1 2 2

Sample Output 1

1
665496237
2

When K = 1, he will get the 1-st candy, 2-nd candy, or 3-rd candy. In any case, his candy will have one color, so the expected value of the number of different colors is 1.

When K = 2, he will get the 1-st and 2-nd candies, 2-nd and 3-rd candies, or 1-st and 3-rd candies.

  • If he gets the 1-st and 2-nd candies, they have two different colors.
  • If he gets the 2-nd and 3-rd candies, they have one color.
  • If he gets the 1-st and 3-rd candies, they have two different colors.

Thus, the expected value of the number of different colors is \frac{1}{3} \cdot 2 + \frac{1}{3} \cdot 1 + \frac{1}{3} \cdot 2 = \frac{5}{3}.
Be sure to print it modulo 998244353 as described in Notes.

When K = 3, he will always get the 1-st, 2-nd, and 3-rd candies, which have two different colors, so the expected value of the number of different colors is 2.


Sample Input 2

11
3 1 4 1 5 9 2 6 5 3 5

Sample Output 2

1
725995895
532396991
768345657
786495555
937744700
574746754
48399732
707846002
907494873
7
H - Cabbage Master

Time Limit: 3 sec / Memory Limit: 1024 MB

配点 : 600

問題文

キャベツ農家の高橋君は、品種 1 から品種 N までの N 種類のキャベツを育てました。高橋君は品種 i (1 \leq i \leq N) のキャベツを A_i 個持っています。ここで、 すべてのキャベツは区別できます。
キャベツの卸先として会社 1 から会社 M までの M 個の会社があり、会社 j (1 \leq j \leq M) からは B_j 個のキャベツの注文を受けています。
出荷できるキャベツの品種は会社ごとに異なっており、すべての i, j の組 (1 \leq i \leq N, 1 \leq j \leq M) について

  • c_{i, j} = 1 のとき、品種 i のキャベツを会社 j に出荷できます。
  • c_{i, j} = 0 のとき、品種 i のキャベツを会社 j に出荷できません。

高橋君は、すべてのキャベツの出荷先を適切に決めることで、すべての会社 j (1 \leq j \leq M) にキャベツを B_j 個以上出荷することができれば「キャベツ名人」の称号を得ることができます。

すぬけ君は、高橋君がどのようにキャベツの出荷先を決めても「キャベツ名人」の称号を得られないように 0 個以上のキャベツを選んで食べることにしました。キャベツが苦手なすぬけ君は、前述の条件のもとで食べるキャベツの個数が 最少 となるように食べるキャベツの組み合わせを選択します。

すぬけ君が食べるキャベツの個数、およびすぬけ君が食べるキャベツの選び方が何通りあるかを 998244353 で割ったあまりの 2 つを出力してください。
ただし、 キャベツの選び方が異なるとは、一方の選び方で食べられたがもう一方の選び方で食べられていないようなキャベツが存在することをいいます。ここで、異なる 2 つのキャベツは 品種が同じでも区別される ことに注意してください。

制約

  • 1 \leq N \leq 20
  • 1 \leq M \leq 10^4
  • 1 \leq A_i \leq 10^5
  • 1 \leq B_j \leq 10^5
  • c_{i, j} \in \lbrace 0, 1 \rbrace
  • 任意の 1 \leq j \leq M に対して、ある 1 \leq i \leq N が存在して c_{i, j} = 1 が成り立つ
  • 入力はすべて整数

入力

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

N M
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_M
c_{1, 1} c_{1, 2} \ldots c_{1, M}
c_{2, 1} c_{2, 2} \ldots c_{2, M}
\vdots
c_{N, 1} c_{N, 2} \ldots c_{N, M}

出力

すぬけ君が食べるキャベツの個数 X と、すぬけ君が食べるキャベツの選び方が何通りあるかを 998244353 で割ったあまり Y を、この順番に空白区切りで出力せよ。

X Y

入力例 1

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

出力例 1

2 6

高橋君がキャベツ名人になれないようにするために、すぬけ君が食べるキャベツの個数は 2 個です。 また、便宜上 「品種 ij 番目のキャベツ」を (i,j) のように表したとき、すぬけ君が食べるキャベツの組み合わせとして考えられるものは以下の 6 通りです。

  • (1, 1), (1, 2)
  • (1, 1), (2, 1)
  • (1, 1), (2, 2)
  • (1, 2), (2, 1)
  • (1, 2), (2, 2)
  • (2, 1), (2, 2)

入力例 2

1 1
3
4
1

出力例 2

0 1

すぬけ君がキャベツを 1 個も食べなくても、高橋君がキャベツ名人になることができない場合もあります。
このとき、すぬけ君が食べるキャベツの個数は 0 個であり、すぬけ君が食べるキャベツの組み合わせとして考えられるのは、「どのキャベツも食べない」という 1 通りのみです。


入力例 3

1 3
100
30 30 30
1 1 1

出力例 3

11 892328666

すぬけ君が食べるキャベツの選び方が何通りあるかについては、 998244353 で割ったあまりを出力することに注意してください。

Score : 600 points

Problem Statement

Takahashi, a cabbage farmer, has grown N brands of cabbages, called Brand 1 through Brand N. He has A_i heads of cabbage of Brand i (1 \leq i \leq N). Here, all heads of cabbages are distinguishable.
He has M clients called Company 1 through Company M. Company j (1 \leq j \leq M) has ordered B_j heads of cabbages.
Different companies accept different brands of cabbages. For each pair i, j (1 \leq i \leq N, 1 \leq j \leq M),

  • if c_{i, j} = 1, cabbage of Brand i can be shipped to Company j;
  • if c_{i, j} = 0, cabbage of Brand i cannot be shipped to Company j.

Takahashi will be called a Cabbage Master if he succeeds in deciding where to ship the heads of cabbages so that B_j or more heads of cabbages will be shipped to every company j (1 \leq j \leq M).

Snuke has decided to choose and eat zero or more heads of cabbages so that Takahashi cannot get the title of Cabbage Master, regardless of where to ship his cabbages. He does not like cabbage very much, so he will choose to eat the minimum number of heads of cabbages needed to achieve his objective.

Print the number of heads of cabbages Snuke will eat, and the number of ways, modulo 998244353, for Snuke to choose heads of cabbages to eat. Two ways to choose heads of cabbages are considered different when there is a head of cabbage that is eaten in one way but not in the other. Here, remember that any two heads of cabbages are distinguishable even if they are of the same brand.

Constraints

  • 1 \leq N \leq 20
  • 1 \leq M \leq 10^4
  • 1 \leq A_i \leq 10^5
  • 1 \leq B_j \leq 10^5
  • c_{i, j} \in \lbrace 0, 1 \rbrace
  • For every 1 \leq j \leq M, there exists 1 \leq i \leq N such that c_{i, j} = 1.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_M
c_{1, 1} c_{1, 2} \ldots c_{1, M}
c_{2, 1} c_{2, 2} \ldots c_{2, M}
\vdots
c_{N, 1} c_{N, 2} \ldots c_{N, M}

Output

Print X, the number of heads of cabbages Snuke will eat, and Y, the number of ways for Snuke to choose heads of cabbages to eat, modulo 998244353, in this order, with a space in between.

X Y

Sample Input 1

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

Sample Output 1

2 6

Snuke will eat two heads of cabbages to prevent Takahashi from becoming a Cabbage Master. There are six such ways to choose heads of cabbages to eat, as shown below, where (i, j) denotes the j-th head of cabbage of Brand i.

  • (1, 1), (1, 2)
  • (1, 1), (2, 1)
  • (1, 1), (2, 2)
  • (1, 2), (2, 1)
  • (1, 2), (2, 2)
  • (2, 1), (2, 2)

Sample Input 2

1 1
3
4
1

Sample Output 2

0 1

It is possible that Takahashi is unable to become a Cabbage Master even if Snuke eats no cabbage. Then, Snuke will eat zero heads of cabbages, and there is just one way for him to choose heads of cabbages to eat: do not eat anything.


Sample Input 3

1 3
100
30 30 30
1 1 1

Sample Output 3

11 892328666

For the number of ways for Snuke to choose heads of cabbages to eat, be sure to print it modulo 998244353.