Find the number of connected labeled simple graphs with $$$n$$$ vertices and $$$m$$$ edges (modulo $$$998\,244\,353$$$, obviously).
The only line contains two integers $$$n$$$, $$$m$$$ ($$$1 \le n \le 10 ^ 5$$$, $$$0 \le m \le n + 50$$$).
Print one integer — the answer to the problem modulo $$$998\,244\,353$$$.
10 9
100000000
4 5
6
5 3
0
3 10
0
100000 100050
526410635
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.
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).
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)$$$.
Print one integer — the answer to the problem modulo $$$998\,244\,353$$$.
2 22 0
10
10 516 31 16 18 7 17 31 26 7 21
840
2 50383198634384164 901251460473164
400397424
$$$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$$$).
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?
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 the minimal number of operations required to make the array powerful.
48 1 1 32
0
46 7 46 343
4
32 253 59149
111
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)$$$.
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$$$.
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}$$$.
32assa3acbcab7qwdasdqasdqaqw
0.500000000000 0.333333333333 0.428571428571
Given a tree with $$$n$$$ nodes, each node has a color black or white, and also given $$$q$$$ queries:
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).
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.
Print $$$q$$$ integers — the number of connected monochromatic subsets modulo $$$998\,244\,353$$$ after each query.
6 51 0 0 0 0 14 34 51 22 44 612542
18 9 7 13 10
You are playing a game on array $$$a_1, a_2, \ldots, a_n$$$. Each turn you will do the following:
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:
Good luck!
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.
For each query of the second type, print the minimal number of turns to finish the game.
5 101 2 3 1 52 1 51 1 4 102 1 51 5 5 61 4 5 22 1 51 2 2 12 1 51 1 1 22 1 5
1 2 2 2 1
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:
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.
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$$$.
For each test case, output the maximum possible $$$mix$$$ value of splitting.
410-1 0 -1 12 4 2 3 0 0 0 1 7 3101 1 0 -16 0 1 1 5 1 1 6 2 1100 -2 -3 16 3 0 1 4 0 6 9 7 3101 1 -1 02 4 3 2 1 6 4 0 1 0
-9 38 -5 44
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]$$$.
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.
The input contains a single integer $$$n$$$ $$$(1 \le n \le 20)$$$.
Print the number of distinct products.
1
1
2
2
3
4
4
8
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).
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.
Print the answer.
21 10050 150
51
53 938354 916557 932778 991411 998
35553823
$$$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$$$.
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$$$.
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$$$.
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$$$.
4101 2-1 2 0 1 -1 2 -1 -3 4 250 02 2 -2 -2 250 -42 2 -2 -2 254 02 2 -2 -2 2
YES 4 2 -1 2 -1 2 0 1 -1 -3 YES 2 -2 -2 2 2 YES 2 -2 2 -2 2 NO
"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$$$.
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$$$.
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.
51 2 21 13 3 91 1 1 1 1 1 1 1 13 3 210 103 3 132 2 31 2 1
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