You play a strategic video game (yeah, we ran out of good problem legends). In this game you control a large army, and your goal is to conquer $$$n$$$ castles of your opponent.Let's describe the game process in detail. Initially you control an army of $$$k$$$ warriors. Your enemy controls $$$n$$$ castles; to conquer the $$$i$$$-th castle, you need at least $$$a_i$$$ warriors (you are so good at this game that you don't lose any warriors while taking over a castle, so your army stays the same after the fight). After you take control over a castle, you recruit new warriors into your army — formally, after you capture the $$$i$$$-th castle, $$$b_i$$$ warriors join your army. Furthermore, after capturing a castle (or later) you can defend it: if you leave at least one warrior in a castle, this castle is considered defended. Each castle has an importance parameter $$$c_i$$$, and your total score is the sum of importance values over all defended castles. There are two ways to defend a castle:  if you are currently in the castle $$$i$$$, you may leave one warrior to defend castle $$$i$$$;  there are $$$m$$$ one-way portals connecting the castles. Each portal is characterised by two numbers of castles $$$u$$$ and $$$v$$$ (for each portal holds $$$u > v$$$). A portal can be used as follows: if you are currently in the castle $$$u$$$, you may send one warrior to defend castle $$$v$$$. Obviously, when you order your warrior to defend some castle, he leaves your army.You capture the castles in fixed order: you have to capture the first one, then the second one, and so on. After you capture the castle $$$i$$$ (but only before capturing castle $$$i + 1$$$) you may recruit new warriors from castle $$$i$$$, leave a warrior to defend castle $$$i$$$, and use any number of portals leading from castle $$$i$$$ to other castles having smaller numbers. As soon as you capture the next castle, these actions for castle $$$i$$$ won't be available to you.If, during some moment in the game, you don't have enough warriors to capture the next castle, you lose. Your goal is to maximize the sum of importance values over all defended castles (note that you may hire new warriors in the last castle, defend it and use portals leading from it even after you capture it — your score will be calculated afterwards).Can you determine an optimal strategy of capturing and defending the castles?

The first line contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$1 \le n \le 5000$$$, $$$0 \le m \le \min(\frac{n(n - 1)}{2}, 3 \cdot 10^5)$$$, $$$0 \le k \le 5000$$$) — the number of castles, the number of portals and initial size of your army, respectively. Then $$$n$$$ lines follow. The $$$i$$$-th line describes the $$$i$$$-th castle with three integers $$$a_i$$$, $$$b_i$$$ and $$$c_i$$$ ($$$0 \le a_i, b_i, c_i \le 5000$$$) — the number of warriors required to capture the $$$i$$$-th castle, the number of warriors available for hire in this castle and its importance value. Then $$$m$$$ lines follow. The $$$i$$$-th line describes the $$$i$$$-th portal with two integers $$$u_i$$$ and $$$v_i$$$ ($$$1 \le v_i < u_i \le n$$$), meaning that the portal leads from the castle $$$u_i$$$ to the castle $$$v_i$$$. There are no two same portals listed. It is guaranteed that the size of your army won't exceed $$$5000$$$ under any circumstances (i. e. $$$k + \sum\limits_{i = 1}^{n} b_i \le 5000$$$).

If it's impossible to capture all the castles, print one integer $$$-1$$$. Otherwise, print one integer equal to the maximum sum of importance values of defended castles.

NoteThe best course of action in the first example is as follows:  capture the first castle;  hire warriors from the first castle, your army has $$$11$$$ warriors now;  capture the second castle;  capture the third castle;  hire warriors from the third castle, your army has $$$13$$$ warriors now;  capture the fourth castle;  leave one warrior to protect the fourth castle, your army has $$$12$$$ warriors now. This course of action (and several other ones) gives $$$5$$$ as your total score.The best course of action in the second example is as follows:  capture the first castle;  hire warriors from the first castle, your army has $$$11$$$ warriors now;  capture the second castle;  capture the third castle;  hire warriors from the third castle, your army has $$$13$$$ warriors now;  capture the fourth castle;  leave one warrior to protect the fourth castle, your army has $$$12$$$ warriors now;  send one warrior to protect the first castle through the third portal, your army has $$$11$$$ warriors now. This course of action (and several other ones) gives $$$22$$$ as your total score.In the third example it's impossible to capture the last castle: you need $$$14$$$ warriors to do so, but you can accumulate no more than $$$13$$$ without capturing it.


Three friends are going to meet each other. Initially, the first friend stays at the position $$$x = a$$$, the second friend stays at the position $$$x = b$$$ and the third friend stays at the position $$$x = c$$$ on the coordinate axis $$$Ox$$$.In one minute each friend independently from other friends can change the position $$$x$$$ by $$$1$$$ to the left or by $$$1$$$ to the right (i.e. set $$$x := x - 1$$$ or $$$x := x + 1$$$) or even don't change it.Let's introduce the total pairwise distance — the sum of distances between each pair of friends. Let $$$a'$$$, $$$b'$$$ and $$$c'$$$ be the final positions of the first, the second and the third friend, correspondingly. Then the total pairwise distance is $$$|a' - b'| + |a' - c'| + |b' - c'|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.Friends are interested in the minimum total pairwise distance they can reach if they will move optimally. Each friend will move no more than once. So, more formally, they want to know the minimum total pairwise distance they can reach after one minute.You have to answer $$$q$$$ independent test cases.

The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 1000$$$) — the number of test cases. The next $$$q$$$ lines describe test cases. The $$$i$$$-th test case is given as three integers $$$a, b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^9$$$) — initial positions of the first, second and third friend correspondingly. The positions of friends can be equal.

For each test case print the answer on it — the minimum total pairwise distance (the minimum sum of distances between each pair of friends) if friends change their positions optimally. Each friend will move no more than once. So, more formally, you have to find the minimum total pairwise distance they can reach after one minute.


Recently a lot of students were enrolled in Berland State University. All students were divided into groups according to their education program. Some groups turned out to be too large to attend lessons in the same auditorium, so these groups should be divided into two subgroups. Your task is to help divide the first-year students of the computer science faculty.There are $$$t$$$ new groups belonging to this faculty. Students have to attend classes on three different subjects — maths, programming and P. E. All classes are held in different places according to the subject — maths classes are held in auditoriums, programming classes are held in computer labs, and P. E. classes are held in gyms.Each group should be divided into two subgroups so that there is enough space in every auditorium, lab or gym for all students of the subgroup. For the first subgroup of the $$$i$$$-th group, maths classes are held in an auditorium with capacity of $$$a_{i, 1}$$$ students; programming classes are held in a lab that accomodates up to $$$b_{i, 1}$$$ students; and P. E. classes are held in a gym having enough place for $$$c_{i, 1}$$$ students. Analogically, the auditorium, lab and gym for the second subgroup can accept no more than $$$a_{i, 2}$$$, $$$b_{i, 2}$$$ and $$$c_{i, 2}$$$ students, respectively.As usual, some students skip some classes. Each student considers some number of subjects (from $$$0$$$ to $$$3$$$) to be useless — that means, he skips all classes on these subjects (and attends all other classes). This data is given to you as follows — the $$$i$$$-th group consists of:  $$$d_{i, 1}$$$ students which attend all classes;  $$$d_{i, 2}$$$ students which attend all classes, except for P. E.;  $$$d_{i, 3}$$$ students which attend all classes, except for programming;  $$$d_{i, 4}$$$ students which attend only maths classes;  $$$d_{i, 5}$$$ students which attend all classes, except for maths;  $$$d_{i, 6}$$$ students which attend only programming classes;  $$$d_{i, 7}$$$ students which attend only P. E. There is one more type of students — those who don't attend any classes at all (but they, obviously, don't need any place in auditoriums, labs or gyms, so the number of those students is insignificant in this problem).Your task is to divide each group into two subgroups so that every auditorium (or lab, or gym) assigned to each subgroup has enough place for all students from this subgroup attending the corresponding classes (if it is possible). Each student of the $$$i$$$-th group should belong to exactly one subgroup of the $$$i$$$-th group; it is forbidden to move students between groups.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 300$$$) — the number of groups. Then the descriptions of groups follow. The description of the $$$i$$$-th group consists of three lines:   the first line contains three integers $$$a_{i, 1}$$$, $$$b_{i, 1}$$$ and $$$c_{i, 1}$$$ ($$$1 \le a_{i, 1}, b_{i, 1}, c_{i, 1} \le 3000$$$) — the capacity of the auditorium, lab and gym assigned to the first subgroup of the $$$i$$$-th group, respectively;  the second line contains three integers $$$a_{i, 2}$$$, $$$b_{i, 2}$$$ and $$$c_{i, 2}$$$ ($$$1 \le a_{i, 2}, b_{i, 2}, c_{i, 2} \le 3000$$$) — the capacity of the auditorium, lab and gym assigned to the second subgroup of the $$$i$$$-th group, respectively;  the third line contains integers $$$d_{i, 1}$$$, $$$d_{i, 2}$$$, ..., $$$d_{i, 7}$$$ ($$$0 \le d_{i, j} \le 3000$$$) — the number of students belonging to each of the seven aforementioned types in the $$$i$$$-th group. It is not guaranteed that the sum of these values is positive — a group can consist entirely of students that don't attend classes at all.  It is guaranteed that the total number of students in all groups is not greater than $$$3000$$$.

For each group, print the result of its division as follows:   if it is impossible to divide the group, print one integer $$$-1$$$;  otherwise print seven integers $$$f_{i, 1}$$$, $$$f_{i, 2}$$$, ..., $$$f_{i, 7}$$$ ($$$0 \le f_{i, j} \le d_{i, j}$$$) — the number of students the first, second, ..., seventh type in the first subgroup of the $$$i$$$-th group (all other students will be assigned to the second subgroup). If there are multiple answers, print any of them.


Recently, Norge found a string $$$s = s_1 s_2 \ldots s_n$$$ consisting of $$$n$$$ lowercase Latin letters. As an exercise to improve his typing speed, he decided to type all substrings of the string $$$s$$$. Yes, all $$$\frac{n (n + 1)}{2}$$$ of them!A substring of $$$s$$$ is a non-empty string $$$x = s[a \ldots b] = s_{a} s_{a + 1} \ldots s_{b}$$$ ($$$1 \leq a \leq b \leq n$$$). For example, "auto" and "ton" are substrings of "automaton".Shortly after the start of the exercise, Norge realized that his keyboard was broken, namely, he could use only $$$k$$$ Latin letters $$$c_1, c_2, \ldots, c_k$$$ out of $$$26$$$.After that, Norge became interested in how many substrings of the string $$$s$$$ he could still type using his broken keyboard. Help him to find this number.

The first line contains two space-separated integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$, $$$1 \leq k \leq 26$$$) — the length of the string $$$s$$$ and the number of Latin letters still available on the keyboard. The second line contains the string $$$s$$$ consisting of exactly $$$n$$$ lowercase Latin letters. The third line contains $$$k$$$ space-separated distinct lowercase Latin letters $$$c_1, c_2, \ldots, c_k$$$ — the letters still available on the keyboard.

Print a single number — the number of substrings of $$$s$$$ that can be typed using only available letters $$$c_1, c_2, \ldots, c_k$$$.


You are given an array $$$a$$$ consisting of $$$n$$$ integers.You can remove at most one element from this array. Thus, the final length of the array is $$$n-1$$$ or $$$n$$$.Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array.Recall that the contiguous subarray $$$a$$$ with indices from $$$l$$$ to $$$r$$$ is $$$a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$$$. The subarray $$$a[l \dots r]$$$ is called strictly increasing if $$$a_l < a_{l+1} < \dots < a_r$$$.

The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 2 \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$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$.

Print one integer — the maximum possible length of the strictly increasing contiguous subarray of the array $$$a$$$ after removing at most one element.

NoteIn the first example, you can delete $$$a_3=5$$$. Then the resulting array will be equal to $$$[1, 2, 3, 4]$$$ and the length of its largest increasing subarray will be equal to $$$4$$$.


You are given an array $$$a$$$ consisting of $$$n$$$ integers. In one move, you can jump from the position $$$i$$$ to the position $$$i - a_i$$$ (if $$$1 \le i - a_i$$$) or to the position $$$i + a_i$$$ (if $$$i + a_i \le n$$$).For each position $$$i$$$ from $$$1$$$ to $$$n$$$ you want to know the minimum the number of moves required to reach any position $$$j$$$ such that $$$a_j$$$ has the opposite parity from $$$a_i$$$ (i.e. if $$$a_i$$$ is odd then $$$a_j$$$ has to be even and vice versa).

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 $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$.

Print $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$, where $$$d_i$$$ is the minimum the number of moves required to reach any position $$$j$$$ such that $$$a_j$$$ has the opposite parity from $$$a_i$$$ (i.e. if $$$a_i$$$ is odd then $$$a_j$$$ has to be even and vice versa) or -1 if it is impossible to reach such a position.


You are given two integers $$$a$$$ and $$$m$$$. Calculate the number of integers $$$x$$$ such that $$$0 \le x < m$$$ and $$$\gcd(a, m) = \gcd(a + x, m)$$$.Note: $$$\gcd(a, b)$$$ is the greatest common divisor of $$$a$$$ and $$$b$$$.

The first line contains the single integer $$$T$$$ ($$$1 \le T \le 50$$$) — the number of test cases. Next $$$T$$$ lines contain test cases — one per line. Each line contains two integers $$$a$$$ and $$$m$$$ ($$$1 \le a < m \le 10^{10}$$$).

Print $$$T$$$ integers — one per test case. For each test case print the number of appropriate $$$x$$$-s.

NoteIn the first test case appropriate $$$x$$$-s are $$$[0, 1, 3, 4, 6, 7]$$$.In the second test case the only appropriate $$$x$$$ is $$$0$$$.


You are given two bracket sequences (not necessarily regular) $$$s$$$ and $$$t$$$ consisting only of characters '(' and ')'. You want to construct the shortest regular bracket sequence that contains both given bracket sequences as subsequences (not necessarily contiguous).Recall what is the regular bracket sequence:  () is the regular bracket sequence;  if $$$S$$$ is the regular bracket sequence, then ($$$S$$$) is a regular bracket sequence;  if $$$S$$$ and $$$T$$$ regular bracket sequences, then $$$ST$$$ (concatenation of $$$S$$$ and $$$T$$$) is a regular bracket sequence. Recall that the subsequence of the string $$$s$$$ is such string $$$t$$$ that can be obtained from $$$s$$$ by removing some (possibly, zero) amount of characters. For example, "coder", "force", "cf" and "cores" are subsequences of "codeforces", but "fed" and "z" are not.

The first line of the input contains one bracket sequence $$$s$$$ consisting of no more than $$$200$$$ characters '(' and ')'. The second line of the input contains one bracket sequence $$$t$$$ consisting of no more than $$$200$$$ characters '(' and ')'.

Print one line — the shortest regular bracket sequence that contains both given bracket sequences as subsequences (not necessarily contiguous). If there are several answers, you can print any.


An online contest will soon be held on ForceCoders, a large competitive programming platform. The authors have prepared $$$n$$$ problems; and since the platform is very popular, $$$998244351$$$ coder from all over the world is going to solve them.For each problem, the authors estimated the number of people who would solve it: for the $$$i$$$-th problem, the number of accepted solutions will be between $$$l_i$$$ and $$$r_i$$$, inclusive.The creator of ForceCoders uses different criteria to determine if the contest is good or bad. One of these criteria is the number of inversions in the problem order. An inversion is a pair of problems $$$(x, y)$$$ such that $$$x$$$ is located earlier in the contest ($$$x < y$$$), but the number of accepted solutions for $$$y$$$ is strictly greater.Obviously, both the creator of ForceCoders and the authors of the contest want the contest to be good. Now they want to calculate the probability that there will be no inversions in the problem order, assuming that for each problem $$$i$$$, any integral number of accepted solutions for it (between $$$l_i$$$ and $$$r_i$$$) is equally probable, and all these numbers are independent.

The first line contains one integer $$$n$$$ ($$$2 \le n \le 50$$$) — the number of problems in the contest. Then $$$n$$$ lines follow, the $$$i$$$-th line contains two integers $$$l_i$$$ and $$$r_i$$$ ($$$0 \le l_i \le r_i \le 998244351$$$) — the minimum and maximum number of accepted solutions for the $$$i$$$-th problem, respectively.

The probability that there will be no inversions in the contest can be expressed as an irreducible fraction $$$\frac{x}{y}$$$, where $$$y$$$ is coprime with $$$998244353$$$. Print one integer — the value of $$$xy^{-1}$$$, taken modulo $$$998244353$$$, where $$$y^{-1}$$$ is an integer such that $$$yy^{-1} \equiv 1$$$ $$$(mod$$$ $$$998244353)$$$.

NoteThe real answer in the first test is $$$\frac{1}{2}$$$.


You are given a permutation $$$p_1, p_2, \dots , p_n$$$ (an array where each integer from $$$1$$$ to $$$n$$$ appears exactly once). The weight of the $$$i$$$-th element of this permutation is $$$a_i$$$.At first, you separate your permutation into two non-empty sets — prefix and suffix. More formally, the first set contains elements $$$p_1, p_2, \dots , p_k$$$, the second — $$$p_{k+1}, p_{k+2}, \dots , p_n$$$, where $$$1 \le k < n$$$.After that, you may move elements between sets. The operation you are allowed to do is to choose some element of the first set and move it to the second set, or vice versa (move from the second set to the first). You have to pay $$$a_i$$$ dollars to move the element $$$p_i$$$.Your goal is to make it so that each element of the first set is less than each element of the second set. Note that if one of the sets is empty, this condition is met.For example, if $$$p = [3, 1, 2]$$$ and $$$a = [7, 1, 4]$$$, then the optimal strategy is: separate $$$p$$$ into two parts $$$[3, 1]$$$ and $$$[2]$$$ and then move the $$$2$$$-element into first set (it costs $$$4$$$). And if $$$p = [3, 5, 1, 6, 2, 4]$$$, $$$a = [9, 1, 9, 9, 1, 9]$$$, then the optimal strategy is: separate $$$p$$$ into two parts $$$[3, 5, 1]$$$ and $$$[6, 2, 4]$$$, and then move the $$$2$$$-element into first set (it costs $$$1$$$), and $$$5$$$-element into second set (it also costs $$$1$$$).Calculate the minimum number of dollars you have to spend.

The first line contains one integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the length of permutation. The second line contains $$$n$$$ integers $$$p_1, p_2, \dots , p_n$$$ ($$$1 \le p_i \le n$$$). It's guaranteed that this sequence contains each element from $$$1$$$ to $$$n$$$ exactly once. The third line contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$).

Print one integer — the minimum number of dollars you have to spend.


Mishka wants to buy some food in the nearby shop. Initially, he has $$$s$$$ burles on his card. Mishka can perform the following operation any number of times (possibly, zero): choose some positive integer number $$$1 \le x \le s$$$, buy food that costs exactly $$$x$$$ burles and obtain $$$\lfloor\frac{x}{10}\rfloor$$$ burles as a cashback (in other words, Mishka spends $$$x$$$ burles and obtains $$$\lfloor\frac{x}{10}\rfloor$$$ back). The operation $$$\lfloor\frac{a}{b}\rfloor$$$ means $$$a$$$ divided by $$$b$$$ rounded down.It is guaranteed that you can always buy some food that costs $$$x$$$ for any possible value of $$$x$$$.Your task is to say the maximum number of burles Mishka can spend if he buys food optimally.For example, if Mishka has $$$s=19$$$ burles then the maximum number of burles he can spend is $$$21$$$. Firstly, he can spend $$$x=10$$$ burles, obtain $$$1$$$ burle as a cashback. Now he has $$$s=10$$$ burles, so can spend $$$x=10$$$ burles, obtain $$$1$$$ burle as a cashback and spend it too.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The next $$$t$$$ lines describe test cases. Each test case is given on a separate line and consists of one integer $$$s$$$ ($$$1 \le s \le 10^9$$$) — the number of burles Mishka initially has.

For each test case print the answer on it — the maximum number of burles Mishka can spend if he buys food optimally.


You are given an array $$$a$$$ consisting of $$$n$$$ integers.In one move, you can choose two indices $$$1 \le i, j \le n$$$ such that $$$i \ne j$$$ and set $$$a_i := a_j$$$. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose $$$i$$$ and $$$j$$$ and replace $$$a_i$$$ with $$$a_j$$$).Your task is to say if it is possible to obtain an array with an odd (not divisible by $$$2$$$) sum of elements.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2000$$$) — the number of test cases. The next $$$2t$$$ lines describe test cases. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2000$$$) — the number of elements in $$$a$$$. The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 2000$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2000$$$ ($$$\sum n \le 2000$$$).

For each test case, print the answer on it — "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.


There is a robot on a coordinate plane. Initially, the robot is located at the point $$$(0, 0)$$$. Its path is described as a string $$$s$$$ of length $$$n$$$ consisting of characters 'L', 'R', 'U', 'D'.Each of these characters corresponds to some move:   'L' (left): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x - 1, y)$$$;  'R' (right): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x + 1, y)$$$;  'U' (up): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y + 1)$$$;  'D' (down): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y - 1)$$$. The company that created this robot asked you to optimize the path of the robot somehow. To do this, you can remove any non-empty substring of the path. But this company doesn't want their customers to notice the change in the robot behavior. It means that if before the optimization the robot ended its path at the point $$$(x_e, y_e)$$$, then after optimization (i.e. removing some single substring from $$$s$$$) the robot also ends its path at the point $$$(x_e, y_e)$$$.This optimization is a low-budget project so you need to remove the shortest possible non-empty substring to optimize the robot's path such that the endpoint of his path doesn't change. It is possible that you can't optimize the path. Also, it is possible that after the optimization the target path is an empty string (i.e. deleted substring is the whole string $$$s$$$).Recall that the substring of $$$s$$$ is such string that can be obtained from $$$s$$$ by removing some amount of characters (possibly, zero) from the prefix and some amount of characters (possibly, zero) from the suffix. For example, the substrings of "LURLLR" are "LU", "LR", "LURLLR", "URL", but not "RR" and "UL".You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The next $$$2t$$$ lines describe test cases. Each test case is given on two lines. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of the robot's path. The second line of the test case contains one string $$$s$$$ consisting of $$$n$$$ characters 'L', 'R', 'U', 'D' — the robot's path. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$).

For each test case, print the answer on it. If you cannot remove such non-empty substring that the endpoint of the robot's path doesn't change, print -1. Otherwise, print two integers $$$l$$$ and $$$r$$$ such that $$$1 \le l \le r \le n$$$ — endpoints of the substring you remove. The value $$$r-l+1$$$ should be minimum possible. If there are several answers, print any of them.


There are $$$n$$$ monsters standing in a row numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th monster has $$$h_i$$$ health points (hp). You have your attack power equal to $$$a$$$ hp and your opponent has his attack power equal to $$$b$$$ hp.You and your opponent are fighting these monsters. Firstly, you and your opponent go to the first monster and fight it till his death, then you and your opponent go the second monster and fight it till his death, and so on. A monster is considered dead if its hp is less than or equal to $$$0$$$.The fight with a monster happens in turns.   You hit the monster by $$$a$$$ hp. If it is dead after your hit, you gain one point and you both proceed to the next monster.  Your opponent hits the monster by $$$b$$$ hp. If it is dead after his hit, nobody gains a point and you both proceed to the next monster. You have some secret technique to force your opponent to skip his turn. You can use this technique at most $$$k$$$ times in total (for example, if there are two monsters and $$$k=4$$$, then you can use the technique $$$2$$$ times on the first monster and $$$1$$$ time on the second monster, but not $$$2$$$ times on the first monster and $$$3$$$ times on the second monster).Your task is to determine the maximum number of points you can gain if you use the secret technique optimally.

The first line of the input contains four integers $$$n, a, b$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5, 1 \le a, b, k \le 10^9$$$) — the number of monsters, your attack power, the opponent's attack power and the number of times you can use the secret technique. The second line of the input contains $$$n$$$ integers $$$h_1, h_2, \dots, h_n$$$ ($$$1 \le h_i \le 10^9$$$), where $$$h_i$$$ is the health points of the $$$i$$$-th monster.

Print one integer — the maximum number of points you can gain if you use the secret technique optimally.


This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.You are given a string $$$s$$$ consisting of $$$n$$$ lowercase Latin letters.You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $$$s$$$).After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.The goal is to make the string sorted, i.e. all characters should be in alphabetical order.Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.

The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 200$$$) — the length of $$$s$$$. The second line of the input contains the string $$$s$$$ consisting of exactly $$$n$$$ lowercase Latin letters.

If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line. Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $$$n$$$ characters, the $$$i$$$-th character should be '0' if the $$$i$$$-th character is colored the first color and '1' otherwise).


There are $$$n$$$ railway stations in Berland. They are connected to each other by $$$n-1$$$ railway sections. The railway network is connected, i.e. can be represented as an undirected tree.You have a map of that network, so for each railway section you know which stations it connects.Each of the $$$n-1$$$ sections has some integer value of the scenery beauty. However, these values are not marked on the map and you don't know them. All these values are from $$$1$$$ to $$$10^6$$$ inclusive.You asked $$$m$$$ passengers some questions: the $$$j$$$-th one told you three values:  his departure station $$$a_j$$$;  his arrival station $$$b_j$$$;  minimum scenery beauty along the path from $$$a_j$$$ to $$$b_j$$$ (the train is moving along the shortest path from $$$a_j$$$ to $$$b_j$$$). You are planning to update the map and set some value $$$f_i$$$ on each railway section — the scenery beauty. The passengers' answers should be consistent with these values.Print any valid set of values $$$f_1, f_2, \dots, f_{n-1}$$$, which the passengers' answer is consistent with or report that it doesn't exist.

The first line contains a single integer $$$n$$$ ($$$2 \le n \le 5000$$$) — the number of railway stations in Berland. The next $$$n-1$$$ lines contain descriptions of the railway sections: the $$$i$$$-th section description is two integers $$$x_i$$$ and $$$y_i$$$ ($$$1 \le x_i, y_i \le n, x_i \ne y_i$$$), where $$$x_i$$$ and $$$y_i$$$ are the indices of the stations which are connected by the $$$i$$$-th railway section. All the railway sections are bidirected. Each station can be reached from any other station by the railway. The next line contains a single integer $$$m$$$ ($$$1 \le m \le 5000$$$) — the number of passengers which were asked questions. Then $$$m$$$ lines follow, the $$$j$$$-th line contains three integers $$$a_j$$$, $$$b_j$$$ and $$$g_j$$$ ($$$1 \le a_j, b_j \le n$$$; $$$a_j \ne b_j$$$; $$$1 \le g_j \le 10^6$$$) — the departure station, the arrival station and the minimum scenery beauty along his path.

If there is no answer then print a single integer -1. Otherwise, print $$$n-1$$$ integers $$$f_1, f_2, \dots, f_{n-1}$$$ ($$$1 \le f_i \le 10^6$$$), where $$$f_i$$$ is some valid scenery beauty along the $$$i$$$-th railway section. If there are multiple answers, you can print any of them.


This is a hard version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.You are given a string $$$s$$$ consisting of $$$n$$$ lowercase Latin letters.You have to color all its characters the minimum number of colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $$$s$$$).After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.The goal is to make the string sorted, i.e. all characters should be in alphabetical order.Your task is to find the minimum number of colors which you have to color the given string in so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.

The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of $$$s$$$. The second line of the input contains the string $$$s$$$ consisting of exactly $$$n$$$ lowercase Latin letters.

In the first line print one integer $$$res$$$ ($$$1 \le res \le n$$$) — the minimum number of colors in which you have to color the given string so that after coloring it can become sorted by some sequence of swaps. In the second line print any possible coloring that can be used to sort the string using some sequence of swaps described in the problem statement. The coloring is the array $$$c$$$ of length $$$n$$$, where $$$1 \le c_i \le res$$$ and $$$c_i$$$ means the color of the $$$i$$$-th character.


Polycarp is the project manager in the IT-company. Right now, he needs to choose developers for his team to start a new project. The company has $$$n$$$ developers "on the bench" (i.e not involved in other projects). Polycarp assessed the skills of each of them: $$$a_i$$$ ($$$-10^4 \le a_i \le 10^4$$$) — an integer characteristic of the $$$i$$$-th developer. This value can be either positive, zero or even negative (some developers cause distractions).After Polycarp chooses a subset of developers for his team, the strength of the team will be determined by the sum of $$$a_i$$$ values for all selected developers.Polycarp fears that if he chooses a team in such a way that maximizes the sum of the characteristics of $$$a_i$$$, other managers may find this unacceptable. For this reason, he plans to create such a team that the sum of the $$$a_i$$$ values for it is strictly less than the maximum possible value.Help Polycarp choose any team that:  the sum of the characteristics $$$a_i$$$ for all members of the selected team is strictly less than the maximum value that can be achieved by choosing the team in some other way  and at the same time, the sum of the characteristics of $$$a_i$$$ for all members of the selected team is the greatest possible. If, following the requirements above, you can select a team in several ways, then just find any of them. It's guaranteed that the sum of the characteristics in the desired subset is strictly positive (i.e. Polycarp can always choose a non-empty team).

The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. Each test case begins with a line containing one integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of developers "on the bench". The second line of a test case contains a sequence of integers $$$a_1, a_2, \dots, a_n$$$ ($$$-10^4 \le a_i \le 10^4$$$) — the characteristics of the $$$n$$$ developers. It is guaranteed that the characteristics are such that the sum of the characteristics in the answer is strictly positive. It is guaranteed that the sum of $$$n$$$ over all test cases in the input doesn't exceed $$$10^5$$$.

Print the answers for the given $$$t$$$ test cases in the order that they appear in the input. In the first line of each answer, print a positive integer $$$s$$$ — the sum of the characteristics in the desired subset. The second line should contain only the characters 0 and 1 and match the answer:   the character in the $$$i$$$-th position should be equal to 1 if the $$$i$$$-th developer belongs to the team;  the character in the $$$i$$$-th position should be equal to 0 if the $$$i$$$-th developer does not belong to the team.  If there are several answers, print any of them.

NoteIn the first test case, the maximum subset $$$a_1, a_3, a_5$$$ has a sum equal to $$$3$$$, so Polycarp should choose a team with the maximum total sum which is less than $$$3$$$.In the second test case, the maximum subset $$$a_1, a_2$$$ has a sum equal to $$$12$$$, so Polycarp should choose a team with the maximum total sum which is less than $$$12$$$.In the third test case, the maximum subset $$$a_1, a_3$$$ has a sum equal to $$$9$$$.In the fourth test case, the maximum subset $$$a_1, a_2$$$ has a sum equal to $$$8$$$.In the fifth test case, there are several subsets with a maximum sum equal to $$$3$$$, so Polycarp should choose a team with a lower total sum.


Tanya likes cartoons. She knows that $$$n$$$ new cartoons will be released in his favorite cinema: the $$$i$$$-th of them will be airing from the day $$$a_i$$$ to the day $$$b_i$$$ ($$$1 \le a_i \le b_i \le 10^9$$$).The cinema has a special offer: there is a huge discount every day when only one cartoon is airing.Tanya doesn't care which cartoon she will watch but she'd like to save some money. That's why she asks you to find any day $$$x$$$ when only one cartoon will be airing. Formally: find $$$x$$$ such that there is exactly one $$$i$$$ ($$$1 \le i \le n$$$) with $$$a_i \le x \le b_i$$$. If there are several possible answers, print any of them. If there is no such day, print -1.

The first line contains single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The following are descriptions of the $$$t$$$ test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 2000$$$) — the number of cartoons. In the next $$$n$$$ lines, the cartoons themselves are described, one per line, by a pair of integers $$$a_i$$$, $$$b_i$$$ ($$$1 \le a_i \le b_i \le 10^9$$$) — the first and last airing days for the $$$i$$$-th cartoon. It is guaranteed that the sum of the values $$$n$$$ for all test cases in the input does not exceed $$$2000$$$.

Print $$$t$$$ answers to given test cases in the order in which they appear in the input: the $$$i$$$-th answer is such $$$x$$$, that only one cartoon will be airing on day $$$x$$$ or -1 if there are no such days.

NoteIn the third test case: at day $$$1$$$ and $$$2$$$, first and third cartoons will be airing, and days $$$3$$$ and $$$4$$$, second and third cartoons will be airing. So, there is no day when only one cartoon will be airing.In the fourth test case, $$$11$$$ is also a possible answer.


Polycarp is working on the implementation of displaying likes on the Codehorses social network. The number of likes should be displayed in a format that will be easy to read by users. It was decided that for large numbers of likes the format should be like 123K (one hundred twenty-three thousand) or like 56M (fifty-six million).The following displaying strategy has been approved:  the number will be displayed either as an integer number from 0 to 999, or as a positive integer number of thousands (from 1K to 999K), or as a positive integer number of millions (from 1M on),  the specified exact number of likes $$$n$$$ when displaying should be rounded to the nearest view from the case above (if rounding is ambiguous, it must be rounded up): for example, $$$1785$$$ should be rounded to 2K instead of 1K, $$$4500000$$$ should be rounded to 5M. Help Polycarp implement this part of the functionality: for a given non-negative integer number of likes $$$n$$$, print its view in the Codehorses interface.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases in the input. The following are descriptions of the $$$t$$$ input test cases, one per line. The description of each test case consists of a single line that contains a non-negative integer $$$n$$$ ($$$0 \le n \le 2\cdot10^9$$$) — the number of likes.

Print $$$t$$$ answers to the given test cases in the order from the input. Each printed value must have one of the following types:   either an integer from 0 to 999 which corresponds just to the number of likes,  or a number of thousands from 1K to 999K,  or a number of millions from 1M to 2000M.  The answer is equal to a view which is the closest (by difference) to the given number $$$n$$$. If this rounding is ambiguous, then round answer up (to a greater value).

NoteLet's describe some test cases:   $$$1782$$$ can be displayed either as 1K or as 2K but 2K is the nearest view;  $$$1500$$$ have same difference with 1K and 2K so it should be rounded up;  $$$999999$$$ should be displayed as 1M since it's closer to it than to 999K.


For the first time, Polycarp's startup ended the year with a profit! Now he is about to distribute $$$k$$$ burles as a bonus among $$$n$$$ employees.It is known that the current salary of the $$$i$$$-th employee is $$$a_i$$$ and all the values of $$$a_i$$$ in the company are different.Polycarp wants to distribute the $$$k$$$ burles between $$$n$$$ employees so this month the $$$i$$$-th employee will be paid not $$$a_i$$$, but $$$a_i+d_i$$$ ($$$d_i \ge 0$$$, $$$d_i$$$ is an integer), where $$$d_i$$$ is the bonus for the $$$i$$$-th employee. Of course, $$$d_1+d_2+\dots+d_n=k$$$.Polycarp will follow two rules for choosing the values $$$d_i$$$:  the relative order of the salaries should not be changed: the employee with originally the highest salary ($$$a_i$$$ is the maximum) should have the highest total payment after receiving their bonus ($$$a_i+d_i$$$ is also the maximum), the employee whose salary was originally the second-largest should receive the second-largest total payment after receiving their bonus and so on.  to emphasize that annual profit is a group effort, Polycarp wants to minimize the maximum total payment to an employee (i.e minimize the maximum value of $$$a_i+d_i$$$). Help Polycarp decide the non-negative integer bonuses $$$d_i$$$ such that:  their sum is $$$k$$$,  for each employee, the number of those who receive strictly more than them remains unchanged (that is, if you sort employees by $$$a_i$$$ and by $$$a_i+d_i$$$, you get the same order of employees),  all $$$a_i + d_i$$$ are different,  the maximum of the values $$$a_i+d_i$$$ is the minimum possible. Help Polycarp and print any of the possible answers $$$d_1, d_2, \dots, d_n$$$.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the input. Then $$$t$$$ test cases follow. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le k \le 10^9$$$) — the number of employees and the total bonus. The second line of each test case contains $$$n$$$ different integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the current salary of the $$$i$$$-th employee. It is guaranteed that the sum of all $$$n$$$ values in the input does not exceed $$$10^5$$$.

Print the answers to $$$t$$$ test cases in the order they appear in the input. Print each answer as a sequence of non-negative integers $$$d_1, d_2, \dots, d_n$$$. If there are several answers, print any of them.


Treeland consists of $$$n$$$ cities and $$$n-1$$$ two-way roads connecting pairs of cities. From every city, you can reach every other city moving only by the roads. You are right, the system of cities and roads in this country forms an undirected tree.The government has announced a program for the modernization of urban infrastructure of some cities. You have been assigned to select an arbitrary subset of cities $$$S$$$ to upgrade (potentially all the cities) that satisfies the following requirements:  the subset of cities must be "connected", that is, from any city of the subset $$$S$$$ you can get to any other city of the subset $$$S$$$ by roads, moving only through cities from $$$S$$$,  the number of "dead-ends" in $$$S$$$ must be equal to the given number $$$k$$$. A city is a "dead-end" if it is the only city in $$$S$$$ or connected to exactly one another city from $$$S$$$.     This shows one of the possible ways to select $$$S$$$ (blue vertices) for a given configuration and $$$k=4$$$. Dead-ends are vertices with numbers $$$1$$$, $$$4$$$, $$$6$$$ and $$$7$$$. Help Treeland upgrade its cities. Find any of the possible subsets $$$S$$$ or determine that such a subset does not exist.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the input. This is followed by the test cases themselves. Each test case begins with a line that contains two integers $$$n$$$ and $$$k$$$ ($$$2 \le n \le 3 \cdot 10^5$$$, $$$1 \le k \le n$$$) — the number of cities in Treeland and the number of "dead-end" cities required in the subset $$$S$$$. This is followed by $$$n-1$$$ lines with road descriptions. Each road is given by two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le n$$$; $$$x \ne y$$$) — the numbers of the cities that are connected by this road. It is guaranteed that from every city you can reach any other, moving only by the roads. The sum of the values of $$$n$$$ for all test cases in the input does not exceed $$$3 \cdot 10^5$$$.

For each test case print Yes or No (in any case, upper or lower), depending on whether the answer exists or not. If the answer exists, then print an integer $$$m$$$ ($$$1 \le m \le n$$$) — the number of cities in the found subset. Then print $$$m$$$ different numbers from $$$1$$$ to $$$n$$$ — the numbers of the cities in the found subset. City numbers can be printed in any order. If there are several answers, print any of them.


You are given a string $$$s$$$ of lowercase Latin letters. It is required to paint each letter of the string in one of two colors (red or blue) so that if you write all the red letters from left to right and write all the blue letters from left to right, then the lexicographically maximum of the two written strings is lexicographically minimal. For each index, in the string $$$s$$$ you can choose either of two colors.Formally, we write out:  the string $$$r$$$ (can be empty) — all red letters in the order from left to right (red subsequence),  the string $$$b$$$ (can be empty) — all blue letters in the order from left to right (blue subsequence). Your task is to paint the string such that $$$\max(r, b)$$$ is minimal. Small reminder: the empty string is the lexicographically smallest string.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the test. Next, the test cases are given, one per line. Each test case is a non-empty string $$$s$$$ of length between $$$2$$$ to $$$100$$$ characters, inclusive, which consists of lowercase Latin letters.

Print $$$t$$$ lines, the $$$i$$$-th of them should contain the answer to the $$$i$$$-th test case of the input. Print a string of length $$$n$$$, where $$$n$$$ is the length of the given string $$$s$$$: the $$$j$$$-th character of the string should be either 'R'or 'B' depending on the color of the $$$j$$$-th character in the answer (painted in red or blue). If there are several possible answers, print any of them.


Recently, Polycarp has been a fan of cinema novelties and is trying not to miss them!In the near future, $$$n$$$ new movies will be released: the $$$i$$$-th of them will be airing from the day $$$a_i$$$ and to the day $$$b_i$$$. This means that if Polycarp wants to watch the $$$i$$$-th movie in the cinema, he must do so in the period from $$$a_i$$$ to $$$b_i$$$ inclusive.If perhaps Polycarp will not have the opportunity to watch a movie in a cinema, he can then do it after day $$$b_i$$$ by watching it using an online service. Of course, this is an undesirable outcome for Polycarp because the whole world will have time to discuss this movie on social networks!Polycarp can watch no more than $$$m$$$ movies per day. Help Polycarp find a movie-watching schedule such that every movie will be watched in the cinema. If such a schedule does not exist, then Polycarp wants to watch movies so that:  for each movie that he doesn't have time to watch in the cinema, we will find the number of days between the end of its airing and the day when Polycarpus watches the movie,  the maximum of the values from the previous point should be as small as possible.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the input. The following are descriptions of the $$$t$$$ test cases. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$1 \le m \le 10^9$$$) — the number of movies and the maximum number of movies that Polycarp can view per day. In the next $$$n$$$ lines, the movies themselves are described, one per line, by a pair of integers $$$a_i$$$, $$$b_i$$$ ($$$1 \le a_i \le b_i \le 10^9$$$) — the first and last airing days for the $$$i$$$-th movie. It is guaranteed that the sum of the values $$$n$$$ for all test cases in the input does not exceed $$$2 \cdot 10^5$$$.

Print $$$t$$$ answers to given test cases in the order in which they appear in the input: the $$$i$$$-th answer should consist of two lines. Print the integer $$$d$$$ in the first line of each test case answer:   $$$d=0$$$, if there is a schedule such that all movies are watched during airing,  $$$d>0$$$, if such a schedule does not exist — in this case, $$$d$$$ is equal to the minimum value of maximum among all the watching "delays" after the end of airing.  In the second line of the answer to each test case, print $$$n$$$ positive integers $$$t_1, t_2, \dots, t_n$$$, where $$$t_i$$$ is the number of the day when Polycarp needs to watch the $$$i$$$-th movie in the optimal schedule. If there are several answers, print any of them.


Recently, Polycarp has invented a new mobile game with falling blocks.In the game, $$$n$$$ blocks are falling down, one at a time, towards a flat surface with length $$$d$$$ units. Each block can be represented as a rectangle with coordinates from $$$l_i$$$ to $$$r_i$$$ and unit height, dropped downwards from very high up. A block falls until it comes in contact with the flat surface or any other block. Let's define that block $$$a$$$ covers block $$$b$$$ if $$$l_a \le l_b \le r_b \le r_a$$$. Consider what happens when a new block $$$i$$$ falls. If the new (upper) block $$$i$$$ comes in contact with any block $$$j$$$ such that block $$$i$$$ does not cover block $$$j$$$, block $$$i$$$ will stick to block $$$j$$$, and no blocks will disappear. Otherwise, all blocks that block $$$i$$$ covers and is in contact with will be vaporized, and block $$$i$$$ will continue falling with the ability to vaporize lower blocks.For example, consider what happens when three blocks $$$(1,2)$$$, $$$(2,3)$$$ and $$$(1,3)$$$ fall, in that order. The first block will stick to the flat surface. Then, the second block will stick to the first block. Finally, the third block will vaporize the second block, keep falling, vaporize the first block, and stick to the flat surface.    Here is a graphic for the first example. After each block falls, help Polycarp determine how many blocks will remain!

The first line contains two integers $$$n$$$ and $$$d$$$ ($$$1 \le n, d \le 10^5$$$)  — the number of falling blocks and the length of the flat surface. The $$$i$$$-th of the following $$$n$$$ lines contains integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le d$$$)  — the coordinates of the $$$i$$$-th block.

Output $$$n$$$ integers. The $$$i$$$-th integer should be the number of blocks that will be left after the $$$i$$$-th block falls.

NoteThe first example is explained above.In the second example, this is what happens after each block falls:   Block $$$1$$$ will stick to the flat surface.  Block $$$2$$$ will stick to the flat surface.  Block $$$3$$$ will stick to blocks $$$1$$$ and $$$2$$$. Note that block $$$3$$$ will not vaporize block $$$2$$$ because it does not cover block $$$1$$$ and is in contact with it.  Block $$$4$$$ will vaporize all the blocks and stick to the flat surface.  Block $$$5$$$ will stick to block $$$4$$$  Block $$$6$$$ will stick to block $$$5$$$.  Block $$$7$$$ will stick to block $$$6$$$. Note that no blocks are vaporized because although block $$$7$$$ covers block $$$4$$$ and block $$$5$$$, they never come in contact.  Block $$$8$$$ vaporizes block $$$7$$$ and sticks to block $$$6$$$.


For a given positive integer $$$m$$$, a positive number is called a $$$m$$$-number if the product of its digits is $$$m$$$. For example, the beginning of a series of $$$24$$$-numbers are as follows: $$$38$$$, $$$46$$$, $$$64$$$, $$$83$$$, $$$138$$$, $$$146$$$, $$$164$$$, $$$183$$$, $$$226$$$ ...You are given a positive integer $$$m$$$ and $$$k$$$. Print $$$k$$$-th among $$$m$$$-numbers if all $$$m$$$-numbers are sorted in ascending order.

A single line of input contains two integers $$$m$$$ and $$$k$$$ ($$$2 \le m \le 10^9$$$, $$$1 \le k \le 10^9$$$).

Print the desired number — $$$k$$$-th among all $$$m$$$-numbers if $$$m$$$-numbers are sorted in ascending order. If the answer does not exist, print -1.


Anu has created her own function $$$f$$$: $$$f(x, y) = (x | y) - y$$$ where $$$|$$$ denotes the bitwise OR operation. For example, $$$f(11, 6) = (11|6) - 6 = 15 - 6 = 9$$$. It can be proved that for any nonnegative numbers $$$x$$$ and $$$y$$$ value of $$$f(x, y)$$$ is also nonnegative. She would like to research more about this function and has created multiple problems for herself. But she isn't able to solve all of them and needs your help. Here is one of these problems.A value of an array $$$[a_1, a_2, \dots, a_n]$$$ is defined as $$$f(f(\dots f(f(a_1, a_2), a_3), \dots a_{n-1}), a_n)$$$ (see notes). You are given an array with not necessarily distinct elements. How should you reorder its elements so that the value of the array is maximal possible?

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$). Elements of the array are not guaranteed to be different.

Output $$$n$$$ integers, the reordering of the array with maximum value. If there are multiple answers, print any.


Guy-Manuel and Thomas are planning $$$144$$$ trips around the world.You are given a simple weighted undirected connected graph with $$$n$$$ vertexes and $$$m$$$ edges with the following restriction: there isn't any simple cycle (i. e. a cycle which doesn't pass through any vertex more than once) of length greater than $$$3$$$ which passes through the vertex $$$1$$$. The cost of a path (not necessarily simple) in this graph is defined as the XOR of weights of all edges in that path with each edge being counted as many times as the path passes through it.But the trips with cost $$$0$$$ aren't exciting. You may choose any subset of edges incident to the vertex $$$1$$$ and remove them. How many are there such subsets, that, when removed, there is not any nontrivial cycle with the cost equal to $$$0$$$ which passes through the vertex $$$1$$$ in the resulting graph? A cycle is called nontrivial if it passes through some edge odd number of times. As the answer can be very big, output it modulo $$$10^9+7$$$.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n,m \le 10^5$$$) — the number of vertexes and edges in the graph. The $$$i$$$-th of the next $$$m$$$ lines contains three integers $$$a_i$$$, $$$b_i$$$ and $$$w_i$$$ ($$$1 \le a_i, b_i \le n, a_i \neq b_i, 0 \le w_i < 32$$$) — the endpoints of the $$$i$$$-th edge and its weight. It's guaranteed there aren't any multiple edges, the graph is connected and there isn't any simple cycle of length greater than $$$3$$$ which passes through the vertex $$$1$$$.

NoteThe pictures below represent the graphs from examples.  In the first example, there aren't any nontrivial cycles with cost $$$0$$$, so we can either remove or keep the only edge incident to the vertex $$$1$$$.  In the second example, if we don't remove the edge $$$1-2$$$, then there is a cycle $$$1-2-4-5-2-1$$$ with cost $$$0$$$; also if we don't remove the edge $$$1-3$$$, then there is a cycle $$$1-3-2-4-5-2-3-1$$$ of cost $$$0$$$. The only valid subset consists of both edges.  In the third example, all subsets are valid except for those two in which both edges $$$1-3$$$ and $$$1-4$$$ are kept.


Guy-Manuel and Thomas are going to build a polygon spaceship. You're given a strictly convex (i. e. no three points are collinear) polygon $$$P$$$ which is defined by coordinates of its vertices. Define $$$P(x,y)$$$ as a polygon obtained by translating $$$P$$$ by vector $$$\overrightarrow {(x,y)}$$$. The picture below depicts an example of the translation:Define $$$T$$$ as a set of points which is the union of all $$$P(x,y)$$$ such that the origin $$$(0,0)$$$ lies in $$$P(x,y)$$$ (both strictly inside and on the boundary). There is also an equivalent definition: a point $$$(x,y)$$$ lies in $$$T$$$ only if there are two points $$$A,B$$$ in $$$P$$$ such that $$$\overrightarrow {AB} = \overrightarrow {(x,y)}$$$. One can prove $$$T$$$ is a polygon too. For example, if $$$P$$$ is a regular triangle then $$$T$$$ is a regular hexagon. At the picture below $$$P$$$ is drawn in black and some $$$P(x,y)$$$ which contain the origin are drawn in colored: The spaceship has the best aerodynamic performance if $$$P$$$ and $$$T$$$ are similar. Your task is to check whether the polygons $$$P$$$ and $$$T$$$ are similar.

The first line of input will contain a single integer $$$n$$$ ($$$3 \le n \le 10^5$$$) — the number of points. The $$$i$$$-th of the next $$$n$$$ lines contains two integers $$$x_i, y_i$$$ ($$$|x_i|, |y_i| \le 10^9$$$), denoting the coordinates of the $$$i$$$-th vertex. It is guaranteed that these points are listed in counterclockwise order and these points form a strictly convex polygon.

Output "YES" in a separate line, if $$$P$$$ and $$$T$$$ are similar. Otherwise, output "NO" in a separate line. You can print each letter in any case (upper or lower).

NoteThe following image shows the first sample: both $$$P$$$ and $$$T$$$ are squares. The second sample was shown in the statements.


There are $$$n$$$ water tanks in a row, $$$i$$$-th of them contains $$$a_i$$$ liters of water. The tanks are numbered from $$$1$$$ to $$$n$$$ from left to right.You can perform the following operation: choose some subsegment $$$[l, r]$$$ ($$$1\le l \le r \le n$$$), and redistribute water in tanks $$$l, l+1, \dots, r$$$ evenly. In other words, replace each of $$$a_l, a_{l+1}, \dots, a_r$$$ by $$$\frac{a_l + a_{l+1} + \dots + a_r}{r-l+1}$$$. For example, if for volumes $$$[1, 3, 6, 7]$$$ you choose $$$l = 2, r = 3$$$, new volumes of water will be $$$[1, 4.5, 4.5, 7]$$$. You can perform this operation any number of times.What is the lexicographically smallest sequence of volumes of water that you can achieve?As a reminder:A sequence $$$a$$$ is lexicographically smaller than a sequence $$$b$$$ of the same length if and only if the following holds: in the first (leftmost) position where $$$a$$$ and $$$b$$$ differ, the sequence $$$a$$$ has a smaller element than the corresponding element in $$$b$$$.

The first line contains an integer $$$n$$$ ($$$1 \le n \le 10^6$$$) — the number of water tanks. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^6$$$) — initial volumes of water in the water tanks, in liters. Because of large input, reading input as doubles is not recommended.

Print the lexicographically smallest sequence you can get. In the $$$i$$$-th line print the final volume of water in the $$$i$$$-th tank. Your answer is considered correct if the absolute or relative error of each $$$a_i$$$ does not exceed $$$10^{-9}$$$. Formally, let your answer be $$$a_1, a_2, \dots, a_n$$$, and the jury's answer be $$$b_1, b_2, \dots, b_n$$$. Your answer is accepted if and only if $$$\frac{|a_i - b_i|}{\max{(1, |b_i|)}} \le 10^{-9}$$$ for each $$$i$$$.

NoteIn the first sample, you can get the sequence by applying the operation for subsegment $$$[1, 3]$$$.In the second sample, you can't get any lexicographically smaller sequence.


This problem is interactive.We have hidden a permutation $$$p_1, p_2, \dots, p_n$$$ of numbers from $$$1$$$ to $$$n$$$ from you, where $$$n$$$ is even. You can try to guess it using the following queries:$$$?$$$ $$$k$$$ $$$a_1$$$ $$$a_2$$$ $$$\dots$$$ $$$a_k$$$.In response, you will learn if the average of elements with indexes $$$a_1, a_2, \dots, a_k$$$ is an integer. In other words, you will receive $$$1$$$ if $$$\frac{p_{a_1} + p_{a_2} + \dots + p_{a_k}}{k}$$$ is integer, and $$$0$$$ otherwise. You have to guess the permutation. You can ask not more than $$$18n$$$ queries.Note that permutations $$$[p_1, p_2, \dots, p_k]$$$ and $$$[n + 1 - p_1, n + 1 - p_2, \dots, n + 1 - p_k]$$$ are indistinguishable. Therefore, you are guaranteed that $$$p_1 \le \frac{n}{2}$$$.Note that the permutation $$$p$$$ is fixed before the start of the interaction and doesn't depend on your queries. In other words, interactor is not adaptive.Note that you don't have to minimize the number of queries.

The first line contains a single integer $$$n$$$ ($$$2 \le n \le 800$$$, $$$n$$$ is even).


Guy-Manuel and Thomas have an array $$$a$$$ of $$$n$$$ integers [$$$a_1, a_2, \dots, a_n$$$]. In one step they can add $$$1$$$ to any element of the array. Formally, in one step they can choose any integer index $$$i$$$ ($$$1 \le i \le n$$$) and do $$$a_i := a_i + 1$$$.If either the sum or the product of all elements in the array is equal to zero, Guy-Manuel and Thomas do not mind to do this operation one more time.What is the minimum number of steps they need to do to make both the sum and the product of all elements in the array different from zero? Formally, find the minimum number of steps to make $$$a_1 + a_2 +$$$ $$$\dots$$$ $$$+ a_n \ne 0$$$ and $$$a_1 \cdot a_2 \cdot$$$ $$$\dots$$$ $$$\cdot a_n \ne 0$$$.

Each test contains multiple test cases.  The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^3$$$). The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$-100 \le a_i \le 100$$$) — elements of the array .

For each test case, output the minimum number of steps required to make both sum and product of all elements in the array different from zero.

NoteIn the first test case, the sum is $$$0$$$. If we add $$$1$$$ to the first element, the array will be $$$[3,-1,-1]$$$, the sum will be equal to $$$1$$$ and the product will be equal to $$$3$$$.In the second test case, both product and sum are $$$0$$$. If we add $$$1$$$ to the second and the third element, the array will be $$$[-1,1,1,1]$$$, the sum will be equal to $$$2$$$ and the product will be equal to $$$-1$$$. It can be shown that fewer steps can't be enough.In the third test case, both sum and product are non-zero, we don't need to do anything.In the fourth test case, after adding $$$1$$$ twice to the first element the array will be $$$[2,-2,1]$$$, the sum will be $$$1$$$ and the product will be $$$-4$$$.


Reminder: the median of the array $$$[a_1, a_2, \dots, a_{2k+1}]$$$ of odd number of elements is defined as follows: let $$$[b_1, b_2, \dots, b_{2k+1}]$$$ be the elements of the array in the sorted order. Then median of this array is equal to $$$b_{k+1}$$$.There are $$$2n$$$ students, the $$$i$$$-th student has skill level $$$a_i$$$. It's not guaranteed that all skill levels are distinct.Let's define skill level of a class as the median of skill levels of students of the class.As a principal of the school, you would like to assign each student to one of the $$$2$$$ classes such that each class has odd number of students (not divisible by $$$2$$$). The number of students in the classes may be equal or different, by your choice. Every student has to be assigned to exactly one class. Among such partitions, you want to choose one in which the absolute difference between skill levels of the classes is minimized.What is the minimum possible absolute difference you can achieve?

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of students halved. The second line of each test case contains $$$2n$$$ integers $$$a_1, a_2, \dots, a_{2 n}$$$ ($$$1 \le a_i \le 10^9$$$) — skill levels of students. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For each test case, output a single integer, the minimum possible absolute difference between skill levels of two classes of odd sizes.

NoteIn the first test, there is only one way to partition students — one in each class. The absolute difference of the skill levels will be $$$|1 - 1| = 0$$$.In the second test, one of the possible partitions is to make the first class of students with skill levels $$$[6, 4, 2]$$$, so that the skill level of the first class will be $$$4$$$, and second with $$$[5, 1, 3]$$$, so that the skill level of the second class will be $$$3$$$. Absolute difference will be $$$|4 - 3| = 1$$$.Note that you can't assign like $$$[2, 3]$$$, $$$[6, 5, 4, 1]$$$ or $$$[]$$$, $$$[6, 5, 4, 1, 2, 3]$$$ because classes have even number of students.$$$[2]$$$, $$$[1, 3, 4]$$$ is also not possible because students with skills $$$5$$$ and $$$6$$$ aren't assigned to a class.In the third test you can assign the students in the following way: $$$[3, 4, 13, 13, 20], [2, 5, 8, 16, 17]$$$ or $$$[3, 8, 17], [2, 4, 5, 13, 13, 16, 20]$$$. Both divisions give minimal possible absolute difference.


You are given three strings $$$a$$$, $$$b$$$ and $$$c$$$ of the same length $$$n$$$. The strings consist of lowercase English letters only. The $$$i$$$-th letter of $$$a$$$ is $$$a_i$$$, the $$$i$$$-th letter of $$$b$$$ is $$$b_i$$$, the $$$i$$$-th letter of $$$c$$$ is $$$c_i$$$.For every $$$i$$$ ($$$1 \leq i \leq n$$$) you must swap (i.e. exchange) $$$c_i$$$ with either $$$a_i$$$ or $$$b_i$$$. So in total you'll perform exactly $$$n$$$ swap operations, each of them either $$$c_i \leftrightarrow a_i$$$ or $$$c_i \leftrightarrow b_i$$$ ($$$i$$$ iterates over all integers between $$$1$$$ and $$$n$$$, inclusive).For example, if $$$a$$$ is "code", $$$b$$$ is "true", and $$$c$$$ is "help", you can make $$$c$$$ equal to "crue" taking the $$$1$$$-st and the $$$4$$$-th letters from $$$a$$$ and the others from $$$b$$$. In this way $$$a$$$ becomes "hodp" and $$$b$$$ becomes "tele".Is it possible that after these swaps the string $$$a$$$ becomes exactly the same as the string $$$b$$$?

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains a string of lowercase English letters $$$a$$$. The second line of each test case contains a string of lowercase English letters $$$b$$$. The third line of each test case contains a string of lowercase English letters $$$c$$$. It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding $$$100$$$.

Print $$$t$$$ lines with answers for all test cases. For each test case: If it is possible to make string $$$a$$$ equal to string $$$b$$$ print "YES" (without quotes), otherwise print "NO" (without quotes). You can print either lowercase or uppercase letters in the answers.

NoteIn the first test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.In the second test case, you should swap $$$c_i$$$ with $$$a_i$$$ for all possible $$$i$$$. After the swaps $$$a$$$ becomes "bca", $$$b$$$ becomes "bca" and $$$c$$$ becomes "abc". Here the strings $$$a$$$ and $$$b$$$ are equal.In the third test case, you should swap $$$c_1$$$ with $$$a_1$$$, $$$c_2$$$ with $$$b_2$$$, $$$c_3$$$ with $$$b_3$$$ and $$$c_4$$$ with $$$a_4$$$. Then string $$$a$$$ becomes "baba", string $$$b$$$ becomes "baba" and string $$$c$$$ becomes "abab". Here the strings $$$a$$$ and $$$b$$$ are equal.In the fourth test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.

4
aaa
bbb
ccc
abc
bca
bca
aabb
bbaa
baba
imi
mii
iim


Warawreh created a great company called Nanosoft. The only thing that Warawreh still has to do is to place a large picture containing its logo on top of the company's building.The logo of Nanosoft can be described as four squares of the same size merged together into one large square. The top left square is colored with red, the top right square is colored with green, the bottom left square is colored with yellow and the bottom right square is colored with blue.An Example of some correct logos:An Example of some incorrect logos:Warawreh went to Adhami's store in order to buy the needed picture. Although Adhami's store is very large he has only one picture that can be described as a grid of $$$n$$$ rows and $$$m$$$ columns. The color of every cell in the picture will be green (the symbol 'G'), red (the symbol 'R'), yellow (the symbol 'Y') or blue (the symbol 'B').Adhami gave Warawreh $$$q$$$ options, in every option he gave him a sub-rectangle from that picture and told him that he can cut that sub-rectangle for him. To choose the best option, Warawreh needs to know for every option the maximum area of sub-square inside the given sub-rectangle that can be a Nanosoft logo. If there are no such sub-squares, the answer is $$$0$$$.Warawreh couldn't find the best option himself so he asked you for help, can you help him?

The first line of input contains three integers $$$n$$$, $$$m$$$ and $$$q$$$ $$$(1 \leq n , m \leq 500, 1 \leq q \leq 3 \cdot 10^{5})$$$  — the number of row, the number columns and the number of options. For the next $$$n$$$ lines, every line will contain $$$m$$$ characters. In the $$$i$$$-th line the $$$j$$$-th character will contain the color of the cell at the $$$i$$$-th row and $$$j$$$-th column of the Adhami's picture. The color of every cell will be one of these: {'G','Y','R','B'}. For the next $$$q$$$ lines, the input will contain four integers $$$r_1$$$, $$$c_1$$$, $$$r_2$$$ and $$$c_2$$$ $$$(1 \leq r_1 \leq r_2 \leq n, 1 \leq c_1 \leq c_2 \leq m)$$$. In that option, Adhami gave to Warawreh a sub-rectangle of the picture with the upper-left corner in the cell $$$(r_1, c_1)$$$ and with the bottom-right corner in the cell $$$(r_2, c_2)$$$.

For every option print the maximum area of sub-square inside the given sub-rectangle, which can be a NanoSoft Logo. If there are no such sub-squares, print $$$0$$$.

NotePicture for the first test:The pictures from the left to the right corresponds to the options. The border of the sub-rectangle in the option is marked with black, the border of the sub-square with the maximal possible size, that can be cut is marked with gray.

5 5 5
RRGGB
RRGGY
YYBBG
YYBBR
RBBRG
1 1 5 5
2 2 5 5
2 2 3 3
1 1 3 5
4 4 5 5

6 10 5
RRRGGGRRGG
RRRGGGRRGG
RRRGGGYYBB
YYYBBBYYBB
YYYBBBRGRG
YYYBBBYBYB
1 1 6 10
1 3 3 10
2 2 6 6
1 7 6 10
2 1 5 10

8 8 8
RRRRGGGG
RRRRGGGG
RRRRGGGG
RRRRGGGG
YYYYBBBB
YYYYBBBB
YYYYBBBB
YYYYBBBB
1 1 8 8
5 2 5 7
3 1 8 6
2 3 5 8
1 2 6 8
2 1 5 5
2 1 7 7
6 5 7 5


Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $$$a$$$ of $$$n$$$ non-negative integers.Dark created that array $$$1000$$$ years ago, so some elements in that array disappeared. Dark knows that Motarack hates to see an array that has two adjacent elements with a high absolute difference between them. He doesn't have much time so he wants to choose an integer $$$k$$$ ($$$0 \leq k \leq 10^{9}$$$) and replaces all missing elements in the array $$$a$$$ with $$$k$$$.Let $$$m$$$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $$$|a_i - a_{i+1}|$$$ for all $$$1 \leq i \leq n - 1$$$) in the array $$$a$$$ after Dark replaces all missing elements with $$$k$$$.Dark should choose an integer $$$k$$$ so that $$$m$$$ is minimized. Can you help him?

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^{5}$$$) — the size of the array $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-1 \leq a_i \leq 10 ^ {9}$$$). If $$$a_i = -1$$$, then the $$$i$$$-th integer is missing. It is guaranteed that at least one integer is missing in every test case. It is guaranteed, that the sum of $$$n$$$ for all test cases does not exceed $$$4 \cdot 10 ^ {5}$$$.

Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $$$m$$$ and an integer $$$k$$$ ($$$0 \leq k \leq 10^{9}$$$) that makes the maximum absolute difference between adjacent elements in the array $$$a$$$ equal to $$$m$$$. Make sure that after replacing all the missing elements with $$$k$$$, the maximum absolute difference between adjacent elements becomes $$$m$$$. If there is more than one possible $$$k$$$, you can print any of them.

NoteIn the first test case after replacing all missing elements with $$$11$$$ the array becomes $$$[11, 10, 11, 12, 11]$$$. The absolute difference between any adjacent elements is $$$1$$$. It is impossible to choose a value of $$$k$$$, such that the absolute difference between any adjacent element will be $$$\leq 0$$$. So, the answer is $$$1$$$.In the third test case after replacing all missing elements with $$$6$$$ the array becomes $$$[6, 6, 9, 6, 3, 6]$$$.  $$$|a_1 - a_2| = |6 - 6| = 0$$$;  $$$|a_2 - a_3| = |6 - 9| = 3$$$;  $$$|a_3 - a_4| = |9 - 6| = 3$$$;  $$$|a_4 - a_5| = |6 - 3| = 3$$$;  $$$|a_5 - a_6| = |3 - 6| = 3$$$. So, the maximum difference between any adjacent elements is $$$3$$$.


Ayoub thinks that he is a very smart person, so he created a function $$$f(s)$$$, where $$$s$$$ is a binary string (a string which contains only symbols "0" and "1"). The function $$$f(s)$$$ is equal to the number of substrings in the string $$$s$$$ that contains at least one symbol, that is equal to "1".More formally, $$$f(s)$$$ is equal to the number of pairs of integers $$$(l, r)$$$, such that $$$1 \leq l \leq r \leq |s|$$$ (where $$$|s|$$$ is equal to the length of string $$$s$$$), such that at least one of the symbols $$$s_l, s_{l+1}, \ldots, s_r$$$ is equal to "1". For example, if $$$s = $$$"01010" then $$$f(s) = 12$$$, because there are $$$12$$$ such pairs $$$(l, r)$$$: $$$(1, 2), (1, 3), (1, 4), (1, 5), (2, 2), (2, 3), (2, 4), (2, 5), (3, 4), (3, 5), (4, 4), (4, 5)$$$.Ayoub also thinks that he is smarter than Mahmoud so he gave him two integers $$$n$$$ and $$$m$$$ and asked him this problem. For all binary strings $$$s$$$ of length $$$n$$$ which contains exactly $$$m$$$ symbols equal to "1", find the maximum value of $$$f(s)$$$.Mahmoud couldn't solve the problem so he asked you for help. Can you help him?

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^5$$$)  — the number of test cases. The description of the test cases follows. The only line for each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n \leq 10^{9}$$$, $$$0 \leq m \leq n$$$) — the length of the string and the number of symbols equal to "1" in it.

For every test case print one integer number — the maximum value of $$$f(s)$$$ over all strings $$$s$$$ of length $$$n$$$, which has exactly $$$m$$$ symbols, equal to "1".

NoteIn the first test case, there exists only $$$3$$$ strings of length $$$3$$$, which has exactly $$$1$$$ symbol, equal to "1". These strings are: $$$s_1 = $$$"100", $$$s_2 = $$$"010", $$$s_3 = $$$"001". The values of $$$f$$$ for them are: $$$f(s_1) = 3, f(s_2) = 4, f(s_3) = 3$$$, so the maximum value is $$$4$$$ and the answer is $$$4$$$.In the second test case, the string $$$s$$$ with the maximum value is "101".In the third test case, the string $$$s$$$ with the maximum value is "111".In the fourth test case, the only string $$$s$$$ of length $$$4$$$, which has exactly $$$0$$$ symbols, equal to "1" is "0000" and the value of $$$f$$$ for that string is $$$0$$$, so the answer is $$$0$$$.In the fifth test case, the string $$$s$$$ with the maximum value is "01010" and it is described as an example in the problem statement.


Jaber is a superhero in a large country that can be described as a grid with $$$n$$$ rows and $$$m$$$ columns, where every cell in that grid contains a different city.Jaber gave every city in that country a specific color between $$$1$$$ and $$$k$$$. In one second he can go from the current city to any of the cities adjacent by the side or to any city with the same color as the current city color.Jaber has to do $$$q$$$ missions. In every mission he will be in the city at row $$$r_1$$$ and column $$$c_1$$$, and he should help someone in the city at row $$$r_2$$$ and column $$$c_2$$$.Jaber wants your help to tell him the minimum possible time to go from the starting city to the finishing city for every mission.

The first line contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$1 \leq n, m \leq 1000$$$, $$$1 \leq k \leq min(40 , n \cdot m)$$$) — the number of rows, columns and colors. Each of the next $$$n$$$ lines contains $$$m$$$ integers. In the $$$i$$$-th line, the $$$j$$$-th integer is $$$a_{ij}$$$ ($$$1 \leq a_{ij} \leq k$$$), which is the color assigned to the city in the $$$i$$$-th row and $$$j$$$-th column. The next line contains one integer $$$q$$$ ($$$1 \leq q \leq 10^{5}$$$)  — the number of missions. For the next $$$q$$$ lines, every line contains four integers $$$r_1$$$, $$$c_1$$$, $$$r_2$$$, $$$c_2$$$ ($$$1 \leq r_1 , r_2 \leq n$$$, $$$1 \leq c_1 , c_2 \leq m$$$)  — the coordinates of the starting and the finishing cities of the corresponding mission. It is guaranteed that for every color between $$$1$$$ and $$$k$$$ there is at least one city of that color.

For every mission print the minimum possible time to reach city at the cell $$$(r_2, c_2)$$$ starting from city at the cell $$$(r_1, c_1)$$$.

NoteIn the first example:  mission $$$1$$$: Jaber should go from the cell $$$(1,1)$$$ to the cell $$$(3,3)$$$ because they have the same colors, then from the cell $$$(3,3)$$$ to the cell $$$(3,4)$$$ because they are adjacent by side (two moves in total);  mission $$$2$$$: Jaber already starts in the finishing cell. In the second example:  mission $$$1$$$: $$$(1,1)$$$ $$$\rightarrow$$$ $$$(1,2)$$$ $$$\rightarrow$$$ $$$(2,2)$$$;  mission $$$2$$$: $$$(1,1)$$$ $$$\rightarrow$$$ $$$(3,2)$$$ $$$\rightarrow$$$ $$$(3,3)$$$ $$$\rightarrow$$$ $$$(3,4)$$$;  mission $$$3$$$: $$$(1,1)$$$ $$$\rightarrow$$$ $$$(3,2)$$$ $$$\rightarrow$$$ $$$(3,3)$$$ $$$\rightarrow$$$ $$$(2,4)$$$;  mission $$$4$$$: $$$(1,1)$$$ $$$\rightarrow$$$ $$$(1,2)$$$ $$$\rightarrow$$$ $$$(1,3)$$$ $$$\rightarrow$$$ $$$(1,4)$$$ $$$\rightarrow$$$ $$$(4,4)$$$.


Bashar was practicing for the national programming contest. Because of sitting too much in front of the computer without doing physical movements and eating a lot Bashar became much fatter. Bashar is going to quit programming after the national contest and he is going to become an actor (just like his father), so he should lose weight.In order to lose weight, Bashar is going to run for $$$k$$$ kilometers. Bashar is going to run in a place that looks like a grid of $$$n$$$ rows and $$$m$$$ columns. In this grid there are two one-way roads of one-kilometer length between each pair of adjacent by side cells, one road is going from the first cell to the second one, and the other road is going from the second cell to the first one. So, there are exactly $$$(4 n m - 2n - 2m)$$$ roads.Let's take, for example, $$$n = 3$$$ and $$$m = 4$$$. In this case, there are $$$34$$$ roads. It is the picture of this case (arrows describe roads):Bashar wants to run by these rules:  He starts at the top-left cell in the grid;  In one move Bashar may go up (the symbol 'U'), down (the symbol 'D'), left (the symbol 'L') or right (the symbol 'R'). More formally, if he stands in the cell in the row $$$i$$$ and in the column $$$j$$$, i.e. in the cell $$$(i, j)$$$ he will move to:   in the case 'U' to the cell $$$(i-1, j)$$$;  in the case 'D' to the cell $$$(i+1, j)$$$;  in the case 'L' to the cell $$$(i, j-1)$$$;  in the case 'R' to the cell $$$(i, j+1)$$$;   He wants to run exactly $$$k$$$ kilometers, so he wants to make exactly $$$k$$$ moves;  Bashar can finish in any cell of the grid;  He can't go out of the grid so at any moment of the time he should be on some cell;  Bashar doesn't want to get bored while running so he must not visit the same road twice. But he can visit the same cell any number of times. Bashar asks you if it is possible to run by such rules. If it is possible, you should tell him how should he run.You should give him $$$a$$$ steps to do and since Bashar can't remember too many steps, $$$a$$$ should not exceed $$$3000$$$. In every step, you should give him an integer $$$f$$$ and a string of moves $$$s$$$ of length at most $$$4$$$ which means that he should repeat the moves in the string $$$s$$$ for $$$f$$$ times. He will perform the steps in the order you print them.For example, if the steps are $$$2$$$ RUD, $$$3$$$ UUL then the moves he is going to move are RUD $$$+$$$ RUD $$$+$$$ UUL $$$+$$$ UUL $$$+$$$ UUL $$$=$$$ RUDRUDUULUULUUL.Can you help him and give him a correct sequence of moves such that the total distance he will run is equal to $$$k$$$ kilometers or say, that it is impossible?

The only line contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$1 \leq n, m \leq 500$$$, $$$1 \leq k \leq 10 ^{9}$$$), which are the number of rows and the number of columns in the grid and the total distance Bashar wants to run.

If there is no possible way to run $$$k$$$ kilometers, print "NO" (without quotes), otherwise print "YES" (without quotes) in the first line. If the answer is "YES", on the second line print an integer $$$a$$$ ($$$1 \leq a \leq 3000$$$) — the number of steps, then print $$$a$$$ lines describing the steps. To describe a step, print an integer $$$f$$$ ($$$1 \leq f \leq 10^{9}$$$) and a string of moves $$$s$$$ of length at most $$$4$$$. Every character in $$$s$$$ should be 'U', 'D', 'L' or 'R'. Bashar will start from the top-left cell. Make sure to move exactly $$$k$$$ moves without visiting the same road twice and without going outside the grid. He can finish at any cell. We can show that if it is possible to run exactly $$$k$$$ kilometers, then it is possible to describe the path under such output constraints.

NoteThe moves Bashar is going to move in the first example are: "RRLL".It is not possible to run $$$1000000000$$$ kilometers in the second example because the total length of the roads is smaller and Bashar can't run the same road twice.The moves Bashar is going to move in the third example are: "RRDDLLRR".The moves Bashar is going to move in the fifth example are: "RRRLLLDRRRDULLLD". It is the picture of his run (the roads on this way are marked with red and numbered in the order of his running):


You are given a string $$$s$$$. Each character is either 0 or 1.You want all 1's in the string to form a contiguous subsegment. For example, if the string is 0, 1, 00111 or 01111100, then all 1's form a contiguous subsegment, and if the string is 0101, 100001 or 11111111111101, then this condition is not met.You may erase some (possibly none) 0's from the string. What is the minimum number of 0's that you have to erase?

The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ lines follow, each representing a test case. Each line contains one string $$$s$$$ ($$$1 \le |s| \le 100$$$); each character of $$$s$$$ is either 0 or 1.

Print $$$t$$$ integers, where the $$$i$$$-th integer is the answer to the $$$i$$$-th testcase (the minimum number of 0's that you have to erase from $$$s$$$).

NoteIn the first test case you have to delete the third and forth symbols from string 010011 (it turns into 0111).


Your company was appointed to lay new asphalt on the highway of length $$$n$$$. You know that every day you can either repair one unit of the highway (lay new asphalt over one unit of the highway) or skip repairing.Skipping the repair is necessary because of the climate. The climate in your region is periodical: there are $$$g$$$ days when the weather is good and if you lay new asphalt these days it becomes high-quality pavement; after that, the weather during the next $$$b$$$ days is bad, and if you lay new asphalt these days it becomes low-quality pavement; again $$$g$$$ good days, $$$b$$$ bad days and so on.You can be sure that you start repairing at the start of a good season, in other words, days $$$1, 2, \dots, g$$$ are good.You don't really care about the quality of the highway, you just want to make sure that at least half of the highway will have high-quality pavement. For example, if the $$$n = 5$$$ then at least $$$3$$$ units of the highway should have high quality; if $$$n = 4$$$ then at least $$$2$$$ units should have high quality.What is the minimum number of days is needed to finish the repair of the whole highway?

The first line contains a single integer $$$T$$$ ($$$1 \le T \le 10^4$$$) — the number of test cases. Next $$$T$$$ lines contain test cases — one per line. Each line contains three integers $$$n$$$, $$$g$$$ and $$$b$$$ ($$$1 \le n, g, b \le 10^9$$$) — the length of the highway and the number of good and bad days respectively.

Print $$$T$$$ integers — one per test case. For each test case, print the minimum number of days required to repair the whole highway if at least half of it should have high quality.

NoteIn the first test case, you can just lay new asphalt each day, since days $$$1, 3, 5$$$ are good.In the second test case, you can also lay new asphalt each day, since days $$$1$$$-$$$8$$$ are good.


Polycarp wants to assemble his own keyboard. Layouts with multiple rows are too complicated for him — his keyboard will consist of only one row, where all $$$26$$$ lowercase Latin letters will be arranged in some order.Polycarp uses the same password $$$s$$$ on all websites where he is registered (it is bad, but he doesn't care). He wants to assemble a keyboard that will allow to type this password very easily. He doesn't like to move his fingers while typing the password, so, for each pair of adjacent characters in $$$s$$$, they should be adjacent on the keyboard. For example, if the password is abacaba, then the layout cabdefghi... is perfect, since characters a and c are adjacent on the keyboard, and a and b are adjacent on the keyboard. It is guaranteed that there are no two adjacent equal characters in $$$s$$$, so, for example, the password cannot be password (two characters s are adjacent).Can you help Polycarp with choosing the perfect layout of the keyboard, if it is possible?

The first line contains one integer $$$T$$$ ($$$1 \le T \le 1000$$$) — the number of test cases. Then $$$T$$$ lines follow, each containing one string $$$s$$$ ($$$1 \le |s| \le 200$$$) representing the test case. $$$s$$$ consists of lowercase Latin letters only. There are no two adjacent equal characters in $$$s$$$.

For each test case, do the following:   if it is impossible to assemble a perfect keyboard, print NO (in upper case, it matters in this problem);  otherwise, print YES (in upper case), and then a string consisting of $$$26$$$ lowercase Latin letters — the perfect layout. Each Latin letter should appear in this string exactly once. If there are multiple answers, print any of them.

5
ababa
codedoca
abcda
zxzytyz
abcdefghijklmnopqrstuvwxyza

YES
bacdefghijklmnopqrstuvwxyz
YES
edocabfghijklmnpqrstuvwxyz
NO
YES
xzytabcdefghijklmnopqrsuvw
NO


You have a bag of size $$$n$$$. Also you have $$$m$$$ boxes. The size of $$$i$$$-th box is $$$a_i$$$, where each $$$a_i$$$ is an integer non-negative power of two.You can divide boxes into two parts of equal size. Your goal is to fill the bag completely.For example, if $$$n = 10$$$ and $$$a = [1, 1, 32]$$$ then you have to divide the box of size $$$32$$$ into two parts of size $$$16$$$, and then divide the box of size $$$16$$$. So you can fill the bag with boxes of size $$$1$$$, $$$1$$$ and $$$8$$$.Calculate the minimum number of divisions required to fill the bag of size $$$n$$$.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 10^{18}, 1 \le m \le 10^5$$$) — the size of bag and the number of boxes, respectively. The second line of each test case contains $$$m$$$ integers $$$a_1, a_2, \dots , a_m$$$ ($$$1 \le a_i \le 10^9$$$) — the sizes of boxes. It is guaranteed that each $$$a_i$$$ is a power of two. It is also guaranteed that sum of all $$$m$$$ over all test cases does not exceed $$$10^5$$$.

For each test case print one integer — the minimum number of divisions required to fill the bag of size $$$n$$$ (or $$$-1$$$, if it is impossible).


You are given a string $$$s$$$. You can build new string $$$p$$$ from $$$s$$$ using the following operation no more than two times:   choose any subsequence $$$s_{i_1}, s_{i_2}, \dots, s_{i_k}$$$ where $$$1 \le i_1 < i_2 < \dots < i_k \le |s|$$$;  erase the chosen subsequence from $$$s$$$ ($$$s$$$ can become empty);  concatenate chosen subsequence to the right of the string $$$p$$$ (in other words, $$$p = p + s_{i_1}s_{i_2}\dots s_{i_k}$$$). Of course, initially the string $$$p$$$ is empty. For example, let $$$s = \text{ababcd}$$$. At first, let's choose subsequence $$$s_1 s_4 s_5 = \text{abc}$$$ — we will get $$$s = \text{bad}$$$ and $$$p = \text{abc}$$$. At second, let's choose $$$s_1 s_2 = \text{ba}$$$ — we will get $$$s = \text{d}$$$ and $$$p = \text{abcba}$$$. So we can build $$$\text{abcba}$$$ from $$$\text{ababcd}$$$.Can you build a given string $$$t$$$ using the algorithm above?

The first line contains the single integer $$$T$$$ ($$$1 \le T \le 100$$$) — the number of test cases. Next $$$2T$$$ lines contain test cases — two per test case. The first line contains string $$$s$$$ consisting of lowercase Latin letters ($$$1 \le |s| \le 400$$$) — the initial string. The second line contains string $$$t$$$ consisting of lowercase Latin letters ($$$1 \le |t| \le |s|$$$) — the string you'd like to build. It's guaranteed that the total length of strings $$$s$$$ doesn't exceed $$$400$$$.

Print $$$T$$$ answers — one per test case. Print YES (case insensitive) if it's possible to build $$$t$$$ and NO (case insensitive) otherwise.


You are given a matrix $$$n \times m$$$, initially filled with zeroes. We define $$$a_{i, j}$$$ as the element in the $$$i$$$-th row and the $$$j$$$-th column of the matrix.Two cells of the matrix are connected if they share a side, and the elements in these cells are equal. Two cells of the matrix belong to the same connected component if there exists a sequence $$$s_1$$$, $$$s_2$$$, ..., $$$s_k$$$ such that $$$s_1$$$ is the first cell, $$$s_k$$$ is the second cell, and for every $$$i \in [1, k - 1]$$$, $$$s_i$$$ and $$$s_{i + 1}$$$ are connected.You are given $$$q$$$ queries of the form $$$x_i$$$ $$$y_i$$$ $$$c_i$$$ ($$$i \in [1, q]$$$). For every such query, you have to do the following:  replace the element $$$a_{x, y}$$$ with $$$c$$$;  count the number of connected components in the matrix. There is one additional constraint: for every $$$i \in [1, q - 1]$$$, $$$c_i \le c_{i + 1}$$$.

The first line contains three integers $$$n$$$, $$$m$$$ and $$$q$$$ ($$$1 \le n, m \le 300$$$, $$$1 \le q \le 2 \cdot 10^6$$$) — the number of rows, the number of columns and the number of queries, respectively. Then $$$q$$$ lines follow, each representing a query. The $$$i$$$-th line contains three integers $$$x_i$$$, $$$y_i$$$ and $$$c_i$$$ ($$$1 \le x_i \le n$$$, $$$1 \le y_i \le m$$$, $$$1 \le c_i \le \max(1000, \lceil \frac{2 \cdot 10^6}{nm} \rceil)$$$). For every $$$i \in [1, q - 1]$$$, $$$c_i \le c_{i + 1}$$$.

Print $$$q$$$ integers, the $$$i$$$-th of them should be equal to the number of components in the matrix after the first $$$i$$$ queries are performed.


Being tired of participating in too many Codeforces rounds, Gildong decided to take some rest in a park. He sat down on a bench, and soon he found two rabbits hopping around. One of the rabbits was taller than the other.He noticed that the two rabbits were hopping towards each other. The positions of the two rabbits can be represented as integer coordinates on a horizontal line. The taller rabbit is currently on position $$$x$$$, and the shorter rabbit is currently on position $$$y$$$ ($$$x \lt y$$$). Every second, each rabbit hops to another position. The taller rabbit hops to the positive direction by $$$a$$$, and the shorter rabbit hops to the negative direction by $$$b$$$.  For example, let's say $$$x=0$$$, $$$y=10$$$, $$$a=2$$$, and $$$b=3$$$. At the $$$1$$$-st second, each rabbit will be at position $$$2$$$ and $$$7$$$. At the $$$2$$$-nd second, both rabbits will be at position $$$4$$$.Gildong is now wondering: Will the two rabbits be at the same position at the same moment? If so, how long will it take? Let's find a moment in time (in seconds) after which the rabbits will be at the same point.

Each test contains one or more test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Each test case contains exactly one line. The line consists of four integers $$$x$$$, $$$y$$$, $$$a$$$, $$$b$$$ ($$$0 \le x \lt y \le 10^9$$$, $$$1 \le a,b \le 10^9$$$) — the current position of the taller rabbit, the current position of the shorter rabbit, the hopping distance of the taller rabbit, and the hopping distance of the shorter rabbit, respectively.

For each test case, print the single integer: number of seconds the two rabbits will take to be at the same position. If the two rabbits will never be at the same position simultaneously, print $$$-1$$$.

NoteThe first case is explained in the description.In the second case, each rabbit will be at position $$$3$$$ and $$$7$$$ respectively at the $$$1$$$-st second. But in the $$$2$$$-nd second they will be at $$$6$$$ and $$$4$$$ respectively, and we can see that they will never be at the same position since the distance between the two rabbits will only increase afterward.


Returning back to problem solving, Gildong is now studying about palindromes. He learned that a palindrome is a string that is the same as its reverse. For example, strings "pop", "noon", "x", and "kkkkkk" are palindromes, while strings "moon", "tv", and "abab" are not. An empty string is also a palindrome.Gildong loves this concept so much, so he wants to play with it. He has $$$n$$$ distinct strings of equal length $$$m$$$. He wants to discard some of the strings (possibly none or all) and reorder the remaining strings so that the concatenation becomes a palindrome. He also wants the palindrome to be as long as possible. Please help him find one.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 100$$$, $$$1 \le m \le 50$$$) — the number of strings and the length of each string. Next $$$n$$$ lines contain a string of length $$$m$$$ each, consisting of lowercase Latin letters only. All strings are distinct.

In the first line, print the length of the longest palindrome string you made. In the second line, print that palindrome. If there are multiple answers, print any one of them. If the palindrome is empty, print an empty line or don't print this line at all.

NoteIn the first example, "battab" is also a valid answer.In the second example, there can be 4 different valid answers including the sample output. We are not going to provide any hints for what the others are.In the third example, the empty string is the only valid palindrome string.

9 4
abab
baba
abcd
bcde
cdef
defg
wxyz
zyxw
ijji