XXI Open Cup, Grand Prix of Tokyo
A. Ascending Matrix
time limit per test
2 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

You are given integers $$$N,M,K,R,C,$$$ and $$$V$$$. Find the number of $$$N$$$ by $$$M$$$ integer matrices $$$a = (a_{i,j})$$$ that satisfy all of the following conditions, modulo $$$998244353$$$.

  • $$$1 \leq a_{i,j} \leq K$$$ for all $$$1 \leq i \leq N,\, 1 \leq j \leq M$$$.
  • $$$a_{i,j} \leq a_{i,j+1}$$$ for all $$$1 \leq i \leq N,\, 1 \leq j \leq M-1$$$.
  • $$$a_{i,j} \leq a_{i+1,j}$$$ for all $$$1 \leq i \leq N-1,\, 1 \leq j \leq M$$$.
  • $$$a_{R,C}=V$$$.
Input

The first line contains integers $$$N$$$, $$$M$$$ ($$$1 \leq N,M \leq 200$$$), $$$K$$$ ($$$1 \leq K \leq 100$$$), $$$R$$$ ($$$1 \leq R \leq N$$$), $$$C$$$ ($$$1 \leq C \leq M$$$), and $$$V$$$ ($$$1 \leq V \leq K$$$).

Output

Print the answer.

Examples
Input
2 2 2 1 1 1
Output
5
Input
2 2 2 1 2 1
Output
3
Input
4 5 6 2 3 4
Output
3700125
Input
200 100 100 70 60 30
Output
546626227

B. Bit Operation
time limit per test
2 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

You are given an integer array $$$A$$$ of length $$$N$$$, consisting of $$$0$$$'s and $$$1$$$'s. Let $$$a$$$ be initially the array $$$A$$$. You are going to perform the following operation $$$N-1$$$ times.

  • Let $$$n$$$ be the current length of $$$a$$$. Choose an integer $$$i$$$ ($$$1 \leq i \leq n-1$$$) and delete the $$$i$$$-th and the $$$(i+1)$$$-th elements of $$$a$$$. Then, by letting $$$x$$$ and $$$y$$$ be the deleted elements, insert either $$$x\mathbin{\&}y$$$ or $$$x\mathbin{|}y$$$ to the position of the deleted elements. Here $$$x\mathbin{\&}y$$$ and $$$x\mathbin{|}y$$$ denote the bit-AND and bit-OR operations, respectively.

There are $$$2^{N-1} \times (N-1)!$$$ ways to perform the operations. Count the number of ways that result in a single value of $$$1$$$, modulo $$$998244353$$$.

Input

The first line contains an integer $$$N$$$ ($$$1 \leq N \leq 10^6$$$).

The second line contains integers $$$A_1,A_2,\ldots,A_N$$$ ($$$0 \leq A_i \leq 1$$$).

Output

Print the answer.

Examples
Input
3
0 1 0
Output
2
Input
5
1 1 1 1 1
Output
384
Input
7
0 1 1 0 1 0 1
Output
25515

C. Count Min Ratio
time limit per test
4 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

You have $$$R$$$ red balls, $$$B$$$ blue balls, and one green ball. You are going to arrange the balls in a row. The score of an arrangement is defined as follows:

  • Let $$$l_{\mathrm{R}},l_{\mathrm{B}},r_{\mathrm{R}},r_{\mathrm{B}}$$$ be the number of red/blue balls to the left/right of the green ball, respectively. Then, the score is the maximum integer $$$x$$$ such that $$$l_{\mathrm{B}} \times x \leq l_{\mathrm{R}}$$$ and $$$r_{\mathrm{B}} \times x \leq r_{\mathrm{R}}$$$.

Find the sum of scores of all possible arrangements, modulo $$$998244353$$$. Note that balls of the same color cannot be distinguished, thus two arrangements are considered different if and only if there is such an $$$i$$$ that the color of the $$$i$$$-th ball in the first arrangement differs from that of the second.

Input

The first line contains integers $$$R$$$ ($$$1 \leq R \leq 10^{18}$$$) and $$$B$$$ ($$$1 \leq B \leq 10^6$$$).

Output

Print the answer.

Examples
Input
10 3
Output
8390
Input
3 10
Output
0
Input
100 10
Output
801171977
Input
999999999999999999 999999
Output
448294209

D. Do Use FFT
time limit per test
10 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

You are given integer sequences $$$A$$$, $$$B$$$, and $$$C$$$, each of length $$$N$$$. For each $$$k=1,2,\ldots,N$$$, find the following value modulo $$$998244353$$$.

$$$$$$ \sum_{1 \leq i \leq N} \left( C_i \times \prod_{1 \leq j \leq k} (A_i+B_j) \right) $$$$$$

Input

The first line contains an integer $$$N$$$ ($$$1 \leq N \leq 250000$$$).

The second line contains $$$N$$$ integers $$$A_1,A_2,\ldots,A_N$$$ ($$$0 \leq A_i \lt 998244353$$$).

The third line contains $$$N$$$ integers $$$B_1,B_2,\ldots,B_N$$$ ($$$0 \leq B_i \lt 998244353$$$).

The fourth line contains $$$N$$$ integers $$$C_1,C_2,\ldots,C_N$$$ ($$$0 \leq C_i \lt 998244353$$$).

Output

For each $$$k=1,2,\ldots,N$$$, print the answer.

Example
Input
3
1 2 3
4 5 6
7 8 9
Output
146 1050 8694

E. Edge Subsets
time limit per test
6 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

You are given integers $$$A,B$$$, and a simple undirected graph of $$$N$$$ vertices and $$$M$$$ edges. The vertices are numbered from $$$1$$$ through $$$N$$$, and the edges from $$$1$$$ through $$$M$$$. The edge $$$i$$$ connects the vertices $$$U_i$$$ and $$$V_i$$$. Here, it is guaranteed that $$$V_i-U_i=A$$$ or $$$V_i-U_i=B$$$.

Find the number of matchings of the graph, modulo $$$998244353$$$. Note that a matching of the graph is a subset of edges whose end-points are all distinct.

Input

The first line contains integers $$$N$$$ ($$$3 \leq N \leq 200$$$), $$$M$$$ ($$$1 \leq M \leq 400$$$), $$$A$$$, and $$$B$$$ ($$$1 \leq A \lt B \leq N-1$$$).

The following $$$M$$$ lines describe the edges. The $$$i$$$-th of those lines contains integers $$$U_i$$$ and $$$V_i$$$ ($$$1 \leq U_i \lt V_i \leq N$$$, $$$V_i-U_i=A$$$ or $$$V_i-U_i=B$$$). There are no self-loops or multi-edges.

Output

Print the answer.

Examples
Input
4 3 1 2
1 2
1 3
3 4
Output
5
Input
10 14 2 4
5 7
7 9
2 6
6 8
1 5
3 7
4 8
1 3
4 6
8 10
3 5
5 9
2 4
6 10
Output
225

F. Find the LCA
time limit per test
7 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

You are given an integer sequence $$$A_1,A_2,\ldots,A_N$$$. You'll make a rooted tree with $$$N$$$ vertices numbered from $$$1$$$ through $$$N$$$. The vertex $$$1$$$ is the root, and for each vertex $$$i$$$ ($$$2 \leq i \leq N$$$), its parent $$$p_i$$$ must satisfy $$$p_i \lt i$$$.

You define the score of a rooted tree as follows:

  • Let $$$x$$$ be the lowest common ancestor of the vertex $$$N-1$$$ and the vertex $$$N$$$. Then, the score is

    $$$$$$ \prod_{v \in (\text{subtree rooted at $x$})} A_v $$$$$$

    Note that we consider $$$x$$$ itself is in the subtree rooted at $$$x$$$.

There are $$$(N-1)!$$$ ways to make a tree. Find the sum of scores of all possible trees, modulo $$$998244353$$$.

Input

The first line contains an integer $$$N$$$ ($$$3 \leq N \leq 250000$$$).

The second line contains integers $$$A_1,A_2,\ldots,A_N$$$ ($$$1 \leq A_i \lt 998244353$$$).

Output

Print the answer.

Examples
Input
3
2 2 2
Output
12
Input
5
1 2 3 4 5
Output
2080

G. Games
time limit per test
4 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

You are given an integer sequence $$$A_1,A_2,\ldots,A_N$$$ and an integer $$$K$$$.

You'll prepare $$$K$$$ piles of stones. Each pile should contain exactly $$$A_i$$$ piles for some $$$i$$$. All piles are distinguishable; there are $$$N^K$$$ different configurations.

You and Mike will play a game with the piles. You and Mike alternately do the following operation, with you going first.

  • Choose at most $$$6$$$ piles (choosing $$$0$$$ piles is not allowed) and remove an arbitrary positive number of stones from each of the chosen piles. Note that the player can remove different numbers of stones from different piles.

The player who cannot make a valid move loses. Assuming both players play optimally, count the number of initial configurations that result in your loss, modulo $$$998244353$$$.

Input

The first line contains integers $$$N$$$ ($$$1 \leq N \leq 100$$$) and $$$K$$$ ($$$1 \leq K \leq 10^{18}$$$).

The second line contains integers $$$A_1,A_2,\ldots,A_N$$$ ($$$1 \leq A_1 \lt A_2 \lt \cdots \lt A_N \leq 100$$$).

Output

Print the answer.

Examples
Input
1 7
1
Output
1
Input
5 100
2 3 5 7 9
Output
842434993

H. Harsh Comments
time limit per test
1 second
memory limit per test
1024 megabytes
input
standard input
output
standard output

Posted on a blog are $$$N+M$$$ harsh comments. You made $$$N$$$ comments, and the $$$i$$$-th of them has $$$A_i$$$ downvotes. The $$$i$$$-th of the other $$$M$$$ comments has $$$B_i$$$ downvotes.

Mike is going to delete the comments, one by one, by repeating the following operation:

  • Choose a comment randomly and delete it. More precisely, let $$$x_1,x_2,\ldots,x_k$$$ be numbers of downvotes the remaining comments have. Then, he will choose the $$$i$$$-th of them with the probability $$$x_i/\left(\sum_{1\leq j \leq k}x_j \right)$$$ and detele it.

Note that the choices in the operations are independent.

Find the expected number of operations Mike will do until he deletes all of your comments. The answer is a rational number, so print it modulo $$$998244353$$$ as usual. We can prove that such representation is always possible under the constraints of this problem.

Input

The first line contains integers $$$N$$$ and $$$M$$$ ($$$1 \leq N,M \leq 100$$$).

The second line contains integers $$$A_1,A_2,\ldots,A_N$$$ ($$$1 \leq A_i \leq 100$$$).

The third line contains integers $$$B_1,B_2,\ldots,B_M$$$ ($$$1 \leq B_i$$$, $$$\sum_{1 \leq i \leq N} A_i + \sum_{1 \leq i \leq M} B_i \lt 998244353$$$).

Output

Print the answer.

Examples
Input
1 2
1
1 1
Output
2
Input
1 1
2
1
Output
332748119
Input
3 3
2 3 5
7 11 900000000
Output
636512475

I. Inverse Problem
time limit per test
1 second
memory limit per test
1024 megabytes
input
standard input
output
standard output

You are given an integer $$$N$$$ and an integer sequence $$$X$$$ of length $$$M$$$. Count, modulo $$$998244353$$$, the number of permutations $$$P = (P_1,P_2,\ldots,P_N)$$$ of $$$(1,2,\ldots,N)$$$ that satisfy the following condition:

  • The lexicographically smallest subsequence of $$$P$$$ of length $$$M$$$ coincides with $$$X$$$.
Input

The first line contains integers $$$N$$$ ($$$1 \leq N \leq 250000$$$) and $$$M$$$ ($$$1 \leq M \leq N$$$).

The second line contains integers $$$X_1,X_2,\ldots,X_M$$$ ($$$1 \leq X_i \leq N$$$, $$$X_i \neq X_j$$$ for all $$$i \neq j$$$).

Output

Print the answer.

Examples
Input
3 2
1 2
Output
3
Input
10 5
2 7 8 3 6
Output
0
Input
5 5
1 2 3 4 5
Output
1

J. Japanese Knowledge
time limit per test
10 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

This problem might be well-known in some countries, but how do other countries learn about such problems if nobody poses them?

You are given a non-decreasing positive integer sequence $$$A = (A_1, A_2, \ldots, A_N)$$$ of length $$$N$$$. For each $$$k=0,1,2,\ldots,N$$$, count the number of non-decreasing non-negative integer sequences $$$x = (x_1, x_2, \ldots, x_N)$$$ of length $$$N$$$ that satisfy following conditions, modulo $$$998244353$$$:

  • $$$x_i \leq A_i$$$ for all $$$1 \leq i \leq N$$$.
  • The number of indices $$$i$$$ with $$$x_i=A_i$$$ is exactly $$$k$$$.
Input

The first line contains an integer $$$N$$$ ($$$1 \leq N \leq 250000$$$).

The second line contains $$$N$$$ integers $$$A_1,A_2,\ldots,A_N$$$ ($$$1 \leq A_1 \leq A_2 \leq \cdots \leq A_N \leq 250000$$$).

Output

For each $$$k=0,1,2,\ldots,N$$$, print the answer.

Examples
Input
3
1 2 3
Output
5 5 3 1
Input
4
3 3 3 3
Output
15 10 6 3 1
Input
5
10 10 11 11 12
Output
3982 1285 352 77 12 1