Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter.Their algorithm will be tested on an array of integers, where the $$$i$$$-th integer represents the color of the $$$i$$$-th pixel in the image. The image is in black and white, therefore the color of each pixel will be an integer between 0 and 255 (inclusive).To implement the filter, students are required to divide the black and white color range [0, 255] into groups of consecutive colors, and select one color in each group to be the group’s key. In order to preserve image details, the size of a group must not be greater than $$$k$$$, and each color should belong to exactly one group.Finally, the students will replace the color of each pixel in the array with that color’s assigned group key.To better understand the effect, here is an image of a basking turtle where the Posterization Filter was applied with increasing $$$k$$$ to the right.   To make the process of checking the final answer easier, Professor Ibrahim wants students to divide the groups and assign the keys in a way that produces the lexicographically smallest possible array.

The first line of input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 10^5$$$, $$$1 \leq k \leq 256$$$), the number of pixels in the image, and the maximum size of a group, respectively. The second line contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$0 \leq p_i \leq 255$$$), where $$$p_i$$$ is the color of the $$$i$$$-th pixel.

Print $$$n$$$ space-separated integers; the lexicographically smallest possible array that represents the image after applying the Posterization filter.

NoteOne possible way to group colors and assign keys for the first sample:Color $$$2$$$ belongs to the group $$$[0,2]$$$, with group key $$$0$$$.Color $$$14$$$ belongs to the group $$$[12,14]$$$, with group key $$$12$$$.Colors $$$3$$$ and $$$4$$$ belong to group $$$[3, 5]$$$, with group key $$$3$$$.Other groups won't affect the result so they are not listed here.


The city of Fishtopia can be imagined as a grid of $$$4$$$ rows and an odd number of columns. It has two main villages; the first is located at the top-left cell $$$(1,1)$$$, people who stay there love fishing at the Tuna pond at the bottom-right cell $$$(4, n)$$$. The second village is located at $$$(4, 1)$$$ and its people love the Salmon pond at $$$(1, n)$$$.The mayor of Fishtopia wants to place $$$k$$$ hotels in the city, each one occupying one cell. To allow people to enter the city from anywhere, hotels should not be placed on the border cells.A person can move from one cell to another if those cells are not occupied by hotels and share a side.Can you help the mayor place the hotels in a way such that there are equal number of shortest paths from each village to its preferred pond?

The first line of input contain two integers, $$$n$$$ and $$$k$$$ ($$$3 \leq n \leq 99$$$, $$$0 \leq k \leq 2\times(n-2)$$$), $$$n$$$ is odd, the width of the city, and the number of hotels to be placed, respectively.

Print "YES", if it is possible to place all the hotels in a way that satisfies the problem statement, otherwise print "NO". If it is possible, print an extra $$$4$$$ lines that describe the city, each line should have $$$n$$$ characters, each of which is "#" if that cell has a hotel on it, or "." if not.


SaMer has written the greatest test case of all time for one of his problems. For a given array of integers, the problem asks to find the minimum number of groups the array can be divided into, such that the product of any pair of integers in the same group is a perfect square. Each integer must be in exactly one group. However, integers in a group do not necessarily have to be contiguous in the array.SaMer wishes to create more cases from the test case he already has. His test case has an array $$$A$$$ of $$$n$$$ integers, and he needs to find the number of contiguous subarrays of $$$A$$$ that have an answer to the problem equal to $$$k$$$ for each integer $$$k$$$ between $$$1$$$ and $$$n$$$ (inclusive).

The first line of input contains a single integer $$$n$$$ ($$$1 \leq n \leq 5000$$$), the size of the array. The second line contains $$$n$$$ integers $$$a_1$$$,$$$a_2$$$,$$$\dots$$$,$$$a_n$$$ ($$$-10^8 \leq a_i \leq 10^8$$$), the values of the array.

Output $$$n$$$ space-separated integers, the $$$k$$$-th integer should be the number of contiguous subarrays of $$$A$$$ that have an answer to the problem equal to $$$k$$$.


The nation of Panel holds an annual show called The Number Games, where each district in the nation will be represented by one contestant.The nation has $$$n$$$ districts numbered from $$$1$$$ to $$$n$$$, each district has exactly one path connecting it to every other district. The number of fans of a contestant from district $$$i$$$ is equal to $$$2^i$$$.This year, the president decided to reduce the costs. He wants to remove $$$k$$$ contestants from the games. However, the districts of the removed contestants will be furious and will not allow anyone to cross through their districts. The president wants to ensure that all remaining contestants are from districts that can be reached from one another. He also wishes to maximize the total number of fans of the participating contestants.Which contestants should the president remove?

The first line of input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \leq k < n \leq 10^6$$$) — the number of districts in Panel, and the number of contestants the president wishes to remove, respectively. The next $$$n-1$$$ lines each contains two integers $$$a$$$ and $$$b$$$ ($$$1 \leq a, b \leq n$$$, $$$a \ne b$$$), that describe a road that connects two different districts $$$a$$$ and $$$b$$$ in the nation. It is guaranteed that there is exactly one path between every two districts.

Print $$$k$$$ space-separated integers: the numbers of the districts of which the contestants should be removed, in increasing order of district number.

NoteIn the first sample, the maximum possible total number of fans is $$$2^2 + 2^5 + 2^6 = 100$$$. We can achieve it by removing the contestants of the districts 1, 3, and 4.


You are given a special connected undirected graph where each vertex belongs to at most one simple cycle.Your task is to remove as many edges as needed to convert this graph into a tree (connected graph with no cycles). For each node, independently, output the maximum distance between it and a leaf in the resulting tree, assuming you were to remove the edges in a way that minimizes this distance.

The first line of input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n \leq 5\cdot 10^5$$$), the number of nodes and the number of edges, respectively. Each of the following $$$m$$$ lines contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u,v \leq n$$$, $$$u \ne v$$$), and represents an edge connecting the two nodes $$$u$$$ and $$$v$$$. Each pair of nodes is connected by at most one edge. It is guaranteed that the given graph is connected and each vertex belongs to at most one simple cycle.

Print $$$n$$$ space-separated integers, the $$$i$$$-th integer represents the maximum distance between node $$$i$$$ and a leaf if the removed edges were chosen in a way that minimizes this distance.

NoteIn the first sample, a possible way to minimize the maximum distance from vertex $$$1$$$ is by removing the marked edges in the following image:  Note that to minimize the answer for different nodes, you can remove different edges.


Katie, Kuro and Shiro are best friends. They have known each other since kindergarten. That's why they often share everything with each other and work together on some very hard problems.Today is Shiro's birthday. She really loves pizza so she wants to invite her friends to the pizza restaurant near her house to celebrate her birthday, including her best friends Katie and Kuro.She has ordered a very big round pizza, in order to serve her many friends. Exactly $$$n$$$ of Shiro's friends are here. That's why she has to divide the pizza into $$$n + 1$$$ slices (Shiro also needs to eat). She wants the slices to be exactly the same size and shape. If not, some of her friends will get mad and go home early, and the party will be over.Shiro is now hungry. She wants to cut the pizza with minimum of straight cuts. A cut is a straight segment, it might have ends inside or outside the pizza. But she is too lazy to pick up the calculator.As usual, she will ask Katie and Kuro for help. But they haven't come yet. Could you help Shiro with this problem?

A single line contains one non-negative integer $$$n$$$ ($$$0 \le n \leq 10^{18}$$$) — the number of Shiro's friends. The circular pizza has to be sliced into $$$n + 1$$$ pieces.

A single integer — the number of straight cuts Shiro needs.

NoteTo cut the round pizza into quarters one has to make two cuts through the center with angle $$$90^{\circ}$$$ between them.To cut the round pizza into five equal parts one has to make five cuts.


Two famous competing companies ChemForces and TopChemist decided to show their sets of recently discovered chemical elements on an exhibition. However they know that no element should be present in the sets of both companies.In order to avoid this representatives of both companies decided to make an agreement on the sets the companies should present. The sets should be chosen in the way that maximizes the total income of the companies.All elements are enumerated with integers. The ChemForces company has discovered $$$n$$$ distinct chemical elements with indices $$$a_1, a_2, \ldots, a_n$$$, and will get an income of $$$x_i$$$ Berland rubles if the $$$i$$$-th element from this list is in the set of this company.The TopChemist company discovered $$$m$$$ distinct chemical elements with indices $$$b_1, b_2, \ldots, b_m$$$, and it will get an income of $$$y_j$$$ Berland rubles for including the $$$j$$$-th element from this list to its set.In other words, the first company can present any subset of elements from $$$\{a_1, a_2, \ldots, a_n\}$$$ (possibly empty subset), the second company can present any subset of elements from $$$\{b_1, b_2, \ldots, b_m\}$$$ (possibly empty subset). There shouldn't be equal elements in the subsets.Help the representatives select the sets in such a way that no element is presented in both sets and the total income is the maximum possible.

The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$)  — the number of elements discovered by ChemForces. The $$$i$$$-th of the next $$$n$$$ lines contains two integers $$$a_i$$$ and $$$x_i$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$1 \leq x_i \leq 10^9$$$)  — the index of the $$$i$$$-th element and the income of its usage on the exhibition. It is guaranteed that all $$$a_i$$$ are distinct. The next line contains a single integer $$$m$$$ ($$$1 \leq m \leq 10^5$$$)  — the number of chemicals invented by TopChemist. The $$$j$$$-th of the next $$$m$$$ lines contains two integers $$$b_j$$$ and $$$y_j$$$, ($$$1 \leq b_j \leq 10^9$$$, $$$1 \leq y_j \leq 10^9$$$)  — the index of the $$$j$$$-th element and the income of its usage on the exhibition. It is guaranteed that all $$$b_j$$$ are distinct.

Print the maximum total income you can obtain by choosing the sets for both companies in such a way that no element is presented in both sets.

NoteIn the first example ChemForces can choose the set ($$$3, 7$$$), while TopChemist can choose ($$$1, 2, 4$$$). This way the total income is $$$(10 + 2) + (4 + 4 + 4) = 24$$$.In the second example ChemForces can choose the only element $$$10^9$$$, while TopChemist can choose ($$$14, 92, 35$$$). This way the total income is $$$(239) + (15 + 65 + 89) = 408$$$.


Ramesses knows a lot about problems involving trees (undirected connected graphs without cycles)!He created a new useful tree decomposition, but he does not know how to construct it, so he asked you for help!The decomposition is the splitting the edges of the tree in some simple paths in such a way that each two paths have at least one common vertex. Each edge of the tree should be in exactly one path.Help Remesses, find such a decomposition of the tree or derermine that there is no such decomposition.

The first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 10^{5}$$$) the number of nodes in the tree. Each of the next $$$n - 1$$$ lines contains two integers $$$a_i$$$ and $$$b_i$$$ ($$$1 \leq a_i, b_i \leq n$$$, $$$a_i \neq b_i$$$) — the edges of the tree. It is guaranteed that the given edges form a tree.

If there are no decompositions, print the only line containing "No". Otherwise in the first line print "Yes", and in the second line print the number of paths in the decomposition $$$m$$$.  Each of the next $$$m$$$ lines should contain two integers $$$u_i$$$, $$$v_i$$$ ($$$1 \leq u_i, v_i \leq n$$$, $$$u_i \neq v_i$$$) denoting that one of the paths in the decomposition is the simple path between nodes $$$u_i$$$ and $$$v_i$$$.  Each pair of paths in the decomposition should have at least one common vertex, and each edge of the tree should be presented in exactly one path. You can print the paths and the ends of each path in arbitrary order. If there are multiple decompositions, print any.

NoteThe tree from the first example is shown on the picture below:  The number next to each edge corresponds to the path number in the decomposition. It is easy to see that this decomposition suits the required conditions.The tree from the second example is shown on the picture below:  We can show that there are no valid decompositions of this tree.The tree from the third example is shown on the picture below:  The number next to each edge corresponds to the path number in the decomposition. It is easy to see that this decomposition suits the required conditions.


A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" are not.A substring $$$s[l \ldots r]$$$ ($$$1 \leq l \leq r \leq |s|$$$) of a string $$$s = s_{1}s_{2} \ldots s_{|s|}$$$ is the string $$$s_{l}s_{l + 1} \ldots s_{r}$$$.Anna does not like palindromes, so she makes her friends call her Ann. She also changes all the words she reads in a similar way. Namely, each word $$$s$$$ is changed into its longest substring that is not a palindrome. If all the substrings of $$$s$$$ are palindromes, she skips the word at all.Some time ago Ann read the word $$$s$$$. What is the word she changed it into?

The first line contains a non-empty string $$$s$$$ with length at most $$$50$$$ characters, containing lowercase English letters only.

If there is such a substring in $$$s$$$ that is not a palindrome, print the maximum length of such a substring. Otherwise print $$$0$$$. Note that there can be multiple longest substrings that are not palindromes, but their length is unique.

Note"mew" is not a palindrome, so the longest substring of it that is not a palindrome, is the string "mew" itself. Thus, the answer for the first example is $$$3$$$.The string "uffuw" is one of the longest non-palindrome substrings (of length $$$5$$$) of the string "wuffuw", so the answer for the second example is $$$5$$$.All substrings of the string "qqqqqqqq" consist of equal characters so they are palindromes. This way, there are no non-palindrome substrings. Thus, the answer for the third example is $$$0$$$.


It's marriage season in Ringland!Ringland has a form of a circle's boundary of length $$$L$$$. There are $$$n$$$ bridegrooms and $$$n$$$ brides, and bridegrooms decided to marry brides.Of course, each bridegroom should choose exactly one bride, and each bride should be chosen by exactly one bridegroom.All objects in Ringland are located on the boundary of the circle, including the capital, bridegrooms' castles and brides' palaces. The castle of the $$$i$$$-th bridegroom is located at the distance $$$a_i$$$ from the capital in clockwise direction, and the palace of the $$$i$$$-th bride is located at the distance $$$b_i$$$ from the capital in clockwise direction.Let's define the inconvenience of a marriage the maximum distance that some bride should walk along the circle from her palace to her bridegroom's castle in the shortest direction (in clockwise or counter-clockwise direction).Help the bridegrooms of Ringland to choose brides in such a way that the inconvenience of the marriage is the smallest possible.

The first line contains two integers $$$n$$$ and $$$L$$$ ($$$1 \leq n \leq 2 \cdot 10^{5}$$$, $$$1 \leq L \leq 10^{9}$$$) — the number of bridegrooms and brides and the length of Ringland. The next line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i < L$$$) — the distances from the capital to the castles of bridegrooms in clockwise direction. The next line contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$0 \leq b_i < L$$$) — the distances from the capital to the palaces of brides in clockwise direction.

In the only line print the smallest possible inconvenience of the wedding, where the inconvenience is the largest distance traveled by a bride.

NoteIn the first example the first bridegroom should marry the second bride, the second bridegroom should marry the first bride. This way, the second bride should walk the distance of $$$1$$$, and the first bride should also walk the same distance. Thus, the inconvenience is equal to $$$1$$$.In the second example let $$$p_i$$$ be the bride the $$$i$$$-th bridegroom will marry. One of optimal $$$p$$$ is the following: $$$(6,8,1,4,5,10,3,2,7,9)$$$.


Grisha come to a contest and faced the following problem.You are given an array of size $$$n$$$, initially consisting of zeros. The elements of the array are enumerated from $$$1$$$ to $$$n$$$. You perform $$$q$$$ operations on the array. The $$$i$$$-th operation is described with three integers $$$l_i$$$, $$$r_i$$$ and $$$x_i$$$ ($$$1 \leq l_i \leq r_i \leq n$$$, $$$1 \leq x_i \leq n$$$) and means that you should add $$$x_i$$$ to each of the elements with indices $$$l_i, l_i + 1, \ldots, r_i$$$. After all operations you should find the maximum in the array.Grisha is clever, so he solved the problem quickly.However something went wrong inside his head and now he thinks of the following question: "consider we applied some subset of the operations to the array. What are the possible values of the maximum in the array?"Help Grisha, find all integers $$$y$$$ between $$$1$$$ and $$$n$$$ such that if you apply some subset (possibly empty) of the operations, then the maximum in the array becomes equal to $$$y$$$.

The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \leq n, q \leq 10^{4}$$$) — the length of the array and the number of queries in the initial problem. The following $$$q$$$ lines contain queries, one per line. The $$$i$$$-th of these lines contains three integers $$$l_i$$$, $$$r_i$$$ and $$$x_i$$$ ($$$1 \leq l_i \leq r_i \leq n$$$, $$$1 \leq x_i \leq n$$$), denoting a query of adding $$$x_i$$$ to the segment from $$$l_i$$$-th to $$$r_i$$$-th elements of the array, inclusive.

In the first line print the only integer $$$k$$$, denoting the number of integers from $$$1$$$ to $$$n$$$, inclusive, that can be equal to the maximum in the array after applying some subset (possibly empty) of the given operations. In the next line print these $$$k$$$ integers from $$$1$$$ to $$$n$$$ — the possible values of the maximum. Print these integers in increasing order.

NoteConsider the first example. If you consider the subset only of the first query, the maximum is equal to $$$1$$$. If you take only the second query, the maximum equals to $$$2$$$. If you take the first two queries, the maximum becomes $$$3$$$. If you take only the fourth query, the maximum becomes $$$4$$$. If you take the fourth query and something more, the maximum becomes greater that $$$n$$$, so you shouldn't print it.In the second example you can take the first query to obtain $$$1$$$. You can take only the second query to obtain $$$2$$$. You can take all queries to obtain $$$3$$$.In the third example you can obtain the following maximums:  You can achieve the maximim of $$$2$$$ by using queries: $$$(1)$$$.  You can achieve the maximim of $$$3$$$ by using queries: $$$(2)$$$.  You can achieve the maximim of $$$5$$$ by using queries: $$$(1, 2)$$$.  You can achieve the maximim of $$$6$$$ by using queries: $$$(3)$$$.  You can achieve the maximim of $$$8$$$ by using queries: $$$(1, 3)$$$.  You can achieve the maximim of $$$9$$$ by using queries: $$$(2, 3)$$$.


In the School of Magic in Dirtpolis a lot of interesting objects are studied on Computer Science lessons.Consider, for example, the magic multiset. If you try to add an integer to it that is already presented in the multiset, each element in the multiset duplicates. For example, if you try to add the integer $$$2$$$ to the multiset $$$\{1, 2, 3, 3\}$$$, you will get $$$\{1, 1, 2, 2, 3, 3, 3, 3\}$$$. If you try to add an integer that is not presented in the multiset, it is simply added to it. For example, if you try to add the integer $$$4$$$ to the multiset $$$\{1, 2, 3, 3\}$$$, you will get $$$\{1, 2, 3, 3, 4\}$$$.Also consider an array of $$$n$$$ initially empty magic multisets, enumerated from $$$1$$$ to $$$n$$$.You are to answer $$$q$$$ queries of the form "add an integer $$$x$$$ to all multisets with indices $$$l, l + 1, \ldots, r$$$" and "compute the sum of sizes of multisets with indices $$$l, l + 1, \ldots, r$$$". The answers for the second type queries can be large, so print the answers modulo $$$998244353$$$.

The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \leq n, q \leq 2 \cdot 10^{5}$$$) — the number of magic multisets in the array and the number of queries, respectively. The next $$$q$$$ lines describe queries, one per line. Each line starts with an integer $$$t$$$ ($$$1 \leq t \leq 2$$$) — the type of the query. If $$$t$$$ equals $$$1$$$, it is followed by three integers $$$l$$$, $$$r$$$, $$$x$$$ ($$$1 \leq l \leq r \leq n$$$, $$$1 \leq x \leq n$$$) meaning that you should add $$$x$$$ to all multisets with indices from $$$l$$$ to $$$r$$$ inclusive. If $$$t$$$ equals $$$2$$$, it is followed by two integers $$$l$$$, $$$r$$$ ($$$1 \leq l \leq r \leq n$$$) meaning that you should compute the sum of sizes of all multisets with indices from $$$l$$$ to $$$r$$$ inclusive.

For each query of the second type print the sum of sizes of multisets on the given segment. The answers can be large, so print them modulo $$$998244353$$$.

NoteIn the first example after the first two queries the multisets are equal to $$$[\{1, 2\},\{1, 2\},\{\},\{\}]$$$, after the third query they are equal to $$$[\{1, 1, 2, 2\},\{1, 1, 2, 2\},\{1\},\{1\}]$$$.In the second example the first multiset evolves as follows: $$$\{\} \to \{3\} \to \{3, 3\} \to \{2, 3, 3\} \to \{1, 2, 3, 3\} \to \{1, 1, 2, 2, 3, 3, 3, 3\}$$$.


Mr Keks is a typical white-collar in Byteland.He has a bookshelf in his office with some books on it, each book has an integer positive price.Mr Keks defines the value of a shelf as the sum of books prices on it. Miraculously, Mr Keks was promoted and now he is moving into a new office.He learned that in the new office he will have not a single bookshelf, but exactly $$$k$$$ bookshelves. He decided that the beauty of the $$$k$$$ shelves is the bitwise AND of the values of all the shelves.He also decided that he won't spend time on reordering the books, so he will place several first books on the first shelf, several next books on the next shelf and so on. Of course, he will place at least one book on each shelf. This way he will put all his books on $$$k$$$ shelves in such a way that the beauty of the shelves is as large as possible. Compute this maximum possible beauty.

The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \leq k \leq n \leq 50$$$) — the number of books and the number of shelves in the new office. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots a_n$$$, ($$$0 < a_i < 2^{50}$$$) — the prices of the books in the order they stand on the old shelf.

Print the maximum possible beauty of $$$k$$$ shelves in the new office.


You are given a tree of $$$n$$$ vertices. You are to select $$$k$$$ (not necessarily distinct) simple paths in such a way that it is possible to split all edges of the tree into three sets: edges not contained in any path, edges that are a part of exactly one of these paths, and edges that are parts of all selected paths, and the latter set should be non-empty.Compute the number of ways to select $$$k$$$ paths modulo $$$998244353$$$.The paths are enumerated, in other words, two ways are considered distinct if there are such $$$i$$$ ($$$1 \leq i \leq k$$$) and an edge that the $$$i$$$-th path contains the edge in one way and does not contain it in the other.

The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n, k \leq 10^{5}$$$) — the number of vertices in the tree and the desired number of paths. The next $$$n - 1$$$ lines describe edges of the tree. Each line contains two integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le n$$$, $$$a \ne b$$$) — the endpoints of an edge. It is guaranteed that the given edges form a tree.

Print the number of ways to select $$$k$$$ enumerated not necessarily distinct simple paths in such a way that for each edge either it is not contained in any path, or it is contained in exactly one path, or it is contained in all $$$k$$$ paths, and the intersection of all paths is non-empty.  As the answer can be large, print it modulo $$$998244353$$$.


You're given a row with $$$n$$$ chairs. We call a seating of people "maximal" if the two following conditions hold:  There are no neighbors adjacent to anyone seated.  It's impossible to seat one more person without violating the first rule. The seating is given as a string consisting of zeros and ones ($$$0$$$ means that the corresponding seat is empty, $$$1$$$ — occupied). The goal is to determine whether this seating is "maximal".Note that the first and last seats are not adjacent (if $$$n \ne 2$$$).

The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of chairs. The next line contains a string of $$$n$$$ characters, each of them is either zero or one, describing the seating.

Output "Yes" (without quotation marks) if the seating is "maximal". Otherwise print "No". You are allowed to print letters in whatever case you'd like (uppercase or lowercase).

NoteIn sample case one the given seating is maximal.In sample case two the person at chair three has a neighbour to the right.In sample case three it is possible to seat yet another person into chair three.


You're given a tree with $$$n$$$ vertices.Your task is to determine the maximum possible number of edges that can be removed in such a way that all the remaining connected components will have even size.

The first line contains an integer $$$n$$$ ($$$1 \le n \le 10^5$$$) denoting the size of the tree.  The next $$$n - 1$$$ lines contain two integers $$$u$$$, $$$v$$$ ($$$1 \le u, v \le n$$$) each, describing the vertices connected by the $$$i$$$-th edge. It's guaranteed that the given edges form a tree.

Output a single integer $$$k$$$ — the maximum number of edges that can be removed to leave all connected components with even size, or $$$-1$$$ if it is impossible to remove edges in order to satisfy this property.

NoteIn the first example you can remove the edge between vertices $$$1$$$ and $$$4$$$. The graph after that will have two connected components with two vertices in each.In the second example you can't remove edges in such a way that all components have even number of vertices, so the answer is $$$-1$$$.


In the Bus of Characters there are $$$n$$$ rows of seat, each having $$$2$$$ seats. The width of both seats in the $$$i$$$-th row is $$$w_i$$$ centimeters. All integers $$$w_i$$$ are distinct.Initially the bus is empty. On each of $$$2n$$$ stops one passenger enters the bus. There are two types of passengers:   an introvert always chooses a row where both seats are empty. Among these rows he chooses the one with the smallest seats width and takes one of the seats in it;  an extrovert always chooses a row where exactly one seat is occupied (by an introvert). Among these rows he chooses the one with the largest seats width and takes the vacant place in it. You are given the seats width in each row and the order the passengers enter the bus. Determine which row each passenger will take.

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 200\,000$$$) — the number of rows in the bus. The second line contains the sequence of integers $$$w_1, w_2, \dots, w_n$$$ ($$$1 \le w_i \le 10^{9}$$$), where $$$w_i$$$ is the width of each of the seats in the $$$i$$$-th row. It is guaranteed that all $$$w_i$$$ are distinct. The third line contains a string of length $$$2n$$$, consisting of digits '0' and '1' — the description of the order the passengers enter the bus. If the $$$j$$$-th character is '0', then the passenger that enters the bus on the $$$j$$$-th stop is an introvert. If the $$$j$$$-th character is '1', the the passenger that enters the bus on the $$$j$$$-th stop is an extrovert. It is guaranteed that the number of extroverts equals the number of introverts (i. e. both numbers equal $$$n$$$), and for each extrovert there always is a suitable row.

Print $$$2n$$$ integers — the rows the passengers will take. The order of passengers should be the same as in input.

NoteIn the first example the first passenger (introvert) chooses the row $$$2$$$, because it has the seats with smallest width. The second passenger (introvert) chooses the row $$$1$$$, because it is the only empty row now. The third passenger (extrovert) chooses the row $$$1$$$, because it has exactly one occupied seat and the seat width is the largest among such rows. The fourth passenger (extrovert) chooses the row $$$2$$$, because it is the only row with an empty place.


For long time scientists study the behavior of sharks. Sharks, as many other species, alternate short movements in a certain location and long movements between locations.Max is a young biologist. For $$$n$$$ days he watched a specific shark, and now he knows the distance the shark traveled in each of the days. All the distances are distinct. Max wants to know now how many locations the shark visited. He assumed there is such an integer $$$k$$$ that if the shark in some day traveled the distance strictly less than $$$k$$$, then it didn't change the location; otherwise, if in one day the shark traveled the distance greater than or equal to $$$k$$$; then it was changing a location in that day. Note that it is possible that the shark changed a location for several consecutive days, in each of them the shark traveled the distance at least $$$k$$$.The shark never returned to the same location after it has moved from it. Thus, in the sequence of $$$n$$$ days we can find consecutive nonempty segments when the shark traveled the distance less than $$$k$$$ in each of the days: each such segment corresponds to one location. Max wants to choose such $$$k$$$ that the lengths of all such segments are equal.Find such integer $$$k$$$, that the number of locations is as large as possible. If there are several such $$$k$$$, print the smallest one.

The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of days. The second line contains $$$n$$$ distinct positive integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$) — the distance traveled in each of the day.

Print a single integer $$$k$$$, such that    the shark was in each location the same number of days,  the number of locations is maximum possible satisfying the first condition,  $$$k$$$ is smallest possible satisfying the first and second conditions.

NoteIn the first example the shark travels inside a location on days $$$1$$$ and $$$2$$$ (first location), then on $$$4$$$-th and $$$5$$$-th days (second location), then on $$$7$$$-th and $$$8$$$-th days (third location). There are three locations in total.In the second example the shark only moves inside a location on the $$$2$$$-nd day, so there is only one location.


Petr is a detective in Braginsk. Somebody stole a huge amount of money from a bank and Petr is to catch him. Somebody told Petr that some luxurious car moves along the roads without stopping.Petr knows that it is the robbers who drive the car. The roads in Braginsk are one-directional and each of them connects two intersections. Petr wants to select one intersection such that if the robbers continue to drive the roads indefinitely, they will sooner or later come to that intersection. The initial position of the robbers is unknown. Find such an intersection that fits the requirements.

The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$2 \leq n \le 10^5$$$, $$$2 \leq m \leq 5 \cdot 10^5$$$) — the number of intersections and the number of directed roads in Braginsk, respectively. Each of the next $$$m$$$ lines contains two integers $$$u_i$$$ and $$$v_i$$$ ($$$1 \le u_i, v_i \le n$$$, $$$u_i \ne v_i$$$) — the start and finish of the $$$i$$$-th directed road. It is guaranteed that the robbers can move along the roads indefinitely.

Print a single integer $$$k$$$ — the intersection Petr needs to choose. If there are multiple answers, print any. If there are no such intersections, print $$$-1$$$.

NoteIn the first example the robbers can move, for example, along the following routes: $$$(1-2-3-1)$$$, $$$(3-4-5-3)$$$, $$$(1-2-3-4-5-3-1)$$$. We can show that if Petr chooses the $$$3$$$-rd intersection, he will eventually meet the robbers independently of their route.


You are given several queries. Each query consists of three integers $$$p$$$, $$$q$$$ and $$$b$$$. You need to answer whether the result of $$$p/q$$$ in notation with base $$$b$$$ is a finite fraction.A fraction in notation with base $$$b$$$ is finite if it contains finite number of numerals after the decimal point. It is also possible that a fraction has zero numerals after the decimal point.

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of queries. Next $$$n$$$ lines contain queries, one per line. Each line contains three integers $$$p$$$, $$$q$$$, and $$$b$$$ ($$$0 \le p \le 10^{18}$$$, $$$1 \le q \le 10^{18}$$$, $$$2 \le b \le 10^{18}$$$). All numbers are given in notation with base $$$10$$$.

For each question, in a separate line, print Finite if the fraction is finite and Infinite otherwise.


Consider a billiard table of rectangular size $$$n \times m$$$ with four pockets. Let's introduce a coordinate system with the origin at the lower left corner (see the picture).   There is one ball at the point $$$(x, y)$$$ currently. Max comes to the table and strikes the ball. The ball starts moving along a line that is parallel to one of the axes or that makes a $$$45^{\circ}$$$ angle with them. We will assume that:   the angles between the directions of the ball before and after a collision with a side are equal,  the ball moves indefinitely long, it only stops when it falls into a pocket,  the ball can be considered as a point, it falls into a pocket if and only if its coordinates coincide with one of the pockets,  initially the ball is not in a pocket. Note that the ball can move along some side, in this case the ball will just fall into the pocket at the end of the side.Your task is to determine whether the ball will fall into a pocket eventually, and if yes, which of the four pockets it will be.

The only line contains $$$6$$$ integers $$$n$$$, $$$m$$$, $$$x$$$, $$$y$$$, $$$v_x$$$, $$$v_y$$$ ($$$1 \leq n, m \leq 10^9$$$, $$$0 \leq x \leq n$$$; $$$0 \leq y \leq m$$$; $$$-1 \leq v_x, v_y \leq 1$$$; $$$(v_x, v_y) \neq (0, 0)$$$) — the width of the table, the length of the table, the $$$x$$$-coordinate of the initial position of the ball, the $$$y$$$-coordinate of the initial position of the ball, the $$$x$$$-component of its initial speed and the $$$y$$$-component of its initial speed, respectively. It is guaranteed that the ball is not initially in a pocket.

Print the coordinates of the pocket the ball will fall into, or $$$-1$$$ if the ball will move indefinitely.

NoteThe first sample:   The second sample:   In the third sample the ball will never change its $$$y$$$ coordinate, so the ball will never fall into a pocket.


For an array $$$b$$$ of length $$$m$$$ we define the function $$$f$$$ as  $$$ f(b) = \begin{cases} b[1] & \quad \text{if } m = 1 \\ f(b[1] \oplus b[2],b[2] \oplus b[3],\dots,b[m-1] \oplus b[m]) & \quad \text{otherwise,} \end{cases} $$$ where $$$\oplus$$$ is bitwise exclusive OR.For example, $$$f(1,2,4,8)=f(1\oplus2,2\oplus4,4\oplus8)=f(3,6,12)=f(3\oplus6,6\oplus12)=f(5,10)=f(5\oplus10)=f(15)=15$$$You are given an array $$$a$$$ and a few queries. Each query is represented as two integers $$$l$$$ and $$$r$$$. The answer is the maximum value of $$$f$$$ on all continuous subsegments of the array $$$a_l, a_{l+1}, \ldots, a_r$$$.

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 5000$$$) — the length of $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 2^{30}-1$$$) — the elements of the array. The third line contains a single integer $$$q$$$ ($$$1 \le q \le 100\,000$$$) — the number of queries. Each of the next $$$q$$$ lines contains a query represented as two integers $$$l$$$, $$$r$$$ ($$$1 \le l \le r \le n$$$).

Print $$$q$$$ lines — the answers for the queries.

NoteIn first sample in both queries the maximum value of the function is reached on the subsegment that is equal to the whole segment.In second sample, optimal segment for first query are $$$[3,6]$$$, for second query — $$$[2,5]$$$, for third — $$$[3,4]$$$, for fourth — $$$[1,2]$$$.


You work in a big office. It is a 9 floor building with an elevator that can accommodate up to 4 people. It is your responsibility to manage this elevator.Today you are late, so there are queues on some floors already. For each person you know the floor where he currently is and the floor he wants to reach. Also, you know the order in which people came to the elevator.According to the company's rules, if an employee comes to the elevator earlier than another one, he has to enter the elevator earlier too (even if these employees stay on different floors). Note that the employees are allowed to leave the elevator in arbitrary order.The elevator has two commands:   Go up or down one floor. The movement takes 1 second.  Open the doors on the current floor. During this operation all the employees who have reached their destination get out of the elevator. Then all the employees on the floor get in the elevator in the order they are queued up while it doesn't contradict the company's rules and there is enough space in the elevator. Each employee spends 1 second to get inside and outside the elevator. Initially the elevator is empty and is located on the floor 1.You are interested what is the minimum possible time you need to spend to deliver all the employees to their destination. It is not necessary to return the elevator to the floor 1.

The first line contains an integer n (1 ≤ n ≤ 2000) — the number of employees. The i-th of the next n lines contains two integers ai and bi (1 ≤ ai, bi ≤ 9, ai ≠ bi) — the floor on which an employee initially is, and the floor he wants to reach. The employees are given in the order they came to the elevator.

Print a single integer — the minimal possible time in seconds.

Note Explaination for the first sample  t = 0 t = 2 t = 3 t = 5 t = 6 t = 7 t = 9 t = 10


In the NN country, there are $$$n$$$ cities, numbered from $$$1$$$ to $$$n$$$, and $$$n - 1$$$ roads, connecting them. There is a roads path between any two cities.There are $$$m$$$ bidirectional bus routes between cities. Buses drive between two cities taking the shortest path with stops in every city they drive through. Travelling by bus, you can travel from any stop on the route to any other. You can travel between cities only by bus.You are interested in $$$q$$$ questions: is it possible to get from one city to another and what is the minimum number of buses you need to use for it?

The first line contains a single integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the number of cities. The second line contains $$$n - 1$$$ integers $$$p_2, p_3, \ldots, p_n$$$ ($$$1 \le p_i < i$$$), where $$$p_i$$$ means that cities $$$p_i$$$ and $$$i$$$ are connected by road. The third line contains a single integer $$$m$$$ ($$$1 \le m \le 2 \cdot 10^5$$$) — the number of bus routes. Each of the next $$$m$$$ lines contains $$$2$$$ integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le n$$$, $$$a \neq b$$$), meaning that there is a bus route between cities $$$a$$$ and $$$b$$$. It is possible that there is more than one route between two cities. The next line contains a single integer $$$q$$$ ($$$1 \le q \le 2 \cdot 10^5$$$) — the number of questions you are interested in. Each of the next $$$q$$$ lines contains $$$2$$$ integers $$$v$$$ and $$$u$$$ ($$$1 \le v, u \le n$$$, $$$v \neq u$$$), meaning that you are interested if it is possible to get from city $$$v$$$ to city $$$u$$$ and what is the minimum number of buses you need to use for it.

Print the answer for each question on a separate line. If there is no way to get from one city to another, print $$$-1$$$. Otherwise print the minimum number of buses you have to use.

Note  Routes for first sample are marked on the picture.


Arkady has got an infinite plane painted in color $$$0$$$. Then he draws $$$n$$$ rectangles filled with paint with sides parallel to the Cartesian coordinate axes, one after another. The color of the $$$i$$$-th rectangle is $$$i$$$ (rectangles are enumerated from $$$1$$$ to $$$n$$$ in the order he draws them). It is possible that new rectangles cover some of the previous ones completely or partially.Count the number of different colors on the plane after Arkady draws all the rectangles.

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 100\,000$$$) — the number of rectangles. The $$$i$$$-th of the next $$$n$$$ lines contains $$$4$$$ integers $$$x_1$$$, $$$y_1$$$, $$$x_2$$$ and $$$y_2$$$ ($$$-10^9 \le x_1 < x_2 \le 10^9$$$, $$$-10^9 \le y_1 < y_2 \le 10^9$$$) — the coordinates of corners of the $$$i$$$-th rectangle.

In the single line print the number of different colors in the plane, including color $$$0$$$.

Note  That's how the plane looks in the first sample That's how the plane looks in the second sample$$$0$$$ = white, $$$1$$$ = cyan, $$$2$$$ = blue, $$$3$$$ = purple, $$$4$$$ = yellow, $$$5$$$ = red.


Two players play a game.Initially there are $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the board, i. e. $$$n - 1$$$ turns are made. The first player makes the first move, then players alternate turns.The first player wants to minimize the last number that would be left on the board, while the second player wants to maximize it.You want to know what number will be left on the board after $$$n - 1$$$ turns if both players make optimal moves.

The first line contains one integer $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of numbers on the board. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^6$$$).

Print one number that will be left on the board.

NoteIn the first sample, the first player erases $$$3$$$ and the second erases $$$1$$$. $$$2$$$ is left on the board.In the second sample, $$$2$$$ is left on the board regardless of the actions of the players.


You are given n switches and m lamps. The i-th switch turns on some subset of the lamps. This information is given as the matrix a consisting of n rows and m columns where ai, j = 1 if the i-th switch turns on the j-th lamp and ai, j = 0 if the i-th switch is not connected to the j-th lamp.Initially all m lamps are turned off.Switches change state only from "off" to "on". It means that if you press two or more switches connected to the same lamp then the lamp will be turned on after any of this switches is pressed and will remain its state even if any switch connected to this lamp is pressed afterwards.It is guaranteed that if you push all n switches then all m lamps will be turned on.Your think that you have too many switches and you would like to ignore one of them. Your task is to say if there exists such a switch that if you will ignore (not use) it but press all the other n - 1 switches then all the m lamps will be turned on.

The first line of the input contains two integers n and m (1 ≤ n, m ≤ 2000) — the number of the switches and the number of the lamps. The following n lines contain m characters each. The character ai, j is equal to '1' if the i-th switch turns on the j-th lamp and '0' otherwise. It is guaranteed that if you press all n switches all m lamps will be turned on.

Print "YES" if there is a switch that if you will ignore it and press all the other n - 1 switches then all m lamps will be turned on. Print "NO" if there is no such switch.


You have m = n·k wooden staves. The i-th stave has length ai. You have to assemble n barrels consisting of k staves each, you can use any k staves to construct a barrel. Each stave must belong to exactly one barrel.Let volume vj of barrel j be equal to the length of the minimal stave in it.  You want to assemble exactly n barrels with the maximal total sum of volumes. But you have to make them equal enough, so a difference between volumes of any pair of the resulting barrels must not exceed l, i.e. |vx - vy| ≤ l for any 1 ≤ x ≤ n and 1 ≤ y ≤ n.Print maximal total sum of volumes of equal enough barrels or 0 if it's impossible to satisfy the condition above.

The first line contains three space-separated integers n, k and l (1 ≤ n, k ≤ 105, 1 ≤ n·k ≤ 105, 0 ≤ l ≤ 109). The second line contains m = n·k space-separated integers a1, a2, ..., am (1 ≤ ai ≤ 109) — lengths of staves.

Print single integer — maximal total sum of the volumes of barrels or 0 if it's impossible to construct exactly n barrels satisfying the condition |vx - vy| ≤ l for any 1 ≤ x ≤ n and 1 ≤ y ≤ n.

NoteIn the first example you can form the following barrels: [1, 2], [2, 2], [2, 3], [2, 3].In the second example you can form the following barrels: [10], [10].In the third example you can form the following barrels: [2, 5].In the fourth example difference between volumes of barrels in any partition is at least 2 so it is impossible to make barrels equal enough.


One day Alex decided to remember childhood when computers were not too powerful and lots of people played only default games. Alex enjoyed playing Minesweeper that time. He imagined that he saved world from bombs planted by terrorists, but he rarely won.Alex has grown up since then, so he easily wins the most difficult levels. This quickly bored him, and he thought: what if the computer gave him invalid fields in the childhood and Alex could not win because of it?He needs your help to check it.A Minesweeper field is a rectangle $$$n \times m$$$, where each cell is either empty, or contains a digit from $$$1$$$ to $$$8$$$, or a bomb. The field is valid if for each cell:   if there is a digit $$$k$$$ in the cell, then exactly $$$k$$$ neighboring cells have bombs.  if the cell is empty, then all neighboring cells have no bombs. Two cells are neighbors if they have a common side or a corner (i. e. a cell has at most $$$8$$$ neighboring cells).

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 100$$$) — the sizes of the field. The next $$$n$$$ lines contain the description of the field. Each line contains $$$m$$$ characters, each of them is "." (if this cell is empty), "*" (if there is bomb in this cell), or a digit from $$$1$$$ to $$$8$$$, inclusive.

Print "YES", if the field is valid and "NO" otherwise. You can choose the case (lower or upper) for each letter arbitrarily.

NoteIn the second example the answer is "NO" because, if the positions of the bombs are preserved, the first line of the field should be *2*1.You can read more about Minesweeper in Wikipedia's article.


You are given a chessboard of size 1 × n. It is guaranteed that n is even. The chessboard is painted like this: "BWBW...BW".Some cells of the board are occupied by the chess pieces. Each cell contains no more than one chess piece. It is known that the total number of pieces equals to .In one step you can move one of the pieces one cell to the left or to the right. You cannot move pieces beyond the borders of the board. You also cannot move pieces to the cells that are already occupied.Your task is to place all the pieces in the cells of the same color using the minimum number of moves (all the pieces must occupy only the black cells or only the white cells after all the moves are made).

The first line of the input contains one integer n (2 ≤ n ≤ 100, n is even) — the size of the chessboard.  The second line of the input contains  integer numbers  (1 ≤ pi ≤ n) — initial positions of the pieces. It is guaranteed that all the positions are distinct.

Print one integer — the minimum number of moves you have to make to place all the pieces in the cells of the same color.

NoteIn the first example the only possible strategy is to move the piece at the position 6 to the position 5 and move the piece at the position 2 to the position 3. Notice that if you decide to place the pieces in the white cells the minimum number of moves will be 3.In the second example the possible strategy is to move  in 4 moves, then  in 3 moves,  in 2 moves and  in 1 move.


Mishka received a gift of multicolored pencils for his birthday! Unfortunately he lives in a monochrome world, where everything is of the same color and only saturation differs. This pack can be represented as a sequence a1, a2, ..., an of n integer numbers — saturation of the color of each pencil. Now Mishka wants to put all the mess in the pack in order. He has an infinite number of empty boxes to do this. He would like to fill some boxes in such a way that:  Each pencil belongs to exactly one box;  Each non-empty box has at least k pencils in it;  If pencils i and j belong to the same box, then |ai - aj| ≤ d, where |x| means absolute value of x. Note that the opposite is optional, there can be pencils i and j such that |ai - aj| ≤ d and they belong to different boxes. Help Mishka to determine if it's possible to distribute all the pencils into boxes. Print "YES" if there exists such a distribution. Otherwise print "NO".

The first line contains three integer numbers n, k and d (1 ≤ k ≤ n ≤ 5·105, 0 ≤ d ≤ 109) — the number of pencils, minimal size of any non-empty box and maximal difference in saturation between any pair of pencils in the same box, respectively. The second line contains n integer numbers a1, a2, ..., an (1 ≤ ai ≤ 109) — saturation of color of each pencil.

Print "YES" if it's possible to distribute all the pencils into boxes and satisfy all the conditions. Otherwise print "NO".

NoteIn the first example it is possible to distribute pencils into 2 boxes with 3 pencils in each with any distribution. And you also can put all the pencils into the same box, difference of any pair in it won't exceed 10.In the second example you can split pencils of saturations [4, 5, 3, 4] into 2 boxes of size 2 and put the remaining ones into another box.


You are going to the beach with the idea to build the greatest sand castle ever in your head! The beach is not as three-dimensional as you could have imagined, it can be decribed as a line of spots to pile up sand pillars. Spots are numbered 1 through infinity from left to right. Obviously, there is not enough sand on the beach, so you brought n packs of sand with you. Let height hi of the sand pillar on some spot i be the number of sand packs you spent on it. You can't split a sand pack to multiple pillars, all the sand from it should go to a single one. There is a fence of height equal to the height of pillar with H sand packs to the left of the first spot and you should prevent sand from going over it. Finally you ended up with the following conditions to building the castle:  h1 ≤ H: no sand from the leftmost spot should go over the fence;  For any  |hi - hi + 1| ≤ 1: large difference in heights of two neighboring pillars can lead sand to fall down from the higher one to the lower, you really don't want this to happen;  : you want to spend all the sand you brought with you. As you have infinite spots to build, it is always possible to come up with some valid castle structure. Though you want the castle to be as compact as possible. Your task is to calculate the minimum number of spots you can occupy so that all the aforementioned conditions hold.

The only line contains two integer numbers n and H (1 ≤ n, H ≤ 1018) — the number of sand packs you have and the height of the fence, respectively.

Print the minimum number of spots you can occupy so the all the castle building conditions hold.

NoteHere are the heights of some valid castles:   n = 5, H = 2, [2, 2, 1, 0, ...], [2, 1, 1, 1, 0, ...], [1, 0, 1, 2, 1, 0, ...]  n = 6, H = 8, [3, 2, 1, 0, ...], [2, 2, 1, 1, 0, ...], [0, 1, 0, 1, 2, 1, 1, 0...] (this one has 5 spots occupied) The first list for both cases is the optimal answer, 3 spots are occupied in them.And here are some invalid ones:  n = 5, H = 2, [3, 2, 0, ...], [2, 3, 0, ...], [1, 0, 2, 2, ...]  n = 6, H = 8, [2, 2, 2, 0, ...], [6, 0, ...], [1, 4, 1, 0...], [2, 2, 1, 0, ...]


You are given a string s of length n consisting of lowercase English letters.For two given strings s and t, say S is the set of distinct characters of s and T is the set of distinct characters of t. The strings s and t are isomorphic if their lengths are equal and there is a one-to-one mapping (bijection) f between S and T for which f(si) = ti. Formally:  f(si) = ti for any index i,  for any character  there is exactly one character  that f(x) = y,  for any character  there is exactly one character  that f(x) = y. For example, the strings "aababc" and "bbcbcz" are isomorphic. Also the strings "aaaww" and "wwwaa" are isomorphic. The following pairs of strings are not isomorphic: "aab" and "bbb", "test" and "best".You have to handle m queries characterized by three integers x, y, len (1 ≤ x, y ≤ n - len + 1). For each query check if two substrings s[x... x + len - 1] and s[y... y + len - 1] are isomorphic.

The first line contains two space-separated integers n and m (1 ≤ n ≤ 2·105, 1 ≤ m ≤ 2·105) — the length of the string s and the number of queries. The second line contains string s consisting of n lowercase English letters. The following m lines contain a single query on each line: xi, yi and leni (1 ≤ xi, yi ≤ n, 1 ≤ leni ≤ n - max(xi, yi) + 1) — the description of the pair of the substrings to check.

For each query in a separate line print "YES" if substrings s[xi... xi + leni - 1] and s[yi... yi + leni - 1] are isomorphic and "NO" otherwise.

NoteThe queries in the example are following:   substrings "a" and "a" are isomorphic: f(a) = a;  substrings "ab" and "ca" are isomorphic: f(a) = c, f(b) = a;  substrings "bac" and "aba" are not isomorphic since f(b) and f(c) must be equal to a at same time;  substrings "bac" and "cab" are isomorphic: f(b) = c, f(a) = a, f(c) = b.


There are $$$n$$$ players numbered from $$$0$$$ to $$$n-1$$$ with ranks. The $$$i$$$-th player has rank $$$i$$$.Players can form teams: the team should consist of three players and no pair of players in the team should have a conflict. The rank of the team is calculated using the following algorithm: let $$$i$$$, $$$j$$$, $$$k$$$ be the ranks of players in the team and $$$i < j < k$$$, then the rank of the team is equal to $$$A \cdot i + B \cdot j + C \cdot k$$$.You are given information about the pairs of players who have a conflict. Calculate the total sum of ranks over all possible valid teams modulo $$$2^{64}$$$.

The first line contains two space-separated integers $$$n$$$ and $$$m$$$ ($$$3 \le n \le 2 \cdot 10^5$$$, $$$0 \le m \le 2 \cdot 10^5$$$) — the number of players and the number of conflicting pairs. The second line contains three space-separated integers $$$A$$$, $$$B$$$ and $$$C$$$ ($$$1 \le A, B, C \le 10^6$$$) — coefficients for team rank calculation. Each of the next $$$m$$$ lines contains two space-separated integers $$$u_i$$$ and $$$v_i$$$ ($$$0 \le u_i, v_i < n, u_i \neq v_i$$$) — pair of conflicting players. It's guaranteed that each unordered pair of players appears in the input file no more than once.

Print single integer — the total sum of ranks over all possible teams modulo $$$2^{64}$$$.


Petr likes to come up with problems about randomly generated data. This time problem is about random permutation. He decided to generate a random permutation this way: he takes identity permutation of numbers from $$$1$$$ to $$$n$$$ and then $$$3n$$$ times takes a random pair of different elements and swaps them. Alex envies Petr and tries to imitate him in all kind of things. Alex has also come up with a problem about random permutation. He generates a random permutation just like Petr but swaps elements $$$7n+1$$$ times instead of $$$3n$$$ times. Because it is more random, OK?!You somehow get a test from one of these problems and now you want to know from which one.

In the first line of input there is one integer $$$n$$$ ($$$10^{3} \le n \le 10^{6}$$$). In the second line there are $$$n$$$ distinct integers between $$$1$$$ and $$$n$$$ — the permutation of size $$$n$$$ from the test. It is guaranteed that all tests except for sample are generated this way: First we choose $$$n$$$ — the size of the permutation. Then we randomly choose a method to generate a permutation — the one of Petr or the one of Alex. Then we generate a permutation using chosen method.

If the test is generated via Petr's method print "Petr" (without quotes). If the test is generated via Alex's method print "Um_nik" (without quotes).

NotePlease note that the sample is not a valid test (because of limitations for $$$n$$$) and is given only to illustrate input/output format. Your program still has to print correct answer to this test to get AC.Due to randomness of input hacks in this problem are forbidden.


Some company is going to hold a fair in Byteland. There are $$$n$$$ towns in Byteland and $$$m$$$ two-way roads between towns. Of course, you can reach any town from any other town using roads.There are $$$k$$$ types of goods produced in Byteland and every town produces only one type. To hold a fair you have to bring at least $$$s$$$ different types of goods. It costs $$$d(u,v)$$$ coins to bring goods from town $$$u$$$ to town $$$v$$$ where $$$d(u,v)$$$ is the length of the shortest path from $$$u$$$ to $$$v$$$. Length of a path is the number of roads in this path.The organizers will cover all travel expenses but they can choose the towns to bring goods from. Now they want to calculate minimum expenses to hold a fair in each of $$$n$$$ towns.

There are $$$4$$$ integers $$$n$$$, $$$m$$$, $$$k$$$, $$$s$$$ in the first line of input ($$$1 \le n \le 10^{5}$$$, $$$0 \le m \le 10^{5}$$$, $$$1 \le s \le k \le min(n, 100)$$$) — the number of towns, the number of roads, the number of different types of goods, the number of different types of goods necessary to hold a fair. In the next line there are $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_{i} \le k$$$), where $$$a_i$$$ is the type of goods produced in the $$$i$$$-th town. It is guaranteed that all integers between $$$1$$$ and $$$k$$$ occur at least once among integers $$$a_{i}$$$. In the next $$$m$$$ lines roads are described. Each road is described by two integers $$$u$$$ $$$v$$$ ($$$1 \le u, v \le n$$$, $$$u \ne v$$$) — the towns connected by this road. It is guaranteed that there is no more than one road between every two towns. It is guaranteed that you can go from any town to any other town via roads.

Print $$$n$$$ numbers, the $$$i$$$-th of them is the minimum number of coins you need to spend on travel expenses to hold a fair in town $$$i$$$. Separate numbers with spaces.


You are given a set of size $$$m$$$ with integer elements between $$$0$$$ and $$$2^{n}-1$$$ inclusive. Let's build an undirected graph on these integers in the following way: connect two integers $$$x$$$ and $$$y$$$ with an edge if and only if $$$x \& y = 0$$$. Here $$$\&$$$ is the bitwise AND operation. Count the number of connected components in that graph.

In the first line of input there are two integers $$$n$$$ and $$$m$$$ ($$$0 \le n \le 22$$$, $$$1 \le m \le 2^{n}$$$). In the second line there are $$$m$$$ integers $$$a_1, a_2, \ldots, a_m$$$ ($$$0 \le a_{i} < 2^{n}$$$) — the elements of the set. All $$$a_{i}$$$ are distinct.

Print the number of connected components.

NoteGraph from first sample:Graph from second sample:


You are working as an analyst in a company working on a new system for big data storage. This system will store $$$n$$$ different objects. Each object should have a unique ID.To create the system, you choose the parameters of the system — integers $$$m \ge 1$$$ and $$$b_{1}, b_{2}, \ldots, b_{m}$$$. With these parameters an ID of some object in the system is an array of integers $$$[a_{1}, a_{2}, \ldots, a_{m}]$$$ where $$$1 \le a_{i} \le b_{i}$$$ holds for every $$$1 \le i \le m$$$.Developers say that production costs are proportional to $$$\sum_{i=1}^{m} b_{i}$$$. You are asked to choose parameters $$$m$$$ and $$$b_{i}$$$ so that the system will be able to assign unique IDs to $$$n$$$ different objects and production costs are minimized. Note that you don't have to use all available IDs.

In the only line of input there is one positive integer $$$n$$$. The length of the decimal representation of $$$n$$$ is no greater than $$$1.5 \cdot 10^{6}$$$. The integer does not contain leading zeros.

Print one number — minimal value of $$$\sum_{i=1}^{m} b_{i}$$$.


Let the main characters of this problem be personages from some recent movie. New Avengers seem to make a lot of buzz. I didn't watch any part of the franchise and don't know its heroes well, but it won't stop me from using them in this problem statement. So, Thanos and Dr. Strange are doing their superhero and supervillain stuff, but then suddenly they stumble across a regular competitive programming problem.You are given a tree with $$$n$$$ vertices.In each vertex $$$v$$$ there is positive integer $$$a_{v}$$$.You have to answer $$$q$$$ queries.Each query has a from $$$u$$$ $$$v$$$ $$$x$$$.You have to calculate $$$\prod_{w \in P} gcd(x, a_{w}) \mod (10^{9} + 7)$$$, where $$$P$$$ is a set of vertices on path from $$$u$$$ to $$$v$$$. In other words, you are to calculate the product of $$$gcd(x, a_{w})$$$ for all vertices $$$w$$$ on the path from $$$u$$$ to $$$v$$$. As it might be large, compute it modulo $$$10^9+7$$$. Here $$$gcd(s, t)$$$ denotes the greatest common divisor of $$$s$$$ and $$$t$$$.Note that the numbers in vertices do not change after queries.I suppose that you are more interested in superhero business of Thanos and Dr. Strange than in them solving the problem. So you are invited to solve this problem instead of them.

In the first line of input there is one integer $$$n$$$ ($$$1 \le n \le 10^{5}$$$) — the size of the tree. In the next $$$n-1$$$ lines the edges of the tree are described. The $$$i$$$-th edge is described with two integers $$$u_{i}$$$ and $$$v_{i}$$$ ($$$1 \le u_{i}, v_{i} \le n$$$) and it connects the vertices $$$u_{i}$$$ and $$$v_{i}$$$. It is guaranteed that graph with these edges is a tree. In the next line there are $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_{v} \le 10^{7}$$$). In the next line there is one integer $$$q$$$ ($$$1 \le q \le 10^{5}$$$) — the number of queries. And in the next $$$q$$$ lines the queries are described. Each query is described with three integers $$$u_{i}$$$, $$$v_{i}$$$ and $$$x_{i}$$$ ($$$1 \le u_{i}, v_{i} \le n$$$, $$$1 \le x_{i} \le 10^{7}$$$).

Print $$$q$$$ numbers — the answers to the queries in the order they are given in the input. Print each answer modulo $$$10^9+7 = 1000000007$$$. Print each number on a separate line.


Surely you have seen insane videos by South Korean rapper PSY, such as "Gangnam Style", "Gentleman" and "Daddy". You might also hear that PSY has been recording video "Oppa Funcan Style" two years ago (unfortunately we couldn't find it on the internet). We will remind you what this hit looked like (you can find original description here):On the ground there are $$$n$$$ platforms, which are numbered with integers from $$$1$$$ to $$$n$$$, on $$$i$$$-th platform there is a dancer with number $$$i$$$. Further, every second all the dancers standing on the platform with number $$$i$$$ jump to the platform with the number $$$f(i)$$$. The moving rule $$$f$$$ is selected in advance and is not changed throughout the clip.The duration of the clip was $$$k$$$ seconds and the rule $$$f$$$ was chosen in such a way that after $$$k$$$ seconds all dancers were in their initial positions (i.e. the $$$i$$$-th dancer stood on the platform with the number $$$i$$$). That allowed to loop the clip and collect even more likes.PSY knows that enhanced versions of old artworks become more and more popular every day. So he decided to release a remastered-version of his video.In his case "enhanced version" means even more insanity, so the number of platforms can be up to $$$10^{18}$$$! But the video director said that if some dancer stays on the same platform all the time, then the viewer will get bored and will turn off the video immediately. Therefore, for all $$$x$$$ from $$$1$$$ to $$$n$$$ $$$f(x) \neq x$$$ must hold.Big part of classic video's success was in that looping, so in the remastered version all dancers should return to their initial positions in the end of the clip as well.PSY hasn't decided on the exact number of platforms and video duration yet, so he asks you to check if there is a good rule $$$f$$$ for different options.

In the first line of input there is one integer $$$t$$$ ($$$1 \le t \le 10^{4}$$$) — the number of options for $$$n$$$ and $$$k$$$ to check. In the next $$$t$$$ lines the options are given: each option is described with two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10^{18}$$$, $$$1 \le k \le 10^{15}$$$) — the number of dancers and the duration in seconds. It is guaranteed that the number of different values of $$$k$$$ in one test is not greater than $$$50$$$.

Print $$$t$$$ lines. If the $$$i$$$-th option of the video is feasible, print "YES" (without quotes) in $$$i$$$-th line, otherwise print "NO" (without quotes).


Year 2118. Androids are in mass production for decades now, and they do all the work for humans. But androids have to go to school to be able to solve creative tasks. Just like humans before.It turns out that high school struggles are not gone. If someone is not like others, he is bullied. Vasya-8800 is an economy-class android which is produced by a little-known company. His design is not perfect, his characteristics also could be better. So he is bullied by other androids.One of the popular pranks on Vasya is to force him to compare $$$x^y$$$ with $$$y^x$$$. Other androids can do it in milliseconds while Vasya's memory is too small to store such big numbers.Please help Vasya! Write a fast program to compare $$$x^y$$$ with $$$y^x$$$ for Vasya, maybe then other androids will respect him.

On the only line of input there are two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 10^{9}$$$).

If $$$x^y < y^x$$$, then print '<' (without quotes). If $$$x^y > y^x$$$, then print '>' (without quotes). If $$$x^y = y^x$$$, then print '=' (without quotes).

NoteIn the first example $$$5^8 = 5 \cdot 5 \cdot 5 \cdot 5 \cdot 5 \cdot 5 \cdot 5 \cdot 5 = 390625$$$, and $$$8^5 = 8 \cdot 8 \cdot 8 \cdot 8 \cdot 8 = 32768$$$. So you should print '>'.In the second example $$$10^3 = 1000 < 3^{10} = 59049$$$.In the third example $$$6^6 = 46656 = 6^6$$$.


You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems:  the Power Gem of purple color,  the Time Gem of green color,  the Space Gem of blue color,  the Soul Gem of orange color,  the Reality Gem of red color,  the Mind Gem of yellow color. Using colors of Gems you saw in the Gauntlet determine the names of absent Gems.

In the first line of input there is one integer $$$n$$$ ($$$0 \le n \le 6$$$) — the number of Gems in Infinity Gauntlet. In next $$$n$$$ lines there are colors of Gems you saw. Words used for colors are: purple, green, blue, orange, red, yellow. It is guaranteed that all the colors are distinct. All colors are given in lowercase English letters.

In the first line output one integer $$$m$$$ ($$$0 \le m \le 6$$$) — the number of absent Gems. Then in $$$m$$$ lines print the names of absent Gems, each on its own line. Words used for names are: Power, Time, Space, Soul, Reality, Mind. Names can be printed in any order. Keep the first letter uppercase, others lowercase.

NoteIn the first sample Thanos already has Reality, Power, Mind and Soul Gems, so he needs two more: Time and Space.In the second sample Thanos doesn't have any Gems, so he needs all six.


It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem.There are $$$n$$$ displays placed along a road, and the $$$i$$$-th of them can display a text with font size $$$s_i$$$ only. Maria Stepanovna wants to rent such three displays with indices $$$i < j < k$$$ that the font size increases if you move along the road in a particular direction. Namely, the condition $$$s_i < s_j < s_k$$$ should be held.The rent cost is for the $$$i$$$-th display is $$$c_i$$$. Please determine the smallest cost Maria Stepanovna should pay.

The first line contains a single integer $$$n$$$ ($$$3 \le n \le 3\,000$$$) — the number of displays. The second line contains $$$n$$$ integers $$$s_1, s_2, \ldots, s_n$$$ ($$$1 \le s_i \le 10^9$$$) — the font sizes on the displays in the order they stand along the road. The third line contains $$$n$$$ integers $$$c_1, c_2, \ldots, c_n$$$ ($$$1 \le c_i \le 10^8$$$) — the rent costs for each display.

If there are no three displays that satisfy the criteria, print -1. Otherwise print a single integer — the minimum total rent cost of three displays with indices $$$i < j < k$$$ such that $$$s_i < s_j < s_k$$$.

NoteIn the first example you can, for example, choose displays $$$1$$$, $$$4$$$ and $$$5$$$, because $$$s_1 < s_4 < s_5$$$ ($$$2 < 4 < 10$$$), and the rent cost is $$$40 + 10 + 40 = 90$$$.In the second example you can't select a valid triple of indices, so the answer is -1.


There are $$$n$$$ students in a school class, the rating of the $$$i$$$-th student on Codehorses is $$$a_i$$$. You have to form a team consisting of $$$k$$$ students ($$$1 \le k \le n$$$) such that the ratings of all team members are distinct.If it is impossible to form a suitable team, print "NO" (without quotes). Otherwise print "YES", and then print $$$k$$$ distinct numbers which should be the indices of students in the team you form. If there are multiple answers, print any of them.

The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 100$$$) — the number of students and the size of the team you have to form. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 100$$$), where $$$a_i$$$ is the rating of $$$i$$$-th student.

If it is impossible to form a suitable team, print "NO" (without quotes). Otherwise print "YES", and then print $$$k$$$ distinct integers from $$$1$$$ to $$$n$$$ which should be the indices of students in the team you form. All the ratings of the students in the team should be distinct. You may print the indices in any order. If there are multiple answers, print any of them. Assume that the students are numbered from $$$1$$$ to $$$n$$$.

NoteAll possible answers for the first example:   {1 2 5}  {2 3 5}  {2 4 5} Note that the order does not matter.


You are given $$$k$$$ sequences of integers. The length of the $$$i$$$-th sequence equals to $$$n_i$$$.You have to choose exactly two sequences $$$i$$$ and $$$j$$$ ($$$i \ne j$$$) such that you can remove exactly one element in each of them in such a way that the sum of the changed sequence $$$i$$$ (its length will be equal to $$$n_i - 1$$$) equals to the sum of the changed sequence $$$j$$$ (its length will be equal to $$$n_j - 1$$$).Note that it's required to remove exactly one element in each of the two chosen sequences.Assume that the sum of the empty (of the length equals $$$0$$$) sequence is $$$0$$$.

The first line contains an integer $$$k$$$ ($$$2 \le k \le 2 \cdot 10^5$$$) — the number of sequences. Then $$$k$$$ pairs of lines follow, each pair containing a sequence. The first line in the $$$i$$$-th pair contains one integer $$$n_i$$$ ($$$1 \le n_i < 2 \cdot 10^5$$$) — the length of the $$$i$$$-th sequence. The second line of the $$$i$$$-th pair contains a sequence of $$$n_i$$$ integers $$$a_{i, 1}, a_{i, 2}, \dots, a_{i, n_i}$$$. The elements of sequences are integer numbers from $$$-10^4$$$ to $$$10^4$$$. The sum of lengths of all given sequences don't exceed $$$2 \cdot 10^5$$$, i.e. $$$n_1 + n_2 + \dots + n_k \le 2 \cdot 10^5$$$.

If it is impossible to choose two sequences such that they satisfy given conditions, print "NO" (without quotes). Otherwise in the first line print "YES" (without quotes), in the second line — two integers $$$i$$$, $$$x$$$ ($$$1 \le i \le k, 1 \le x \le n_i$$$), in the third line — two integers $$$j$$$, $$$y$$$ ($$$1 \le j \le k, 1 \le y \le n_j$$$). It means that the sum of the elements of the $$$i$$$-th sequence without the element with index $$$x$$$ equals to the sum of the elements of the $$$j$$$-th sequence without the element with index $$$y$$$. Two chosen sequences must be distinct, i.e. $$$i \ne j$$$. You can print them in any order. If there are multiple possible answers, print any of them.

NoteIn the first example there are two sequences $$$[2, 3, 1, 3, 2]$$$ and $$$[1, 1, 2, 2, 2, 1]$$$. You can remove the second element from the first sequence to get $$$[2, 1, 3, 2]$$$ and you can remove the sixth element from the second sequence to get $$$[1, 1, 2, 2, 2]$$$. The sums of the both resulting sequences equal to $$$8$$$, i.e. the sums are equal.


You are given an integer $$$n$$$ from $$$1$$$ to $$$10^{18}$$$ without leading zeroes.In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes.What is the minimum number of moves you have to make to obtain a number that is divisible by $$$25$$$? Print -1 if it is impossible to obtain a number that is divisible by $$$25$$$.

The first line contains an integer $$$n$$$ ($$$1 \le n \le 10^{18}$$$). It is guaranteed that the first (left) digit of the number $$$n$$$ is not a zero.

If it is impossible to obtain a number that is divisible by $$$25$$$, print -1. Otherwise print the minimum number of moves required to obtain such number. Note that you can swap only adjacent digits in the given number.

NoteIn the first example one of the possible sequences of moves is 5071 $$$\rightarrow$$$ 5701 $$$\rightarrow$$$ 7501 $$$\rightarrow$$$ 7510 $$$\rightarrow$$$ 7150.


There are $$$n$$$ distinct points on a coordinate line, the coordinate of $$$i$$$-th point equals to $$$x_i$$$. Choose a subset of the given set of points such that the distance between each pair of points in a subset is an integral power of two. It is necessary to consider each pair of points, not only adjacent. Note that any subset containing one element satisfies the condition above. Among all these subsets, choose a subset with maximum possible size.In other words, you have to choose the maximum possible number of points $$$x_{i_1}, x_{i_2}, \dots, x_{i_m}$$$ such that for each pair $$$x_{i_j}$$$, $$$x_{i_k}$$$ it is true that $$$|x_{i_j} - x_{i_k}| = 2^d$$$ where $$$d$$$ is some non-negative integer number (not necessarily the same for each pair of points).

The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of points. The second line contains $$$n$$$ pairwise distinct integers $$$x_1, x_2, \dots, x_n$$$ ($$$-10^9 \le x_i \le 10^9$$$) — the coordinates of points.

In the first line print $$$m$$$ — the maximum possible number of points in a subset that satisfies the conditions described above. In the second line print $$$m$$$ integers — the coordinates of points in the subset you have chosen. If there are multiple answers, print any of them.

NoteIn the first example the answer is $$$[7, 3, 5]$$$. Note, that $$$|7-3|=4=2^2$$$, $$$|7-5|=2=2^1$$$ and $$$|3-5|=2=2^1$$$. You can't find a subset having more points satisfying the required property.


Polycarp lives on a coordinate line at the point $$$x = 0$$$. He goes to his friend that lives at the point $$$x = a$$$. Polycarp can move only from left to right, he can pass one unit of length each second.Now it's raining, so some segments of his way are in the rain. Formally, it's raining on $$$n$$$ non-intersecting segments, the $$$i$$$-th segment which is in the rain is represented as $$$[l_i, r_i]$$$ ($$$0 \le l_i < r_i \le a$$$).There are $$$m$$$ umbrellas lying on the line, the $$$i$$$-th umbrella is located at point $$$x_i$$$ ($$$0 \le x_i \le a$$$) and has weight $$$p_i$$$. When Polycarp begins his journey, he doesn't have any umbrellas.During his journey from $$$x = 0$$$ to $$$x = a$$$ Polycarp can pick up and throw away umbrellas. Polycarp picks up and throws down any umbrella instantly. He can carry any number of umbrellas at any moment of time. Because Polycarp doesn't want to get wet, he must carry at least one umbrella while he moves from $$$x$$$ to $$$x + 1$$$ if a segment $$$[x, x + 1]$$$ is in the rain (i.e. if there exists some $$$i$$$ such that $$$l_i \le x$$$ and $$$x + 1 \le r_i$$$).The condition above is the only requirement. For example, it is possible to go without any umbrellas to a point where some rain segment starts, pick up an umbrella at this point and move along with an umbrella. Polycarp can swap umbrellas while he is in the rain.Each unit of length passed increases Polycarp's fatigue by the sum of the weights of umbrellas he carries while moving.Can Polycarp make his way from point $$$x = 0$$$ to point $$$x = a$$$? If yes, find the minimum total fatigue after reaching $$$x = a$$$, if Polycarp picks up and throws away umbrellas optimally.

The first line contains three integers $$$a$$$, $$$n$$$ and $$$m$$$ ($$$1 \le a, m \le 2000, 1 \le n \le \lceil\frac{a}{2}\rceil$$$) — the point at which Polycarp's friend lives, the number of the segments in the rain and the number of umbrellas. Each of the next $$$n$$$ lines contains two integers $$$l_i$$$ and $$$r_i$$$ ($$$0 \le l_i < r_i \le a$$$) — the borders of the $$$i$$$-th segment under rain. It is guaranteed that there is no pair of intersecting segments. In other words, for each pair of segments $$$i$$$ and $$$j$$$ either $$$r_i < l_j$$$ or $$$r_j < l_i$$$. Each of the next $$$m$$$ lines contains two integers $$$x_i$$$ and $$$p_i$$$ ($$$0 \le x_i \le a$$$, $$$1 \le p_i \le 10^5$$$) — the location and the weight of the $$$i$$$-th umbrella.

Print "-1" (without quotes) if Polycarp can't make his way from point $$$x = 0$$$ to point $$$x = a$$$. Otherwise print one integer — the minimum total fatigue after reaching $$$x = a$$$, if Polycarp picks up and throws away umbrellas optimally.

NoteIn the first example the only possible strategy is to take the fourth umbrella at the point $$$x = 1$$$, keep it till the point $$$x = 7$$$ (the total fatigue at $$$x = 7$$$ will be equal to $$$12$$$), throw it away, move on from $$$x = 7$$$ to $$$x = 8$$$ without an umbrella, take the third umbrella at $$$x = 8$$$ and keep it till the end (the total fatigue at $$$x = 10$$$ will be equal to $$$14$$$). In the second example the only possible strategy is to take the first umbrella, move with it till the point $$$x = 9$$$, throw it away and proceed without an umbrella till the end.


When the curtains are opened, a canvas unfolds outside. Kanno marvels at all the blonde colours along the riverside — not tangerines, but blossoms instead."What a pity it's already late spring," sighs Mino with regret, "one more drizzling night and they'd be gone.""But these blends are at their best, aren't they?" Absorbed in the landscape, Kanno remains optimistic. The landscape can be expressed as a row of consecutive cells, each of which either contains a flower of colour amber or buff or canary yellow, or is empty.When a flower withers, it disappears from the cell that it originally belonged to, and it spreads petals of its colour in its two neighbouring cells (or outside the field if the cell is on the side of the landscape). In case petals fall outside the given cells, they simply become invisible.You are to help Kanno determine whether it's possible that after some (possibly none or all) flowers shed their petals, at least one of the cells contains all three colours, considering both petals and flowers. Note that flowers can wither in arbitrary order.

The first and only line of input contains a non-empty string $$$s$$$ consisting of uppercase English letters 'A', 'B', 'C' and characters '.' (dots) only ($$$\lvert s \rvert \leq 100$$$) — denoting cells containing an amber flower, a buff one, a canary yellow one, and no flowers, respectively.

Output "Yes" if it's possible that all three colours appear in some cell, and "No" otherwise. You can print each letter in any case (upper or lower).

NoteIn the first example, the buff and canary yellow flowers can leave their petals in the central cell, blending all three colours in it.In the second example, it's impossible to satisfy the requirement because there is no way that amber and buff meet in any cell.


Berland Football Cup starts really soon! Commentators from all over the world come to the event.Organizers have already built $$$n$$$ commentary boxes. $$$m$$$ regional delegations will come to the Cup. Every delegation should get the same number of the commentary boxes. If any box is left unoccupied then the delegations will be upset. So each box should be occupied by exactly one delegation.If $$$n$$$ is not divisible by $$$m$$$, it is impossible to distribute the boxes to the delegations at the moment.Organizers can build a new commentary box paying $$$a$$$ burles and demolish a commentary box paying $$$b$$$ burles. They can both build and demolish boxes arbitrary number of times (each time paying a corresponding fee). It is allowed to demolish all the existing boxes.What is the minimal amount of burles organizers should pay to satisfy all the delegations (i.e. to make the number of the boxes be divisible by $$$m$$$)?

The only line contains four integer numbers $$$n$$$, $$$m$$$, $$$a$$$ and $$$b$$$ ($$$1 \le n, m \le 10^{12}$$$, $$$1 \le a, b \le 100$$$), where $$$n$$$ is the initial number of the commentary boxes, $$$m$$$ is the number of delegations to come, $$$a$$$ is the fee to build a box and $$$b$$$ is the fee to demolish a box.

Output the minimal amount of burles organizers should pay to satisfy all the delegations (i.e. to make the number of the boxes be divisible by $$$m$$$). It is allowed that the final number of the boxes is equal to $$$0$$$.

NoteIn the first example organizers can build $$$5$$$ boxes to make the total of $$$14$$$ paying $$$3$$$ burles for the each of them.In the second example organizers can demolish $$$2$$$ boxes to make the total of $$$0$$$ paying $$$7$$$ burles for the each of them.In the third example organizers are already able to distribute all the boxes equally among the delegations, each one get $$$5$$$ boxes.


Walking along a riverside, Mino silently takes a note of something."Time," Mino thinks aloud."What?""Time and tide wait for no man," explains Mino. "My name, taken from the river, always reminds me of this.""And what are you recording?""You see it, tide. Everything has its own period, and I think I've figured out this one," says Mino with confidence.Doubtfully, Kanno peeks at Mino's records. The records are expressed as a string $$$s$$$ of characters '0', '1' and '.', where '0' denotes a low tide, '1' denotes a high tide, and '.' denotes an unknown one (either high or low).You are to help Mino determine whether it's possible that after replacing each '.' independently with '0' or '1', a given integer $$$p$$$ is not a period of the resulting string. In case the answer is yes, please also show such a replacement to Mino.In this problem, a positive integer $$$p$$$ is considered a period of string $$$s$$$, if for all $$$1 \leq i \leq \lvert s \rvert - p$$$, the $$$i$$$-th and $$$(i + p)$$$-th characters of $$$s$$$ are the same. Here $$$\lvert s \rvert$$$ is the length of $$$s$$$.

The first line contains two space-separated integers $$$n$$$ and $$$p$$$ ($$$1 \leq p \leq n \leq 2000$$$) — the length of the given string and the supposed period, respectively. The second line contains a string $$$s$$$ of $$$n$$$ characters — Mino's records. $$$s$$$ only contains characters '0', '1' and '.', and contains at least one '.' character.

Output one line — if it's possible that $$$p$$$ is not a period of the resulting string, output any one of such strings; otherwise output "No" (without quotes, you can print letters in any case (upper or lower)).

NoteIn the first example, $$$7$$$ is not a period of the resulting string because the $$$1$$$-st and $$$8$$$-th characters of it are different.In the second example, $$$6$$$ is not a period of the resulting string because the $$$4$$$-th and $$$10$$$-th characters of it are different.In the third example, $$$9$$$ is always a period because the only constraint that the first and last characters are the same is already satisfied.Note that there are multiple acceptable answers for the first two examples, you can print any of them.


Gathering darkness shrouds the woods and the world. The moon sheds its light on the boat and the river."To curtain off the moonlight should be hardly possible; the shades present its mellow beauty and restful nature." Intonates Mino."See? The clouds are coming." Kanno gazes into the distance."That can't be better," Mino turns to Kanno. The sky can be seen as a one-dimensional axis. The moon is at the origin whose coordinate is $$$0$$$.There are $$$n$$$ clouds floating in the sky. Each cloud has the same length $$$l$$$. The $$$i$$$-th initially covers the range of $$$(x_i, x_i + l)$$$ (endpoints excluded). Initially, it moves at a velocity of $$$v_i$$$, which equals either $$$1$$$ or $$$-1$$$.Furthermore, no pair of clouds intersect initially, that is, for all $$$1 \leq i \lt j \leq n$$$, $$$\lvert x_i - x_j \rvert \geq l$$$.With a wind velocity of $$$w$$$, the velocity of the $$$i$$$-th cloud becomes $$$v_i + w$$$. That is, its coordinate increases by $$$v_i + w$$$ during each unit of time. Note that the wind can be strong and clouds can change their direction.You are to help Mino count the number of pairs $$$(i, j)$$$ ($$$i < j$$$), such that with a proper choice of wind velocity $$$w$$$ not exceeding $$$w_\mathrm{max}$$$ in absolute value (possibly negative and/or fractional), the $$$i$$$-th and $$$j$$$-th clouds both cover the moon at the same future moment. This $$$w$$$ doesn't need to be the same across different pairs.

The first line contains three space-separated integers $$$n$$$, $$$l$$$, and $$$w_\mathrm{max}$$$ ($$$1 \leq n \leq 10^5$$$, $$$1 \leq l, w_\mathrm{max} \leq 10^8$$$) — the number of clouds, the length of each cloud and the maximum wind speed, respectively. The $$$i$$$-th of the following $$$n$$$ lines contains two space-separated integers $$$x_i$$$ and $$$v_i$$$ ($$$-10^8 \leq x_i \leq 10^8$$$, $$$v_i \in \{-1, 1\}$$$) — the initial position and the velocity of the $$$i$$$-th cloud, respectively. The input guarantees that for all $$$1 \leq i \lt j \leq n$$$, $$$\lvert x_i - x_j \rvert \geq l$$$.

Output one integer — the number of unordered pairs of clouds such that it's possible that clouds from each pair cover the moon at the same future moment with a proper choice of wind velocity $$$w$$$.

NoteIn the first example, the initial positions and velocities of clouds are illustrated below.  The pairs are:   $$$(1, 3)$$$, covering the moon at time $$$2.5$$$ with $$$w = -0.4$$$;  $$$(1, 4)$$$, covering the moon at time $$$3.5$$$ with $$$w = -0.6$$$;  $$$(1, 5)$$$, covering the moon at time $$$4.5$$$ with $$$w = -0.7$$$;  $$$(2, 5)$$$, covering the moon at time $$$2.5$$$ with $$$w = -2$$$. Below is the positions of clouds at time $$$2.5$$$ with $$$w = -0.4$$$. At this moment, the $$$1$$$-st and $$$3$$$-rd clouds both cover the moon.  In the second example, the only pair is $$$(1, 4)$$$, covering the moon at time $$$15$$$ with $$$w = 0$$$.Note that all the times and wind velocities given above are just examples among infinitely many choices.


You have a Petri dish with bacteria and you are preparing to dive into the harsh micro-world. But, unfortunately, you don't have any microscope nearby, so you can't watch them.You know that you have $$$n$$$ bacteria in the Petri dish and size of the $$$i$$$-th bacteria is $$$a_i$$$. Also you know intergalactic positive integer constant $$$K$$$.The $$$i$$$-th bacteria can swallow the $$$j$$$-th bacteria if and only if $$$a_i > a_j$$$ and $$$a_i \le a_j + K$$$. The $$$j$$$-th bacteria disappear, but the $$$i$$$-th bacteria doesn't change its size. The bacteria can perform multiple swallows. On each swallow operation any bacteria $$$i$$$ can swallow any bacteria $$$j$$$ if $$$a_i > a_j$$$ and $$$a_i \le a_j + K$$$. The swallow operations go one after another.For example, the sequence of bacteria sizes $$$a=[101, 53, 42, 102, 101, 55, 54]$$$ and $$$K=1$$$. The one of possible sequences of swallows is: $$$[101, 53, 42, 102, \underline{101}, 55, 54]$$$ $$$\to$$$ $$$[101, \underline{53}, 42, 102, 55, 54]$$$ $$$\to$$$ $$$[\underline{101}, 42, 102, 55, 54]$$$ $$$\to$$$ $$$[42, 102, 55, \underline{54}]$$$ $$$\to$$$ $$$[42, 102, 55]$$$. In total there are $$$3$$$ bacteria remained in the Petri dish.Since you don't have a microscope, you can only guess, what the minimal possible number of bacteria can remain in your Petri dish when you finally will find any microscope.

The first line contains two space separated positive integers $$$n$$$ and $$$K$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$1 \le K \le 10^6$$$) — number of bacteria and intergalactic constant $$$K$$$. The second line contains $$$n$$$ space separated integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^6$$$) — sizes of bacteria you have.

Print the only integer — minimal possible number of bacteria can remain.

NoteThe first example is clarified in the problem statement.In the second example an optimal possible sequence of swallows is: $$$[20, 15, 10, 15, \underline{20}, 25]$$$ $$$\to$$$ $$$[20, 15, 10, \underline{15}, 25]$$$ $$$\to$$$ $$$[20, 15, \underline{10}, 25]$$$ $$$\to$$$ $$$[20, \underline{15}, 25]$$$ $$$\to$$$ $$$[\underline{20}, 25]$$$ $$$\to$$$ $$$[25]$$$.In the third example no bacteria can swallow any other bacteria.


The cool breeze blows gently, the flowing water ripples steadily."Flowing and passing like this, the water isn't gone ultimately; Waxing and waning like that, the moon doesn't shrink or grow eventually.""Everything is transient in a way and perennial in another."Kanno doesn't seem to make much sense out of Mino's isolated words, but maybe it's time that they enjoy the gentle breeze and the night sky — the inexhaustible gifts from nature.Gazing into the sky of stars, Kanno indulges in a night's tranquil dreams. There is a set $$$S$$$ of $$$n$$$ points on a coordinate plane.Kanno starts from a point $$$P$$$ that can be chosen on the plane. $$$P$$$ is not added to $$$S$$$ if it doesn't belong to $$$S$$$. Then the following sequence of operations (altogether called a move) is repeated several times, in the given order:  Choose a line $$$l$$$ such that it passes through at least two elements in $$$S$$$ and passes through Kanno's current position. If there are multiple such lines, one is chosen equiprobably.  Move to one of the points that belong to $$$S$$$ and lie on $$$l$$$. The destination is chosen equiprobably among all possible ones, including Kanno's current position (if it does belong to $$$S$$$). There are $$$q$$$ queries each consisting of two integers $$$(t_i, m_i)$$$. For each query, you're to help Kanno maximize the probability of the stopping position being the $$$t_i$$$-th element in $$$S$$$ after $$$m_i$$$ moves with a proper selection of $$$P$$$, and output this maximum probability. Note that according to rule 1, $$$P$$$ should belong to at least one line that passes through at least two points from $$$S$$$.

The first line contains a positive integer $$$n$$$ ($$$2 \leq n \leq 200$$$) — the number of points in $$$S$$$. The $$$i$$$-th of the following $$$n$$$ lines contains two space-separated integers $$$x_i$$$ and $$$y_i$$$ ($$$-10^4 \leq x_i, y_i \leq 10^4$$$) — the coordinates of the $$$i$$$-th point in $$$S$$$. The input guarantees that for all $$$1 \leq i \lt j \leq n$$$, $$$(x_i, y_i) \neq (x_j, y_j)$$$ holds. The next line contains a positive integer $$$q$$$ ($$$1 \leq q \leq 200$$$) — the number of queries. Each of the following $$$q$$$ lines contains two space-separated integers $$$t$$$ and $$$m$$$ ($$$1 \leq t_i \leq n$$$, $$$1 \leq m_i \leq 10^4$$$) — the index of the target point and the number of moves, respectively.

Output $$$q$$$ lines each containing a decimal number — the $$$i$$$-th among them denotes the maximum probability of staying on the $$$t_i$$$-th point after $$$m_i$$$ steps, with a proper choice of starting position $$$P$$$. Your answer will be considered correct if each number in your output differs from the corresponding one in jury's answer by at most $$$10^{-6}$$$. Formally, let your answer be $$$a$$$, and the jury's answer be $$$b$$$. Your answer is considered correct if $$$|a - b| \le 10^{-6}$$$.

NoteThe points in $$$S$$$ and possible candidates for line $$$l$$$ are depicted in the following figure.  For the first query, when $$$P = (-1, -3)$$$, $$$l$$$ is uniquely determined to be $$$3x = y$$$, and thus Kanno will move to $$$(0, 0)$$$ with a probability of $$$\frac 1 2$$$.For the third query, when $$$P = (2, 2)$$$, $$$l$$$ is chosen equiprobably between $$$x + y = 4$$$ and $$$x = y$$$. Kanno will then move to the other four points with a probability of $$$\frac 1 2 \cdot \frac 1 3 = \frac 1 6$$$ each, or stay at $$$(2, 2)$$$ with a probability of $$$\frac 1 3$$$.


As the boat drifts down the river, a wood full of blossoms shows up on the riverfront."I've been here once," Mino exclaims with delight, "it's breathtakingly amazing.""What is it like?""Look, Kanno, you've got your paintbrush, and I've got my words. Have a try, shall we?" There are four kinds of flowers in the wood, Amaranths, Begonias, Centaureas and Dianthuses.The wood can be represented by a rectangular grid of $$$n$$$ rows and $$$m$$$ columns. In each cell of the grid, there is exactly one type of flowers.According to Mino, the numbers of connected components formed by each kind of flowers are $$$a$$$, $$$b$$$, $$$c$$$ and $$$d$$$ respectively. Two cells are considered in the same connected component if and only if a path exists between them that moves between cells sharing common edges and passes only through cells containing the same flowers.You are to help Kanno depict such a grid of flowers, with $$$n$$$ and $$$m$$$ arbitrarily chosen under the constraints given below. It can be shown that at least one solution exists under the constraints of this problem.Note that you can choose arbitrary $$$n$$$ and $$$m$$$ under the constraints below, they are not given in the input.

The first and only line of input contains four space-separated integers $$$a$$$, $$$b$$$, $$$c$$$ and $$$d$$$ ($$$1 \leq a, b, c, d \leq 100$$$) — the required number of connected components of Amaranths, Begonias, Centaureas and Dianthuses, respectively.

In the first line, output two space-separated integers $$$n$$$ and $$$m$$$ ($$$1 \leq n, m \leq 50$$$) — the number of rows and the number of columns in the grid respectively. Then output $$$n$$$ lines each consisting of $$$m$$$ consecutive English letters, representing one row of the grid. Each letter should be among 'A', 'B', 'C' and 'D', representing Amaranths, Begonias, Centaureas and Dianthuses, respectively. In case there are multiple solutions, print any. You can output each letter in either case (upper or lower).

NoteIn the first example, each cell of Amaranths, Begonias and Centaureas forms a connected component, while all the Dianthuses form one.

7 7
DDDDDDD
DDDBDBD
DDCDCDD
DBDADBD
DDCDCDD
DBDBDDD
DDDDDDD


Adilbek's house is located on a street which can be represented as the OX axis. This street is really dark, so Adilbek wants to install some post lamps to illuminate it. Street has $$$n$$$ positions to install lamps, they correspond to the integer numbers from $$$0$$$ to $$$n - 1$$$ on the OX axis. However, some positions are blocked and no post lamp can be placed there.There are post lamps of different types which differ only by their power. When placed in position $$$x$$$, post lamp of power $$$l$$$ illuminates the segment $$$[x; x + l]$$$. The power of each post lamp is always a positive integer number.The post lamp shop provides an infinite amount of lamps of each type from power $$$1$$$ to power $$$k$$$. Though each customer is only allowed to order post lamps of exactly one type. Post lamps of power $$$l$$$ cost $$$a_l$$$ each.What is the minimal total cost of the post lamps of exactly one type Adilbek can buy to illuminate the entire segment $$$[0; n]$$$ of the street? If some lamps illuminate any other segment of the street, Adilbek does not care, so, for example, he may place a lamp of power $$$3$$$ in position $$$n - 1$$$ (even though its illumination zone doesn't completely belong to segment $$$[0; n]$$$).

The first line contains three integer numbers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^6$$$, $$$0 \le m \le n$$$) — the length of the segment of the street Adilbek wants to illuminate, the number of the blocked positions and the maximum power of the post lamp available. The second line contains $$$m$$$ integer numbers $$$s_1, s_2, \dots, s_m$$$ ($$$0 \le s_1 < s_2 < \dots s_m < n$$$) — the blocked positions. The third line contains $$$k$$$ integer numbers $$$a_1, a_2, \dots, a_k$$$ ($$$1 \le a_i \le 10^6$$$) — the costs of the post lamps.

Print the minimal total cost of the post lamps of exactly one type Adilbek can buy to illuminate the entire segment $$$[0; n]$$$ of the street. If illumintaing the entire segment $$$[0; n]$$$ is impossible, print -1.