Summer in Berland lasts $$$n$$$ days, the price of one portion of ice cream on the $$$i$$$-th day is $$$c_i$$$. Over the summer, Tanya wants to eat exactly $$$k$$$ portions of ice cream. At the same time, on the $$$i$$$-th day, she decided that she would eat at least $$$a_i$$$ portions, but not more than $$$b_i$$$ ($$$a_i \le b_i$$$) portions. In other words, let $$$d_i$$$ be equal to the number of portions that she eats on the $$$i$$$-th day. Then $$$d_1+d_2+\dots+d_n=k$$$ and $$$a_i \le d_i \le b_i$$$ for each $$$i$$$.Given that portions of ice cream can only be eaten on the day of purchase, find the minimum amount of money that Tanya can spend on ice cream in the summer.

The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 2\cdot10^5$$$, $$$0 \le k \le 10^9$$$) — the number of days and the total number of servings of ice cream that Tanya will eat in the summer. The following $$$n$$$ lines contain descriptions of the days, one description per line. Each description consists of three integers $$$a_i, b_i, c_i$$$ ($$$0 \le a_i \le b_i \le 10^9$$$, $$$1 \le c_i \le 10^6$$$).

Print the minimum amount of money that Tanya can spend on ice cream in the summer. If there is no way for Tanya to buy and satisfy all the requirements, then print -1.

NoteIn the first example, Tanya needs to eat $$$3$$$ portions of ice cream on the first day, $$$1$$$ portions of ice cream on the second day and $$$3$$$ portions of ice cream on the third day. In this case, the amount of money spent is $$$3\cdot6+1\cdot4+3\cdot3=31$$$. It can be shown that any other valid way to eat exactly $$$7$$$ portions of ice cream costs more.


The Golden Ring is the special tourist route in Berland. This route consists of $$$n$$$ cities and the cyclic railway route. Cities are numbered from $$$1$$$ to $$$n$$$ so that:  the next city for $$$1$$$ is the city $$$2$$$,  the next city for $$$2$$$ is the city $$$3$$$,  ...  the next city for $$$n$$$ is the city $$$1$$$. Thus, the route is a cycle, cities are numbered in the direction of travel (the route is directed in one way).Blogger Polycarp wants to start his journey in the city $$$1$$$. For each city he knows the value $$$a_i$$$ — how many selfies he wants to do in $$$i$$$-th city. He can take no more than one selfie in one visit to each city. Since he is traveling by train, he can't skip the city (he always moves from the city $$$i$$$ to the city $$$i+1$$$ for $$$1 \le i < n$$$ and from $$$n$$$ to $$$1$$$). Thus, when the train stops in the city, Polycarp must visit this city. If Polycarp visits the city multiple times, all visits are counted separately.What is the least number of city visits Polycarp will have to complete to fulfill his plan for the number of selfies for each city? Note that he always visits the city $$$1$$$, since it is this city that his journey begins in.

The first line contains an integer $$$n$$$ ($$$3 \le n \le 2\cdot10^5$$$) — the number of cities in the Golden Ring of Berland. The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 10^9$$$), where $$$a_i$$$ is equal to the required number of selfies in the $$$i$$$-th city. It is guaranteed that at least one of the numbers $$$a_i$$$ is strictly greater than zero.

Print a single integer — the required minimum number of visits.


Polycarp recently became an employee of the company "Double Permutation Inc." Now he is a fan of permutations and is looking for them everywhere!A permutation in this problem is a sequence of integers $$$p_1, p_2, \dots, p_k$$$ such that every integer from $$$1$$$ to $$$k$$$ occurs exactly once in it. For example, the following sequences are permutations of $$$[3, 1, 4, 2]$$$, $$$[1]$$$ and $$$[6, 1, 2, 3, 5, 4]$$$. The following sequences are not permutations: $$$[0, 1]$$$, $$$[1, 2, 2]$$$, $$$[1, 2, 4]$$$ and $$$[2, 3]$$$.In the lobby of the company's headquarter statistics on visits to the company's website for the last $$$n$$$ days are published — the sequence $$$a_1, a_2, \dots, a_n$$$. Polycarp wants to color all the elements of this sequence in one of three colors (red, green or blue) so that:  all red numbers, being written out of $$$a_1, a_2, \dots, a_n$$$ from left to right (that is, without changing their relative order), must form some permutation (let's call it $$$P$$$);  all green numbers, being written out of $$$a_1, a_2, \dots, a_n$$$ from left to right (that is, without changing their relative order), must form the same permutation $$$P$$$;  among blue numbers there should not be elements that are equal to some element of the permutation $$$P$$$. Help Polycarp to color all $$$n$$$ numbers so that the total number of red and green elements is maximum.

The first line contains an integer $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 2\cdot10^5$$$).

Print a string $$$s$$$ of length $$$n$$$ such that:   $$$s_i$$$='R', if the element $$$a_i$$$ must be colored in red;  $$$s_i$$$='G', if the element $$$a_i$$$ must be colored in green;  $$$s_i$$$='B', if the element $$$a_i$$$ must be colored in blue.  The string $$$s$$$ should maximize the total number of red and green elements when fulfilling the requirements from the main part of the problem statement. If there are several optimal answers, print any of them.


There are $$$n$$$ table bowling players, the rating of the $$$i$$$-th player equals $$$r_i$$$. Compose a maximum number of teams in a such way that:  each player belongs to at most one team;  each team contains exactly $$$a+b$$$ players;  each team contains a group of $$$a$$$ players with the same rating and a group of $$$b$$$ players with another same rating, which must be $$$k$$$ times larger than the rating of the players in the first group. For example, if $$$n=12$$$, $$$r=[1, 1, 2, 2, 2, 2, 2, 3, 3, 4, 6, 6]$$$, $$$a=1$$$, $$$b=2$$$, $$$k=2$$$, you can compose two teams with ratings $$$[1, 2, 2]$$$ and one team with ratings $$$[3, 6, 6]$$$. So, the maximum number of teams is $$$3$$$.Find the maximum number of teams by given $$$n, r_1 \dots r_n, a, b$$$ and $$$k$$$ to compose in respect to the given requirements.

The first line of the input contains four integers $$$n$$$, $$$a$$$, $$$b$$$ and $$$k$$$ ($$$1 \le n,a,b \le 3\cdot10^5$$$, $$$2 \le k \le 1000$$$). The second line contains the sequence of player's ratings — integers $$$r_1, r_2, \dots, r_n$$$ ($$$1 \le r_i \le 10^6$$$).

Print only one integer — the maximum number of teams that can be composed from $$$n$$$ given players.


Polycarp really likes writing the word "kotlin". He wrote this word several times in a row without spaces. For example, he could write the string like "kotlinkotlinkotlinkotlin".Polycarp sliced (cut) the written string into $$$n$$$ pieces and mixed them. As a result, he has $$$n$$$ strings $$$s_1, s_2, \dots, s_n$$$ and he can arrange them in the right order, concatenate (join) all of them and get a string like "kotlinkotlin...kotlin".Help Polycarp to find the right order of strings $$$s_1, s_2, \dots, s_n$$$, so that if he writes the strings in this order, he will get the word "kotlin" or the sequence of this word.Pay attention that you must use all given strings and you must use each string only once.

The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of Polycarp's strings. Next lines of the input contain $$$n$$$ Polycarp's strings. Total sum of their lengths doesn't exceed $$$3\cdot10^5$$$. It's guaranteed that there is the right order of arrangement the strings that if you concatenate them into one string, you will get some non-empty sequence of the word "kotlin".

Print $$$n$$$ different integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), where $$$p_i$$$ is an index of the string that should be the $$$i$$$-th in a required concatenation. In other words, the result of concatenation $$$s_{p_1}+s_{p_2}+\dots+s_{p_n}$$$ must be in the form "kotlinkotlin...kotlin". If there are many solutions, print any of them.


Konrad is a Human Relations consultant working for VoltModder, a large electrical equipment producer. Today, he has been tasked with evaluating the level of happiness in the company.There are $$$n$$$ people working for VoltModder, numbered from $$$1$$$ to $$$n$$$. Each employee earns a different amount of money in the company — initially, the $$$i$$$-th person earns $$$i$$$ rubles per day.On each of $$$q$$$ following days, the salaries will be revised. At the end of the $$$i$$$-th day, employee $$$v_i$$$ will start earning $$$n+i$$$ rubles per day and will become the best-paid person in the company. The employee will keep his new salary until it gets revised again.Some pairs of people don't like each other. This creates a great psychological danger in the company. Formally, if two people $$$a$$$ and $$$b$$$ dislike each other and $$$a$$$ earns more money than $$$b$$$, employee $$$a$$$ will brag about this to $$$b$$$. A dangerous triple is a triple of three employees $$$a$$$, $$$b$$$ and $$$c$$$, such that $$$a$$$ brags to $$$b$$$, who in turn brags to $$$c$$$. If $$$a$$$ dislikes $$$b$$$, then $$$b$$$ dislikes $$$a$$$.At the beginning of each day, Konrad needs to evaluate the number of dangerous triples in the company. Can you help him do it?

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 100\,000$$$, $$$0 \le m \le 100\,000$$$) — the number of employees in the company and the number of pairs of people who don't like each other. Each of the following $$$m$$$ lines contains two integers $$$a_i$$$, $$$b_i$$$ ($$$1 \le a_i, b_i \le n$$$, $$$a_i \neq b_i$$$) denoting that employees $$$a_i$$$ and $$$b_i$$$ hate each other (that is, $$$a_i$$$ dislikes $$$b_i$$$ and $$$b_i$$$ dislikes $$$a_i$$$). Each such relationship will be mentioned exactly once. The next line contains an integer $$$q$$$ ($$$0 \le q \le 100\,000$$$) — the number of salary revisions. The $$$i$$$-th of the following $$$q$$$ lines contains a single integer $$$v_i$$$ ($$$1 \le v_i \le n$$$) denoting that at the end of the $$$i$$$-th day, employee $$$v_i$$$ will earn the most.

Output $$$q + 1$$$ integers. The $$$i$$$-th of them should contain the number of dangerous triples in the company at the beginning of the $$$i$$$-th day.

NoteConsider the first sample test. The $$$i$$$-th row in the following image shows the structure of the company at the beginning of the $$$i$$$-th day. A directed edge from $$$a$$$ to $$$b$$$ denotes that employee $$$a$$$ brags to employee $$$b$$$. The dangerous triples are marked by highlighted edges.


Warning: This problem has an unusual memory limit!Bob decided that he will not waste his prime years implementing GUI forms for a large corporation and instead will earn his supper on the Stock Exchange Reykjavik. The Stock Exchange Reykjavik is the only actual stock exchange in the world. The only type of transaction is to take a single share of stock $$$x$$$ and exchange it for a single share of stock $$$y$$$, provided that the current price of share $$$x$$$ is at least the current price of share $$$y$$$. There are $$$2n$$$ stocks listed on the SER that are of interest to Bob, numbered from $$$1$$$ to $$$2n$$$. Bob owns a single share of stocks $$$1$$$ through $$$n$$$ and would like to own a single share of each of $$$n+1$$$ through $$$2n$$$ some time in the future.Bob managed to forecast the price of each stock — in time $$$t \geq 0$$$, the stock $$$i$$$ will cost $$$a_i \cdot \lfloor t \rfloor + b_i$$$. The time is currently $$$t = 0$$$. Help Bob find the earliest moment in time in which he can own a single share of each of $$$n+1$$$ through $$$2n$$$, and the minimum number of stock exchanges he has to perform in order to do that.You may assume that the Stock Exchange has an unlimited amount of each stock at any point in time.

The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 2200$$$) — the number stocks currently owned by Bob. Each of the next $$$2n$$$ lines contains integers $$$a_i$$$ and $$$b_i$$$ ($$$0 \leq a_i, b_i \leq 10^9$$$), representing the stock price of stock $$$i$$$.

If it is impossible for Bob to achieve his goal, output a single integer $$$-1$$$. Otherwise, output two integers $$$T$$$ and $$$E$$$, where $$$T$$$ is the minimum time in which he can achieve his goal, and $$$E$$$ is the minimum number of exchanges in which he can achieve his goal at time $$$T$$$.

NoteIn the first example, Bob simply waits until time $$$t = 3$$$, when both stocks cost exactly the same amount.In the second example, the optimum strategy is to exchange stock $$$2$$$ for stock $$$1$$$ at time $$$t = 1$$$, then exchange one share of stock $$$1$$$ for stock $$$3$$$ at time $$$t = 5$$$ (where both cost $$$15$$$) and then at time $$$t = 6$$$ exchange the second on for the stock number $$$4$$$ (when they cost $$$18$$$ and $$$17$$$, respectively). Note that he can achieve his goal also with only two exchanges, but this would take total time of $$$t = 9$$$, when he would finally be able to exchange the share number $$$2$$$ for the share number $$$3$$$. In the third example, Bob can never achieve his goal, as the second stock is always strictly more expensive than the first one.


Recently, on the course of algorithms and data structures, Valeriy learned how to use a deque. He built a deque filled with $$$n$$$ elements. The $$$i$$$-th element is $$$a_i$$$ ($$$i$$$ = $$$1, 2, \ldots, n$$$). He gradually takes the first two leftmost elements from the deque (let's call them $$$A$$$ and $$$B$$$, respectively), and then does the following: if $$$A > B$$$, he writes $$$A$$$ to the beginning and writes $$$B$$$ to the end of the deque, otherwise, he writes to the beginning $$$B$$$, and $$$A$$$ writes to the end of the deque. We call this sequence of actions an operation.For example, if deque was $$$[2, 3, 4, 5, 1]$$$, on the operation he will write $$$B=3$$$ to the beginning and $$$A=2$$$ to the end, so he will get $$$[3, 4, 5, 1, 2]$$$.The teacher of the course, seeing Valeriy, who was passionate about his work, approached him and gave him $$$q$$$ queries. Each query consists of the singular number $$$m_j$$$ $$$(j = 1, 2, \ldots, q)$$$. It is required for each query to answer which two elements he will pull out on the $$$m_j$$$-th operation.Note that the queries are independent and for each query the numbers $$$A$$$ and $$$B$$$ should be printed in the order in which they will be pulled out of the deque.Deque is a data structure representing a list of elements where insertion of new elements or deletion of existing elements can be made from both sides.

The first line contains two integers $$$n$$$ and $$$q$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq q \leq 3 \cdot 10^5$$$) — the number of elements in the deque and the number of queries. The second line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$, where $$$a_i$$$ $$$(0 \leq a_i \leq 10^9)$$$ — the deque element in $$$i$$$-th position. The next $$$q$$$ lines contain one number each, meaning $$$m_j$$$ ($$$1 \leq m_j \leq 10^{18}$$$).

For each teacher's query, output two numbers $$$A$$$ and $$$B$$$ — the numbers that Valeriy pulls out of the deque for the $$$m_j$$$-th operation.


This morning Tolik has understood that while he was sleeping he had invented an incredible problem which will be a perfect fit for Codeforces! But, as a "Discuss tasks" project hasn't been born yet (in English, well), he decides to test a problem and asks his uncle.After a long time thinking, Tolik's uncle hasn't any ideas on how to solve it. But, he doesn't want to tell Tolik about his inability to solve it, so he hasn't found anything better than asking you how to solve this task.In this task you are given a cell field $$$n \cdot m$$$, consisting of $$$n$$$ rows and $$$m$$$ columns, where point's coordinates $$$(x, y)$$$ mean it is situated in the $$$x$$$-th row and $$$y$$$-th column, considering numeration from one ($$$1 \leq x \leq n, 1 \leq y \leq m$$$). Initially, you stand in the cell $$$(1, 1)$$$. Every move you can jump from cell $$$(x, y)$$$, which you stand in, by any non-zero vector $$$(dx, dy)$$$, thus you will stand in the $$$(x+dx, y+dy)$$$ cell. Obviously, you can't leave the field, but also there is one more important condition — you're not allowed to use one vector twice. Your task is to visit each cell of the field exactly once (the initial cell is considered as already visited).Tolik's uncle is a very respectful person. Help him to solve this task!

The first and only line contains two positive integers $$$n, m$$$ ($$$1 \leq n \cdot m \leq 10^{6}$$$) — the number of rows and columns of the field respectively.

Print "-1" (without quotes) if it is impossible to visit every cell exactly once. Else print $$$n \cdot m$$$ pairs of integers, $$$i$$$-th from them should contain two integers $$$x_i, y_i$$$ ($$$1 \leq x_i \leq n, 1 \leq y_i \leq m$$$) — cells of the field in order of visiting, so that all of them are distinct and vectors of jumps between them are distinct too. Notice that the first cell should have $$$(1, 1)$$$ coordinates, according to the statement.

NoteThe vectors from the first example in the order of making jumps are $$$(0, 2), (0, -1), (1, 0), (0, 1), (0, -2)$$$.


Serge came to the school dining room and discovered that there is a big queue here. There are $$$m$$$ pupils in the queue. He's not sure now if he wants to wait until the queue will clear, so he wants to know which dish he will receive if he does. As Serge is very tired, he asks you to compute it instead of him.Initially there are $$$n$$$ dishes with costs $$$a_1, a_2, \ldots, a_n$$$. As you already know, there are the queue of $$$m$$$ pupils who have $$$b_1, \ldots, b_m$$$ togrogs respectively (pupils are enumerated by queue order, i.e the first pupil in the queue has $$$b_1$$$ togrogs and the last one has $$$b_m$$$ togrogs)Pupils think that the most expensive dish is the most delicious one, so every pupil just buys the most expensive dish for which he has money (every dish has a single copy, so when a pupil has bought it nobody can buy it later), and if a pupil doesn't have money for any dish, he just leaves the queue (so brutal capitalism...)But money isn't a problem at all for Serge, so Serge is buying the most expensive dish if there is at least one remaining.Moreover, Serge's school has a very unstable economic situation and the costs of some dishes or number of togrogs of some pupils can change. More formally, you must process $$$q$$$ queries:  change $$$a_i$$$ to $$$x$$$. It means that the price of the $$$i$$$-th dish becomes $$$x$$$ togrogs.  change $$$b_i$$$ to $$$x$$$. It means that the $$$i$$$-th pupil in the queue has $$$x$$$ togrogs now. Nobody leaves the queue during those queries because a saleswoman is late.After every query, you must tell Serge price of the dish which he will buy if he has waited until the queue is clear, or $$$-1$$$ if there are no dishes at this point, according to rules described above.

The first line contains integers $$$n$$$ and $$$m$$$ ($$$1 \leq n, m \leq 300\ 000$$$) — number of dishes and pupils respectively. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 10^{6}$$$) — elements of array $$$a$$$. The third line contains $$$m$$$ integers $$$b_1, b_2, \ldots, b_{m}$$$ ($$$1 \leq b_i \leq 10^{6}$$$) — elements of array $$$b$$$. The fourth line conatins integer $$$q$$$ ($$$1 \leq q \leq 300\ 000$$$) — number of queries. Each of the following $$$q$$$ lines contains as follows:    if a query changes price of some dish, it contains $$$1$$$, and two integers $$$i$$$ and $$$x$$$ ($$$1 \leq i \leq n$$$, $$$1 \leq x \leq 10^{6}$$$), what means $$$a_i$$$ becomes $$$x$$$.  if a query changes number of togrogs of some pupil, it contains $$$2$$$, and two integers $$$i$$$ and $$$x$$$ ($$$1 \leq i \leq m$$$, $$$1 \leq x \leq 10^{6}$$$), what means $$$b_i$$$ becomes $$$x$$$.

For each of $$$q$$$ queries prints the answer as the statement describes, the answer of the $$$i$$$-th query in the $$$i$$$-th line (the price of the dish which Serge will buy or $$$-1$$$ if nothing remains)

NoteIn the first sample after the first query, there is one dish with price $$$100$$$ togrogs and one pupil with one togrog, so Serge will buy the dish with price $$$100$$$ togrogs.In the second sample after the first query, there is one dish with price one togrog and one pupil with $$$100$$$ togrogs, so Serge will get nothing.In the third sample after the first query, nobody can buy the dish with price $$$8$$$, so Serge will take it. After the second query, all dishes will be bought, after the third one the third and fifth pupils will by the first and the second dishes respectively and nobody will by the fourth one.


While playing with geometric figures Alex has accidentally invented a concept of a $$$n$$$-th order rhombus in a cell grid.A $$$1$$$-st order rhombus is just a square $$$1 \times 1$$$ (i.e just a cell).A $$$n$$$-th order rhombus for all $$$n \geq 2$$$ one obtains from a $$$n-1$$$-th order rhombus adding all cells which have a common side with it to it (look at the picture to understand it better).    Alex asks you to compute the number of cells in a $$$n$$$-th order rhombus.

The first and only input line contains integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — order of a rhombus whose numbers of cells should be computed.

Print exactly one integer — the number of cells in a $$$n$$$-th order rhombus.

NoteImages of rhombus corresponding to the examples are given in the statement.


Nick had received an awesome array of integers $$$a=[a_1, a_2, \dots, a_n]$$$ as a gift for his $$$5$$$ birthday from his mother. He was already going to explore its various properties but after unpacking he was disappointed a lot because the product $$$a_1 \cdot a_2 \cdot \dots a_n$$$ of its elements seemed to him not large enough.He was ready to throw out the array, but his mother reassured him. She told him, that array would not be spoiled after the following operation: choose any index $$$i$$$ ($$$1 \le i \le n$$$) and do $$$a_i := -a_i - 1$$$.For example, he can change array $$$[3, -1, -4, 1]$$$ to an array $$$[-4, -1, 3, 1]$$$ after applying this operation to elements with indices $$$i=1$$$ and $$$i=3$$$. Kolya had immediately understood that sometimes it's possible to increase the product of integers of the array a lot. Now he has decided that he wants to get an array with the maximal possible product of integers using only this operation with its elements (possibly zero, one or more times, as many as he wants), it is not forbidden to do this operation several times for the same index. Help Kolya and print the array with the maximal possible product of elements $$$a_1 \cdot a_2 \cdot \dots a_n$$$ which can be received using only this operation in some order.If there are multiple answers, print any of them.

The first line contains integer $$$n$$$ ($$$1 \leq n \leq 10^{5}$$$) — number of integers in the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-10^{6} \leq a_i \leq 10^{6}$$$) — elements of the array

Print $$$n$$$ numbers — elements of the array with the maximal possible product of elements which can be received using only this operation in some order from the given array. If there are multiple answers, print any of them.


Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now.Sasha and Masha are about to buy some coconuts which are sold at price $$$z$$$ chizhiks per coconut. Sasha has $$$x$$$ chizhiks, Masha has $$$y$$$ chizhiks. Each girl will buy as many coconuts as she can using only her money. This way each girl will buy an integer non-negative number of coconuts.The girls discussed their plans and found that the total number of coconuts they buy can increase (or decrease) if one of them gives several chizhiks to the other girl. The chizhiks can't be split in parts, so the girls can only exchange with integer number of chizhiks.Consider the following example. Suppose Sasha has $$$5$$$ chizhiks, Masha has $$$4$$$ chizhiks, and the price for one coconut be $$$3$$$ chizhiks. If the girls don't exchange with chizhiks, they will buy $$$1 + 1 = 2$$$ coconuts. However, if, for example, Masha gives Sasha one chizhik, then Sasha will have $$$6$$$ chizhiks, Masha will have $$$3$$$ chizhiks, and the girls will buy $$$2 + 1 = 3$$$ coconuts. It is not that easy to live on the island now, so Sasha and Mash want to exchange with chizhiks in such a way that they will buy the maximum possible number of coconuts. Nobody wants to have a debt, so among all possible ways to buy the maximum possible number of coconuts find such a way that minimizes the number of chizhiks one girl gives to the other (it is not important who will be the person giving the chizhiks).

The first line contains three integers $$$x$$$, $$$y$$$ and $$$z$$$ ($$$0 \le x, y \le 10^{18}$$$, $$$1 \le z \le 10^{18}$$$) — the number of chizhics Sasha has, the number of chizhics Masha has and the price of a coconut.

Print two integers: the maximum possible number of coconuts the girls can buy and the minimum number of chizhiks one girl has to give to the other.

NoteThe first example is described in the statement. In the second example the optimal solution is to dot exchange any chizhiks. The girls will buy $$$3 + 4 = 7$$$ coconuts.


Dima worked all day and wrote down on a long paper strip his favorite number $$$n$$$ consisting of $$$l$$$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.

The first line contains a single integer $$$l$$$ ($$$2 \le l \le 100\,000$$$) — the length of the Dima's favorite number. The second line contains the positive integer $$$n$$$ initially written on the strip: the Dima's favorite number. The integer $$$n$$$ consists of exactly $$$l$$$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.

Print a single integer — the smallest number Dima can obtain.

NoteIn the first example Dima can split the number $$$1234567$$$ into integers $$$1234$$$ and $$$567$$$. Their sum is $$$1801$$$.In the second example Dima can split the number $$$101$$$ into integers $$$10$$$ and $$$1$$$. Their sum is $$$11$$$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.


Fedor runs for president of Byteland! In the debates, he will be asked how to solve Byteland's transport problem. It's a really hard problem because of Byteland's transport system is now a tree (connected graph without cycles). Fedor's team has found out in the ministry of transport of Byteland that there is money in the budget only for one additional road. In the debates, he is going to say that he will build this road as a way to maximize the number of distinct simple paths in the country. A simple path is a path which goes through every vertex no more than once. Two simple paths are named distinct if sets of their edges are distinct. But Byteland's science is deteriorated, so Fedor's team hasn't succeeded to find any scientists to answer how many distinct simple paths they can achieve after adding exactly one edge on the transport system?Help Fedor to solve it.An edge can be added between vertices that are already connected, but it can't be a loop.In this problem, we consider only simple paths of length at least two.

The first line contains one integer $$$n$$$ ($$$2 \leq n \leq 500\ 000$$$) — number of vertices in Byteland's transport system. Each of the following $$$n - 1$$$ lines contains two integers $$$v_i$$$ and $$$u_i$$$ ($$$1 \leq v_i, u_i \leq n$$$). It's guaranteed that the graph is tree.

Print exactly one integer — a maximal number of simple paths that can be achieved after adding one edge.


Misha was interested in water delivery from childhood. That's why his mother sent him to the annual Innovative Olympiad in Irrigation (IOI). Pupils from all Berland compete there demonstrating their skills in watering. It is extremely expensive to host such an olympiad, so after the first $$$n$$$ olympiads the organizers introduced the following rule of the host city selection.The host cities of the olympiads are selected in the following way. There are $$$m$$$ cities in Berland wishing to host the olympiad, they are numbered from $$$1$$$ to $$$m$$$. The host city of each next olympiad is determined as the city that hosted the olympiad the smallest number of times before. If there are several such cities, the city with the smallest index is selected among them.Misha's mother is interested where the olympiad will be held in some specific years. The only information she knows is the above selection rule and the host cities of the first $$$n$$$ olympiads. Help her and if you succeed, she will ask Misha to avoid flooding your house.

The first line contains three integers $$$n$$$, $$$m$$$ and $$$q$$$ ($$$1 \leq n, m, q \leq 500\,000$$$) — the number of olympiads before the rule was introduced, the number of cities in Berland wishing to host the olympiad, and the number of years Misha's mother is interested in, respectively. The next line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq m$$$), where $$$a_i$$$ denotes the city which hosted the olympiad in the $$$i$$$-th year. Note that before the rule was introduced the host city was chosen arbitrarily. Each of the next $$$q$$$ lines contains an integer $$$k_i$$$ ($$$n + 1 \leq k_i \leq 10^{18}$$$) — the year number Misha's mother is interested in host city in.

Print $$$q$$$ integers. The $$$i$$$-th of them should be the city the olympiad will be hosted in the year $$$k_i$$$.

NoteIn the first example Misha's mother is interested in the first $$$10$$$ years after the rule was introduced. The host cities these years are 4, 3, 4, 2, 3, 4, 1, 2, 3, 4.In the second example the host cities after the new city is introduced are 2, 3, 1, 2, 3, 5, 1, 2, 3, 4, 5, 1.


This problem differs from the previous problem only in constraints.Petya decided to visit Byteland during the summer holidays. It turned out that the history of this country is quite unusual.Initially, there were $$$n$$$ different countries on the land that is now Berland. Each country had its own territory that was represented as a rectangle on the map. The sides of the rectangle were parallel to the axes, and the corners were located at points with integer coordinates. Territories of no two countries intersected, but it was possible that some territories touched each other. As time passed, sometimes two countries merged into one. It only happened if the union of their territories was also a rectangle. In the end only one country remained — Byteland.Initially, each country had a rectangular castle inside its territory. Its sides were parallel to the axes and its corners had integer coordinates. Some castles might touch the border of the corresponding country and sides or other castles. Miraculously, after all the unions the castles are still intact. Unfortunately, their locations are the only information we have to restore the initial territories of the countries.  The possible formation of Byteland. The castles are shown in blue. Petya wonders why no information about the initial countries remained. He suspected that the whole story is a fake. You were recommended to him as a smart person. Please check whether or not there exists a possible set of initial territories that could make the story true.

The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 100\,000$$$) — the number of countries and castles. Each of the next $$$n$$$ lines contains four integers $$$a_i, b_i, c_i, d_i$$$ ($$$0 \leq a_i < c_i \leq 10^9$$$, $$$0 \leq b_i < d_i \leq 10^9$$$) — the coordinates of the $$$i$$$-th castle, where $$$(a_i, b_i)$$$ are the coordinates of the lower left corner and $$$(c_i, d_i)$$$ are the coordinates of the upper right corner. It is guaranteed that no two castles intersect, however, they may touch.

If there exists a possible set of territories that satisfies the story, print "YES", otherwise print "NO". You can print each letter in any case (upper or lower).

NoteThe castles in the first and second examples are shown on the pictures below.


This problem differs from the next problem only in constraints.Petya decided to visit Byteland during the summer holidays. It turned out that the history of this country is quite unusual.Initially, there were $$$n$$$ different countries on the land that is now Berland. Each country had its own territory that was represented as a rectangle on the map. The sides of the rectangle were parallel to the axes, and the corners were located at points with integer coordinates. Territories of no two countries intersected, but it was possible that some territories touched each other. As time passed, sometimes two countries merged into one. It only happened if the union of their territories was also a rectangle. In the end only one country remained — Byteland.Initially, each country had a rectangular castle inside its territory. Its sides were parallel to the axes and its corners had integer coordinates. Some castles might touch the border of the corresponding country and sides or other castles. Miraculously, after all the unions the castles are still intact. Unfortunately, their locations are the only information we have to restore the initial territories of the countries.  The possible formation of Byteland. The castles are shown in blue. Petya wonders why no information about the initial countries remained. He suspected that the whole story is a fake. You were recommended to him as a smart person. Please check whether or not there exists a possible set of initial territories that could make the story true.

The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of countries and castles. Each of the next $$$n$$$ lines contains four integers $$$a_i, b_i, c_i, d_i$$$ ($$$0 \leq a_i < c_i \leq 10^9$$$, $$$0 \leq b_i < d_i \leq 10^9$$$) — the coordinates of the $$$i$$$-th castle, where $$$(a_i, b_i)$$$ are the coordinates of the lower left corner and $$$(c_i, d_i)$$$ are the coordinates of the upper right corner. It is guaranteed, that no two castles intersect, however, they may touch.


You have a given picture with size $$$w \times h$$$. Determine if the given picture has a single "+" shape or not. A "+" shape is described below:  A "+" shape has one center nonempty cell.  There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction.  All other cells are empty. Find out if the given picture has single "+" shape.

The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h$$$, $$$w \le 500$$$) — the height and width of the picture. The $$$i$$$-th of the next $$$h$$$ lines contains string $$$s_{i}$$$ of length $$$w$$$ consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space.

If the given picture satisfies all conditions, print "YES". Otherwise, print "NO". You can output each letter in any case (upper or lower).

NoteIn the first example, the given picture contains one "+".In the second example, two vertical branches are located in a different column.In the third example, there is a dot outside of the shape.In the fourth example, the width of the two vertical branches is $$$2$$$.In the fifth example, there are two shapes.In the sixth example, there is an empty space inside of the shape.


We call a function good if its domain of definition is some set of integers and if in case it's defined in $$$x$$$ and $$$x-1$$$, $$$f(x) = f(x-1) + 1$$$ or $$$f(x) = f(x-1)$$$.Tanya has found $$$n$$$ good functions $$$f_{1}, \ldots, f_{n}$$$, which are defined on all integers from $$$0$$$ to $$$10^{18}$$$ and $$$f_i(0) = 0$$$ and $$$f_i(10^{18}) = L$$$ for all $$$i$$$ from $$$1$$$ to $$$n$$$. It's an notorious coincidence that $$$n$$$ is a divisor of $$$L$$$. She suggests Alesya a game. Using one question Alesya can ask Tanya a value of any single function in any single point. To win Alesya must choose integers $$$l_{i}$$$ and $$$r_{i}$$$ ($$$0 \leq l_{i} \leq r_{i} \leq 10^{18}$$$), such that $$$f_{i}(r_{i}) - f_{i}(l_{i}) \geq \frac{L}{n}$$$ (here $$$f_i(x)$$$ means the value of $$$i$$$-th function at point $$$x$$$) for all $$$i$$$ such that $$$1 \leq i \leq n$$$ so that for any pair of two functions their segments $$$[l_i, r_i]$$$ don't intersect (but may have one common point).Unfortunately, Tanya doesn't allow to make more than $$$2 \cdot 10^{5}$$$ questions. Help Alesya to win!It can be proved that it's always possible to choose $$$[l_i, r_i]$$$ which satisfy the conditions described above.It's guaranteed, that Tanya doesn't change functions during the game, i.e. interactor is not adaptive

The first line contains two integers $$$n$$$ and $$$L$$$ ($$$1 \leq n \leq 1000$$$, $$$1 \leq L \leq 10^{18}$$$, $$$n$$$ is a divisor of $$$L$$$)  — number of functions and their value in $$$10^{18}$$$.

When you've found needed $$$l_i, r_i$$$, print $$$"!"$$$ without quotes on a separate line and then $$$n$$$ lines, $$$i$$$-th from them should contain two integers $$$l_i$$$, $$$r_i$$$ divided by space.

NoteIn the example Tanya has $$$5$$$ same functions where $$$f(0) = 0$$$, $$$f(1) = 1$$$, $$$f(2) = 2$$$, $$$f(3) = 3$$$, $$$f(4) = 4$$$ and all remaining points have value $$$5$$$.Alesya must choose two integers for all functions so that difference of values of a function in its points is not less than $$$\frac{L}{n}$$$ (what is $$$1$$$ here) and length of intersection of segments is zero.One possible way is to choose pairs $$$[0$$$, $$$1]$$$, $$$[1$$$, $$$2]$$$, $$$[2$$$, $$$3]$$$, $$$[3$$$, $$$4]$$$ and $$$[4$$$, $$$5]$$$ for functions $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$ and $$$5$$$ respectively.


You are given $$$n$$$ words, each of which consists of lowercase alphabet letters. Each word contains at least one vowel. You are going to choose some of the given words and make as many beautiful lyrics as possible.Each lyric consists of two lines. Each line consists of two words separated by whitespace. A lyric is beautiful if and only if it satisfies all conditions below.   The number of vowels in the first word of the first line is the same as the number of vowels in the first word of the second line.  The number of vowels in the second word of the first line is the same as the number of vowels in the second word of the second line.  The last vowel of the first line is the same as the last vowel of the second line. Note that there may be consonants after the vowel. Also, letters "a", "e", "o", "i", and "u" are vowels. Note that "y" is never vowel.For example of a beautiful lyric,  "hello hellooowww" "whatsup yowowowow"  is a beautiful lyric because there are two vowels each in "hello" and "whatsup", four vowels each in "hellooowww" and "yowowowow" (keep in mind that "y" is not a vowel), and the last vowel of each line is "o".For example of a not beautiful lyric,  "hey man""iam mcdic"  is not a beautiful lyric because "hey" and "iam" don't have same number of vowels and the last vowels of two lines are different ("a" in the first and "i" in the second).How many beautiful lyrics can you write from given words? Note that you cannot use a word more times than it is given to you. For example, if a word is given three times, you can use it at most three times.

The first line contains single integer $$$n$$$ ($$$1 \le n \le 10^{5}$$$) — the number of words. The $$$i$$$-th of the next $$$n$$$ lines contains string $$$s_{i}$$$ consisting lowercase alphabet letters — the $$$i$$$-th word. It is guaranteed that the sum of the total word length is equal or less than $$$10^{6}$$$. Each word contains at least one vowel.

In the first line, print $$$m$$$ — the number of maximum possible beautiful lyrics. In next $$$2m$$$ lines, print $$$m$$$ beautiful lyrics (two lines per lyric). If there are multiple answers, print any.

NoteIn the first example, those beautiful lyrics are one of the possible answers. Let's look at the first lyric on the sample output of the first example. "about proud hooray round" forms a beautiful lyric because "about" and "hooray" have same number of vowels, "proud" and "round" have same number of vowels, and both lines have same last vowel. On the other hand, you cannot form any beautiful lyric with the word "codeforces".In the second example, you cannot form any beautiful lyric from given words.In the third example, you can use the word "same" up to three times.

14
wow
this
is
the
first
mcdics
codeforces
round
hooray
i
am
proud
about
that

7
arsijo
suggested
the
idea
for
this
problem

3
about proud
hooray round
wow first
this is
i that
mcdics am


You have a given integer $$$n$$$. Find the number of ways to fill all $$$3 \times n$$$ tiles with the shape described in the picture below. Upon filling, no empty spaces are allowed. Shapes cannot overlap.  This picture describes when $$$n = 4$$$. The left one is the shape and the right one is $$$3 \times n$$$ tiles.

The only line contains one integer $$$n$$$ ($$$1 \le n \le 60$$$) — the length.

NoteIn the first example, there are $$$4$$$ possible cases of filling.In the second example, you cannot fill the shapes in $$$3 \times 1$$$ tiles.


You have given tree consist of $$$n$$$ vertices. Select a vertex as root vertex that satisfies the condition below.  For all vertices $$$v_{1}$$$ and $$$v_{2}$$$, if $$$distance$$$($$$root$$$, $$$v_{1}$$$) $$$= distance$$$($$$root$$$, $$$v_{2})$$$ then $$$degree$$$($$$v_{1}$$$) $$$= degree$$$($$$v_{2}$$$), where $$$degree$$$ means the number of vertices connected to that vertex, and $$$distance$$$ means the number of edges between two vertices. Determine and find if there is such root vertex in the tree. If there are multiple answers, find any of them.

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^{5}$$$) — the number of vertices. Each of the next $$$n-1$$$ lines contains two integers $$$v_{i}$$$ and $$$u_{i}$$$ ($$$1 \le v_{i} \lt u_{i} \le n$$$) — it means there is an edge exist between $$$v_{i}$$$ and $$$u_{i}$$$. It is guaranteed that the graph forms tree.

If there is such root vertex exists, print any of them. Otherwise, print $$$-1$$$.

NoteThis is the picture for the first example. $$$1$$$, $$$5$$$, $$$7$$$ also can be a valid answer.  This is the picture for the second example. You can see that it's impossible to find such root vertex.


Let $$$f_{x} = c^{2x-6} \cdot f_{x-1} \cdot f_{x-2} \cdot f_{x-3}$$$ for $$$x \ge 4$$$.You have given integers $$$n$$$, $$$f_{1}$$$, $$$f_{2}$$$, $$$f_{3}$$$, and $$$c$$$. Find $$$f_{n} \bmod (10^{9}+7)$$$.


Innokenty works at a flea market and sells some random stuff rare items. Recently he found an old rectangular blanket. It turned out that the blanket is split in $$$n \cdot m$$$ colored pieces that form a rectangle with $$$n$$$ rows and $$$m$$$ columns. The colored pieces attracted Innokenty's attention so he immediately came up with the following business plan. If he cuts out a subrectangle consisting of three colored stripes, he can sell it as a flag of some country. Innokenty decided that a subrectangle is similar enough to a flag of some country if it consists of three stripes of equal heights placed one above another, where each stripe consists of cells of equal color. Of course, the color of the top stripe must be different from the color of the middle stripe; and the color of the middle stripe must be different from the color of the bottom stripe.Innokenty has not yet decided what part he will cut out, but he is sure that the flag's boundaries should go along grid lines. Also, Innokenty won't rotate the blanket. Please help Innokenty and count the number of different subrectangles Innokenty can cut out and sell as a flag. Two subrectangles located in different places but forming the same flag are still considered different.   These subrectangles are flags.       These subrectangles are not flags.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1\,000$$$) — the number of rows and the number of columns on the blanket. Each of the next $$$n$$$ lines contains $$$m$$$ lowercase English letters from 'a' to 'z' and describes a row of the blanket. Equal letters correspond to equal colors, different letters correspond to different colors.

In the only line print the number of subrectangles which form valid flags.

Note  The selected subrectangles are flags in the first example.


Polycarp knows that if the sum of the digits of a number is divisible by $$$3$$$, then the number itself is divisible by $$$3$$$. He assumes that the numbers, the sum of the digits of which is divisible by $$$4$$$, are also somewhat interesting. Thus, he considers a positive integer $$$n$$$ interesting if its sum of digits is divisible by $$$4$$$.Help Polycarp find the nearest larger or equal interesting number for the given number $$$a$$$. That is, find the interesting number $$$n$$$ such that $$$n \ge a$$$ and $$$n$$$ is minimal.

The only line in the input contains an integer $$$a$$$ ($$$1 \le a \le 1000$$$).

Print the nearest greater or equal interesting number for the given number $$$a$$$. In other words, print the interesting number $$$n$$$ such that $$$n \ge a$$$ and $$$n$$$ is minimal.


Vova is playing a computer game. There are in total $$$n$$$ turns in the game and Vova really wants to play all of them. The initial charge of his laptop battery (i.e. the charge before the start of the game) is $$$k$$$.During each turn Vova can choose what to do:   If the current charge of his laptop battery is strictly greater than $$$a$$$, Vova can just play, and then the charge of his laptop battery will decrease by $$$a$$$;  if the current charge of his laptop battery is strictly greater than $$$b$$$ ($$$b<a$$$), Vova can play and charge his laptop, and then the charge of his laptop battery will decrease by $$$b$$$;  if the current charge of his laptop battery is less than or equal to $$$a$$$ and $$$b$$$ at the same time then Vova cannot do anything and loses the game. Regardless of Vova's turns the charge of the laptop battery is always decreases.Vova wants to complete the game (Vova can complete the game if after each of $$$n$$$ turns the charge of the laptop battery is strictly greater than $$$0$$$). Vova has to play exactly $$$n$$$ turns. Among all possible ways to complete the game, Vova wants to choose the one where the number of turns when he just plays (first type turn) is the maximum possible. It is possible that Vova cannot complete the game at all.Your task is to find out the maximum possible number of turns Vova can just play (make the first type turn) or report that Vova cannot complete the game.You have to answer $$$q$$$ independent queries.

The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 10^5$$$) — the number of queries. Each query is presented by a single line. The only line of the query contains four integers $$$k, n, a$$$ and $$$b$$$ ($$$1 \le k, n \le 10^9, 1 \le b < a \le 10^9$$$) — the initial charge of Vova's laptop battery, the number of turns in the game and values $$$a$$$ and $$$b$$$, correspondingly.

For each query print one integer: -1 if Vova cannot complete the game or the maximum number of turns Vova can just play (make the first type turn) otherwise.

NoteIn the first example query Vova can just play $$$4$$$ turns and spend $$$12$$$ units of charge and then one turn play and charge and spend $$$2$$$ more units. So the remaining charge of the battery will be $$$1$$$.In the second example query Vova cannot complete the game because even if he will play and charge the battery during each turn then the charge of the laptop battery will be $$$0$$$ after the last turn.


This problem is actually a subproblem of problem G from the same contest.There are $$$n$$$ candies in a candy box. The type of the $$$i$$$-th candy is $$$a_i$$$ ($$$1 \le a_i \le n$$$).You have to prepare a gift using some of these candies with the following restriction: the numbers of candies of each type presented in a gift should be all distinct (i. e. for example, a gift having two candies of type $$$1$$$ and two candies of type $$$2$$$ is bad). It is possible that multiple types of candies are completely absent from the gift. It is also possible that not all candies of some types will be taken to a gift.Your task is to find out the maximum possible size of the single gift you can prepare using the candies you have.You have to answer $$$q$$$ independent queries.If you are Python programmer, consider using PyPy instead of Python when you submit your code.

The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 2 \cdot 10^5$$$) — the number of queries. Each query is represented by two lines. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of candies. The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the type of the $$$i$$$-th candy in the box. It is guaranteed that the sum of $$$n$$$ over all queries does not exceed $$$2 \cdot 10^5$$$.

For each query print one integer — the maximum possible size of the single gift you can compose using candies you got in this query with the restriction described in the problem statement.

NoteIn the first query, you can prepare a gift with two candies of type $$$8$$$ and one candy of type $$$5$$$, totalling to $$$3$$$ candies.Note that this is not the only possible solution — taking two candies of type $$$4$$$ and one candy of type $$$6$$$ is also valid.


The only difference between the easy and the hard versions is constraints.A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between them. For example, for the string "abaca" the following strings are subsequences: "abaca", "aba", "aaa", "a" and "" (empty string). But the following strings are not subsequences: "aabaca", "cb" and "bcaa".You are given a string $$$s$$$ consisting of $$$n$$$ lowercase Latin letters.In one move you can take any subsequence $$$t$$$ of the given string and add it to the set $$$S$$$. The set $$$S$$$ can't contain duplicates. This move costs $$$n - |t|$$$, where $$$|t|$$$ is the length of the added subsequence (i.e. the price equals to the number of the deleted characters).Your task is to find out the minimum possible total cost to obtain a set $$$S$$$ of size $$$k$$$ or report that it is impossible to do so.

The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 100$$$) — the length of the string and the size of the set, correspondingly. The second line of the input contains a string $$$s$$$ consisting of $$$n$$$ lowercase Latin letters.

Print one integer — if it is impossible to obtain the set $$$S$$$ of size $$$k$$$, print -1. Otherwise, print the minimum possible total cost to do it.

NoteIn the first example we can generate $$$S$$$ = { "asdf", "asd", "adf", "asf", "sdf" }. The cost of the first element in $$$S$$$ is $$$0$$$ and the cost of the others is $$$1$$$. So the total cost of $$$S$$$ is $$$4$$$.


There are $$$n$$$ products in the shop. The price of the $$$i$$$-th product is $$$a_i$$$. The owner of the shop wants to equalize the prices of all products. However, he wants to change prices smoothly.In fact, the owner of the shop can change the price of some product $$$i$$$ in such a way that the difference between the old price of this product $$$a_i$$$ and the new price $$$b_i$$$ is at most $$$k$$$. In other words, the condition $$$|a_i - b_i| \le k$$$ should be satisfied ($$$|x|$$$ is the absolute value of $$$x$$$).He can change the price for each product not more than once. Note that he can leave the old prices for some products. The new price $$$b_i$$$ of each product $$$i$$$ should be positive (i.e. $$$b_i > 0$$$ should be satisfied for all $$$i$$$ from $$$1$$$ to $$$n$$$).Your task is to find out the maximum possible equal price $$$B$$$ of all productts with the restriction that for all products the condiion $$$|a_i - B| \le k$$$ should be satisfied (where $$$a_i$$$ is the old price of the product and $$$B$$$ is the same new price of all products) or report that it is impossible to find such price $$$B$$$.Note that the chosen price $$$B$$$ should be integer.You should answer $$$q$$$ independent queries.

The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 100$$$) — the number of queries. Each query is presented by two lines. The first line of the query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 100, 1 \le k \le 10^8$$$) — the number of products and the value $$$k$$$. The second line of the query contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^8$$$), where $$$a_i$$$ is the price of the $$$i$$$-th product.

Print $$$q$$$ integers, where the $$$i$$$-th integer is the answer $$$B$$$ on the $$$i$$$-th query. If it is impossible to equalize prices of all given products with restriction that for all products the condition $$$|a_i - B| \le k$$$ should be satisfied (where $$$a_i$$$ is the old price of the product and $$$B$$$ is the new equal price of all products), print -1. Otherwise print the maximum possible equal price of all products.

NoteIn the first example query you can choose the price $$$B=2$$$. It is easy to see that the difference between each old price and each new price $$$B=2$$$ is no more than $$$1$$$.In the second example query you can choose the price $$$B=6$$$ and then all the differences between old and new price $$$B=6$$$ will be no more than $$$2$$$.In the third example query you cannot choose any suitable price $$$B$$$. For any value $$$B$$$ at least one condition out of two will be violated: $$$|1-B| \le 2$$$, $$$|6-B| \le 2$$$.In the fourth example query all values $$$B$$$ between $$$1$$$ and $$$7$$$ are valid. But the maximum is $$$7$$$, so it's the answer.


You have given integers $$$a$$$, $$$b$$$, $$$p$$$, and $$$q$$$. Let $$$f(x) = \text{abs}(\text{sin}(\frac{p}{q} \pi x))$$$.Find minimum possible integer $$$x$$$ that maximizes $$$f(x)$$$ where $$$a \le x \le b$$$.

Each test contains multiple test cases.  The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains four integers $$$a$$$, $$$b$$$, $$$p$$$, and $$$q$$$ ($$$0 \le a \le b \le 10^{9}$$$, $$$1 \le p$$$, $$$q \le 10^{9}$$$).

Print the minimum possible integer $$$x$$$ for each test cases, separated by newline.

NoteIn the first test case, $$$f(0) = 0$$$, $$$f(1) = f(2) \approx 0.866$$$, $$$f(3) = 0$$$.In the second test case, $$$f(55) \approx 0.999969$$$, which is the largest among all possible values.


This problem is a version of problem D from the same contest with some additional constraints and tasks.There are $$$n$$$ candies in a candy box. The type of the $$$i$$$-th candy is $$$a_i$$$ ($$$1 \le a_i \le n$$$). You have to prepare a gift using some of these candies with the following restriction: the numbers of candies of each type presented in a gift should be all distinct (i. e. for example, a gift having two candies of type $$$1$$$ and two candies of type $$$2$$$ is bad).It is possible that multiple types of candies are completely absent from the gift. It is also possible that not all candies of some types will be taken to a gift.You really like some of the candies and don't want to include them into the gift, but you want to eat them yourself instead. For each candy, a number $$$f_i$$$ is given, which is equal to $$$0$$$ if you really want to keep $$$i$$$-th candy for yourself, or $$$1$$$ if you don't mind including it into your gift. It is possible that two candies of the same type have different values of $$$f_i$$$.You want your gift to be as large as possible, but you don't want to include too many of the candies you want to eat into the gift. So, you want to calculate the maximum possible number of candies that can be included into a gift, and among all ways to choose maximum number of candies, you want to maximize the number of candies having $$$f_i = 1$$$ in your gift.You have to answer $$$q$$$ independent queries.If you are Python programmer, consider using PyPy instead of Python when you submit your code.

The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 2 \cdot 10^5$$$) — the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of candies. Then $$$n$$$ lines follow, each containing two integers $$$a_i$$$ and $$$f_i$$$ ($$$1 \le a_i \le n$$$, $$$0 \le f_i \le 1$$$), where $$$a_i$$$ is the type of the $$$i$$$-th candy, and $$$f_i$$$ denotes whether you want to keep the $$$i$$$-th candy for yourself ($$$0$$$ if you want to keep it, $$$1$$$ if you don't mind giving it away). It is guaranteed that the sum of $$$n$$$ over all queries does not exceed $$$2 \cdot 10^5$$$.

For each query print two integers:   the maximum number of candies in a gift you can compose, according to the constraints in the statement;  the maximum number of candies having $$$f_i = 1$$$ in a gift you can compose that contains the maximum possible number of candies.

NoteIn the first query, you can include two candies of type $$$4$$$ and one candy of type $$$5$$$. All of them have $$$f_i = 1$$$ and you don't mind giving them away as part of the gift.


One important contest will take place on the most famous programming platform (Topforces) very soon!The authors have a pool of $$$n$$$ problems and should choose at most three of them into this contest. The prettiness of the $$$i$$$-th problem is $$$a_i$$$. The authors have to compose the most pretty contest (in other words, the cumulative prettinesses of chosen problems should be maximum possible).But there is one important thing in the contest preparation: because of some superstitions of authors, the prettinesses of problems cannot divide each other. In other words, if the prettinesses of chosen problems are $$$x, y, z$$$, then $$$x$$$ should be divisible by neither $$$y$$$, nor $$$z$$$, $$$y$$$ should be divisible by neither $$$x$$$, nor $$$z$$$ and $$$z$$$ should be divisible by neither $$$x$$$, nor $$$y$$$. If the prettinesses of chosen problems are $$$x$$$ and $$$y$$$ then neither $$$x$$$ should be divisible by $$$y$$$ nor $$$y$$$ should be divisible by $$$x$$$. Any contest composed from one problem is considered good.Your task is to find out the maximum possible total prettiness of the contest composed of at most three problems from the given pool.You have to answer $$$q$$$ independent queries.If you are Python programmer, consider using PyPy instead of Python when you submit your code.

The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 2 \cdot 10^5$$$) — the number of queries. The first line of the query contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of problems. The second line of the query contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$2 \le a_i \le 2 \cdot 10^5$$$), where $$$a_i$$$ is the prettiness of the $$$i$$$-th problem. It is guaranteed that the sum of $$$n$$$ over all queries does not exceed $$$2 \cdot 10^5$$$.

For each query print one integer — the maximum possible cumulative prettiness of the contest composed of at most three problems from the given pool of problems in the query.


Heidi and Doctor Who hopped out of the TARDIS and found themselves at EPFL in 2018. They were surrounded by stormtroopers and Darth Vader was approaching. Miraculously, they managed to escape to a nearby rebel base but the Doctor was very confused. Heidi reminded him that last year's HC2 theme was Star Wars. Now he understood, and he's ready to face the evils of the Empire!The rebels have $$$s$$$ spaceships, each with a certain attacking power $$$a$$$.They want to send their spaceships to destroy the empire bases and steal enough gold and supplies in order to keep the rebellion alive.The empire has $$$b$$$ bases, each with a certain defensive power $$$d$$$, and a certain amount of gold $$$g$$$.A spaceship can attack all the bases which have a defensive power less than or equal to its attacking power.If a spaceship attacks a base, it steals all the gold in that base.The rebels are still undecided which spaceship to send out first, so they asked for the Doctor's help. They would like to know, for each spaceship, the maximum amount of gold it can steal.

The first line contains integers $$$s$$$ and $$$b$$$ ($$$1 \leq s, b \leq 10^5$$$), the number of spaceships and the number of bases, respectively. The second line contains $$$s$$$ integers $$$a$$$ ($$$0 \leq a \leq 10^9$$$), the attacking power of each spaceship. The next $$$b$$$ lines contain integers $$$d, g$$$ ($$$0 \leq d \leq 10^9$$$, $$$0 \leq g \leq 10^4$$$), the defensive power and the gold of each base, respectively.

Print $$$s$$$ integers, the maximum amount of gold each spaceship can steal, in the same order as the spaceships are given in the input.

NoteThe first spaceship can only attack the first base.The second spaceship can attack the first and third bases.The third spaceship can attack the first, second and third bases.


Melody Pond was stolen from her parents as a newborn baby by Madame Kovarian, to become a weapon of the Silence in their crusade against the Doctor. Madame Kovarian changed Melody's name to River Song, giving her a new identity that allowed her to kill the Eleventh Doctor.Heidi figured out that Madame Kovarian uses a very complicated hashing function in order to change the names of the babies she steals. In order to prevent this from happening to future Doctors, Heidi decided to prepare herself by learning some basic hashing techniques.The first hashing function she designed is as follows.Given two positive integers $$$(x, y)$$$ she defines $$$H(x,y):=x^2+2xy+x+1$$$.Now, Heidi wonders if the function is reversible. That is, given a positive integer $$$r$$$, can you find a pair $$$(x, y)$$$ (of positive integers) such that $$$H(x, y) = r$$$?If multiple such pairs exist, output the one with smallest possible $$$x$$$. If there is no such pair, output "NO".

The first and only line contains an integer $$$r$$$ ($$$1 \le r \le 10^{12}$$$).

Output integers $$$x, y$$$ such that $$$H(x,y) = r$$$ and $$$x$$$ is smallest possible, or "NO" if no such pair exists.


After learning about polynomial hashing, Heidi decided to learn about shift-xor hashing. In particular, she came across this interesting problem.Given a bitstring $$$y \in \{0,1\}^n$$$ find out the number of different $$$k$$$ ($$$0 \leq k < n$$$) such that there exists $$$x \in \{0,1\}^n$$$ for which $$$y = x \oplus \mbox{shift}^k(x).$$$In the above, $$$\oplus$$$ is the xor operation and $$$\mbox{shift}^k$$$ is the operation of shifting a bitstring cyclically to the right $$$k$$$ times. For example, $$$001 \oplus 111 = 110$$$ and $$$\mbox{shift}^3(00010010111000) = 00000010010111$$$.

The first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$), the length of the bitstring $$$y$$$. The second line contains the bitstring $$$y$$$.

Output a single integer: the number of suitable values of $$$k$$$.


The rebels have saved enough gold to launch a full-scale attack. Now the situation is flipped, the rebels will send out the spaceships to attack the Empire bases!The galaxy can be represented as an undirected graph with $$$n$$$ planets (nodes) and $$$m$$$ wormholes (edges), each connecting two planets.A total of $$$s$$$ rebel spaceships and $$$b$$$ empire bases are located at different planets in the galaxy.Each spaceship is given a location $$$x$$$, denoting the index of the planet on which it is located, an attacking strength $$$a$$$, a certain amount of fuel $$$f$$$, and a price to operate $$$p$$$.Each base is given a location $$$x$$$, a defensive strength $$$d$$$, and a certain amount of gold $$$g$$$.A spaceship can attack a base if both of these conditions hold:   the spaceship's attacking strength is greater or equal than the defensive strength of the base  the spaceship's fuel is greater or equal to the shortest distance, computed as the number of wormholes, between the spaceship's node and the base's node The rebels are very proud fighters. So, if a spaceship cannot attack any base, no rebel pilot will accept to operate it.If a spaceship is operated, the profit generated by that spaceship is equal to the gold of the base it attacks minus the price to operate the spaceship. Note that this might be negative. A spaceship that is operated will attack the base that maximizes its profit.Darth Vader likes to appear rich at all times. Therefore, whenever a base is attacked and its gold stolen, he makes sure to immediately refill that base with gold.Therefore, for the purposes of the rebels, multiple spaceships can attack the same base, in which case each spaceship will still receive all the gold of that base.The rebels have tasked Heidi and the Doctor to decide which set of spaceships to operate in order to maximize the total profit.However, as the war has been going on for a long time, the pilots have formed unbreakable bonds, and some of them refuse to operate spaceships if their friends are not also operating spaceships.They have a list of $$$k$$$ dependencies of the form $$$s_1, s_2$$$, denoting that spaceship $$$s_1$$$ can be operated only if spaceship $$$s_2$$$ is also operated.

The first line of input contains integers $$$n$$$ and $$$m$$$ ($$$1 \leq n \leq 100$$$, $$$0 \leq m \leq 10000$$$), the number of nodes and the number of edges, respectively. The next $$$m$$$ lines contain integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq n$$$) denoting an undirected edge between the two nodes. The next line contains integers $$$s$$$, $$$b$$$ and $$$k$$$ ($$$1 \leq s, b \leq 10^5$$$, $$$0 \leq k \leq 1000$$$), the number of spaceships, bases, and dependencies, respectively. The next $$$s$$$ lines contain integers $$$x, a, f, p$$$ ($$$1 \leq x \leq n$$$, $$$0 \leq a, f, p \leq 10^9$$$), denoting the location, attack, fuel, and price of the spaceship. Ships are numbered from $$$1$$$ to $$$s$$$. The next $$$b$$$ lines contain integers $$$x, d, g$$$ ($$$1 \leq x \leq n$$$, $$$0 \leq d, g \leq 10^9$$$), denoting the location, defence, and gold of the base. The next $$$k$$$ lines contain integers $$$s_1$$$ and $$$s_2$$$ ($$$1 \leq s_1, s_2 \leq s$$$), denoting a dependency of $$$s_1$$$ on $$$s_2$$$.

Print a single integer, the maximum total profit that can be achieved.

NoteThe optimal strategy is to operate spaceships 1, 2, and 4, which will attack bases 1, 1, and 2, respectively.


Now Heidi is ready to crack Madame Kovarian's hashing function.Madame Kovarian has a very strict set of rules for name changes. Two names can be interchanged only if using the following hashing function on them results in a collision. However, the hashing function is parametrized, so one can always find a set of parameters that causes such a collision. Heidi decided to exploit this to her advantage.Given two strings $$$w_1$$$, $$$w_2$$$ of equal length $$$n$$$ consisting of lowercase English letters and an integer $$$m$$$.Consider the standard polynomial hashing function:$$$H_p(w) := \left( \sum_{i=0}^{|w|-1} w_i r^i \right) \mbox{mod}(p)$$$where $$$p$$$ is some prime, and $$$r$$$ is some number such that $$$2\leq r \leq p-2$$$.The goal is to find $$$r$$$ and a prime $$$p$$$ ($$$m \leq p \leq 10^9$$$) such that $$$H_p(w_1) = H_p(w_2)$$$.Strings $$$w_1$$$ and $$$w_2$$$ are sampled independently at random from all strings of length $$$n$$$ over lowercase English letters.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$10 \le n \le 10^5$$$, $$$2 \le m \le 10^5$$$). The second and the third line, respectively, contain the words $$$w_1$$$, $$$w_2$$$ that were sampled independently at random from all strings of length $$$n$$$ over lowercase English letters.

Output integers $$$p, r$$$. $$$p$$$ should be a prime in the range $$$[m, 10^9]$$$ and $$$r$$$ should be an integer satisfying $$$r\in [2,p-2]$$$. At least one solution is guaranteed to exist. In case multiple solutions exist, print any of them.

NoteIn the first example, note that even though $$$p=3$$$ and $$$r=2$$$ also causes a colision of hashes, it is not a correct solution, since $$$m$$$ is $$$5$$$ and thus we want $$$p\geq 5$$$.In the second example, we are aware of the extra 'g' at the end. We just didn't realize that "River Song" and "Melody Pond" have different lengths...


Thanks to the Doctor's help, the rebels managed to steal enough gold to launch a full-scale attack on the Empire! However, Darth Vader is looking for revenge and wants to take back his gold.The rebels have hidden the gold in various bases throughout the galaxy. Darth Vader and the Empire are looking to send out their spaceships to attack these bases.The galaxy can be represented as an undirected graph with $$$n$$$ planets (nodes) and $$$m$$$ wormholes (edges), each connecting two planets.A total of $$$s$$$ empire spaceships and $$$b$$$ rebel bases are located at different planets in the galaxy.Each spaceship is given a location $$$x$$$, denoting the index of the planet on which it is located, an attacking strength $$$a$$$, and a certain amount of fuel $$$f$$$.Each base is given a location $$$x$$$, and a defensive strength $$$d$$$.A spaceship can attack a base if both of these conditions hold:   the spaceship's attacking strength is greater or equal than the defensive strength of the base  the spaceship's fuel is greater or equal to the shortest distance, computed as the number of wormholes, between the spaceship's planet and the base's planet Vader is very particular about his attacking formations. He requires that each spaceship is to attack at most one base and that each base is to be attacked by at most one spaceship.Vader knows that the rebels have hidden $$$k$$$ gold in each base, so he will assign the spaceships to attack bases in such a way that maximizes the number of bases attacked.Therefore, for each base that is attacked, the rebels lose $$$k$$$ gold.However, the rebels have the ability to create any number of dummy bases. With the Doctor's help, these bases would exist beyond space and time, so all spaceship can reach them and attack them. Moreover, a dummy base is designed to seem irresistible: that is, it will always be attacked by some spaceship.Of course, dummy bases do not contain any gold, but creating such a dummy base costs $$$h$$$ gold.What is the minimum gold the rebels can lose if they create an optimal number of dummy bases?

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n \leq 100$$$, $$$0 \leq m \leq 10000$$$), the number of nodes and the number of edges, respectively. The next $$$m$$$ lines contain two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u$$$, $$$v \leq n$$$) denoting an undirected edge between the two nodes. The next line contains four integers $$$s$$$, $$$b$$$, $$$k$$$ and $$$h$$$ ($$$1 \leq s$$$, $$$b \leq 1000$$$, $$$0 \leq k$$$, $$$h \leq 10^9$$$), the number of spaceships, the number of bases, the cost of having a base attacked, and the cost of creating a dummy base, respectively. The next $$$s$$$ lines contain three integers $$$x$$$, $$$a$$$, $$$f$$$ ($$$1 \leq x \leq n$$$, $$$0 \leq a$$$, $$$f \leq 10^9$$$), denoting the location, attack, and fuel of the spaceship. The next $$$b$$$ lines contain two integers $$$x$$$, $$$d$$$ ($$$1 \leq x \leq n$$$, $$$0 \leq d \leq 10^9$$$), denoting the location and defence of the base.

Print a single integer, the minimum cost in terms of gold.

NoteOne way to minimize the cost is to build $$$4$$$ dummy bases, for a total cost of $$$4 \times 3 = 12$$$.One empire spaceship will be assigned to attack each of these dummy bases, resulting in zero actual bases attacked.


The Cybermen and the Daleks have long been the Doctor's main enemies. Everyone knows that both these species enjoy destroying everything they encounter. However, a little-known fact about them is that they both also love taking Turing tests!Heidi designed a series of increasingly difficult tasks for them to spend their time on, which would allow the Doctor enough time to save innocent lives!The funny part is that these tasks would be very easy for a human to solve.The first task is as follows. There are some points on the plane. All but one of them are on the boundary of an axis-aligned square (its sides are parallel to the axes). Identify that point.

The first line contains an integer $$$n$$$ ($$$2 \le n \le 10$$$). Each of the following $$$4n + 1$$$ lines contains two integers $$$x_i, y_i$$$ ($$$0 \leq x_i, y_i \leq 50$$$), describing the coordinates of the next point. It is guaranteed that there are at least $$$n$$$ points on each side of the square and all $$$4n + 1$$$ points are distinct.

Print two integers — the coordinates of the point that is not on the boundary of the square.

NoteIn both examples, the square has four sides $$$x=0$$$, $$$x=2$$$, $$$y=0$$$, $$$y=2$$$.


The Cybermen have again outwitted the Daleks! Unfortunately, this time the Daleks decided to abandon these tasks altogether, which means the Doctor has to deal with them.The Doctor can handle the Daleks on his own, but Heidi now has to make sure that the Cybermen are kept busy with this next task.There are $$$k$$$ rings on a plane. For each ring, $$$n$$$ points are uniformly sampled with a small random noise. The task is to recover the rings given only the noisy samples.The rings and the samples are generated as follows. The center of a ring is uniformly sampled from a disk of radius $$$1\,000\,000$$$ centered at the origin, and the radius of the ring is uniformly sampled from $$$[250\,000, 750\,000]$$$. Let $$$R$$$ be a ring with center $$$(x, y)$$$ and radius $$$r$$$. To sample a point from $$$R$$$, an angle $$$\theta$$$ is uniformly sampled from $$$[0, 2\pi]$$$ and a distance $$$d$$$ is uniformly sampled from $$$[0.9r, 1.1r]$$$. The coordinates of the sampled point are then $$$(x+d\cos(\theta), y+d\sin(\theta))$$$ rounded to the closest integers.The distance between rings is measured by their Hausdorff distance. In our case, the distance between two rings $$$R_1, R_2$$$ can be written as follow. Let $$$d$$$ be the distance between the two centers and $$$r_1, r_2$$$ be the radii. Then the distance is $$$$$$dist(R_1, R_2)=\max(\min(d_{--}, d_{-+}),\min(d_{+-}, d_{++}), \min(d_{--}, d_{+-}), \min(d_{-+}, d_{++}))$$$$$$, where $$$d_{++}=|d+r_1+r_2|$$$, $$$d_{+-}=|d+r_1-r_2|$$$, $$$d_{-+}=|d-r_1+r_2|$$$, $$$d_{--}=|d-r_1-r_2|$$$.We say that a ring $$$R_0$$$ is recovered if one of the rings $$$R$$$ in the output has Hausdorff distance less than $$$100\,000$$$ from $$$R_0$$$. An output is accepted if all the rings are recovered. It is guaranteed that the distances between any two rings is greater than $$$600\,000$$$.Remember that a human can very easily solve this task, so make sure that no human traitors are helping the Cybermen complete this task.

The first line contains an integer $$$k$$$ ($$$1 \leq k \leq 4$$$), the number of rings. The second line contains an integer $$$n$$$ ($$$100 \leq n \leq 1\,000$$$), the number of samples per ring. The following $$$n \times k$$$ lines contain the samples, one sample per line. Each line contains a pair of integers $$$x_i, y_i$$$, where $$$(x_i, y_i)$$$ are the coordinates of the $$$i$$$-th sample.

Print $$$k$$$ lines, each describing a single ring. For each line, print three real numbers $$$x_i, y_i, r_i$$$, where $$$(x_i, y_i)$$$ and $$$r_i$$$ are the coordinates and the radius of the $$$i$$$-th ring. The order of the rings does not matter.

NoteHere is how one of tests with $$$k=4$$$ and $$$n=100$$$ looks like.   You can download the sample input and output here.


The Cybermen solved that first test much quicker than the Daleks. Luckily for us, the Daleks were angry (shocking!) and they destroyed some of the Cybermen.After the fighting stopped, Heidi gave them another task to waste their time on.There are $$$n$$$ points on a plane. Given a radius $$$r$$$, find the maximum number of points that can be covered by an $$$L^1$$$-ball with radius $$$r$$$.An $$$L^1$$$-ball with radius $$$r$$$ and center $$$(x_0, y_0)$$$ in a 2D-plane is defined as the set of points $$$(x, y)$$$ such that the Manhattan distance between $$$(x_0, y_0)$$$ and $$$(x, y)$$$ is at most $$$r$$$.Manhattan distance between $$$(x_0, y_0)$$$ and $$$(x, y)$$$ is defined as $$$|x - x_0| + |y - y_0|$$$.

The first line contains two integers $$$n, r$$$ ($$$1 \le n \le 300\,000, 1 \le r \le 10^6$$$), the number of points and the radius of the ball, respectively.  Each of the next $$$n$$$ lines contains integers $$$x_i, y_i$$$ ($$$-10^6 \leq x_i, y_i \leq 10^6$$$), describing the coordinates of the $$$i$$$-th point. It is guaranteed, that all points are distinct.

Print one integer — the maximum number points that an $$$L^1$$$-ball with radius $$$r$$$ can cover.

NoteIn the first example, a ball centered at $$$(1, 0)$$$ covers the points $$$(1, 1)$$$, $$$(1, -1)$$$, $$$(2, 0)$$$.In the second example, a ball centered at $$$(0, 0)$$$ covers all the points.Note that $$$x_0$$$ and $$$y_0$$$ need not be integer.


After a successful field test, Heidi is considering deploying a trap along some Corridor, possibly not the first one. She wants to avoid meeting the Daleks inside the Time Vortex, so for abundance of caution she considers placing the traps only along those Corridors that are not going to be used according to the current Daleks' plan – which is to use a minimum spanning tree of Corridors. Heidi knows that all energy requirements for different Corridors are now different, and that the Daleks have a single unique plan which they are intending to use.Your task is to calculate the number $$$E_{max}(c)$$$, which is defined in the same way as in the easy version – i.e., the largest $$$e \le 10^9$$$ such that if we changed the energy of corridor $$$c$$$ to $$$e$$$, the Daleks might use it – but now for every corridor that Heidi considers.

The first line: number $$$n$$$ of destinations, number $$$m$$$ of Time Corridors ($$$2 \leq n \leq 10^5$$$, $$$n - 1 \leq m \leq 10^6$$$). The next $$$m$$$ lines: destinations $$$a$$$, $$$b$$$ and energy $$$e$$$ ($$$1 \leq a, b \leq n$$$, $$$a \neq b$$$, $$$0 \leq e \leq 10^9$$$). No pair $$$\{a, b\}$$$ will repeat. The graph is guaranteed to be connected. All energy requirements $$$e$$$ are distinct.

Output $$$m-(n-1)$$$ lines, each containing one integer: $$$E_{max}(c_i)$$$ for the $$$i$$$-th Corridor $$$c_i$$$ from the input that is not part of the current Daleks' plan (minimum spanning tree).

NoteIf $$$m = n-1$$$, then you need not output anything.


The Third Doctor Who once correctly said that travel between parallel universes is "like travelling sideways". However, he incorrectly thought that there were infinite parallel universes, whereas in fact, as we now all know, there will never be more than 250.Heidi recently got her hands on a multiverse observation tool. She was able to see all $$$n$$$ universes lined up in a row, with non-existent links between them. She also noticed that the Doctor was in the $$$k$$$-th universe.The tool also points out that due to restrictions originating from the space-time discontinuum, the number of universes will never exceed $$$m$$$.Obviously, the multiverse is unstable because of free will. Each time a decision is made, one of two events will randomly happen: a new parallel universe is created, or a non-existent link is broken.More specifically,    When a universe is created, it will manifest itself between any two adjacent universes or at one of the ends.   When a link is broken, it could be cut between any two adjacent universes. After separating the multiverse into two segments, the segment NOT containing the Doctor will cease to exist. Heidi wants to perform a simulation of $$$t$$$ decisions. Each time a decision is made, Heidi wants to know the length of the multiverse (i.e. the number of universes), and the position of the Doctor.

The first line contains four integers $$$n$$$, $$$k$$$, $$$m$$$ and $$$t$$$ ($$$2 \le k \le n \le m \le 250$$$, $$$1 \le t \le 1000$$$). Each of the following $$$t$$$ lines is in one of the following formats:    "$$$1$$$ $$$i$$$" — meaning that a universe is inserted at the position $$$i$$$ ($$$1 \le i \le l + 1$$$), where $$$l$$$ denotes the current length of the multiverse.  "$$$0$$$ $$$i$$$" — meaning that the $$$i$$$-th link is broken ($$$1 \le i \le l - 1$$$), where $$$l$$$ denotes the current length of the multiverse.

Output $$$t$$$ lines. Each line should contain $$$l$$$, the current length of the multiverse and $$$k$$$, the current position of the Doctor. It is guaranteed that the sequence of the steps will be valid, i.e. the multiverse will have length at most $$$m$$$ and when the link breaking is performed, there will be at least one universe in the multiverse.

NoteThe multiverse initially consisted of 5 universes, with the Doctor being in the second.First, link 1 was broken, leaving the multiverse with 4 universes, and the Doctor in the first.Then, a universe was added to the leftmost end of the multiverse, increasing the multiverse length to 5, and the Doctor was then in the second universe.Then, the rightmost link was broken.Finally, a universe was added between the first and the second universe.


With your help, Heidi has prepared a plan of trap placement and defence. Yet suddenly, the Doctor popped out of the TARDIS and told her that he had spied on the Daleks' preparations, and there is more of them than ever. Desperate times require desperate measures, so Heidi is going to risk meeting with the Daleks and she will consider placing a trap along any Corridor.This means she needs your help again in calculating $$$E_{max}(c)$$$ – the largest $$$e \le 10^9$$$ such that if we changed the energy requirement of $$$c$$$ to $$$e$$$, then the Daleks might use $$$c$$$ in their invasion – but this time for all Time Corridors.

First line: number $$$n$$$ of destinations, number $$$m$$$ of corridors ($$$2 \leq n \leq 10^5$$$, $$$n - 1 \leq m \leq 10^6$$$). The next $$$m$$$ lines: destinations $$$a$$$, $$$b$$$ and energy $$$e$$$ ($$$1 \leq a, b \leq n$$$, $$$a \neq b$$$, $$$0 \leq e \leq 10^9$$$). No pair $$$\{a, b\}$$$ will repeat. The graph is guaranteed to be connected. It is not guaranteed that all energy requirements $$$e$$$ are distinct, or that the minimum spanning tree is unique.

Output $$$m$$$ lines, each containing one integer: $$$E_{max}(c_i)$$$ for the $$$i$$$-th Corridor $$$c_i$$$ from the input.


Heidi enjoyed performing the simulation because she knew exactly when a new universe would be formed and where, and when a non-existent link would be broken and where.However, the multiverse itself works in mysterious ways. Well, it works using probabilities, which to some people is mysterious.At each unit time, when a decision is made, one of the two events will happen randomly. Let's denote $$$l$$$ as the current length of the multiverse. With a probability of $$$p_{create} = 1 - \frac{l}{m}$$$, a universe will be created. With a probability of $$$p_{break}=\frac{l}{m}$$$, a non-existent link will be broken at some position.More specifically,    When a universe is created, it will manifest itself between any two adjacent universes or at one of the ends. Each position occurs with a probability of $$$\frac{1}{l + 1}$$$.   When a link is broken, it could be cut between any two adjacent universes, each with a probability of $$$\frac{1}{l-1}$$$. After separating the multiverse into two segments, the segment NOT containing the Doctor will cease to exist. As earlier, the Doctor remains in the same universe. However, if at some point the multiverse breaks in such a way that the Doctor finds himself at the leftmost or rightmost end of it, the TARDIS stops functioning.In such a case, the Doctor must actually walk across the multiverse to find the tools to fix it.We are interested in the expected value of the length of the multiverse when such an event occurs.

The first and only line contains three integers $$$n$$$, $$$k$$$ and $$$m$$$ $$$(1 \le k \le n \le m \le 250)$$$, the initial length of the multiverse, the initial position of the Doctor, and the maximum possible length of the multiverse.

Output a single integer on a single line, indicating the expected length of the multiverse. If the answer is $$$\frac{p}{q}$$$, please print $$$r$$$ where $$$p \equiv r \cdot q (\text{mod } 10^9 + 7)$$$.

NoteFor the first and the second test case, without any change to the multiverse, the Doctor is already at one of the ends.For the third test case, the multiverse can only break at a position, which renders the Doctor at one of its ends.For the fourth case, things seem to be a little more complicated, because the multiverse can grow and then be broken again.


Heidi found out that the Daleks have created a network of bidirectional Time Corridors connecting different destinations (at different times!). She suspects that they are planning another invasion on the entire Space and Time. In order to counter the invasion, she plans to deploy a trap in the Time Vortex, along a carefully chosen Time Corridor. She knows that tinkering with the Time Vortex is dangerous, so she consulted the Doctor on how to proceed. She has learned the following:  Different Time Corridors require different amounts of energy to keep stable.  Daleks are unlikely to use all corridors in their invasion. They will pick a set of Corridors that requires the smallest total energy to maintain, yet still makes (time) travel possible between any two destinations (for those in the know: they will use a minimum spanning tree).  Setting the trap may modify the energy required to keep the Corridor stable. Heidi decided to carry out a field test and deploy one trap, placing it along the first Corridor. But she needs to know whether the Daleks are going to use this corridor after the deployment of the trap. She gives you a map of Time Corridors (an undirected graph) with energy requirements for each Corridor.For a Corridor $$$c$$$, $$$E_{max}(c)$$$ is the largest $$$e \le 10^9$$$ such that if we changed the required amount of energy of $$$c$$$ to $$$e$$$, then the Daleks may still be using $$$c$$$ in their invasion (that is, it belongs to some minimum spanning tree). Your task is to calculate $$$E_{max}(c_1)$$$ for the Corridor $$$c_1$$$ that Heidi plans to arm with a trap, which is the first edge in the graph.

The first line contains integers $$$n$$$ and $$$m$$$ ($$$2 \leq n \leq 10^5$$$, $$$n - 1 \leq m \leq 10^6$$$), number of destinations to be invaded and the number of Time Corridors. Each of the next $$$m$$$ lines describes a Corridor: destinations $$$a$$$, $$$b$$$ and energy $$$e$$$ ($$$1 \leq a, b \leq n$$$, $$$a \neq b$$$, $$$0 \leq e \leq 10^9$$$). It's guaranteed, that no pair $$$\{a, b\}$$$ will repeat and that the graph is connected — that is, it is possible to travel between any two destinations using zero or more Time Corridors.

Output a single integer: $$$E_{max}(c_1)$$$ for the first Corridor $$$c_1$$$ from the input.

NoteAfter the trap is set, the new energy requirement for the first Corridor may be either smaller, larger, or equal to the old energy requiremenet.In the example, if the energy of the first Corridor is set to $$$4$$$ or less, then the Daleks may use the set of Corridors $$$\{ \{ 1,2 \}, \{ 2,3 \} \}$$$ (in particular, if it were set to less than $$$4$$$, then this would be the only set of Corridors that they would use). However, if it is larger than $$$4$$$, then they will instead use the set $$$\{ \{2,3\}, \{3,1\} \}$$$.


Methodius received an email from his friend Polycarp. However, Polycarp's keyboard is broken, so pressing a key on it once may cause the corresponding symbol to appear more than once (if you press a key on a regular keyboard, it prints exactly one symbol).For example, as a result of typing the word "hello", the following words could be printed: "hello", "hhhhello", "hheeeellllooo", but the following could not be printed: "hell", "helo", "hhllllooo".Note, that when you press a key, the corresponding symbol must appear (possibly, more than once). The keyboard is broken in a random manner, it means that pressing the same key you can get the different number of letters in the result.For each word in the letter, Methodius has guessed what word Polycarp actually wanted to write, but he is not sure about it, so he asks you to help him.You are given a list of pairs of words. For each pair, determine if the second word could be printed by typing the first one on Polycarp's keyboard.

The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of pairs to check. Further input contains $$$n$$$ descriptions of pairs. The first line of each description contains a single non-empty word $$$s$$$ consisting of lowercase Latin letters. The second line of the description contains a single non-empty word $$$t$$$ consisting of lowercase Latin letters. The lengths of both strings are not greater than $$$10^6$$$. It is guaranteed that the total length of all words $$$s$$$ in the input is not greater than $$$10^6$$$. Also, it is guaranteed that the total length of all words $$$t$$$ in the input is not greater than $$$10^6$$$.

Output $$$n$$$ lines. In the $$$i$$$-th line for the $$$i$$$-th pair of words $$$s$$$ and $$$t$$$ print YES if the word $$$t$$$ could be printed by typing the word $$$s$$$. Otherwise, print NO.

4
hello
hello
hello
helloo
hello
hlllloo
hello
helo

5
aa
bb
codeforces
codeforce
polycarp
poolycarpp
aaaa
aaaab
abcdefghijklmnopqrstuvwxyz
zabcdefghijklmnopqrstuvwxyz


Polycarp decided to relax on his weekend and visited to the performance of famous ropewalkers: Agafon, Boniface and Konrad.The rope is straight and infinite in both directions. At the beginning of the performance, Agafon, Boniface and Konrad are located in positions $$$a$$$, $$$b$$$ and $$$c$$$ respectively. At the end of the performance, the distance between each pair of ropewalkers was at least $$$d$$$.Ropewalkers can walk on the rope. In one second, only one ropewalker can change his position. Every ropewalker can change his position exactly by $$$1$$$ (i. e. shift by $$$1$$$ to the left or right direction on the rope). Agafon, Boniface and Konrad can not move at the same time (Only one of them can move at each moment). Ropewalkers can be at the same positions at the same time and can "walk past each other".You should find the minimum duration (in seconds) of the performance. In other words, find the minimum number of seconds needed so that the distance between each pair of ropewalkers can be greater or equal to $$$d$$$.Ropewalkers can walk to negative coordinates, due to the rope is infinite to both sides.

The only line of the input contains four integers $$$a$$$, $$$b$$$, $$$c$$$, $$$d$$$ ($$$1 \le a, b, c, d \le 10^9$$$). It is possible that any two (or all three) ropewalkers are in the same position at the beginning of the performance.

Output one integer — the minimum duration (in seconds) of the performance.

NoteIn the first example: in the first two seconds Konrad moves for 2 positions to the right (to the position $$$8$$$), while Agafon and Boniface stay at their positions. Thus, the distance between Agafon and Boniface will be $$$|5 - 2| = 3$$$, the distance between Boniface and Konrad will be $$$|2 - 8| = 6$$$ and the distance between Agafon and Konrad will be $$$|5 - 8| = 3$$$. Therefore, all three pairwise distances will be at least $$$d=3$$$, so the performance could be finished within 2 seconds.


The only difference between easy and hard versions is constraints.A session has begun at Beland State University. Many students are taking exams.Polygraph Poligrafovich is going to examine a group of $$$n$$$ students. Students will take the exam one-by-one in order from $$$1$$$-th to $$$n$$$-th. Rules of the exam are following:  The $$$i$$$-th student randomly chooses a ticket.  if this ticket is too hard to the student, he doesn't answer and goes home immediately (this process is so fast that it's considered no time elapses). This student fails the exam.  if the student finds the ticket easy, he spends exactly $$$t_i$$$ minutes to pass the exam. After it, he immediately gets a mark and goes home. Students take the exam in the fixed order, one-by-one, without any interruption. At any moment of time, Polygraph Poligrafovich takes the answer from one student.The duration of the whole exam for all students is $$$M$$$ minutes ($$$\max t_i \le M$$$), so students at the end of the list have a greater possibility to run out of time to pass the exam.For each student $$$i$$$, you should count the minimum possible number of students who need to fail the exam so the $$$i$$$-th student has enough time to pass the exam.For each student $$$i$$$, find the answer independently. That is, if when finding the answer for the student $$$i_1$$$ some student $$$j$$$ should leave, then while finding the answer for $$$i_2$$$ ($$$i_2>i_1$$$) the student $$$j$$$ student does not have to go home.

The first line of the input contains two integers $$$n$$$ and $$$M$$$ ($$$1 \le n \le 100$$$, $$$1 \le M \le 100$$$) — the number of students and the total duration of the exam in minutes, respectively. The second line of the input contains $$$n$$$ integers $$$t_i$$$ ($$$1 \le t_i \le 100$$$) — time in minutes that $$$i$$$-th student spends to answer to a ticket. It's guaranteed that all values of $$$t_i$$$ are not greater than $$$M$$$.

Print $$$n$$$ numbers: the $$$i$$$-th number must be equal to the minimum number of students who have to leave the exam in order to $$$i$$$-th student has enough time to pass the exam.

NoteThe explanation for the example 1.Please note that the sum of the first five exam times does not exceed $$$M=15$$$ (the sum is $$$1+2+3+4+5=15$$$). Thus, the first five students can pass the exam even if all the students before them also pass the exam. In other words, the first five numbers in the answer are $$$0$$$.In order for the $$$6$$$-th student to pass the exam, it is necessary that at least $$$2$$$ students must fail it before (for example, the $$$3$$$-rd and $$$4$$$-th, then the $$$6$$$-th will finish its exam in $$$1+2+5+6=14$$$ minutes, which does not exceed $$$M$$$).In order for the $$$7$$$-th student to pass the exam, it is necessary that at least $$$3$$$ students must fail it before (for example, the $$$2$$$-nd, $$$5$$$-th and $$$6$$$-th, then the $$$7$$$-th will finish its exam in $$$1+3+4+7=15$$$ minutes, which does not exceed $$$M$$$).


A company of $$$n$$$ friends wants to order exactly two pizzas. It is known that in total there are $$$9$$$ pizza ingredients in nature, which are denoted by integers from $$$1$$$ to $$$9$$$.Each of the $$$n$$$ friends has one or more favorite ingredients: the $$$i$$$-th of friends has the number of favorite ingredients equal to $$$f_i$$$ ($$$1 \le f_i \le 9$$$) and your favorite ingredients form the sequence $$$b_{i1}, b_{i2}, \dots, b_{if_i}$$$ ($$$1 \le b_{it} \le 9$$$).The website of CodePizza restaurant has exactly $$$m$$$ ($$$m \ge 2$$$) pizzas. Each pizza is characterized by a set of $$$r_j$$$ ingredients $$$a_{j1}, a_{j2}, \dots, a_{jr_j}$$$ ($$$1 \le r_j \le 9$$$, $$$1 \le a_{jt} \le 9$$$) , which are included in it, and its price is $$$c_j$$$.Help your friends choose exactly two pizzas in such a way as to please the maximum number of people in the company. It is known that a person is pleased with the choice if each of his/her favorite ingredients is in at least one ordered pizza. If there are several ways to choose two pizzas so as to please the maximum number of friends, then choose the one that minimizes the total price of two pizzas.

The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 10^5, 2 \le m \le 10^5$$$) — the number of friends in the company and the number of pizzas, respectively. Next, the $$$n$$$ lines contain descriptions of favorite ingredients of the friends: the $$$i$$$-th of them contains the number of favorite ingredients $$$f_i$$$ ($$$1 \le f_i \le 9$$$) and a sequence of distinct integers $$$b_{i1}, b_{i2}, \dots, b_{if_i}$$$ ($$$1 \le b_{it} \le 9$$$). Next, the $$$m$$$ lines contain pizza descriptions: the $$$j$$$-th of them contains the integer price of the pizza $$$c_j$$$ ($$$1 \le c_j \le 10^9$$$), the number of ingredients $$$r_j$$$ ($$$1 \le r_j \le 9$$$) and the ingredients themselves as a sequence of distinct integers $$$a_{j1}, a_{j2}, \dots, a_{jr_j}$$$ ($$$1 \le a_{jt} \le 9$$$).

Output two integers $$$j_1$$$ and $$$j_2$$$ ($$$1 \le j_1,j_2 \le m$$$, $$$j_1 \ne j_2$$$) denoting the indices of two pizzas in the required set. If there are several solutions, output any of them. Pizza indices can be printed in any order.