OCPC 2024 Winter, Day 5: Batrr Contest
A. Counting Graphs
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Find the number of connected labeled simple graphs with $$$n$$$ vertices and $$$m$$$ edges (modulo $$$998\,244\,353$$$, obviously).

Input

The only line contains two integers $$$n$$$, $$$m$$$ ($$$1 \le n \le 10 ^ 5$$$, $$$0 \le m \le n + 50$$$).

Output

Print one integer — the answer to the problem modulo $$$998\,244\,353$$$.

Examples
Input
10 9
Output
100000000
Input
4 5
Output
6
Input
5 3
Output
0
Input
3 10
Output
0
Input
100000 100050
Output
526410635
Note

A simple graph is a graph that does not have more than one edge between any two vertices and no edge starts and ends at the same vertex.

A labeled graph is a graph with each node labeled differently (but arbitrarily) so that all nodes are considered distinct for purposes of enumeration. For example, graph with edges $$$(1,\ 2),\ (1,\ 3)$$$ is different from graph with edges $$$(3,\ 1),\ (3,\ 2)$$$.

A connected graph is a graph where it's possible to get from any vertex to any other vertex using only the edges belonging to this graph.

B. Submask Problem V7.0
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Given two integers $$$n$$$, $$$k$$$, and an array $$$a$$$ of $$$n$$$ elements.

Define $$$f(x)$$$ as the number of pairs $$$(i, j)$$$ $$$(1 \le i, j \le n)$$$ such that $$$a_i + x$$$ is a submask of $$$a_j + x$$$.

Find the sum of $$$f(0), f(1), \ldots, f(2^k - 1)$$$ (modulo $$$998\,244\,353$$$, obviously).

Input

The first line contains two integers $$$n$$$ and $$$k$$$ $$$(1 \le n \le 2 \times 10^4, 1 \le k \le 60)$$$.

The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ $$$(0 \le a_i \le 2 ^ k - 1)$$$.

Output

Print one integer — the answer to the problem modulo $$$998\,244\,353$$$.

Examples
Input
2 2
2 0
Output
10
Input
10 5
16 31 16 18 7 17 31 26 7 21
Output
840
Input
2 50
383198634384164 901251460473164
Output
400397424
Note

$$$x$$$ is a submask of $$$y$$$ if in binary notation the positions where $$$x$$$ has a 1 (set bit), $$$y$$$ also has a 1(set bit).

For example, $$$5$$$ is a submask of $$$13$$$ ($$$5 = 0101_2, 13 = 1101_2$$$), $$$9$$$ is not a submask of $$$10$$$ ($$$9 = 1001_2, 10 = 1010_2$$$).

C. Powerful Tima
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Tima recently found an array $$$a$$$ of $$$n$$$ elements.

Being a powerful individual himself, he believes that his array should also be powerful.

An array is considered powerful if there exists some integer $$$d$$$ such that every element of the array is a power of $$$d$$$ $$$(1,\ d,\ d^2,\ d^3,\ \ldots)$$$. For example, $$$[8, 1, 1, 32]$$$ is powerful, and $$$[6, 7, 46, 343]$$$ is not.

In one operation, he can decrease or increase any element of the array by one.

What is the minimal number of operations required to make his array powerful?

Input

The first line contains one integer $$$n$$$ $$$(1 \le n \le 10^5)$$$ — length of the array.

The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ $$$(1 \le a_i \le 10 ^{12})$$$ — elements of the array.

Output

Output the minimal number of operations required to make the array powerful.

Examples
Input
4
8 1 1 32
Output
0
Input
4
6 7 46 343
Output
4
Input
3
2 253 59149
Output
111

D. Infinite LCS
time limit per test
1.5 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Consider two strings denoted by $$$s$$$ and $$$t$$$ of length $$$n$$$.

Define $$$f(a, b) = \frac{{\text{lcs}(a, b)}}{{|a| + |b|}}$$$, where $$$a$$$ and $$$b$$$ are strings, $$$\text{lcs}(a, b)$$$ represents the length of the longest common subsequence, and $$$|a|$$$ and $$$|b|$$$ are the respective lengths of strings $$$a$$$ and $$$b$$$.

Now, let $$$g(x, y) = f(\underbrace{s + \ldots + s}_{x\ \text{times}}, \underbrace{t + \ldots + t}_{y\ \text{times}})$$$, where $$$a + b$$$ denotes the concatenation of strings.

Find the maximal possible value of $$$g(x, y)$$$.

Input

The first line contains one integer $$$T$$$ — the number of test cases.

The first line of each test case contains an integer $$$n$$$ $$$(1 \le n \le 200)$$$ — the length of strings $$$s$$$ and $$$t$$$.

The second line contains one string $$$s$$$ of length $$$n$$$.

The third line contains one string $$$t$$$ of length $$$n$$$.

Both strings consist only of lowercase Latin letters.

It is guaranteed that the sum of $$$n^2$$$ over all test cases does not exceed $$$10^5$$$.

Output

For each test case, print the maximal possible value of $$$g(x, y)$$$. Your answer will be considered correct if its relative or absolute error does not exceed $$$10^{-9}$$$.

Example
Input
3
2
as
sa
3
acb
cab
7
qwdasdq
asdqaqw
Output
0.500000000000
0.333333333333
0.428571428571

E. Easy Tree
time limit per test
2 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

Given a tree with $$$n$$$ nodes, each node has a color black or white, and also given $$$q$$$ queries:

  • $$$v$$$ — change the color of node $$$v$$$, from black to white or vice versa.

Let's call a subset of nodes $$$S$$$ connected if for any two nodes $$$(v, u)$$$ from $$$S$$$, all nodes on the path between $$$v$$$ and $$$u$$$ are also in $$$S$$$.

Let's call a subset of nodes $$$S$$$ monochromatic if all nodes from $$$S$$$ have the same color.

After each query, print the number of connected monochromatic subsets (modulo $$$998\,244\,353$$$, obviously).

Input

The first line contains two integers $$$n$$$ and $$$q$$$ $$$(2 \le n \le 2 \times 10^5, 1 \le q \le 2 \times 10^5)$$$ — the size of the tree and the number of queries.

The second line contains $$$n$$$ integers $$$c_1, c_2, \ldots, c_n$$$ $$$(0 \le c_i \le 1)$$$ — initial colors of nodes.

The next $$$n - 1$$$ lines contain two integers $$$v$$$ and $$$u$$$ $$$(1 \le v, u \le n)$$$ — edges of the tree.

The next $$$q$$$ lines contain one integer $$$v$$$ $$$(1 \le v \le n)$$$ — node from the query.

Output

Print $$$q$$$ integers — the number of connected monochromatic subsets modulo $$$998\,244\,353$$$ after each query.

Example
Input
6 5
1 0 0 0 0 1
4 3
4 5
1 2
2 4
4 6
1
2
5
4
2
Output
18
9
7
13
10

F. Easy Game
time limit per test
2 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

You are playing a game on array $$$a_1, a_2, \ldots, a_n$$$. Each turn you will do the following:

  1. Find the minimal index $$$i$$$ with the biggest value $$$a_i$$$.
  2. Delete $$$i$$$. After that, you will have two arrays (possibly empty) $$$a_1, a_2, \ldots, a_{i - 1}$$$ and $$$a_{i + 1}, a_{i+2}, \ldots, a_n$$$.
  3. Choose one of the arrays.
  4. If the chosen array is empty, stop. Otherwise, start again with the chosen array.

You want to finish this game in a minimal number of turns.

Given an array $$$a_1, a_2, \ldots, a_n$$$ of length $$$n$$$ and $$$q$$$ queries of two types:

  • $$$1\ l\ r\ x$$$ — add $$$x$$$ to each $$$a_l, a_{l + 1}, \ldots, a_r$$$.
  • $$$2\ l\ r$$$ — find the minimal number of turns to finish the game on array $$$a_{l}, a_{l + 1}, \ldots, a_r$$$.

Good luck!

Input

The first line contains two integers $$$n$$$ and $$$q$$$ $$$(1 \le n, q \le 10^5)$$$ — the length of the array and the number of queries.

The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ $$$(0 \le a_i \le 10^9)$$$ — initial permutations.

The next $$$q$$$ lines contain descriptions of queries — $$$1\ l\ r\ x$$$ $$$(1 \le l \le r \le n, 0 \le x \le 10^9)$$$ or $$$2\ l\ r$$$ $$$(1 \le l \le r \le n)$$$.

It is guaranteed that there is at least one second-type query.

Output

For each query of the second type, print the minimal number of turns to finish the game.

Example
Input
5 10
1 2 3 1 5
2 1 5
1 1 4 10
2 1 5
1 5 5 6
1 4 5 2
2 1 5
1 2 2 1
2 1 5
1 1 1 2
2 1 5
Output
1
2
2
2
1

G. Easy MIX
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Given an array $$$a$$$ of length $$$n$$$ and constants $$$A$$$, $$$B$$$, $$$C$$$, $$$D$$$.

Let's define the $$$mix$$$ value of an array $$$b_1, b_2, \ldots, b_k$$$ as $$$A \cdot \max(b) + B \cdot \min(b) + C \cdot \text{mex}(b) + D$$$, where:

  • max(b) - the value of the maximum element in $$$b$$$,
  • min(b) - the value of the minimum element in $$$b$$$,
  • mex(b) - the minimum non-negative integer not present in $$$b$$$.

Let's define the $$$mix$$$ value of splitting an array into blocks as the sum of the $$$mix$$$ values of the blocks.

Find the maximum possible $$$mix$$$ value of splitting.

Input

The first line contains one integer $$$T$$$ — the number of test cases.

The first line of each test case contains one integer $$$n$$$ $$$(1 \le n \le 2 \times 10^5)$$$ — length of the array.

The second line contains four integers $$$A, B, C, D$$$ $$$(-10^5 \le A, B, C, D \le 10^5)$$$ — constants for $$$mix$$$ value.

The third line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ $$$(0 \le a_i \le n)$$$ — elements of the array.

It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \times 10^5$$$.

Output

For each test case, output the maximum possible $$$mix$$$ value of splitting.

Example
Input
4
10
-1 0 -1 1
2 4 2 3 0 0 0 1 7 3
10
1 1 0 -1
6 0 1 1 5 1 1 6 2 1
10
0 -2 -3 1
6 3 0 1 4 0 6 9 7 3
10
1 1 -1 0
2 4 3 2 1 6 4 0 1 0
Output
-9
38
-5
44
Note

Splitting of an array is dividing an array into some number of blocks. Every element in the array should be included in exactly one block. Each block should be a contiguous subarray. For example, $$$[1, 2], [3], [4, 5]$$$ is a splitting of the array $$$[1, 2, 3, 4, 5]$$$, and $$$[1, 2], [2]$$$ is not a splitting of the array $$$[2, 2, 1]$$$.

H. Pattern Recognition
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given a positive integer $$$n$$$.

Consider all possible non-empty subsets of the set $$${1, 2, 3, \ldots, n}$$$. For each subset, calculate the product of its elements.

Find the number of distinct products.

Input

The input contains a single integer $$$n$$$ $$$(1 \le n \le 20)$$$.

Output

Print the number of distinct products.

Examples
Input
1
Output
1
Input
2
Output
2
Input
3
Output
4
Input
4
Output
8

I. Is This FWHT?
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Given $$$n$$$ and sequences $$$l_1, l_2, \ldots l_n$$$ and $$$r_1, r_2, \ldots r_n$$$.

Let's call a sequence of non-negative numbers $$$a_1, a_2, \ldots a_n$$$ good if $$$l_i \le a_i \le r_i$$$ and $$$a_1 \oplus a_2 \oplus \ldots \oplus a_n = 0$$$.

Find the number of different good sequences (modulo $$$998\,244\,353$$$, obviously).

Input

The first line contains one integer $$$n$$$ $$$(1 \le n \le 30)$$$ — length of the sequence.

The next $$$n$$$ lines contain two integers $$$l_i, r_i$$$ ($$$0 \le l_i \le r_i \le 2^{60} - 1$$$) — elements of the sequence.

Output

Print the answer.

Examples
Input
2
1 100
50 150
Output
51
Input
5
3 938
354 916
557 932
778 991
411 998
Output
35553823
Note

$$$a \oplus b$$$ is a well-known bitwise operation called XOR. For example, $$$5 \oplus 7 = 2$$$, $$$1 \oplus 2 = 3$$$, $$$6 \oplus 3 = 5$$$.

J. Construct Permutation
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Given an array $$$a$$$ of length $$$n$$$ and constants $$$A$$$, $$$B$$$.

Let's call an array good if for each $$$i$$$ $$$(1 \le i \lt n)$$$, at least one of the conditions $$$a_i + a_{i + 1} = A$$$ or $$$a_i - a_{i + 1} = B$$$ holds true.

Construct a good permutation of the array $$$a$$$.

Input

The first line contains one integer $$$T$$$ $$$(1 \le t \le 2 \times 10^5)$$$ — the number of test cases.

The first line of each test case contains one integer $$$n$$$ $$$(1 \le n \le 2 \times 10^5)$$$ — length of the array.

The second line contains two integers $$$A, B$$$ $$$(-10^9 \le A, B \le 10^9)$$$ — constants.

The third line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ $$$(-10^9 \le a_i \le 10^9)$$$ — elements of the array.

It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \times 10^5$$$.

Output

For each test case, output "NO" if it is not possible to construct such a permutation.

Otherwise, output in the first line "YES", and then provide the required permutation.

In the only line output $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ — a good permutation of $$$a$$$.

Example
Input
4
10
1 2
-1 2 0 1 -1 2 -1 -3 4 2
5
0 0
2 2 -2 -2 2
5
0 -4
2 2 -2 -2 2
5
4 0
2 2 -2 -2 2
Output
YES
4 2 -1 2 -1 2 0 1 -1 -3
YES
2 -2 -2 2 2
YES
2 -2 2 -2 2
NO

K. Construct Matching
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

"Given a complete bipartite graph with $$$n$$$ vertices on the left part and $$$m$$$ vertices on the right part, where each edge is colored with one of $$$k$$$ colors. Determine the maximum matching for each color separately."

Now, the reverse task. Constructing a complete bipartite graph with $$$n$$$ and $$$m$$$ vertices on the left and right parts respectively, and assigning colors to edges in such a way that the maximum matching for each color corresponds to the given values $$$c_1, c_2, \ldots, c_k$$$.

Input

The first line contains one integer $$$T$$$ $$$(1 \le T \le 10^4)$$$ — the number of test cases.

The first line of each test case contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ $$$(1 \le n, m \le 100, 1 \le k \le n \cdot m)$$$ — the number of vertices on the left and right parts respectively and the number of colors.

The second line contains $$$k$$$ integers $$$c_1, c_2, \ldots, c_k$$$ $$$(1 \le c_i \le 10 ^ 9)$$$ — the maximum matching for each color.

It is guaranteed that the sum of $$$n \cdot m$$$ over all test cases does not exceed $$$10^4$$$.

Output

For each test case, output "NO" if it is not possible to construct such a graph.

Otherwise, output in the first line "YES", and then provide the required graph.

In each of the first $$$n$$$ lines of graph description, output $$$m$$$ integers. The $$$j$$$-th integer in the $$$i$$$-th line denotes the color of the edge between nodes $$$i$$$ on the left part and $$$j$$$ on the right part.

Example
Input
5
1 2 2
1 1
3 3 9
1 1 1 1 1 1 1 1 1
3 3 2
10 10
3 3 1
3
2 2 3
1 2 1
Output
YES
1 2 
YES
1 4 7 
8 2 5 
6 9 3 
NO
YES
1 1 1 
1 1 1 
1 1 1 
YES
2 1 
3 2