Toad Rash has a binary string $$$s$$$. A binary string consists only of zeros and ones.Let $$$n$$$ be the length of $$$s$$$.Rash needs to find the number of such pairs of integers $$$l$$$, $$$r$$$ that $$$1 \leq l \leq r \leq n$$$ and there is at least one pair of integers $$$x$$$, $$$k$$$ such that $$$1 \leq x, k \leq n$$$, $$$l \leq x < x + 2k \leq r$$$, and $$$s_x = s_{x+k} = s_{x+2k}$$$.Find this number of pairs for Rash.

The first line contains the string $$$s$$$ ($$$1 \leq |s| \leq 300\,000$$$), consisting of zeros and ones.

Output one integer: the number of such pairs of integers $$$l$$$, $$$r$$$ that $$$1 \leq l \leq r \leq n$$$ and there is at least one pair of integers $$$x$$$, $$$k$$$ such that $$$1 \leq x, k \leq n$$$, $$$l \leq x < x + 2k \leq r$$$, and $$$s_x = s_{x+k} = s_{x+2k}$$$.

NoteIn the first example, there are three $$$l$$$, $$$r$$$ pairs we need to count: $$$1$$$, $$$6$$$; $$$2$$$, $$$6$$$; and $$$1$$$, $$$5$$$.In the second example, there are no values $$$x$$$, $$$k$$$ for the initial string, so the answer is $$$0$$$.


Dora the explorer has decided to use her money after several years of juicy royalties to go shopping. What better place to shop than Nlogonia?There are $$$n$$$ stores numbered from $$$1$$$ to $$$n$$$ in Nlogonia. The $$$i$$$-th of these stores offers a positive integer $$$a_i$$$.Each day among the last $$$m$$$ days Dora bought a single integer from some of the stores. The same day, Swiper the fox bought a single integer from all the stores that Dora did not buy an integer from on that day.Dora considers Swiper to be her rival, and she considers that she beat Swiper on day $$$i$$$ if and only if the least common multiple of the numbers she bought on day $$$i$$$ is strictly greater than the least common multiple of the numbers that Swiper bought on day $$$i$$$.The least common multiple (LCM) of a collection of integers is the smallest positive integer that is divisible by all the integers in the collection.However, Dora forgot the values of $$$a_i$$$. Help Dora find out if there are positive integer values of $$$a_i$$$ such that she beat Swiper on every day. You don't need to find what are the possible values of $$$a_i$$$ though.Note that it is possible for some values of $$$a_i$$$ to coincide in a solution.

The first line contains integers $$$m$$$ and $$$n$$$ ($$$1\leq m \leq 50$$$, $$$1\leq n \leq 10^4$$$) — the number of days and the number of stores. After this $$$m$$$ lines follow, the $$$i$$$-th line starts with an integer $$$s_i$$$ ($$$1\leq s_i \leq n-1$$$), the number of integers Dora bought on day $$$i$$$, followed by $$$s_i$$$ distinct integers, the indices of the stores where Dora bought an integer on the $$$i$$$-th day. The indices are between $$$1$$$ and $$$n$$$.

Output must consist of a single line containing "possible" if there exist positive integers $$$a_i$$$ such that for each day the least common multiple of the integers bought by Dora is strictly greater than the least common multiple of the integers bought by Swiper on that day. Otherwise, print "impossible". Note that you don't have to restore the integers themselves.

NoteIn the first sample, a possible choice for the values of the $$$a_i$$$ is $$$3, 4, 3, 5, 2$$$. On the first day, Dora buys the integers $$$3, 4$$$ and $$$3$$$, whose LCM is $$$12$$$, while Swiper buys integers $$$5$$$ and $$$2$$$, whose LCM is $$$10$$$. On the second day, Dora buys $$$3, 5$$$ and $$$2$$$, whose LCM is $$$30$$$, and Swiper buys integers $$$3$$$ and $$$4$$$, whose LCM is $$$12$$$.


Toad Pimple has an array of integers $$$a_1, a_2, \ldots, a_n$$$.We say that $$$y$$$ is reachable from $$$x$$$ if $$$x<y$$$ and there exists an integer array $$$p$$$ such that $$$x = p_1 < p_2 < \ldots < p_k=y$$$, and $$$a_{p_i}\, \&\, a_{p_{i+1}} > 0$$$ for all integers $$$i$$$ such that $$$1 \leq i < k$$$.Here $$$\&$$$ denotes the bitwise AND operation.You are given $$$q$$$ pairs of indices, check reachability for each of them.

The first line contains two integers $$$n$$$ and $$$q$$$ ($$$2 \leq n \leq 300\,000$$$, $$$1 \leq q \leq 300\,000$$$) — the number of integers in the array and the number of queries you need to answer. The second line contains $$$n$$$ space-separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 300\,000$$$) — the given array. The next $$$q$$$ lines contain two integers each. The $$$i$$$-th of them contains two space-separated integers $$$x_i$$$ and $$$y_i$$$ ($$$1 \leq x_i < y_i \leq n$$$). You need to check if $$$y_i$$$ is reachable from $$$x_i$$$.

Output $$$q$$$ lines. In the $$$i$$$-th of them print "Shi" if $$$y_i$$$ is reachable from $$$x_i$$$, otherwise, print "Fou".

NoteIn the first example, $$$a_3 = 0$$$. You can't reach it, because AND with it is always zero. $$$a_2\, \&\, a_4 > 0$$$, so $$$4$$$ is reachable from $$$2$$$, and to go from $$$1$$$ to $$$4$$$ you can use $$$p = [1, 2, 4]$$$.


You are given an array $$$a_1, a_2, \dots, a_n$$$. All $$$a_i$$$ are pairwise distinct.Let's define function $$$f(l, r)$$$ as follows:   let's define array $$$b_1, b_2, \dots, b_{r - l + 1}$$$, where $$$b_i = a_{l - 1 + i}$$$;  sort array $$$b$$$ in increasing order;  result of the function $$$f(l, r)$$$ is $$$\sum\limits_{i = 1}^{r - l + 1}{b_i \cdot i}$$$. Calculate $$$\left(\sum\limits_{1 \le l \le r \le n}{f(l, r)}\right) \mod (10^9+7)$$$, i.e. total sum of $$$f$$$ for all subsegments of $$$a$$$ modulo $$$10^9+7$$$.

The first line contains one integer $$$n$$$ ($$$1 \le n \le 5 \cdot 10^5$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$) — array $$$a$$$.

Print one integer — the total sum of $$$f$$$ for all subsegments of $$$a$$$ modulo $$$10^9+7$$$


So we got bored and decided to take our own guess at how would "Inception" production go if the budget for the film had been terribly low.The first scene we remembered was the one that features the whole city bending onto itself:  It feels like it will require high CGI expenses, doesn't it? Luckily, we came up with a similar-looking scene which was a tiny bit cheaper to make.Firstly, forget about 3D, that's hard and expensive! The city is now represented as a number line (infinite to make it easier, of course).Secondly, the city doesn't have to look natural at all. There are $$$n$$$ buildings on the line. Each building is a square $$$1 \times 1$$$. Buildings are numbered from $$$1$$$ to $$$n$$$ in ascending order of their positions. Lower corners of building $$$i$$$ are at integer points $$$a_i$$$ and $$$a_i + 1$$$ of the number line. Also the distance between any two neighbouring buildings $$$i$$$ and $$$i + 1$$$ doesn't exceed $$$d$$$ (really, this condition is here just to make the city look not that sparse). Distance between some neighbouring buildings $$$i$$$ and $$$i + 1$$$ is calculated from the lower right corner of building $$$i$$$ to the lower left corner of building $$$i + 1$$$.Finally, curvature of the bend is also really hard to simulate! Let the bend at some integer coordinate $$$x$$$ be performed with the following algorithm. Take the ray from $$$x$$$ to $$$+\infty$$$ and all the buildings which are on this ray and start turning the ray and the buildings counter-clockwise around point $$$x$$$. At some angle some building will touch either another building or a part of the line. You have to stop bending there (implementing buildings crushing is also not worth its money). Let's call the angle between two rays in the final state the terminal angle $$$\alpha_x$$$.The only thing left is to decide what integer point $$$x$$$ is the best to start bending around. Fortunately, we've already chosen $$$m$$$ candidates to perform the bending.So, can you please help us to calculate terminal angle $$$\alpha_x$$$ for each bend $$$x$$$ from our list of candidates?

The first line contains two integer numbers $$$n$$$ and $$$d$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$0 \le d \le 7000$$$) — the number of buildings and the maximum distance between any pair of neighbouring buildings, respectively. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$a_1 = 0$$$, $$$0 < a_{i + 1} - a_i \le d + 1$$$) — coordinates of left corners of corresponding buildings in ascending order. The third line contains single integer $$$m$$$ ($$$1 \le m \le 2 \cdot 10^5$$$) — the number of candidates. The fourth line contains $$$m$$$ integers $$$x_1, x_2, \dots, x_m$$$ ($$$0 \le x_i \le a_n + 1$$$, $$$x_i < x_{i + 1}$$$) — the coordinates of bends you need to calculate terminal angles for in ascending order.

Print $$$m$$$ numbers. For each bend $$$x_i$$$ print terminal angle $$$\alpha_{x_i}$$$ (in radians). Your answer is considered correct if its absolute error does not exceed $$$10^{-9}$$$. Formally, let your answer be $$$a$$$, and the jury's answer be $$$b$$$. Your answer is accepted if and only if $$$|a - b| \le 10^{-9}$$$.

NoteHere you can see the picture of the city for the first example and the bend at position $$$2$$$ for it. The angle you need to measure is marked blue. You can see that it's equal to $$$\frac \pi 4$$$.You can see that no pair of neighbouring buildings have distance more than $$$4$$$ between them. $$$d = 4$$$ would also suffice for that test.


Toad Ilya has a rooted binary tree with vertex $$$1$$$ being the root. A tree is a connected graph without cycles. A tree is rooted if one vertex is selected and called the root. A vertex $$$u$$$ is a child of a vertex $$$v$$$ if $$$u$$$ and $$$v$$$ are connected by an edge and $$$v$$$ is closer to the root than $$$u$$$. A leaf is a non-root vertex that has no children.In the tree Ilya has each vertex has at most two children, and each edge has some character written on it. The character can be a lowercase English letter or the question mark '?'.Ilya will $$$q$$$ times update the tree a bit. Each update will replace exactly one character on some edge. After each update Ilya needs to find if the tree is anagrammable and if yes, find its anagramnity for each letter. Well, that's difficult to explain, but we'll try.To start with, a string $$$a$$$ is an anagram of a string $$$b$$$ if it is possible to rearrange letters in $$$a$$$ (without changing the letters itself) so that it becomes $$$b$$$. For example, the string "fortyfive" is an anagram of the string "overfifty", but the string "aabb" is not an anagram of the string "bbba".Consider a path from the root of the tree to a leaf. The characters on the edges on this path form a string, we say that this string is associated with this leaf. The tree is anagrammable if and only if it is possible to replace each question mark with a lowercase English letter so that for all pair of leaves the associated strings for these leaves are anagrams of each other.If the tree is anagrammable, then its anagramnity for the letter $$$c$$$ is the maximum possible number of letters $$$c$$$ in a string associated with some leaf in a valid replacement of all question marks.Please after each update find if the tree is anagrammable and if yes, find the $$$\sum{f(c) \cdot ind(c)}$$$ for all letters $$$c$$$, where $$$f(c)$$$ is the anagramnity for the letter $$$c$$$, and $$$ind(x)$$$ is the index of this letter in the alphabet ($$$ind($$$"a"$$$) = 1$$$, $$$ind($$$"b"$$$) = 2$$$, ..., $$$ind($$$"z"$$$) = 26$$$).

The first line of input contains two integers $$$n$$$ and $$$q$$$ ($$$2 \leq n \leq 150\,000$$$, $$$1 \leq q \leq 150\,000$$$) — the number of vertices in the tree and the number of queries. The next $$$n-1$$$ lines describe the initial tree. The $$$i$$$-th of them contains an integer $$$p_i$$$ and a character $$$c_i$$$ ($$$1 \leq p_i \leq i$$$, $$$c_i$$$ is a lowercase English letter or the question mark '?') describing an edge between vertices $$$p_i$$$ and $$$i+1$$$ with character $$$c_i$$$ written on it. The root of this tree is the vertex $$$1$$$, and each vertex has at most two children. The next $$$q$$$ lines describe the queries. The $$$i$$$-th of them contains two integers $$$v$$$ and $$$c$$$ ($$$2 \leq v \leq n$$$, $$$c$$$ is a lowercase English letter or the question mark '?'), meaning that updated character on the edge between $$$p_{v-1}$$$ to $$$v$$$ is $$$c$$$. The updated character can be the same as was written before.

Output $$$q$$$ lines. In the $$$i$$$-th of them print "Fou" if the tree is not anagrammable after the first $$$i$$$ updates. Otherwise output "Shi" and the $$$\sum{f(c) \cdot ind(c)}$$$ for all letters $$$c$$$.

NoteIn the first example after the first query, for each character, you can set all edges equal to that character, and you will get $$$1$$$ such character on each path, so the answer is $$$1 \cdot (1+2+\ldots+26) = 351$$$.In the first example after the second query, you know that all paths should be an anagram of "a", so all paths should be "a", so the answer is $$$1 \cdot 1 = 1$$$.In the first example after the third query, you have two paths with strings "a" and "b", but these strings are not anagrams, so the answer is "Fou".In the first example after the fourth query, you know that all paths should be "b", so the answer is $$$1 \cdot 2 = 2$$$.In the second example after the first query, you know that $$$f($$$'a'$$$) = 2$$$ and $$$f(c) = 1$$$ for all other characters, so the answer is $$$1 \cdot (2 + 3 + \ldots + 26) + 2 = 352$$$.In the second example after the second query, you know that each path should contain one 'a' and one 'b', so the answer is $$$1 \cdot 1 + 1 \cdot 2 = 3$$$.


Toad Mikhail has an array of $$$2^k$$$ integers $$$a_1, a_2, \ldots, a_{2^k}$$$.Find two permutations $$$p$$$ and $$$q$$$ of integers $$$0, 1, \ldots, 2^k-1$$$, such that $$$a_i$$$ is equal to $$$p_i \oplus q_i$$$ for all possible $$$i$$$, or determine there are no such permutations. Here $$$\oplus$$$ denotes the bitwise XOR operation.

The first line contains one integer $$$k$$$ ($$$2 \leq k \leq 12$$$), denoting that the size of the array is $$$2^k$$$. The next line contains $$$2^k$$$ space-separated integers $$$a_1, a_2, \ldots, a_{2^k}$$$ ($$$0 \leq a_i < 2^k$$$) — the elements of the given array.

If the given array can't be represented as element-wise XOR of two permutations of integers $$$0, 1, \ldots, 2^k-1$$$, print "Fou". Otherwise, print "Shi" in the first line. The next two lines should contain the description of two suitable permutations. The first of these lines should contain $$$2^k$$$ space-separated distinct integers $$$p_{1}, p_{2}, \ldots, p_{2^k}$$$, and the second line should contain $$$2^k$$$ space-separated distinct integers $$$q_{1}, q_{2}, \ldots, q_{2^k}$$$. All elements of $$$p$$$ and $$$q$$$ should be between $$$0$$$ and $$$2^k - 1$$$, inclusive; $$$p_i \oplus q_i$$$ should be equal to $$$a_i$$$ for all $$$i$$$ such that $$$1 \leq i \leq 2^k$$$. If there are several possible solutions, you can print any.


Toad Ivan has $$$m$$$ pairs of integers, each integer is between $$$1$$$ and $$$n$$$, inclusive. The pairs are $$$(a_1, b_1), (a_2, b_2), \ldots, (a_m, b_m)$$$. He asks you to check if there exist two integers $$$x$$$ and $$$y$$$ ($$$1 \leq x < y \leq n$$$) such that in each given pair at least one integer is equal to $$$x$$$ or $$$y$$$.

The first line contains two space-separated integers $$$n$$$ and $$$m$$$ ($$$2 \leq n \leq 300\,000$$$, $$$1 \leq m \leq 300\,000$$$) — the upper bound on the values of integers in the pairs, and the number of given pairs. The next $$$m$$$ lines contain two integers each, the $$$i$$$-th of them contains two space-separated integers $$$a_i$$$ and $$$b_i$$$ ($$$1 \leq a_i, b_i \leq n, a_i \neq b_i$$$) — the integers in the $$$i$$$-th pair.

Output "YES" if there exist two integers $$$x$$$ and $$$y$$$ ($$$1 \leq x < y \leq n$$$) such that in each given pair at least one integer is equal to $$$x$$$ or $$$y$$$. Otherwise, print "NO". You can print each letter in any case (upper or lower).

NoteIn the first example, you can't choose any $$$x$$$, $$$y$$$ because for each such pair you can find a given pair where both numbers are different from chosen integers.In the second example, you can choose $$$x=2$$$ and $$$y=4$$$.In the third example, you can choose $$$x=1$$$ and $$$y=2$$$.


We have three positive integers $$$a$$$, $$$b$$$ and $$$c$$$. You don't know their values, but you know some information about them. Consider all three pairwise sums, i.e. the numbers $$$a+b$$$, $$$a+c$$$ and $$$b+c$$$. You know exactly two (any) of three pairwise sums.Your task is to find such three positive integers $$$a$$$, $$$b$$$ and $$$c$$$ which match the given information. It means that if you consider $$$a+b$$$, $$$a+c$$$ and $$$b+c$$$, two out of all three of them are given in the input. Among all such triples, you must choose one with the minimum possible sum $$$a+b+c$$$, and among all triples with the minimum sum, you can print any.You have to process $$$q$$$ independent queries.

The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 1000$$$) — the number of queries. The next $$$q$$$ lines contain queries. Each query is given as two integers $$$x$$$ and $$$y$$$ ($$$2 \le x, y \le 2 \cdot 10^9$$$), where $$$x$$$ and $$$y$$$ are any two out of the three numbers $$$a+b$$$, $$$a+c$$$ and $$$b+c$$$.

For each query print the answer to it: three positive integers $$$a$$$, $$$b$$$ and $$$c$$$ consistent with the given information. Among all such triples, you have to choose one with the minimum possible sum $$$a+b+c$$$. Among all triples with the minimum sum, you can print any.


Everyone knows that two consecutive (adjacent) "minus" signs can be replaced with a single "plus" sign.You are given the string $$$s$$$, consisting of "plus" and "minus" signs only. Zero or more operations can be performed with it. In each operation you can choose any two adjacent "minus" signs, and replace them with a single "plus" sign. Thus, in one operation, the length of the string is reduced by exactly $$$1$$$.You are given two strings $$$s$$$ and $$$t$$$. Determine if you can use $$$0$$$ or more operations to get the string $$$t$$$ from the string $$$s$$$.

The first line of the input contains an integer $$$k$$$ ($$$1 \le k \le 10^5$$$), denoting the number of test cases in the input. The following lines contain descriptions of the test sets, each set consists of two lines. First comes the line containing $$$s$$$ (the length of the line $$$s$$$ does not exceed $$$2\cdot10^5$$$), then comes the line containing $$$t$$$ (the length of the line $$$t$$$ does not exceed $$$2\cdot10^5$$$). The lines $$$s$$$ and $$$t$$$ are non-empty, and they contain only "plus" and "minus" signs. The sum of the lengths of lines $$$s$$$ over all test cases in the input does not exceed $$$2\cdot10^5$$$. Similarly, the sum of the lengths of lines $$$t$$$ over all test cases in the input does not exceed $$$2\cdot10^5$$$.

Print $$$k$$$ lines: the $$$i$$$-th line must contain YES if the answer to the $$$i$$$-th test case is positive, otherwise NO. Print YES and NO using uppercase letters only.


Every day Kotlin heroes analyze the statistics of their website. For $$$n$$$ days, they wrote out $$$n$$$ numbers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i$$$ is the number of visits on the $$$i$$$-th day.They believe that a day is bad if there are at least $$$2$$$ days before it with a strictly greater number of visits. For example, if $$$n=8$$$ and $$$a=[3, 1, 4, 1, 5, 9, 2, 6]$$$, then the day $$$4$$$ is bad (because $$$a_4=1$$$, but there are $$$a_1=3$$$ and $$$a_3=4$$$). Also, the day with the number $$$7$$$ is bad too.Write a program that finds the number of bad days.

The first line contains an integer $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$), where $$$n$$$ is the number of days. The second line contains $$$n$$$ positive integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the number of website visits on the $$$i$$$-th day.

Print the number of bad days, i.e. such days that there are at least two days before it with a strictly greater number of visits.


Polycarp is developing a method for transmitting $$$n$$$ integer sequences over a network. This method should support the transmission of an arbitrary number of integer sequences; sequences can have different lengths. The sequences contain arbitrary non-negative integers.Polycarp developed the following encoding procedure:  We assume that the sequences are numbered from $$$1$$$ to $$$n$$$.  We add a special terminating marker to each sequence at the end, an element equal to -1.  The encoding result is a new single sequence that contains all the elements of the specified $$$n$$$ in a special order: first, add to the result of coding all the first elements of the sequences (in the order from the $$$1$$$-st to the $$$n$$$-th), then all the second elements (in the order from the $$$1$$$-st to the $$$n$$$-th) and so on, if the sequence does not have the corresponding element, then it is simply skipped. The process ends when all elements of all sequences are added. For example, if you want to encode three sequences $$$[3, 1, 4]$$$, $$$[2, 7]$$$ and $$$[1, 2, 3, 4]$$$, then the sequence of actions will be as follows:  we modify all three sequences by appending -1: $$$[3, 1, 4, -1]$$$, $$$[2, 7, -1]$$$ and $$$[1, 2, 3, 4, -1]$$$;  we write out all the first elements, we get $$$[3, 2, 1]$$$;  then write down all the second elements, we get $$$[3, 2, 1, 1, 7, 2]$$$;  then write down all the third elements, we get $$$[3, 2, 1, 1, 7, 2, 4, -1, 3]$$$;  then write down all fourth elements, get $$$[3, 2, 1, 1, 7, 2, 4, -1, 3, -1, 4]$$$ (note that the second sequence has already ended);  then write down all the fifth elements, we get $$$[3, 2, 1, 1, 7, 2, 4, -1, 3, -1, 4, -1]$$$ (note that the first and second sequences have already ended);  all the sequences are ended now, and the encoding process is finished;  the encoding result is: $$$[3, 2, 1, 1, 7, 2, 4, -1, 3, -1, 4, -1]$$$. Your task is to implement decoding by a given encoding result.

The first line contains integer number $$$m$$$ ($$$1 \le m \le 3\cdot10^5$$$), denoting the length of the encoding result. The second line contains the result of encoding as a sequence of integers $$$b_1, b_2, \dots, b_m$$$ ($$$-1 \le b_i \le 100$$$). It is guaranteed that in the initial sequences before encoding contains only non-negative integers from $$$0$$$ to $$$100$$$, that you are in fact given the result of correct encoding (in other words, it is guaranteed that the answer exists). It is possible that one or more initial sequences were empty before encoding.

Print $$$n$$$, where $$$n$$$ is the number of encoded sequences. Then print $$$n$$$ lines in the format $$$k_i, a_{i1}, a_{i2}, \dots, a_{ik_i}$$$, where $$$k_i$$$ is the length of the $$$i$$$-th sequence, and $$$a_{i1}, a_{i2}, \dots, a_{ik_i}$$$ are its elements. Separate the numbers in the lines with spaces. Please note that the encoding procedure is such that every possible encoding result can be decoded in only one way.


The circle line of the Roflanpolis subway has $$$n$$$ stations.There are two parallel routes in the subway. The first one visits stations in order $$$1 \to 2 \to \ldots \to n \to 1 \to 2 \to \ldots$$$ (so the next stop after station $$$x$$$ is equal to $$$(x+1)$$$ if $$$x < n$$$ and $$$1$$$ otherwise). The second route visits stations in order $$$n \to (n-1) \to \ldots \to 1 \to n \to (n-1) \to \ldots$$$ (so the next stop after station $$$x$$$ is equal to $$$(x-1)$$$ if $$$x>1$$$ and $$$n$$$ otherwise). All trains depart their stations simultaneously, and it takes exactly $$$1$$$ minute to arrive at the next station.Two toads live in this city, their names are Daniel and Vlad.Daniel is currently in a train of the first route at station $$$a$$$ and will exit the subway when his train reaches station $$$x$$$.Coincidentally, Vlad is currently in a train of the second route at station $$$b$$$ and he will exit the subway when his train reaches station $$$y$$$.Surprisingly, all numbers $$$a,x,b,y$$$ are distinct.Toad Ilya asks you to check if Daniel and Vlad will ever be at the same station at the same time during their journey. In other words, check if there is a moment when their trains stop at the same station. Note that this includes the moments when Daniel or Vlad enter or leave the subway.

The first line contains five space-separated integers $$$n$$$, $$$a$$$, $$$x$$$, $$$b$$$, $$$y$$$ ($$$4 \leq n \leq 100$$$, $$$1 \leq a, x, b, y \leq n$$$, all numbers among $$$a$$$, $$$x$$$, $$$b$$$, $$$y$$$ are distinct) — the number of stations in Roflanpolis, Daniel's start station, Daniel's finish station, Vlad's start station and Vlad's finish station, respectively.

Output "YES" if there is a time moment when Vlad and Daniel are at the same station, and "NO" otherwise. You can print each letter in any case (upper or lower).

NoteIn the first example, Daniel and Vlad start at the stations $$$(1, 3)$$$. One minute later they are at stations $$$(2, 2)$$$. They are at the same station at this moment. Note that Vlad leaves the subway right after that.Consider the second example, let's look at the stations Vlad and Daniel are at. They are:   initially $$$(2, 9)$$$,  after $$$1$$$ minute $$$(3, 8)$$$,  after $$$2$$$ minutes $$$(4, 7)$$$,  after $$$3$$$ minutes $$$(5, 6)$$$,  after $$$4$$$ minutes $$$(6, 5)$$$,  after $$$5$$$ minutes $$$(7, 4)$$$,  after $$$6$$$ minutes $$$(8, 3)$$$,  after $$$7$$$ minutes $$$(9, 2)$$$,  after $$$8$$$ minutes $$$(10, 1)$$$,  after $$$9$$$ minutes $$$(1, 10)$$$. After that, they both leave the subway because they are at their finish stations, so there is no moment when they both are at the same station.


Imagine that you are the CEO of a big old-fashioned company. Unlike any modern and progressive company (such as JetBrains), your company has a dress code. That's why you have already allocated a spacious room for your employees where they can change their clothes. Moreover, you've already purchased an $$$m$$$-compartment wardrobe, so the $$$i$$$-th employee can keep his/her belongings in the $$$i$$$-th cell (of course, all compartments have equal widths).The issue has occurred: the wardrobe has sliding doors! More specifically, the wardrobe has $$$n$$$ doors (numbered from left to right) and the $$$j$$$-th door has width equal to $$$a_j$$$ wardrobe's cells. The wardrobe has single rails so that no two doors can slide past each other.    Extremely schematic example of a wardrobe: $$$m=9$$$, $$$n=2$$$, $$$a_1=2$$$, $$$a_2=3$$$. The problem is as follows: sometimes to open some cells you must close some other cells (since all doors are placed on the single track). For example, if you have a $$$4$$$-compartment wardrobe (i.e. $$$m=4$$$) with $$$n=2$$$ one-cell doors (i.e. $$$a_1=a_2=1$$$) and you need to open the $$$1$$$-st and the $$$3$$$-rd cells, you have to close the $$$2$$$-nd and the $$$4$$$-th cells.As CEO, you have a complete schedule for the next $$$q$$$ days. Now you are wondering: is it possible that all employees who will come on the $$$k$$$-th day can access their cells simultaneously?

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$1 \le m \le 4 \cdot 10^5$$$) — the number of doors and compartments respectively. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le m$$$, $$$\sum{a_i} \le m$$$) — the corresponding widths of the doors. The third line contains a single integer $$$q$$$ ($$$1 \le q \le 2 \cdot 10^5$$$) — the number of days you have to process. The next $$$q$$$ lines describe schedule of each day. Each schedule is represented as an integer $$$c_k$$$ followed by $$$c_k$$$ integers $$$w_1, w_2, \dots, w_{c_k}$$$ ($$$1 \le c_k \le 2 \cdot 10^5$$$, $$$1 \le w_1 < w_2 < \dots < w_{c_k} \le m$$$) — the number of employees who will come on the $$$k$$$-th day, and their indices in ascending order. It's guaranteed that $$$\sum{c_k}$$$ doesn't exceed $$$2 \cdot 10^5$$$.

Print $$$q$$$ answers. Each answer is "YES" or "NO" (case insensitive). Print "YES" if it is possible, that all employees on the corresponding day can access their compartments simultaneously.


Polycarp has $$$n$$$ wheels and a car with $$$m$$$ slots for wheels. The initial pressure in the $$$i$$$-th wheel is $$$a_i$$$.Polycarp's goal is to take exactly $$$m$$$ wheels among the given $$$n$$$ wheels and equalize the pressure in them (then he can put these wheels in a car and use it for driving). In one minute he can decrease or increase the pressure in any (single) wheel by $$$1$$$. He can increase the pressure no more than $$$k$$$ times in total because it is hard to pump up wheels.Help Polycarp and say what is the minimum number of minutes he needs to spend to equalize the pressure of at least $$$m$$$ wheels among the given $$$n$$$ wheels.

The first line of the input contains three integers $$$n, m$$$ and $$$k$$$ ($$$1 \le m \le n \le 2 \cdot 10^5, 0 \le k \le 10^9$$$) — the number of wheels, the number of slots for wheels in a car and the number of times Polycarp can increase by $$$1$$$ the pressure in a wheel. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the pressure in the $$$i$$$-th wheel.

Print one integer — the minimum number of minutes Polycarp needs to spend to equalize the pressure in at least $$$m$$$ wheels among the given $$$n$$$ wheels.


You are given an undirected graph consisting of $$$n$$$ vertices and $$$m$$$ edges.Recall that a cycle is a path that starts and ends in the same vertex. A cycle in a graph is called simple if it contains each vertex (except the starting and ending one) no more than once (the starting and the ending one is contained always twice). Note that loops are considered to be simple cycles.In one move you can choose any simple cycle in this graph and erase the edges corresponding to this cycle (corresponding vertices remain in the graph). It is allowed to erase the loop or two copies of the same edge (take a look at examples).Your problem is to apply some sequence of moves to obtain the graph without edges. It is not necessary to minimize the number of cycles. If it is impossible, print "NO".

The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 2 \cdot 10^5$$$) — the number of vertices and the number of edges in the graph. The next $$$m$$$ lines contain edges of the graph. The $$$i$$$-th line contains the $$$i$$$-th edge $$$x_i, y_i$$$ ($$$1 \le x_i, y_i \le n$$$), where $$$x_i$$$ and $$$y_i$$$ are vertices connected by the $$$i$$$-th edge. The graph can contain loops or multiple edges.

If it is impossible to decompose the given graph into simple cycles, print "NO" in the first line. Otherwise print "YES" in the first line. In the second line print $$$k$$$ — the number of simple cycles in the graph decomposition. In the next $$$k$$$ lines print cycles themselves. The $$$j$$$-th line should contain the $$$j$$$-th cycle. First, print $$$c_j$$$ — the number of vertices in the $$$j$$$-th cycle. Then print the cycle as a sequence of vertices. All neighbouring (adjacent) vertices in the printed path should be connected by an edge that isn't contained in other cycles.

NoteThe picture corresponding to the first example:


You are given the sequence $$$a_1, a_2, \dots, a_n$$$. You can choose any subset of elements and then reorder them to create a "saw".The sequence $$$b_1, b_2, \dots, b_m$$$ is called a "saw" if the elements satisfy one of the following series of inequalities: $$$b_1>b_2<b_3>b_4<\dots$$$ or $$$b_1<b_2>b_3<b_4>\dots$$$.Find the longest saw which can be obtained from a given array.Note that both the given sequence $$$a$$$ and the required saw $$$b$$$ can contain duplicated (non-unique) values.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases in the input. Then the descriptions of the $$$t$$$ test cases follow. Each test case begins with a line containing integer $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$). Then a line containing $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) follows. It's guaranteed that $$$\sum{n}$$$ doesn't exceed $$$2 \cdot 10^5$$$.

For each test case, print two lines: print the length of the longest saw in the first line, and the saw itself in the second line. If there are several solutions, print any of them.


You are given $$$n$$$ segments on the $$$Ox$$$ axis. The $$$i$$$-th segment is given as a pair $$$l_i, r_i$$$, where $$$l_i$$$ is the position of the left end of the $$$i$$$-th segment and $$$r_i$$$ is the position of the right end of the $$$i$$$-th segment. Segments may intersect, overlap, or even coincide. A segment is a set of numbers (including floating-point numbers) lying between the segment ends or coinciding with them. Formally, the segment $$$[l, r]=\{x~|~x \in \Bbb{R},~l \le x \le r\}$$$.Let the union of segments be the set of all axis points covered by the set of segments. Let's call a subset of the given segments good if its union equals the union of all $$$n$$$ segments.Your task is to calculate the number of good subsets of the given $$$n$$$ segments. Since the answer may be very large, print it modulo $$$998244353$$$.

The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of segments. The next $$$n$$$ lines contain segments. The $$$i$$$-th segment is given as a pair $$$l_i, r_i$$$ ($$$1 \le l_i \le r_i \le 10^9$$$), where $$$l_i$$$ is the left border of the segment and $$$r_i$$$ is the right border of the segment. Segments may intersect, overlap, or even coincide.

Print the number of good subsets of the given set of segments. Since the answer may be very large, print it modulo $$$998244353$$$.


Nauuo is a girl who loves drawing circles.One day she has drawn a circle and wanted to draw a tree on it.The tree is a connected undirected graph consisting of $$$n$$$ nodes and $$$n-1$$$ edges. The nodes are numbered from $$$1$$$ to $$$n$$$.Nauuo wants to draw a tree on the circle, the nodes of the tree should be in $$$n$$$ distinct points on the circle, and the edges should be straight without crossing each other."Without crossing each other" means that every two edges have no common point or the only common point is an endpoint of both edges.Nauuo wants to draw the tree using a permutation of $$$n$$$ elements. A permutation of $$$n$$$ elements is a sequence of integers $$$p_1,p_2,\ldots,p_n$$$ in which every integer from $$$1$$$ to $$$n$$$ appears exactly once.After a permutation is chosen Nauuo draws the $$$i$$$-th node in the $$$p_i$$$-th point on the circle, then draws the edges connecting the nodes.The tree is given, Nauuo wants to know how many permutations are there so that the tree drawn satisfies the rule (the edges are straight without crossing each other). She only wants to know the answer modulo $$$998244353$$$, can you help her?It is obvious that whether a permutation is valid or not does not depend on which $$$n$$$ points on the circle are chosen.

The first line contains a single integer $$$n$$$ ($$$2\le n\le 2\cdot 10^5$$$) — the number of nodes in the tree. Each of the next $$$n-1$$$ lines contains two integers $$$u$$$ and $$$v$$$ ($$$1\le u,v\le n$$$), denoting there is an edge between $$$u$$$ and $$$v$$$. It is guaranteed that the given edges form a tree.

The output contains a single integer — the number of permutations suitable to draw the given tree on a circle satisfying the rule, modulo $$$998244353$$$.

NoteExample 1All valid permutations and their spanning trees are as follows.Here is an example of invalid permutation: the edges $$$(1,3)$$$ and $$$(2,4)$$$ are crossed.Example 2Every permutation leads to a valid tree, so the answer is $$$4! = 24$$$.


Nauuo is a girl who loves playing games related to portals.One day she was playing a game as follows.In an $$$n\times n$$$ grid, the rows are numbered from $$$1$$$ to $$$n$$$ from top to bottom, the columns are numbered from $$$1$$$ to $$$n$$$ from left to right. We denote a cell on the intersection of the $$$r$$$-th row and $$$c$$$-th column as $$$(r,c)$$$.A portal is a pair of doors. You can travel from one of them to another without changing your direction. More formally, if you walk into a cell with a door, you will teleport to the cell with the other door of the same portal and then walk into the next cell facing the original direction. There can not be more than one doors in a single cell.The "next cell" is the nearest cell in the direction you are facing. For example, if you are facing bottom, the next cell of $$$(2,5)$$$ is $$$(3,5)$$$.If you walk into a cell without a door, you must walk into the next cell after that without changing the direction. If the next cell does not exist, you must exit the grid.You have to set some (possibly zero) portals in the grid, so that if you walk into $$$(i,1)$$$ facing right, you will eventually exit the grid from $$$(r_i,n)$$$, if you walk into $$$(1, i)$$$ facing bottom, you will exit the grid from $$$(n,c_i)$$$.It is guaranteed that both $$$r_{1..n}$$$ and $$$c_{1..n}$$$ are permutations of $$$n$$$ elements. A permutation of $$$n$$$ elements is a sequence of numbers $$$p_1,p_2,\ldots,p_n$$$ in which every integer from $$$1$$$ to $$$n$$$ appears exactly once.She got confused while playing the game, can you help her to find a solution?

The first line contains a single integer $$$n$$$ ($$$1\le n\le 1000$$$) — the side length of the grid. The second line contains $$$n$$$ integers $$$r_1,r_2,\ldots,r_n$$$ ($$$1\le r_i\le n$$$) — if you walk into $$$(i,1)$$$ facing right, you should exit the grid from $$$(r_i,n)$$$. It is guaranteed that $$$r_{1..n}$$$ is a permutation of $$$n$$$ elements. The third line contains $$$n$$$ integers $$$c_1,c_2,\ldots,c_n$$$ ($$$1\le c_i\le n$$$) — if you walk into $$$(1,i)$$$ facing bottom, you should exit the grid from $$$(n,c_i)$$$. It is guaranteed that $$$c_{1..n}$$$ is a permutation of $$$n$$$ elements.

If it is impossible to satisfy the rule, print the only number $$$-1$$$. Otherwise the first line should contain a single integer $$$m$$$ ($$$0\le m\le\frac{n^2}2$$$) — the number of portals you set. In the following $$$m$$$ lines, each line should contain four integers $$$x_1,y_1,x_2,y_2$$$, represents that you set a portal consisting of two doors in $$$(x_1,y_1)$$$ and $$$(x_2,y_2)$$$. If there are multiple answers, print any. You do not have to minimize $$$m$$$.

NoteExample 1The cells with the same letter are a portal. You can set portals in this way:It satisfies the rule, because:Example 2You can set portals in this way:


The only difference between easy and hard versions is constraints.Nauuo is a girl who loves random picture websites.One day she made a random picture website by herself which includes $$$n$$$ pictures.When Nauuo visits the website, she sees exactly one picture. The website does not display each picture with equal probability. The $$$i$$$-th picture has a non-negative weight $$$w_i$$$, and the probability of the $$$i$$$-th picture being displayed is $$$\frac{w_i}{\sum_{j=1}^nw_j}$$$. That is to say, the probability of a picture to be displayed is proportional to its weight.However, Nauuo discovered that some pictures she does not like were displayed too often. To solve this problem, she came up with a great idea: when she saw a picture she likes, she would add $$$1$$$ to its weight; otherwise, she would subtract $$$1$$$ from its weight.Nauuo will visit the website $$$m$$$ times. She wants to know the expected weight of each picture after all the $$$m$$$ visits modulo $$$998244353$$$. Can you help her?The expected weight of the $$$i$$$-th picture can be denoted by $$$\frac {q_i} {p_i}$$$ where $$$\gcd(p_i,q_i)=1$$$, you need to print an integer $$$r_i$$$ satisfying $$$0\le r_i<998244353$$$ and $$$r_i\cdot p_i\equiv q_i\pmod{998244353}$$$. It can be proved that such $$$r_i$$$ exists and is unique.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1\le n\le 2\cdot 10^5$$$, $$$1\le m\le 3000$$$) — the number of pictures and the number of visits to the website. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$a_i$$$ is either $$$0$$$ or $$$1$$$) — if $$$a_i=0$$$ , Nauuo does not like the $$$i$$$-th picture; otherwise Nauuo likes the $$$i$$$-th picture. It is guaranteed that there is at least one picture which Nauuo likes. The third line contains $$$n$$$ positive integers $$$w_1,w_2,\ldots,w_n$$$ ($$$w_i \geq 1$$$) — the initial weights of the pictures. It is guaranteed that the sum of all the initial weights does not exceed $$$998244352-m$$$.

The output contains $$$n$$$ integers $$$r_1,r_2,\ldots,r_n$$$ — the expected weights modulo $$$998244353$$$.

NoteIn the first example, if the only visit shows the first picture with a probability of $$$\frac 2 3$$$, the final weights are $$$(1,1)$$$; if the only visit shows the second picture with a probability of $$$\frac1 3$$$, the final weights are $$$(2,2)$$$.So, both expected weights are $$$\frac2 3\cdot 1+\frac 1 3\cdot 2=\frac4 3$$$ .Because $$$332748119\cdot 3\equiv 4\pmod{998244353}$$$, you need to print $$$332748119$$$ instead of $$$\frac4 3$$$ or $$$1.3333333333$$$.In the second example, there is only one picture which Nauuo likes, so every time Nauuo visits the website, $$$w_1$$$ will be increased by $$$1$$$.So, the expected weight is $$$1+2=3$$$.Nauuo is very naughty so she didn't give you any hint of the third example.


Nauuo is a girl who loves playing cards.One day she was playing cards but found that the cards were mixed with some empty ones.There are $$$n$$$ cards numbered from $$$1$$$ to $$$n$$$, and they were mixed with another $$$n$$$ empty cards. She piled up the $$$2n$$$ cards and drew $$$n$$$ of them. The $$$n$$$ cards in Nauuo's hands are given. The remaining $$$n$$$ cards in the pile are also given in the order from top to bottom.In one operation she can choose a card in her hands and play it — put it at the bottom of the pile, then draw the top card from the pile.Nauuo wants to make the $$$n$$$ numbered cards piled up in increasing order (the $$$i$$$-th card in the pile from top to bottom is the card $$$i$$$) as quickly as possible. Can you tell her the minimum number of operations?

The first line contains a single integer $$$n$$$ ($$$1\le n\le 2\cdot 10^5$$$) — the number of numbered cards. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i\le n$$$) — the initial cards in Nauuo's hands. $$$0$$$ represents an empty card. The third line contains $$$n$$$ integers $$$b_1,b_2,\ldots,b_n$$$ ($$$0\le b_i\le n$$$) — the initial cards in the pile, given in order from top to bottom. $$$0$$$ represents an empty card. It is guaranteed that each number from $$$1$$$ to $$$n$$$ appears exactly once, either in $$$a_{1..n}$$$ or $$$b_{1..n}$$$.

The output contains a single integer — the minimum number of operations to make the $$$n$$$ numbered cards piled up in increasing order.

NoteExample 1We can play the card $$$2$$$ and draw the card $$$3$$$ in the first operation. After that, we have $$$[0,3,0]$$$ in hands and the cards in the pile are $$$[0,1,2]$$$ from top to bottom.Then, we play the card $$$3$$$ in the second operation. The cards in the pile are $$$[1,2,3]$$$, in which the cards are piled up in increasing order.Example 2Play an empty card and draw the card $$$1$$$, then play $$$1$$$, $$$2$$$, $$$3$$$ in order.


Nauuo is a girl who loves traveling.One day she went to a tree, Old Driver Tree, literally, a tree with an old driver on it.The tree is a connected graph consisting of $$$n$$$ nodes and $$$n-1$$$ edges. Each node has a color, and Nauuo will visit the ODT through a simple path on the tree in the old driver's car.Nauuo wants to visit see more different colors in her journey, but she doesn't know which simple path she will be traveling on. So, she wants to calculate the sum of the numbers of different colors on all different paths. Can you help her?What's more, the ODT is being redecorated, so there will be $$$m$$$ modifications, each modification will change a single node's color. Nauuo wants to know the answer after each modification too.Note that in this problem, we consider the simple path from $$$u$$$ to $$$v$$$ and the simple path from $$$v$$$ to $$$u$$$ as two different simple paths if and only if $$$u\ne v$$$.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2\le n\le 4\cdot 10^5$$$, $$$1\le m\le 4\cdot 10^5$$$) — the number of nodes and the number of modifications. The second line contains $$$n$$$ integers $$$c_1,c_2,\ldots,c_n$$$ ($$$1\le c_i\le n$$$), where $$$c_i$$$ is the initial color of node $$$i$$$. Each of the next $$$n-1$$$ lines contains two integers $$$u$$$ and $$$v$$$ ($$$1\le u,v\le n$$$), denoting there is an edge between $$$u$$$ and $$$v$$$. It is guaranteed that the given edges form a tree. Each of the next $$$m$$$ lines contains two integers $$$u$$$ and $$$x$$$ ($$$1\le u,x\le n$$$), which means a modification that changes the color of node $$$u$$$ into $$$x$$$.

The output contains $$$m+1$$$ integers — the first integer is the answer at the beginning, the rest integers are the answers after every modification in the given order.

NoteExample 1The number of colors on each simple path at the beginning:


Nauuo is a girl who loves coding.One day she was solving a problem which requires to calculate a sum of some numbers modulo $$$p$$$.She wrote the following code and got the verdict "Wrong answer".She soon discovered the bug — the ModAdd function only worked for numbers in the range $$$[0,p)$$$, but the numbers in the problem may be out of the range. She was curious about the wrong function, so she wanted to know the result of it.However, the original code worked too slow, so she asked you to help her.You are given an array $$$a_1,a_2,\ldots,a_n$$$ and a number $$$p$$$. Nauuo will make $$$m$$$ queries, in each query, you are given $$$l$$$ and $$$r$$$, and you have to calculate the results of Sum(a,l,r,p). You can see the definition of the Sum function in the pseudocode above.Note that the integers won't overflow in the code above.

The first line contains three integers $$$n$$$, $$$m$$$, $$$p$$$ ($$$1 \le n \le 10^6$$$, $$$1 \le m \le 2 \cdot 10^5$$$, $$$1 \le p \le 10^9$$$) — the length of the given array, the number of queries and the modulus. Note that the modulus is used only in the ModAdd function. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$-10^9\le a_i\le10^9$$$) — the given array. In the following $$$m$$$ lines, each line contains two integers $$$l$$$, $$$r$$$ ($$$1\le l\le r\le n$$$) — you have to calculate the result of Sum(a,l,r,p).

The output contains $$$m$$$ integers to answer the queries in the given order.


Nauuo is a girl who loves writing comments.One day, she posted a comment on Codeforces, wondering whether she would get upvotes or downvotes.It's known that there were $$$x$$$ persons who would upvote, $$$y$$$ persons who would downvote, and there were also another $$$z$$$ persons who would vote, but you don't know whether they would upvote or downvote. Note that each of the $$$x+y+z$$$ people would vote exactly one time.There are three different results: if there are more people upvote than downvote, the result will be "+"; if there are more people downvote than upvote, the result will be "-"; otherwise the result will be "0".Because of the $$$z$$$ unknown persons, the result may be uncertain (i.e. there are more than one possible results). More formally, the result is uncertain if and only if there exist two different situations of how the $$$z$$$ persons vote, that the results are different in the two situations.Tell Nauuo the result or report that the result is uncertain.

The only line contains three integers $$$x$$$, $$$y$$$, $$$z$$$ ($$$0\le x,y,z\le100$$$), corresponding to the number of persons who would upvote, downvote or unknown.

If there is only one possible result, print the result : "+", "-" or "0". Otherwise, print "?" to report that the result is uncertain.

NoteIn the first example, Nauuo would definitely get three upvotes and seven downvotes, so the only possible result is "-".In the second example, no matter the person unknown downvotes or upvotes, Nauuo would get more upvotes than downvotes. So the only possible result is "+".In the third example, Nauuo would definitely get one upvote and one downvote, so the only possible result is "0".In the fourth example, if the only one person upvoted, the result would be "+", otherwise, the result would be "-". There are two possible results, so the result is uncertain.


Nauuo is a girl who loves playing chess.One day she invented a game by herself which needs $$$n$$$ chess pieces to play on a $$$m\times m$$$ chessboard. The rows and columns are numbered from $$$1$$$ to $$$m$$$. We denote a cell on the intersection of the $$$r$$$-th row and $$$c$$$-th column as $$$(r,c)$$$.The game's goal is to place $$$n$$$ chess pieces numbered from $$$1$$$ to $$$n$$$ on the chessboard, the $$$i$$$-th piece lies on $$$(r_i,\,c_i)$$$, while the following rule is satisfied: for all pairs of pieces $$$i$$$ and $$$j$$$, $$$|r_i-r_j|+|c_i-c_j|\ge|i-j|$$$. Here $$$|x|$$$ means the absolute value of $$$x$$$.However, Nauuo discovered that sometimes she couldn't find a solution because the chessboard was too small.She wants to find the smallest chessboard on which she can put $$$n$$$ pieces according to the rules.She also wonders how to place the pieces on such a chessboard. Can you help her?

The only line contains a single integer $$$n$$$ ($$$1\le n\le 1000$$$) — the number of chess pieces for the game.

The first line contains a single integer — the minimum value of $$$m$$$, where $$$m$$$ is the length of sides of the suitable chessboard. The $$$i$$$-th of the next $$$n$$$ lines contains two integers $$$r_i$$$ and $$$c_i$$$ ($$$1\le r_i,c_i\le m$$$) — the coordinates of the $$$i$$$-th chess piece. If there are multiple answers, print any.

NoteIn the first example, you can't place the two pieces on a $$$1\times1$$$ chessboard without breaking the rule. But you can place two pieces on a $$$2\times2$$$ chessboard like this:In the second example, you can't place four pieces on a $$$2\times2$$$ chessboard without breaking the rule. For example, if you place the pieces like this:then $$$|r_1-r_3|+|c_1-c_3|=|1-2|+|1-1|=1$$$, $$$|1-3|=2$$$, $$$1<2$$$; and $$$|r_1-r_4|+|c_1-c_4|=|1-2|+|1-2|=2$$$, $$$|1-4|=3$$$, $$$2<3$$$. It doesn't satisfy the rule.However, on a $$$3\times3$$$ chessboard, you can place four pieces like this:


You're given an integer $$$n$$$. For every integer $$$i$$$ from $$$2$$$ to $$$n$$$, assign a positive integer $$$a_i$$$ such that the following conditions hold:  For any pair of integers $$$(i,j)$$$, if $$$i$$$ and $$$j$$$ are coprime, $$$a_i \neq a_j$$$.  The maximal value of all $$$a_i$$$ should be minimized (that is, as small as possible). A pair of integers is called coprime if their greatest common divisor is $$$1$$$.

The only line contains the integer $$$n$$$ ($$$2 \le n \le 10^5$$$).

Print $$$n-1$$$ integers, $$$a_2$$$, $$$a_3$$$, $$$\ldots$$$, $$$a_n$$$ ($$$1 \leq a_i \leq n$$$).  If there are multiple solutions, print any of them.

NoteIn the first example, notice that $$$3$$$ and $$$4$$$ are coprime, so $$$a_3 \neq a_4$$$. Also, notice that $$$a=[1,2,3]$$$ satisfies the first condition, but it's not a correct answer because its maximal value is $$$3$$$.


You're given an array $$$a$$$ of length $$$2n$$$. Is it possible to reorder it in such way so that the sum of the first $$$n$$$ elements isn't equal to the sum of the last $$$n$$$ elements?

The first line contains an integer $$$n$$$ ($$$1 \le n \le 1000$$$), where $$$2n$$$ is the number of elements in the array $$$a$$$. The second line contains $$$2n$$$ space-separated integers $$$a_1$$$, $$$a_2$$$, $$$\ldots$$$, $$$a_{2n}$$$ ($$$1 \le a_i \le 10^6$$$) — the elements of the array $$$a$$$.

If there's no solution, print "-1" (without quotes). Otherwise, print a single line containing $$$2n$$$ space-separated integers. They must form a reordering of $$$a$$$. You are allowed to not change the order.

NoteIn the first example, the first $$$n$$$ elements have sum $$$2+1+3=6$$$ while the last $$$n$$$ elements have sum $$$1+1+2=4$$$. The sums aren't equal.In the second example, there's no solution.


Let's define a function $$$f(p)$$$ on a permutation $$$p$$$ as follows. Let $$$g_i$$$ be the greatest common divisor (GCD) of elements $$$p_1$$$, $$$p_2$$$, ..., $$$p_i$$$ (in other words, it is the GCD of the prefix of length $$$i$$$). Then $$$f(p)$$$ is the number of distinct elements among $$$g_1$$$, $$$g_2$$$, ..., $$$g_n$$$.Let $$$f_{max}(n)$$$ be the maximum value of $$$f(p)$$$ among all permutations $$$p$$$ of integers $$$1$$$, $$$2$$$, ..., $$$n$$$.Given an integers $$$n$$$, count the number of permutations $$$p$$$ of integers $$$1$$$, $$$2$$$, ..., $$$n$$$, such that $$$f(p)$$$ is equal to $$$f_{max}(n)$$$. Since the answer may be large, print the remainder of its division by $$$1000\,000\,007 = 10^9 + 7$$$.

The only line contains the integer $$$n$$$ ($$$2 \le n \le 10^6$$$) — the length of the permutations.

The only line should contain your answer modulo $$$10^9+7$$$.


This is an interactive problem.You're given a tree consisting of $$$n$$$ nodes, rooted at node $$$1$$$. A tree is a connected graph with no cycles.We chose a hidden node $$$x$$$. In order to find this node, you can ask queries of two types:   d $$$u$$$ ($$$1 \le u \le n$$$). We will answer with the distance between nodes $$$u$$$ and $$$x$$$. The distance between two nodes is the number of edges in the shortest path between them.  s $$$u$$$ ($$$1 \le u \le n$$$). We will answer with the second node on the path from $$$u$$$ to $$$x$$$. However, there's a plot twist. If $$$u$$$ is not an ancestor of $$$x$$$, you'll receive "Wrong answer" verdict! Node $$$a$$$ is called an ancestor of node $$$b$$$ if $$$a \ne b$$$ and the shortest path from node $$$1$$$ to node $$$b$$$ passes through node $$$a$$$. Note that in this problem a node is not an ancestor of itself.Can you find $$$x$$$ in no more than $$$36$$$ queries? The hidden node is fixed in each test beforehand and does not depend on your queries.

The first line contains the integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the number of nodes in the tree. Each of the next $$$n-1$$$ lines contains two space-separated integers $$$u$$$ and $$$v$$$ ($$$1 \le u,v \le n$$$) that mean there's an edge between nodes $$$u$$$ and $$$v$$$. It's guaranteed that the given graph is a tree.

To print the answer, print "! x" (without quotes).

NoteIn the first example, the hidden node is node $$$5$$$.  We first ask about the distance between node $$$x$$$ and node $$$2$$$. The answer is $$$3$$$, so node $$$x$$$ is either $$$4$$$ or $$$5$$$. We then ask about the second node in the path from node $$$3$$$ to node $$$x$$$. Note here that node $$$3$$$ is an ancestor of node $$$5$$$. We receive node $$$5$$$ as the answer. Finally, we report that the hidden node is node $$$5$$$.


Given two integers $$$n$$$ and $$$x$$$, construct an array that satisfies the following conditions:   for any element $$$a_i$$$ in the array, $$$1 \le a_i<2^n$$$;  there is no non-empty subsegment with bitwise XOR equal to $$$0$$$ or $$$x$$$,  its length $$$l$$$ should be maximized. A sequence $$$b$$$ is a subsegment of a sequence $$$a$$$ if $$$b$$$ can be obtained from $$$a$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.

The only line contains two integers $$$n$$$ and $$$x$$$ ($$$1 \le n \le 18$$$, $$$1 \le x<2^{18}$$$).

The first line should contain the length of the array $$$l$$$. If $$$l$$$ is positive, the second line should contain $$$l$$$ space-separated integers $$$a_1$$$, $$$a_2$$$, $$$\dots$$$, $$$a_l$$$ ($$$1 \le a_i < 2^n$$$) — the elements of the array $$$a$$$. If there are multiple solutions, print any of them.

NoteIn the first example, the bitwise XOR of the subsegments are $$$\{6,7,4,1,2,3\}$$$.


You are given an integer $$$n$$$ and an integer $$$k$$$.In one step you can do one of the following moves:   decrease $$$n$$$ by $$$1$$$;  divide $$$n$$$ by $$$k$$$ if $$$n$$$ is divisible by $$$k$$$. For example, if $$$n = 27$$$ and $$$k = 3$$$ you can do the following steps: $$$27 \rightarrow 26 \rightarrow 25 \rightarrow 24 \rightarrow 8 \rightarrow 7 \rightarrow 6 \rightarrow 2 \rightarrow 1 \rightarrow 0$$$.You are asked to calculate the minimum number of steps to reach $$$0$$$ from $$$n$$$.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of queries. The only line of each query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10^{18}$$$, $$$2 \le k \le 10^{18}$$$).

For each query print the minimum number of steps to reach $$$0$$$ from $$$n$$$ in single line.

NoteSteps for the first test case are: $$$59 \rightarrow 58 \rightarrow 57 \rightarrow 19 \rightarrow 18 \rightarrow 6 \rightarrow 2 \rightarrow 1 \rightarrow 0$$$.In the second test case you have to divide $$$n$$$ by $$$k$$$ $$$18$$$ times and then decrease $$$n$$$ by $$$1$$$.


You're given an array $$$a$$$ of length $$$n$$$. You can perform the following operation on it as many times as you want:  Pick two integers $$$i$$$ and $$$j$$$ $$$(1 \le i,j \le n)$$$ such that $$$a_i+a_j$$$ is odd, then swap $$$a_i$$$ and $$$a_j$$$. What is lexicographically the smallest array you can obtain?An array $$$x$$$ is lexicographically smaller than an array $$$y$$$ if there exists an index $$$i$$$ such that $$$x_i<y_i$$$, and $$$x_j=y_j$$$ for all $$$1 \le j < i$$$. Less formally, at the first index $$$i$$$ in which they differ, $$$x_i<y_i$$$

The first line contains an integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of elements in the array $$$a$$$. The second line contains $$$n$$$ space-separated integers $$$a_1$$$, $$$a_2$$$, $$$\ldots$$$, $$$a_{n}$$$ ($$$1 \le a_i \le 10^9$$$) — the elements of the array $$$a$$$.

The only line contains $$$n$$$ space-separated integers, the lexicographically smallest array you can obtain.

NoteIn the first example, we can swap $$$1$$$ and $$$4$$$ since $$$1+4=5$$$, which is odd.


You are given a function $$$f$$$ written in some basic language. The function accepts an integer value, which is immediately written into some variable $$$x$$$. $$$x$$$ is an integer variable and can be assigned values from $$$0$$$ to $$$2^{32}-1$$$. The function contains three types of commands:  for $$$n$$$ — for loop;  end — every command between "for $$$n$$$" and corresponding "end" is executed $$$n$$$ times;  add — adds 1 to $$$x$$$. After the execution of these commands, value of $$$x$$$ is returned.Every "for $$$n$$$" is matched with "end", thus the function is guaranteed to be valid. "for $$$n$$$" can be immediately followed by "end"."add" command can be outside of any for loops.Notice that "add" commands might overflow the value of $$$x$$$! It means that the value of $$$x$$$ becomes greater than $$$2^{32}-1$$$ after some "add" command. Now you run $$$f(0)$$$ and wonder if the resulting value of $$$x$$$ is correct or some overflow made it incorrect.If overflow happened then output "OVERFLOW!!!", otherwise print the resulting value of $$$x$$$.

The first line contains a single integer $$$l$$$ ($$$1 \le l \le 10^5$$$) — the number of lines in the function. Each of the next $$$l$$$ lines contains a single command of one of three types:   for $$$n$$$ ($$$1 \le n \le 100$$$) — for loop;  end — every command between "for $$$n$$$" and corresponding "end" is executed $$$n$$$ times;  add — adds 1 to $$$x$$$.

If overflow happened during execution of $$$f(0)$$$, then output "OVERFLOW!!!", otherwise print the resulting value of $$$x$$$.

NoteIn the first example the first "add" is executed 1 time, the second "add" is executed 150 times and the last "add" is executed 10 times. Note that "for $$$n$$$" can be immediately followed by "end" and that "add" can be outside of any for loops.In the second example there are no commands "add", thus the returning value is 0.In the third example "add" command is executed too many times, which causes $$$x$$$ to go over $$$2^{32}-1$$$.

9
add
for 43
end
for 10
for 15
add
end
add
end

11
for 100
for 100
for 100
for 100
for 100
add
end
end
end
end
end


At first, there was a legend related to the name of the problem, but now it's just a formal statement.You are given $$$n$$$ points $$$a_1, a_2, \dots, a_n$$$ on the $$$OX$$$ axis. Now you are asked to find such an integer point $$$x$$$ on $$$OX$$$ axis that $$$f_k(x)$$$ is minimal possible.The function $$$f_k(x)$$$ can be described in the following way:   form a list of distances $$$d_1, d_2, \dots, d_n$$$ where $$$d_i = |a_i - x|$$$ (distance between $$$a_i$$$ and $$$x$$$);  sort list $$$d$$$ in non-descending order;  take $$$d_{k + 1}$$$ as a result. If there are multiple optimal answers you can print any of them.

The first line contains single integer $$$T$$$ ($$$ 1 \le T \le 2 \cdot 10^5$$$) — number of queries. Next $$$2 \cdot T$$$ lines contain descriptions of queries. All queries are independent.  The first line of each query contains two integers $$$n$$$, $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$0 \le k < n$$$) — the number of points and constant $$$k$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_1 < a_2 < \dots < a_n \le 10^9$$$) — points in ascending order. It's guaranteed that $$$\sum{n}$$$ doesn't exceed $$$2 \cdot 10^5$$$.

Print $$$T$$$ integers — corresponding points $$$x$$$ which have minimal possible value of $$$f_k(x)$$$. If there are multiple answers you can print any of them.


You are given $$$n$$$ intervals in form $$$[l; r]$$$ on a number line.You are also given $$$m$$$ queries in form $$$[x; y]$$$. What is the minimal number of intervals you have to take so that every point (not necessarily integer) from $$$x$$$ to $$$y$$$ is covered by at least one of them? If you can't choose intervals so that every point from $$$x$$$ to $$$y$$$ is covered, then print -1 for that query.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 2 \cdot 10^5$$$) — the number of intervals and the number of queries, respectively. Each of the next $$$n$$$ lines contains two integer numbers $$$l_i$$$ and $$$r_i$$$ ($$$0 \le l_i < r_i \le 5 \cdot 10^5$$$) — the given intervals. Each of the next $$$m$$$ lines contains two integer numbers $$$x_i$$$ and $$$y_i$$$ ($$$0 \le x_i < y_i \le 5 \cdot 10^5$$$) — the queries.

Print $$$m$$$ integer numbers. The $$$i$$$-th number should be the answer to the $$$i$$$-th query: either the minimal number of intervals you have to take so that every point (not necessarily integer) from $$$x_i$$$ to $$$y_i$$$ is covered by at least one of them or -1 if you can't choose intervals so that every point from $$$x_i$$$ to $$$y_i$$$ is covered.

NoteIn the first example there are three queries:  query $$$[1; 3]$$$ can be covered by interval $$$[1; 3]$$$;  query $$$[1; 4]$$$ can be covered by intervals $$$[1; 3]$$$ and $$$[2; 4]$$$. There is no way to cover $$$[1; 4]$$$ by a single interval;  query $$$[3; 4]$$$ can be covered by interval $$$[2; 4]$$$. It doesn't matter that the other points are covered besides the given query. In the second example there are four queries:  query $$$[1; 2]$$$ can be covered by interval $$$[1; 3]$$$. Note that you can choose any of the two given intervals $$$[1; 3]$$$;  query $$$[1; 3]$$$ can be covered by interval $$$[1; 3]$$$;  query $$$[1; 4]$$$ can't be covered by any set of intervals;  query $$$[1; 5]$$$ can't be covered by any set of intervals. Note that intervals $$$[1; 3]$$$ and $$$[4; 5]$$$ together don't cover $$$[1; 5]$$$ because even non-integer points should be covered. Here $$$3.5$$$, for example, isn't covered.


You are given an array $$$a_1, a_2, \dots, a_n$$$ and an integer $$$k$$$.You are asked to divide this array into $$$k$$$ non-empty consecutive subarrays. Every element in the array should be included in exactly one subarray. Let $$$f(i)$$$ be the index of subarray the $$$i$$$-th element belongs to. Subarrays are numbered from left to right and from $$$1$$$ to $$$k$$$.Let the cost of division be equal to $$$\sum\limits_{i=1}^{n} (a_i \cdot f(i))$$$. For example, if $$$a = [1, -2, -3, 4, -5, 6, -7]$$$ and we divide it into $$$3$$$ subbarays in the following way: $$$[1, -2, -3], [4, -5], [6, -7]$$$, then the cost of division is equal to $$$1 \cdot 1 - 2 \cdot 1 - 3 \cdot 1 + 4 \cdot 2 - 5 \cdot 2 + 6 \cdot 3 - 7 \cdot 3 = -9$$$.Calculate the maximum cost you can obtain by dividing the array $$$a$$$ into $$$k$$$ non-empty consecutive subarrays.

The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 3 \cdot 10^5$$$). The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$ |a_i| \le 10^6$$$).

Print the maximum cost you can obtain by dividing the array $$$a$$$ into $$$k$$$ nonempty consecutive subarrays.


You have an array $$$a_1, a_2, \dots, a_n$$$. Let's call some subarray $$$a_l, a_{l + 1}, \dots , a_r$$$ of this array a subpermutation if it contains all integers from $$$1$$$ to $$$r-l+1$$$ exactly once. For example, array $$$a = [2, 2, 1, 3, 2, 3, 1]$$$ contains $$$6$$$ subarrays which are subpermutations: $$$[a_2 \dots a_3]$$$, $$$[a_2 \dots a_4]$$$, $$$[a_3 \dots a_3]$$$, $$$[a_3 \dots a_5]$$$, $$$[a_5 \dots a_7]$$$, $$$[a_7 \dots a_7]$$$.You are asked to calculate the number of subpermutations.

The first line contains one integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$). The second line contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le n$$$).  This array can contain the same integers.

Print the number of subpermutations of the array $$$a$$$.


You are given an array $$$a$$$ consisting of $$$n$$$ integers. Each $$$a_i$$$ is one of the six following numbers: $$$4, 8, 15, 16, 23, 42$$$.Your task is to remove the minimum number of elements to make this array good.An array of length $$$k$$$ is called good if $$$k$$$ is divisible by $$$6$$$ and it is possible to split it into $$$\frac{k}{6}$$$ subsequences $$$4, 8, 15, 16, 23, 42$$$.Examples of good arrays:  $$$[4, 8, 15, 16, 23, 42]$$$ (the whole array is a required sequence);  $$$[4, 8, 4, 15, 16, 8, 23, 15, 16, 42, 23, 42]$$$ (the first sequence is formed from first, second, fourth, fifth, seventh and tenth elements and the second one is formed from remaining elements);  $$$[]$$$ (the empty array is good). Examples of bad arrays:   $$$[4, 8, 15, 16, 42, 23]$$$ (the order of elements should be exactly $$$4, 8, 15, 16, 23, 42$$$);  $$$[4, 8, 15, 16, 23, 42, 4]$$$ (the length of the array is not divisible by $$$6$$$);  $$$[4, 8, 15, 16, 23, 42, 4, 8, 15, 16, 23, 23]$$$ (the first sequence can be formed from first six elements but the remaining array cannot form the required sequence).

The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 5 \cdot 10^5$$$) — the number of elements in $$$a$$$. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ (each $$$a_i$$$ is one of the following numbers: $$$4, 8, 15, 16, 23, 42$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$.

Print one integer — the minimum number of elements you have to remove to obtain a good array.


You are given an integer $$$n$$$.You can perform any of the following operations with this number an arbitrary (possibly, zero) number of times:   Replace $$$n$$$ with $$$\frac{n}{2}$$$ if $$$n$$$ is divisible by $$$2$$$;  Replace $$$n$$$ with $$$\frac{2n}{3}$$$ if $$$n$$$ is divisible by $$$3$$$;  Replace $$$n$$$ with $$$\frac{4n}{5}$$$ if $$$n$$$ is divisible by $$$5$$$. For example, you can replace $$$30$$$ with $$$15$$$ using the first operation, with $$$20$$$ using the second operation or with $$$24$$$ using the third operation.Your task is to find the minimum number of moves required to obtain $$$1$$$ from $$$n$$$ or say that it is impossible to do it.You have to answer $$$q$$$ independent queries.

The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 1000$$$) — the number of queries. The next $$$q$$$ lines contain the queries. For each query you are given the integer number $$$n$$$ ($$$1 \le n \le 10^{18}$$$).

Print the answer for each query on a new line. If it is impossible to obtain $$$1$$$ from $$$n$$$, print -1. Otherwise, print the minimum number of moves required to do it.


You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$).

For each query print one integer in a single line — the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times.

NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$.


Authors guessed an array $$$a$$$ consisting of $$$n$$$ integers; each integer is not less than $$$2$$$ and not greater than $$$2 \cdot 10^5$$$. You don't know the array $$$a$$$, but you know the array $$$b$$$ which is formed from it with the following sequence of operations:  Firstly, let the array $$$b$$$ be equal to the array $$$a$$$;  Secondly, for each $$$i$$$ from $$$1$$$ to $$$n$$$:   if $$$a_i$$$ is a prime number, then one integer $$$p_{a_i}$$$ is appended to array $$$b$$$, where $$$p$$$ is an infinite sequence of prime numbers ($$$2, 3, 5, \dots$$$);  otherwise (if $$$a_i$$$ is not a prime number), the greatest divisor of $$$a_i$$$ which is not equal to $$$a_i$$$ is appended to $$$b$$$;   Then the obtained array of length $$$2n$$$ is shuffled and given to you in the input. Here $$$p_{a_i}$$$ means the $$$a_i$$$-th prime number. The first prime $$$p_1 = 2$$$, the second one is $$$p_2 = 3$$$, and so on.Your task is to recover any suitable array $$$a$$$ that forms the given array $$$b$$$. It is guaranteed that the answer exists (so the array $$$b$$$ is obtained from some suitable array $$$a$$$). If there are multiple answers, you can print any.

The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of elements in $$$a$$$. The second line of the input contains $$$2n$$$ integers $$$b_1, b_2, \dots, b_{2n}$$$ ($$$2 \le b_i \le 2750131$$$), where $$$b_i$$$ is the $$$i$$$-th element of $$$b$$$. $$$2750131$$$ is the $$$199999$$$-th prime number.

In the only line of the output print $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$2 \le a_i \le 2 \cdot 10^5$$$) in any order — the array $$$a$$$ from which the array $$$b$$$ can be obtained using the sequence of moves given in the problem statement. If there are multiple answers, you can print any.


You are given an undirected unweighted connected graph consisting of $$$n$$$ vertices and $$$m$$$ edges. It is guaranteed that there are no self-loops or multiple edges in the given graph.Your task is to choose at most $$$\lfloor\frac{n}{2}\rfloor$$$ vertices in this graph so each unchosen vertex is adjacent (in other words, connected by an edge) to at least one of chosen vertices.It is guaranteed that the answer exists. If there are multiple answers, you can print any.You will be given multiple independent queries to answer.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^5$$$) — the number of queries. Then $$$t$$$ queries follow. The first line of each query contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n \le 2 \cdot 10^5$$$, $$$n - 1 \le m \le min(2 \cdot 10^5, \frac{n(n-1)}{2})$$$) — the number of vertices and the number of edges, respectively. The following $$$m$$$ lines denote edges: edge $$$i$$$ is represented by a pair of integers $$$v_i$$$, $$$u_i$$$ ($$$1 \le v_i, u_i \le n$$$, $$$u_i \ne v_i$$$), which are the indices of vertices connected by the edge. There are no self-loops or multiple edges in the given graph, i. e. for each pair ($$$v_i, u_i$$$) there are no other pairs ($$$v_i, u_i$$$) or ($$$u_i, v_i$$$) in the list of edges, and for each pair ($$$v_i, u_i$$$) the condition $$$v_i \ne u_i$$$ is satisfied. It is guaranteed that the given graph is connected. It is guaranteed that $$$\sum m \le 2 \cdot 10^5$$$ over all queries.

For each query print two lines. In the first line print $$$k$$$ ($$$1 \le \lfloor\frac{n}{2}\rfloor$$$) — the number of chosen vertices. In the second line print $$$k$$$ distinct integers $$$c_1, c_2, \dots, c_k$$$ in any order, where $$$c_i$$$ is the index of the $$$i$$$-th chosen vertex. It is guaranteed that the answer exists. If there are multiple answers, you can print any.

NoteIn the first query any vertex or any pair of vertices will suffice.  Note that you don't have to minimize the number of chosen vertices. In the second query two vertices can be enough (vertices $$$2$$$ and $$$4$$$) but three is also ok.


You are given array $$$a_1, a_2, \dots, a_n$$$. You need to split it into $$$k$$$ subsegments (so every element is included in exactly one subsegment).The weight of a subsegment $$$a_l, a_{l+1}, \dots, a_r$$$ is equal to $$$(r - l + 1) \cdot \max\limits_{l \le i \le r}(a_i)$$$. The weight of a partition is a total weight of all its segments.Find the partition of minimal weight.

The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^4$$$, $$$1 \le k \le \min(100, n)$$$) — the length of the array $$$a$$$ and the number of subsegments in the partition. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 2 \cdot 10^4$$$) — the array $$$a$$$.

Print single integer — the minimal weight among all possible partitions.

NoteThe optimal partition in the first example is next: $$$6$$$ $$$1$$$ $$$7$$$ $$$\bigg|$$$ $$$4$$$.The optimal partition in the second example is next: $$$6$$$ $$$\bigg|$$$ $$$1$$$ $$$\bigg|$$$ $$$7$$$ $$$4$$$.One of the optimal partitions in the third example is next: $$$5$$$ $$$\bigg|$$$ $$$1$$$ $$$5$$$ $$$\bigg|$$$ $$$1$$$ $$$\bigg|$$$ $$$5$$$.


You are playing a computer card game called Splay the Sire. Currently you are struggling to defeat the final boss of the game.The boss battle consists of $$$n$$$ turns. During each turn, you will get several cards. Each card has two parameters: its cost $$$c_i$$$ and damage $$$d_i$$$. You may play some of your cards during each turn in some sequence (you choose the cards and the exact order they are played), as long as the total cost of the cards you play during the turn does not exceed $$$3$$$. After playing some (possibly zero) cards, you end your turn, and all cards you didn't play are discarded. Note that you can use each card at most once.Your character has also found an artifact that boosts the damage of some of your actions: every $$$10$$$-th card you play deals double damage.What is the maximum possible damage you can deal during $$$n$$$ turns?

The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of turns. Then $$$n$$$ blocks of input follow, the $$$i$$$-th block representing the cards you get during the $$$i$$$-th turn. Each block begins with a line containing one integer $$$k_i$$$ ($$$1 \le k_i \le 2 \cdot 10^5$$$) — the number of cards you get during $$$i$$$-th turn. Then $$$k_i$$$ lines follow, each containing two integers $$$c_j$$$ and $$$d_j$$$ ($$$1 \le c_j \le 3$$$, $$$1 \le d_j \le 10^9$$$) — the parameters of the corresponding card. It is guaranteed that $$$\sum \limits_{i = 1}^{n} k_i \le 2 \cdot 10^5$$$.

Print one integer — the maximum damage you may deal.

NoteIn the example test the best course of action is as follows:During the first turn, play all three cards in any order and deal $$$18$$$ damage.During the second turn, play both cards and deal $$$7$$$ damage.During the third turn, play the first and the third card and deal $$$13$$$ damage.During the fourth turn, play the first and the third card and deal $$$25$$$ damage.During the fifth turn, play the only card, which will deal double damage ($$$200$$$).


Alice is the leader of the State Refactoring Party, and she is about to become the prime minister. The elections have just taken place. There are $$$n$$$ parties, numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th party has received $$$a_i$$$ seats in the parliament.Alice's party has number $$$1$$$. In order to become the prime minister, she needs to build a coalition, consisting of her party and possibly some other parties. There are two conditions she needs to fulfil:   The total number of seats of all parties in the coalition must be a strict majority of all the seats, i.e. it must have strictly more than half of the seats. For example, if the parliament has $$$200$$$ (or $$$201$$$) seats, then the majority is $$$101$$$ or more seats.  Alice's party must have at least $$$2$$$ times more seats than any other party in the coalition. For example, to invite a party with $$$50$$$ seats, Alice's party must have at least $$$100$$$ seats. For example, if $$$n=4$$$ and $$$a=[51, 25, 99, 25]$$$ (note that Alice'a party has $$$51$$$ seats), then the following set $$$[a_1=51, a_2=25, a_4=25]$$$ can create a coalition since both conditions will be satisfied. However, the following sets will not create a coalition:  $$$[a_2=25, a_3=99, a_4=25]$$$ since Alice's party is not there;  $$$[a_1=51, a_2=25]$$$ since coalition should have a strict majority;  $$$[a_1=51, a_2=25, a_3=99]$$$ since Alice's party should have at least $$$2$$$ times more seats than any other party in the coalition. Alice does not have to minimise the number of parties in a coalition. If she wants, she can invite as many parties as she wants (as long as the conditions are satisfied). If Alice's party has enough people to create a coalition on her own, she can invite no parties.Note that Alice can either invite a party as a whole or not at all. It is not possible to invite only some of the deputies (seats) from another party. In other words, if Alice invites a party, she invites all its deputies.Find and print any suitable coalition.

The first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the number of parties. The second line contains $$$n$$$ space separated integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 100$$$) — the number of seats the $$$i$$$-th party has.

If no coalition satisfying both conditions is possible, output a single line with an integer $$$0$$$. Otherwise, suppose there are $$$k$$$ ($$$1 \leq k \leq n$$$) parties in the coalition (Alice does not have to minimise the number of parties in a coalition), and their indices are $$$c_1, c_2, \dots, c_k$$$ ($$$1 \leq c_i \leq n$$$). Output two lines, first containing the integer $$$k$$$, and the second the space-separated indices $$$c_1, c_2, \dots, c_k$$$.  You may print the parties in any order. Alice's party (number $$$1$$$) must be on that list. If there are multiple solutions, you may print any of them.

NoteIn the first example, Alice picks the second party. Note that she can also pick the third party or both of them. However, she cannot become prime minister without any of them, because $$$100$$$ is not a strict majority out of $$$200$$$.In the second example, there is no way of building a majority, as both other parties are too large to become a coalition partner.In the third example, Alice already has the majority. The fourth example is described in the problem statement.


Recall that string $$$a$$$ is a subsequence of a string $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly zero or all) characters. For example, for the string $$$a$$$="wowwo", the following strings are subsequences: "wowwo", "wowo", "oo", "wow", "", and others, but the following are not subsequences: "owoo", "owwwo", "ooo".The wow factor of a string is the number of its subsequences equal to the word "wow". Bob wants to write a string that has a large wow factor. However, the "w" key on his keyboard is broken, so he types two "v"s instead. Little did he realise that he may have introduced more "w"s than he thought. Consider for instance the string "ww". Bob would type it as "vvvv", but this string actually contains three occurrences of "w":   "vvvv"  "vvvv"  "vvvv" For example, the wow factor of the word "vvvovvv" equals to four because there are four wows:  "vvvovvv"  "vvvovvv"  "vvvovvv"  "vvvovvv" Note that the subsequence "vvvovvv" does not count towards the wow factor, as the "v"s have to be consecutive.For a given string $$$s$$$, compute and output its wow factor. Note that it is not guaranteed that it is possible to get $$$s$$$ from another string replacing "w" with "vv". For example, $$$s$$$ can be equal to "vov".

The input contains a single non-empty string $$$s$$$, consisting only of characters "v" and "o". The length of $$$s$$$ is at most $$$10^6$$$.

Output a single integer, the wow factor of $$$s$$$.

NoteThe first example is explained in the legend.


Let's write all the positive integer numbers one after another from $$$1$$$ without any delimiters (i.e. as a single string). It will be the infinite sequence starting with 123456789101112131415161718192021222324252627282930313233343536...Your task is to print the $$$k$$$-th digit of this sequence.

The first and only line contains integer $$$k$$$ ($$$1 \le k \le 10000$$$) — the position to process ($$$1$$$-based index).

Print the $$$k$$$-th digit of the resulting infinite sequence.


Every person likes prime numbers. Alice is a person, thus she also shares the love for them. Bob wanted to give her an affectionate gift but couldn't think of anything inventive. Hence, he will be giving her a graph. How original, Bob! Alice will surely be thrilled!When building the graph, he needs four conditions to be satisfied:   It must be a simple undirected graph, i.e. without multiple (parallel) edges and self-loops.  The number of vertices must be exactly $$$n$$$ — a number he selected. This number is not necessarily prime.  The total number of edges must be prime.  The degree (i.e. the number of edges connected to the vertex) of each vertex must be prime. Below is an example for $$$n = 4$$$. The first graph (left one) is invalid as the degree of vertex $$$2$$$ (and $$$4$$$) equals to $$$1$$$, which is not prime. The second graph (middle one) is invalid as the total number of edges is $$$4$$$, which is not a prime number. The third graph (right one) is a valid answer for $$$n = 4$$$.   Note that the graph can be disconnected.Please help Bob to find any such graph!

The input consists of a single integer $$$n$$$ ($$$3 \leq n \leq 1\,000$$$) — the number of vertices.

If there is no graph satisfying the conditions, print a single line containing the integer $$$-1$$$. Otherwise, first print a line containing a prime number $$$m$$$ ($$$2 \leq m \leq \frac{n(n-1)}{2}$$$) — the number of edges in the graph. Then, print $$$m$$$ lines, the $$$i$$$-th of which containing two integers $$$u_i$$$, $$$v_i$$$ ($$$1 \leq u_i, v_i \leq n$$$) — meaning that there is an edge between vertices $$$u_i$$$ and $$$v_i$$$. The degree of each vertex must be prime. There must be no multiple (parallel) edges or self-loops. If there are multiple solutions, you may print any of them. Note that the graph can be disconnected.

NoteThe first example was described in the statement.In the second example, the degrees of vertices are $$$[7, 5, 2, 2, 3, 2, 2, 3]$$$. Each of these numbers is prime. Additionally, the number of edges, $$$13$$$, is also a prime number, hence both conditions are satisfied.


This is the first subtask of problem F. The only differences between this and the second subtask are the constraints on the value of $$$m$$$ and the time limit. You need to solve both subtasks in order to hack this one.There are $$$n+1$$$ distinct colours in the universe, numbered $$$0$$$ through $$$n$$$. There is a strip of paper $$$m$$$ centimetres long initially painted with colour $$$0$$$. Alice took a brush and painted the strip using the following process. For each $$$i$$$ from $$$1$$$ to $$$n$$$, in this order, she picks two integers $$$0 \leq a_i < b_i \leq m$$$, such that the segment $$$[a_i, b_i]$$$ is currently painted with a single colour, and repaints it with colour $$$i$$$. Alice chose the segments in such a way that each centimetre is now painted in some colour other than $$$0$$$. Formally, the segment $$$[i-1, i]$$$ is painted with colour $$$c_i$$$ ($$$c_i \neq 0$$$). Every colour other than $$$0$$$ is visible on the strip.Count the number of different pairs of sequences $$$\{a_i\}_{i=1}^n$$$, $$$\{b_i\}_{i=1}^n$$$ that result in this configuration. Since this number may be large, output it modulo $$$998244353$$$.

The first line contains a two integers $$$n$$$, $$$m$$$ ($$$1 \leq n \leq 500$$$, $$$n = m$$$) — the number of colours excluding the colour $$$0$$$ and the length of the paper, respectively. The second line contains $$$m$$$ space separated integers $$$c_1, c_2, \ldots, c_m$$$ ($$$1 \leq c_i \leq n$$$) — the colour visible on the segment $$$[i-1, i]$$$ after the process ends. It is guaranteed that for all $$$j$$$ between $$$1$$$ and $$$n$$$ there is an index $$$k$$$ such that $$$c_k = j$$$. Note that since in this subtask $$$n = m$$$, this means that $$$c$$$ is a permutation of integers $$$1$$$ through $$$n$$$.

Output a single integer — the number of ways Alice can perform the painting, modulo $$$998244353$$$.

NoteIn the first example, there are $$$5$$$ ways, all depicted in the figure below. Here, $$$0$$$ is white, $$$1$$$ is red, $$$2$$$ is green and $$$3$$$ is blue.Below is an example of a painting process that is not valid, as in the second step the segment 1 3 is not single colour, and thus may not be repainted with colour $$$2$$$.


Bob is decorating his kitchen, more precisely, the floor. He has found a prime candidate for the tiles he will use. They come in a simple form factor — a square tile that is diagonally split into white and black part as depicted in the figure below.  The dimension of this tile is perfect for this kitchen, as he will need exactly $$$w \times h$$$ tiles without any scraps. That is, the width of the kitchen is $$$w$$$ tiles, and the height is $$$h$$$ tiles. As each tile can be rotated in one of four ways, he still needs to decide on how exactly he will tile the floor. There is a single aesthetic criterion that he wants to fulfil: two adjacent tiles must not share a colour on the edge — i.e. one of the tiles must have a white colour on the shared border, and the second one must be black.    The picture on the left shows one valid tiling of a $$$3 \times 2$$$ kitchen. The picture on the right shows an invalid arrangement, as the bottom two tiles touch with their white parts. Find the number of possible tilings. As this number may be large, output its remainder when divided by $$$998244353$$$ (a prime number).

The only line contains two space separated integers $$$w$$$, $$$h$$$ ($$$1 \leq w,h \leq 1\,000$$$) — the width and height of the kitchen, measured in tiles.

Output a single integer $$$n$$$ — the remainder of the number of tilings when divided by $$$998244353$$$.


This is the second subtask of problem F. The only differences between this and the first subtask are the constraints on the value of $$$m$$$ and the time limit. It is sufficient to solve this subtask in order to hack it, but you need to solve both subtasks in order to hack the first one.There are $$$n+1$$$ distinct colours in the universe, numbered $$$0$$$ through $$$n$$$. There is a strip of paper $$$m$$$ centimetres long initially painted with colour $$$0$$$. Alice took a brush and painted the strip using the following process. For each $$$i$$$ from $$$1$$$ to $$$n$$$, in this order, she picks two integers $$$0 \leq a_i < b_i \leq m$$$, such that the segment $$$[a_i, b_i]$$$ is currently painted with a single colour, and repaints it with colour $$$i$$$. Alice chose the segments in such a way that each centimetre is now painted in some colour other than $$$0$$$. Formally, the segment $$$[i-1, i]$$$ is painted with colour $$$c_i$$$ ($$$c_i \neq 0$$$). Every colour other than $$$0$$$ is visible on the strip.Count the number of different pairs of sequences $$$\{a_i\}_{i=1}^n$$$, $$$\{b_i\}_{i=1}^n$$$ that result in this configuration. Since this number may be large, output it modulo $$$998244353$$$.

The first line contains a two integers $$$n$$$, $$$m$$$ ($$$1 \leq n \leq 500$$$, $$$n \leq m \leq 10^6$$$) — the number of colours excluding the colour $$$0$$$ and the length of the paper, respectively. The second line contains $$$m$$$ space separated integers $$$c_1, c_2, \ldots, c_m$$$ ($$$1 \leq c_i \leq n$$$) — the colour visible on the segment $$$[i-1, i]$$$ after the process ends. It is guaranteed that for all $$$j$$$ between $$$1$$$ and $$$n$$$ there is an index $$$k$$$ such that $$$c_k = j$$$.

NoteIn the first example, there are $$$5$$$ ways, all depicted in the figure below. Here, $$$0$$$ is white, $$$1$$$ is red, $$$2$$$ is green and $$$3$$$ is blue.Below is an example of a painting process that is not valid, as in the second step the segment 1 3 is not single colour, and thus may not be repainted with colour $$$2$$$.In the second example, Alice must first paint segment 0 3 with colour $$$1$$$ and then segment 1 2 with colour $$$2$$$.


You are given a rooted tree on $$$n$$$ vertices. The vertices are numbered from $$$1$$$ to $$$n$$$; the root is the vertex number $$$1$$$.Each vertex has two integers associated with it: $$$a_i$$$ and $$$b_i$$$. We denote the set of all ancestors of $$$v$$$ (including $$$v$$$ itself) by $$$R(v)$$$. The awesomeness of a vertex $$$v$$$ is defined as $$$$$$\left| \sum_{w \in R(v)} a_w\right| \cdot \left|\sum_{w \in R(v)} b_w\right|,$$$$$$where $$$|x|$$$ denotes the absolute value of $$$x$$$. Process $$$q$$$ queries of one of the following forms:   1 v x — increase $$$a_v$$$ by a positive integer $$$x$$$.  2 v — report the maximum awesomeness in the subtree of vertex $$$v$$$.

The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \leq n \leq 2\cdot 10^5, 1 \leq q \leq 10^5$$$) — the number of vertices in the tree and the number of queries, respectively. The second line contains $$$n - 1$$$ integers $$$p_2, p_3, \dots, p_n$$$ ($$$1 \leq p_i < i$$$), where $$$p_i$$$ means that there is an edge between vertices $$$i$$$ and $$$p_i$$$. The third line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$-5000 \leq a_i \leq 5000$$$), the initial values of $$$a_i$$$ for each vertex. The fourth line contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$-5000 \leq b_i \leq 5000$$$), the values of $$$b_i$$$ for each vertex. Each of the next $$$q$$$ lines describes a query. It has one of the following forms:    1 v x  ($$$1 \leq v \leq n$$$, $$$1\leq x \leq 5000$$$).  2 v  ($$$1 \leq v \leq n$$$).

For each query of the second type, print a single line with the maximum awesomeness in the respective subtree.

NoteThe initial awesomeness of the vertices is $$$[100, 91, 57, 64, 57]$$$. The most awesome vertex in the subtree of vertex $$$1$$$ (the first query) is $$$1$$$, and the most awesome vertex in the subtree of vertex $$$2$$$ (the second query) is $$$2$$$. After the first update (the third query), the awesomeness changes to $$$[100, 169, 57, 160, 57]$$$ and thus the most awesome vertex in the whole tree (the fourth query) is now $$$2$$$.After the second update (the fifth query), the awesomeness becomes $$$[100, 234, 57, 240, 152]$$$, hence the most awesome vertex (the sixth query) is now $$$4$$$.


Alice bought a Congo Prime Video subscription and was watching a documentary on the archaeological findings from Factor's Island on Loch Katrine in Scotland. The archaeologists found a book whose age and origin are unknown. Perhaps Alice can make some sense of it?The book contains a single string of characters "a", "b" and "c". It has been pointed out that no two consecutive characters are the same. It has also been conjectured that the string contains an unusually long subsequence that reads the same from both sides. Help Alice verify this by finding such subsequence that contains at least half of the characters of the original string, rounded down. Note that you don't have to maximise the length of it.A string $$$a$$$ is a subsequence of a string $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly, zero or all) characters.

The input consists of a single string $$$s$$$ ($$$2 \leq |s| \leq 10^6$$$). The string $$$s$$$ consists only of characters "a", "b", "c". It is guaranteed that no two consecutive characters are equal.

Output a palindrome $$$t$$$ that is a subsequence of $$$s$$$ and $$$|t| \geq \lfloor \frac{|s|}{2} \rfloor$$$. If there are multiple solutions, you may print any of them. You don't have to maximise the length of $$$t$$$. If there are no solutions, output a string "IMPOSSIBLE" (quotes for clarity).

NoteIn the first example, other valid answers include "cacac", "caac", "aca" and "ccc".


You are given array $$$a_1, a_2, \dots, a_n$$$. Find the subsegment $$$a_l, a_{l+1}, \dots, a_r$$$ ($$$1 \le l \le r \le n$$$) with maximum arithmetic mean $$$\frac{1}{r - l + 1}\sum\limits_{i=l}^{r}{a_i}$$$ (in floating-point numbers, i.e. without any rounding).If there are many such subsegments find the longest one.

The first line contains single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — length of the array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) — the array $$$a$$$.

Print the single integer — the length of the longest subsegment with maximum possible arithmetic mean.

NoteThe subsegment $$$[3, 4]$$$ is the longest among all subsegments with maximum arithmetic mean.


You a captain of a ship. Initially you are standing in a point $$$(x_1, y_1)$$$ (obviously, all positions in the sea can be described by cartesian plane) and you want to travel to a point $$$(x_2, y_2)$$$. You know the weather forecast — the string $$$s$$$ of length $$$n$$$, consisting only of letters U, D, L and R. The letter corresponds to a direction of wind. Moreover, the forecast is periodic, e.g. the first day wind blows to the side $$$s_1$$$, the second day — $$$s_2$$$, the $$$n$$$-th day — $$$s_n$$$ and $$$(n+1)$$$-th day — $$$s_1$$$ again and so on. Ship coordinates change the following way:  if wind blows the direction U, then the ship moves from $$$(x, y)$$$ to $$$(x, y + 1)$$$;  if wind blows the direction D, then the ship moves from $$$(x, y)$$$ to $$$(x, y - 1)$$$;  if wind blows the direction L, then the ship moves from $$$(x, y)$$$ to $$$(x - 1, y)$$$;  if wind blows the direction R, then the ship moves from $$$(x, y)$$$ to $$$(x + 1, y)$$$. The ship can also either go one of the four directions or stay in place each day. If it goes then it's exactly 1 unit of distance. Transpositions of the ship and the wind add up. If the ship stays in place, then only the direction of wind counts. For example, if wind blows the direction U and the ship moves the direction L, then from point $$$(x, y)$$$ it will move to the point $$$(x - 1, y + 1)$$$, and if it goes the direction U, then it will move to the point $$$(x, y + 2)$$$.You task is to determine the minimal number of days required for the ship to reach the point $$$(x_2, y_2)$$$.

The first line contains two integers $$$x_1, y_1$$$ ($$$0 \le x_1, y_1 \le 10^9$$$) — the initial coordinates of the ship. The second line contains two integers $$$x_2, y_2$$$ ($$$0 \le x_2, y_2 \le 10^9$$$) — the coordinates of the destination point. It is guaranteed that the initial coordinates and destination point coordinates are different. The third line contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the length of the string $$$s$$$. The fourth line contains the string $$$s$$$ itself, consisting only of letters U, D, L and R.

The only line should contain the minimal number of days required for the ship to reach the point $$$(x_2, y_2)$$$. If it's impossible then print "-1".

NoteIn the first example the ship should perform the following sequence of moves: "RRRRU". Then its coordinates will change accordingly: $$$(0, 0)$$$ $$$\rightarrow$$$ $$$(1, 1)$$$ $$$\rightarrow$$$ $$$(2, 2)$$$ $$$\rightarrow$$$ $$$(3, 3)$$$ $$$\rightarrow$$$ $$$(4, 4)$$$ $$$\rightarrow$$$ $$$(4, 6)$$$.In the second example the ship should perform the following sequence of moves: "DD" (the third day it should stay in place). Then its coordinates will change accordingly: $$$(0, 3)$$$ $$$\rightarrow$$$ $$$(0, 3)$$$ $$$\rightarrow$$$ $$$(0, 1)$$$ $$$\rightarrow$$$ $$$(0, 0)$$$.In the third example the ship can never reach the point $$$(0, 1)$$$.


Reziba has many magic gems. Each magic gem can be split into $$$M$$$ normal gems. The amount of space each magic (and normal) gem takes is $$$1$$$ unit. A normal gem cannot be split.Reziba wants to choose a set of magic gems and split some of them, so the total space occupied by the resulting set of gems is $$$N$$$ units. If a magic gem is chosen and split, it takes $$$M$$$ units of space (since it is split into $$$M$$$ gems); if a magic gem is not split, it takes $$$1$$$ unit.How many different configurations of the resulting set of gems can Reziba have, such that the total amount of space taken is $$$N$$$ units? Print the answer modulo $$$1000000007$$$ ($$$10^9+7$$$). Two configurations are considered different if the number of magic gems Reziba takes to form them differs, or the indices of gems Reziba has to split differ.

The input contains a single line consisting of $$$2$$$ integers $$$N$$$ and $$$M$$$ ($$$1 \le N \le 10^{18}$$$, $$$2 \le M \le 100$$$).

Print one integer, the total number of configurations of the resulting set of gems, given that the total amount of space taken is $$$N$$$ units. Print the answer modulo $$$1000000007$$$ ($$$10^9+7$$$).

NoteIn the first example each magic gem can split into $$$2$$$ normal gems, and we know that the total amount of gems are $$$4$$$.Let $$$1$$$ denote a magic gem, and $$$0$$$ denote a normal gem.The total configurations you can have is:   $$$1 1 1 1$$$ (None of the gems split);  $$$0 0 1 1$$$ (First magic gem splits into $$$2$$$ normal gems);  $$$1 0 0 1$$$ (Second magic gem splits into $$$2$$$ normal gems);  $$$1 1 0 0$$$ (Third magic gem splits into $$$2$$$ normal gems);  $$$0 0 0 0$$$ (First and second magic gems split into total $$$4$$$ normal gems). Hence, answer is $$$5$$$.