You have two integers $$$l$$$ and $$$r$$$. Find an integer $$$x$$$ which satisfies the conditions below:
If there are multiple answers, print any of them.
The first line contains two integers $$$l$$$ and $$$r$$$ ($$$1 \le l \le r \le 10^{5}$$$).
If an answer exists, print any of them. Otherwise, print $$$-1$$$.
121 130
123
98766 100000
-1
In the first example, $$$123$$$ is one of the possible answers. However, $$$121$$$ can't be the answer, because there are multiple $$$1$$$s on different digits.
In the second example, there is no valid answer.
Suppose there is a $$$h \times w$$$ grid consisting of empty or full cells. Let's make some definitions:
In other words, the $$$i$$$-th row starts exactly with $$$r_i$$$ full cells. Similarly, the $$$j$$$-th column starts exactly with $$$c_j$$$ full cells.
These are the $$$r$$$ and $$$c$$$ values of some $$$3 \times 4$$$ grid. Black cells are full and white cells are empty. You have values of $$$r$$$ and $$$c$$$. Initially, all cells are empty. Find the number of ways to fill grid cells to satisfy values of $$$r$$$ and $$$c$$$. Since the answer can be very large, find the answer modulo $$$1000000007\,(10^{9} + 7)$$$. In other words, find the remainder after division of the answer by $$$1000000007\,(10^{9} + 7)$$$.
The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h, w \le 10^{3}$$$) — the height and width of the grid.
The second line contains $$$h$$$ integers $$$r_{1}, r_{2}, \ldots, r_{h}$$$ ($$$0 \le r_{i} \le w$$$) — the values of $$$r$$$.
The third line contains $$$w$$$ integers $$$c_{1}, c_{2}, \ldots, c_{w}$$$ ($$$0 \le c_{j} \le h$$$) — the values of $$$c$$$.
Print the answer modulo $$$1000000007\,(10^{9} + 7)$$$.
3 4 0 3 1 0 2 3 0
2
1 1 0 1
0
19 16 16 16 16 16 15 15 0 5 0 4 9 9 1 4 4 0 8 16 12 6 12 19 15 8 6 19 19 14 6 9 16 10 11 15 4
797922655
In the first example, this is the other possible case.
In the second example, it's impossible to make a grid to satisfy such $$$r$$$, $$$c$$$ values.
In the third example, make sure to print answer modulo $$$(10^9 + 7)$$$.
Let's introduce some definitions that will be needed later.
Let $$$prime(x)$$$ be the set of prime divisors of $$$x$$$. For example, $$$prime(140) = \{ 2, 5, 7 \}$$$, $$$prime(169) = \{ 13 \}$$$.
Let $$$g(x, p)$$$ be the maximum possible integer $$$p^k$$$ where $$$k$$$ is an integer such that $$$x$$$ is divisible by $$$p^k$$$. For example:
Let $$$f(x, y)$$$ be the product of $$$g(y, p)$$$ for all $$$p$$$ in $$$prime(x)$$$. For example:
You have integers $$$x$$$ and $$$n$$$. Calculate $$$f(x, 1) \cdot f(x, 2) \cdot \ldots \cdot f(x, n) \bmod{(10^{9} + 7)}$$$.
The only line contains integers $$$x$$$ and $$$n$$$ ($$$2 \le x \le 10^{9}$$$, $$$1 \le n \le 10^{18}$$$) — the numbers used in formula.
Print the answer.
10 2
2
20190929 1605
363165664
947 987654321987654321
593574252
In the first example, $$$f(10, 1) = g(1, 2) \cdot g(1, 5) = 1$$$, $$$f(10, 2) = g(2, 2) \cdot g(2, 5) = 2$$$.
In the second example, actual value of formula is approximately $$$1.597 \cdot 10^{171}$$$. Make sure you print the answer modulo $$$(10^{9} + 7)$$$.
In the third example, be careful about overflow issue.
You have a simple undirected graph consisting of $$$n$$$ vertices and $$$m$$$ edges. The graph doesn't contain self-loops, there is at most one edge between a pair of vertices. The given graph can be disconnected.
Let's make a definition.
Let $$$v_1$$$ and $$$v_2$$$ be two some nonempty subsets of vertices that do not intersect. Let $$$f(v_{1}, v_{2})$$$ be true if and only if all the conditions are satisfied:
Create three vertex sets ($$$v_{1}$$$, $$$v_{2}$$$, $$$v_{3}$$$) which satisfy the conditions below;
Is it possible to create such three vertex sets? If it's possible, print matching vertex set for each vertex.
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$3 \le n \le 10^{5}$$$, $$$0 \le m \le \text{min}(3 \cdot 10^{5}, \frac{n(n-1)}{2})$$$) — the number of vertices and edges in the graph.
The $$$i$$$-th of the next $$$m$$$ lines contains two integers $$$a_{i}$$$ and $$$b_{i}$$$ ($$$1 \le a_{i} \lt b_{i} \le n$$$) — it means there is an edge between $$$a_{i}$$$ and $$$b_{i}$$$. The graph doesn't contain self-loops, there is at most one edge between a pair of vertices. The given graph can be disconnected.
If the answer exists, print $$$n$$$ integers. $$$i$$$-th integer means the vertex set number (from $$$1$$$ to $$$3$$$) of $$$i$$$-th vertex. Otherwise, print $$$-1$$$.
If there are multiple answers, print any.
6 11 1 2 1 3 1 4 1 5 1 6 2 4 2 5 2 6 3 4 3 5 3 6
1 2 2 3 3 3
4 6 1 2 1 3 1 4 2 3 2 4 3 4
-1
In the first example, if $$$v_{1} = \{ 1 \}$$$, $$$v_{2} = \{ 2, 3 \}$$$, and $$$v_{3} = \{ 4, 5, 6 \}$$$ then vertex sets will satisfy all conditions. But you can assign vertices to vertex sets in a different way; Other answers like "2 3 3 1 1 1" will be accepted as well.
In the second example, it's impossible to make such vertex sets.
You have $$$n \times n$$$ square grid and an integer $$$k$$$. Put an integer in each cell while satisfying the conditions below.
Find the number of ways to put integers in the grid. Since the answer can be very large, find the answer modulo $$$(10^{9} + 7)$$$.
These are the examples of valid and invalid grid when $$$n=k=2$$$. The only line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 250$$$, $$$1 \le k \le 10^{9}$$$).
Print the answer modulo $$$(10^{9} + 7)$$$.
2 2
7
123 456789
689974806
In the first example, following $$$7$$$ cases are possible.
In the second example, make sure you print the answer modulo $$$(10^{9} + 7)$$$.
You have an integer $$$n$$$. Let's define following tree generation as McDic's generation:
You have a tree. Determine if this tree can be made by McDic's generation. If yes, then find the parent vertex of removed vertex in tree.
The first line contains integer $$$n$$$ ($$$2 \le n \le 17$$$).
The $$$i$$$-th of the next $$$2^{n} - 3$$$ lines contains two integers $$$a_{i}$$$ and $$$b_{i}$$$ ($$$1 \le a_{i} \lt b_{i} \le 2^{n} - 2$$$) — meaning there is an edge between $$$a_{i}$$$ and $$$b_{i}$$$. It is guaranteed that the given edges form a tree.
Print two lines.
In the first line, print a single integer — the number of answers. If given tree cannot be made by McDic's generation, then print $$$0$$$.
In the second line, print all possible answers in ascending order, separated by spaces. If the given tree cannot be made by McDic's generation, then don't print anything.
4 1 2 1 3 2 4 2 5 3 6 3 13 3 14 4 7 4 8 5 9 5 10 6 11 6 12
1 3
2 1 2
2 1 2
3 1 2 2 3 3 4 4 5 5 6
0
In the first example, $$$3$$$ is the only possible answer.
In the second example, there are $$$2$$$ possible answers.
In the third example, the tree can't be generated by McDic's generation.