Princess Heidi decided to give orders to all her K Rebel ship commanders in person. Unfortunately, she is currently travelling through hyperspace, and will leave it only at N specific moments t1, t2, ..., tN. The meetings with commanders must therefore start and stop at those times. Namely, each commander will board her ship at some time ti and disembark at some later time tj. Of course, Heidi needs to meet with all commanders, and no two meetings can be held during the same time. Two commanders cannot even meet at the beginnings/endings of the hyperspace jumps, because too many ships in one position could give out their coordinates to the enemy. Your task is to find minimum time that Princess Heidi has to spend on meetings, with her schedule satisfying the conditions above.

The first line contains two integers K, N (2 ≤ 2K ≤ N ≤ 500000, K ≤ 5000). The second line contains N distinct integers t1, t2, ..., tN (1 ≤ ti ≤ 109) representing the times when Heidi leaves hyperspace.

Output only one integer: the minimum time spent on meetings.

NoteIn the first example, there are five valid schedules: [1, 4], [6, 7] with total time 4, [1, 4], [6, 12] with total time 9, [1, 4], [7, 12] with total time 8, [1, 6], [7, 12] with total time 10, and [4, 6], [7, 12] with total time 7. So the answer is 4.In the second example, there is only 1 valid schedule: [1, 2], [3, 4], [5, 6].For the third example, one possible schedule with total time 6 is: [1, 3], [4, 5], [14, 15], [23, 25].


Mahmoud and Ehab play a game called the even-odd game. Ehab chooses his favorite integer n and then they take turns, starting from Mahmoud. In each player's turn, he has to choose an integer a and subtract it from n such that:  1 ≤ a ≤ n.  If it's Mahmoud's turn, a has to be even, but if it's Ehab's turn, a has to be odd. If the current player can't choose any number satisfying the conditions, he loses. Can you determine the winner if they both play optimally?

The only line contains an integer n (1 ≤ n ≤ 109), the number at the beginning of the game.

Output "Mahmoud" (without quotes) if Mahmoud wins and "Ehab" (without quotes) otherwise.

NoteIn the first sample, Mahmoud can't choose any integer a initially because there is no positive even integer less than or equal to 1 so Ehab wins.In the second sample, Mahmoud has to choose a = 2 and subtract it from n. It's Ehab's turn and n = 0. There is no positive odd integer less than or equal to 0 so Mahmoud wins.


Mahmoud was trying to solve the vertex cover problem on trees. The problem statement is:Given an undirected tree consisting of n nodes, find the minimum number of vertices that cover all the edges. Formally, we need to find a set of vertices such that for each edge (u, v) that belongs to the tree, either u is in the set, or v is in the set, or both are in the set. Mahmoud has found the following algorithm:  Root the tree at node 1.  Count the number of nodes at an even depth. Let it be evenCnt.  Count the number of nodes at an odd depth. Let it be oddCnt.  The answer is the minimum between evenCnt and oddCnt. The depth of a node in a tree is the number of edges in the shortest path between this node and the root. The depth of the root is 0.Ehab told Mahmoud that this algorithm is wrong, but he didn't believe because he had tested his algorithm against many trees and it worked, so Ehab asked you to find 2 trees consisting of n nodes. The algorithm should find an incorrect answer for the first tree and a correct answer for the second one.

The only line contains an integer n (2 ≤ n ≤ 105), the number of nodes in the desired trees.

The output should consist of 2 independent sections, each containing a tree. The algorithm should find an incorrect answer for the tree in the first section and a correct answer for the tree in the second. If a tree doesn't exist for some section, output "-1" (without quotes) for that section only. If the answer for a section exists, it should contain n - 1 lines, each containing 2 space-separated integers u and v (1 ≤ u, v ≤ n), which means that there's an undirected edge between node u and node v. If the given graph isn't a tree or it doesn't follow the format, you'll receive wrong answer verdict. If there are multiple answers, you can print any of them.

NoteIn the first sample, there is only 1 tree with 2 nodes (node 1 connected to node 2). The algorithm will produce a correct answer in it so we printed  - 1 in the first section, but notice that we printed this tree in the second section.In the second sample:In the first tree, the algorithm will find an answer with 4 nodes, while there exists an answer with 3 nodes like this:  In the second tree, the algorithm will find an answer with 3 nodes which is correct:


Mahmoud wants to send a message to his friend Ehab. Their language consists of n words numbered from 1 to n. Some words have the same meaning so there are k groups of words such that all the words in some group have the same meaning.Mahmoud knows that the i-th word can be sent with cost ai. For each word in his message, Mahmoud can either replace it with another word of the same meaning or leave it as it is. Can you help Mahmoud determine the minimum cost of sending the message?The cost of sending the message is the sum of the costs of sending every word in it.

The first line of input contains integers n, k and m (1 ≤ k ≤ n ≤ 105, 1 ≤ m ≤ 105) — the number of words in their language, the number of groups of words, and the number of words in Mahmoud's message respectively. The second line contains n strings consisting of lowercase English letters of length not exceeding 20 which represent the words. It's guaranteed that the words are distinct. The third line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) where ai is the cost of sending the i-th word. The next k lines describe the groups of words of same meaning. The next k lines each start with an integer x (1 ≤ x ≤ n) which means that there are x words in this group, followed by x integers which represent the indices of words in this group. It's guaranteed that each word appears in exactly one group. The next line contains m space-separated words which represent Mahmoud's message. Each of these words appears in the list of language's words.

The only line should contain the minimum cost to send the message after replacing some words (maybe none) with some words of the same meaning.

NoteIn the first sample, Mahmoud should replace the word "second" with the word "loser" because it has less cost so the cost will be 100+1+5+1=107.In the second sample, Mahmoud shouldn't do any replacement so the cost will be 100+1+5+10=116.

5 4 4
i loser am the second
100 1 1 5 10
1 1
1 3
2 2 5
1 4
i am the second

5 4 4
i loser am the second
100 20 1 5 10
1 1
1 3
2 2 5
1 4
i am the second


Ehab is interested in the bitwise-xor operation and the special graphs. Mahmoud gave him a problem that combines both. He has a complete graph consisting of n vertices numbered from 0 to n - 1. For all 0 ≤ u < v < n, vertex u and vertex v are connected with an undirected edge that has weight  (where  is the bitwise-xor operation). Can you find the weight of the minimum spanning tree of that graph?You can read about complete graphs in https://en.wikipedia.org/wiki/Complete_graphYou can read about the minimum spanning tree in https://en.wikipedia.org/wiki/Minimum_spanning_treeThe weight of the minimum spanning tree is the sum of the weights on the edges included in it.

The only line contains an integer n (2 ≤ n ≤ 1012), the number of vertices in the graph.

The only line contains an integer x, the weight of the graph's minimum spanning tree.

NoteIn the first sample:  The weight of the minimum spanning tree is 1+2+1=4.


Ehab has an array a of n integers. He likes the bitwise-xor operation and he likes to bother Mahmoud so he came up with a problem. He gave Mahmoud q queries. In each of them, he gave Mahmoud 2 integers l and x, and asked him to find the number of subsequences of the first l elements of the array such that their bitwise-xor sum is x. Can you help Mahmoud answer the queries?A subsequence can contain elements that are not neighboring.

The first line contains integers n and q (1 ≤ n, q ≤ 105), the number of elements in the array and the number of queries. The next line contains n integers a1, a2, ..., an (0 ≤ ai < 220), the elements of the array. The next q lines, each contains integers l and x (1 ≤ l ≤ n, 0 ≤ x < 220), representing the queries.

For each query, output its answer modulo 109 + 7 in a newline.

NoteThe bitwise-xor sum of the empty set is 0 and the bitwise-xor sum of a set containing one element is that element itself.


Mahmoud has an array a consisting of n integers. He asked Ehab to find another array b of the same length such that:  b is lexicographically greater than or equal to a.  bi ≥ 2.  b is pairwise coprime: for every 1 ≤ i < j ≤ n, bi and bj are coprime, i. e. GCD(bi, bj) = 1, where GCD(w, z) is the greatest common divisor of w and z. Ehab wants to choose a special array so he wants the lexicographically minimal array between all the variants. Can you find it?An array x is lexicographically greater than an array y if there exists an index i such than xi > yi and xj = yj for all 1 ≤ j < i. An array x is equal to an array y if xi = yi for all 1 ≤ i ≤ n.

The first line contains an integer n (1 ≤ n ≤ 105), the number of elements in a and b. The second line contains n integers a1, a2, ..., an (2 ≤ ai ≤ 105), the elements of a.

Output n space-separated integers, the i-th of them representing bi.

NoteNote that in the second sample, the array is already pairwise coprime so we printed it.


You are given two arrays A and B, each of size n. The error, E, between these two arrays is defined . You have to perform exactly k1 operations on array A and exactly k2 operations on array B. In one operation, you have to choose one element of the array and increase or decrease it by 1.Output the minimum possible value of error after k1 operations on array A and k2 operations on array B have been performed.

The first line contains three space-separated integers n (1 ≤ n ≤ 103), k1 and k2 (0 ≤ k1 + k2 ≤ 103, k1 and k2 are non-negative) — size of arrays and number of operations to perform on A and B respectively. Second line contains n space separated integers a1, a2, ..., an ( - 106 ≤ ai ≤ 106) — array A. Third line contains n space separated integers b1, b2, ..., bn ( - 106 ≤ bi ≤ 106)— array B.

Output a single integer — the minimum possible value of  after doing exactly k1 operations on array A and exactly k2 operations on array B.

NoteIn the first sample case, we cannot perform any operations on A or B. Therefore the minimum possible error E = (1 - 2)2 + (2 - 3)2 = 2. In the second sample case, we are required to perform exactly one operation on A. In order to minimize error, we increment the first element of A by 1. Now, A = [2, 2]. The error is now E = (2 - 2)2 + (2 - 2)2 = 0. This is the minimum possible error obtainable.In the third sample case, we can increase the first element of A to 8, using the all of the 5 moves available to us. Also, the first element of B can be reduced to 8 using the 6 of the 7 available moves. Now A = [8, 4] and B = [8, 4]. The error is now E = (8 - 8)2 + (4 - 4)2 = 0, but we are still left with 1 move for array B. Increasing the second element of B to 5 using the left move, we get B = [8, 5] and E = (8 - 8)2 + (4 - 5)2 = 1.


Pikachu had an array with him. He wrote down all the non-empty subsequences of the array on paper. Note that an array of size n has 2n - 1 non-empty subsequences in it. Pikachu being mischievous as he always is, removed all the subsequences in which Maximum_element_of_the_subsequence  -  Minimum_element_of_subsequence  ≥ dPikachu was finally left with X subsequences. However, he lost the initial array he had, and now is in serious trouble. He still remembers the numbers X and d. He now wants you to construct any such array which will satisfy the above conditions. All the numbers in the final array should be positive integers less than 1018. Note the number of elements in the output array should not be more than 104. If no answer is possible, print  - 1.

The only line of input consists of two space separated integers X and d (1 ≤ X, d ≤ 109).

Output should consist of two lines. First line should contain a single integer n (1 ≤ n ≤ 10 000)— the number of integers in the final array. Second line should consist of n space separated integers — a1, a2, ... , an (1 ≤ ai < 1018). If there is no answer, print a single integer -1. If there are multiple answers, print any of them.

NoteIn the output of the first example case, the remaining subsequences after removing those with Maximum_element_of_the_subsequence  -  Minimum_element_of_subsequence  ≥ 5 are [5], [5, 7], [5, 6], [5, 7, 6], [50], [7], [7, 6], [15], [6], [100]. There are 10 of them. Hence, the array [5, 50, 7, 15, 6, 100] is valid.Similarly, in the output of the second example case, the remaining sub-sequences after removing those with Maximum_element_of_the_subsequence  -  Minimum_element_of_subsequence  ≥ 2 are [10], [100], [1000], [10000]. There are 4 of them. Hence, the array [10, 100, 1000, 10000] is valid.


A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b', they have made sure that at this point, at least one 'a' and one 'b' exist in the string.B now gives this string to C and he appends some number of letters 'c' to the end of the string. However, since C is a good friend of A and B, the number of letters 'c' he appends is equal to the number of 'a' or to the number of 'b' in the string. It is also possible that the number of letters 'c' equals both to the number of letters 'a' and to the number of letters 'b' at the same time.You have a string in your hands, and you want to check if it is possible to obtain the string in this way or not. If it is possible to obtain the string, print "YES", otherwise print "NO" (without the quotes).

The first and only line consists of a string $$$S$$$ ($$$ 1 \le |S| \le 5\,000 $$$). It is guaranteed that the string will only consist of the lowercase English letters 'a', 'b', 'c'.

Print "YES" or "NO", according to the condition.

NoteConsider first example: the number of 'c' is equal to the number of 'a'. Consider second example: although the number of 'c' is equal to the number of the 'b', the order is not correct.Consider third example: the number of 'c' is equal to the number of 'b'.


Given a tree with $$$n$$$ nodes numbered from $$$1$$$ to $$$n$$$. Each node $$$i$$$ has an associated value $$$V_i$$$.If the simple path from $$$u_1$$$ to $$$u_m$$$ consists of $$$m$$$ nodes namely $$$u_1 \rightarrow u_2 \rightarrow u_3 \rightarrow \dots u_{m-1} \rightarrow u_{m}$$$, then its alternating function $$$A(u_{1},u_{m})$$$ is defined as $$$A(u_{1},u_{m}) = \sum\limits_{i=1}^{m} (-1)^{i+1} \cdot V_{u_{i}}$$$. A path can also have $$$0$$$ edges, i.e. $$$u_{1}=u_{m}$$$.Compute the sum of alternating functions of all unique simple paths. Note that the paths are directed: two paths are considered different if the starting vertices differ or the ending vertices differ. The answer may be large so compute it modulo $$$10^{9}+7$$$.

The first line contains an integer $$$n$$$ $$$(2 \leq n \leq 2\cdot10^{5} )$$$ — the number of vertices in the tree. The second line contains $$$n$$$ space-separated integers $$$V_1, V_2, \ldots, V_n$$$ ($$$-10^9\leq V_i \leq 10^9$$$) — values of the nodes. The next $$$n-1$$$ lines each contain two space-separated integers $$$u$$$ and $$$v$$$ $$$(1\leq u, v\leq n, u \neq v)$$$ denoting an edge between vertices $$$u$$$ and $$$v$$$. It is guaranteed that the given graph is a tree.

Print the total sum of alternating functions of all unique simple paths modulo $$$10^{9}+7$$$.


You are given a directed graph with n nodes and m edges, with all edges having a certain weight. There might be multiple edges and self loops, and the graph can also be disconnected. You need to choose a path (possibly passing through same vertices multiple times) in the graph such that the weights of the edges are in strictly increasing order, and these edges come in the order of input. Among all such paths, you need to find the the path that has the maximum possible number of edges, and report this value.Please note that the edges picked don't have to be consecutive in the input.

The first line contains two integers n and m (1 ≤ n ≤ 100000,1 ≤ m ≤ 100000) — the number of vertices and edges in the graph, respectively.  m lines follows.  The i-th of these lines contains three space separated integers ai, bi and wi (1 ≤ ai, bi ≤ n, 0 ≤ wi ≤ 100000), denoting an edge from vertex ai to vertex bi having weight wi

Print one integer in a single line — the maximum number of edges in the path.

NoteThe answer for the first sample input is 2: . Note that you cannot traverse  because edge  appears earlier in the input than the other two edges and hence cannot be picked/traversed after either of the other two edges.In the second sample, it's optimal to pick 1-st, 3-rd and 5-th edges to get the optimal answer: .


You have a full binary tree having infinite levels.Each node has an initial value. If a node has value x, then its left child has value 2·x and its right child has value 2·x + 1. The value of the root is 1. You need to answer Q queries. There are 3 types of queries:  Cyclically shift the values of all nodes on the same level as node with value X by K units. (The values/nodes of any other level are not affected). Cyclically shift the nodes on the same level as node with value X by K units. (The subtrees of these nodes will move along with them). Print the value of every node encountered on the simple path from the node with value X to the root.Positive K implies right cyclic shift and negative K implies left cyclic shift. It is guaranteed that atleast one type 3 query is present.

The first line contains a single integer Q (1 ≤ Q ≤ 105). Then Q queries follow, one per line:   Queries of type 1 and 2 have the following format: T X K (1 ≤ T ≤ 2; 1 ≤ X ≤ 1018; 0 ≤ |K| ≤ 1018), where T is type of the query. Queries of type 3 have the following format: 3 X (1 ≤ X ≤ 1018).

For each query of type 3, print the values of all nodes encountered in descending order.

NoteFollowing are the images of the first 4 levels of the tree in the first test case:Original:    After query 1 2 1:    After query 2 4 -1:


Santa has an infinite number of candies for each of $$$m$$$ flavours. You are given a rooted tree with $$$n$$$ vertices. The root of the tree is the vertex $$$1$$$. Each vertex contains exactly one candy. The $$$i$$$-th vertex has a candy of flavour $$$f_i$$$.Sometimes Santa fears that candies of flavour $$$k$$$ have melted. He chooses any vertex $$$x$$$ randomly and sends the subtree of $$$x$$$ to the Bakers for a replacement. In a replacement, all the candies with flavour $$$k$$$ are replaced with a new candy of the same flavour. The candies which are not of flavour $$$k$$$ are left unchanged. After the replacement, the tree is restored.The actual cost of replacing one candy of flavour $$$k$$$ is $$$c_k$$$ (given for each $$$k$$$). The Baker keeps the price fixed in order to make calculation simple. Every time when a subtree comes for a replacement, the Baker charges $$$C$$$, no matter which subtree it is and which flavour it is.Suppose that for a given flavour $$$k$$$ the probability that Santa chooses a vertex for replacement is same for all the vertices. You need to find out the expected value of error in calculating the cost of replacement of flavour $$$k$$$. The error in calculating the cost is defined as follows.$$$$$$ Error\ E(k) =\ (Actual Cost\ –\ Price\ charged\ by\ the\ Bakers) ^ 2.$$$$$$Note that the actual cost is the cost of replacement of one candy of the flavour $$$k$$$ multiplied by the number of candies in the subtree.Also, sometimes Santa may wish to replace a candy at vertex $$$x$$$ with a candy of some flavour from his pocket.You need to handle two types of operations:   Change the flavour of the candy at vertex $$$x$$$ to $$$w$$$.  Calculate the expected value of error in calculating the cost of replacement for a given flavour $$$k$$$.

The first line of the input contains four integers $$$n$$$ ($$$2 \leqslant n \leqslant 5 \cdot 10^4$$$), $$$m$$$, $$$q$$$, $$$C$$$ ($$$1 \leqslant m, q \leqslant 5 \cdot 10^4$$$, $$$0 \leqslant C \leqslant 10^6$$$) — the number of nodes, total number of different flavours of candies, the number of queries and the price charged by the Bakers for replacement, respectively. The second line contains $$$n$$$ integers $$$f_1, f_2, \dots, f_n$$$ ($$$1 \leqslant f_i \leqslant m$$$), where $$$f_i$$$ is the initial flavour of the candy in the $$$i$$$-th node. The third line contains $$$n - 1$$$ integers $$$p_2, p_3, \dots, p_n$$$ ($$$1 \leqslant p_i \leqslant n$$$), where $$$p_i$$$ is the parent of the $$$i$$$-th node. The next line contains $$$m$$$ integers $$$c_1, c_2, \dots c_m$$$ ($$$1 \leqslant c_i \leqslant 10^2$$$), where $$$c_i$$$ is the cost of replacing one candy of flavour $$$i$$$. The next $$$q$$$ lines describe the queries. Each line starts with an integer $$$t$$$ ($$$1 \leqslant t \leqslant 2$$$) — the type of the query. If $$$t = 1$$$, then the line describes a query of the first type. Two integers $$$x$$$ and $$$w$$$ follow ($$$1 \leqslant  x \leqslant  n$$$, $$$1 \leqslant  w \leqslant m$$$), it means that Santa replaces the candy at vertex $$$x$$$ with flavour $$$w$$$. Otherwise, if $$$t = 2$$$, the line describes a query of the second type and an integer $$$k$$$ ($$$1 \leqslant k \leqslant m$$$) follows, it means that you should print the expected value of the error in calculating the cost of replacement for a given flavour $$$k$$$. The vertices are indexed from $$$1$$$ to $$$n$$$. Vertex $$$1$$$ is the root.

Output the answer to each query of the second type in a separate line. Your answer is considered correct if its absolute or relative error does not exceed $$$10^{-6}$$$. Formally, let your answer be $$$a$$$, and the jury's answer be $$$b$$$. The checker program considers your answer correct if and only if $$$\frac{|a-b|}{max(1,b)}\leqslant 10^{-6}$$$.

NoteFor $$$1$$$-st query, the error in calculating the cost of replacement for flavour $$$1$$$ if vertex $$$1$$$, $$$2$$$ or $$$3$$$ is chosen are $$$66^2$$$, $$$66^2$$$ and $$$(-7)^2$$$ respectively. Since the probability of choosing any vertex is same, therefore the expected value of error is $$$\frac{66^2+66^2+(-7)^2}{3}$$$.Similarly, for $$$2$$$-nd query the expected value of error is $$$\frac{41^2+(-7)^2+(-7)^2}{3}$$$.After $$$3$$$-rd query, the flavour at vertex $$$2$$$ changes from $$$1$$$ to $$$3$$$.For $$$4$$$-th query, the expected value of error is $$$\frac{(-7)^2+(-7)^2+(-7)^2}{3}$$$.Similarly, for $$$5$$$-th query, the expected value of error is $$$\frac{89^2+41^2+(-7)^2}{3}$$$.


You are given a following process. There is a platform with $$$n$$$ columns. $$$1 \times 1$$$ squares are appearing one after another in some columns on this platform. If there are no squares in the column, a square will occupy the bottom row. Otherwise a square will appear at the top of the highest square of this column. When all of the $$$n$$$ columns have at least one square in them, the bottom row is being removed. You will receive $$$1$$$ point for this, and all the squares left will fall down one row. You task is to calculate the amount of points you will receive.

The first line of input contain 2 integer numbers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the length of the platform and the number of the squares. The next line contain $$$m$$$ integer numbers $$$c_1, c_2, \dots, c_m$$$ ($$$1 \le c_i \le n$$$) — column in which $$$i$$$-th square will appear.

Print one integer — the amount of points you will receive.

NoteIn the sample case the answer will be equal to $$$2$$$ because after the appearing of $$$6$$$-th square will be removed one row (counts of the squares on the platform will look like $$$[2~ 3~ 1]$$$, and after removing one row will be $$$[1~ 2~ 0]$$$).After the appearing of $$$9$$$-th square counts will be $$$[2~ 3~ 1]$$$, and after removing one row it will look like $$$[1~ 2~ 0]$$$.So the answer will be equal to $$$2$$$.


Japate, while traveling through the forest of Mala, saw N bags of gold lying in a row. Each bag has some distinct weight of gold between 1 to N. Japate can carry only one bag of gold with him, so he uses the following strategy to choose a bag.Initially, he starts with an empty bag (zero weight). He considers the bags in some order. If the current bag has a higher weight than the bag in his hand, he picks the current bag.Japate put the bags in some order. Japate realizes that he will pick A bags, if he starts picking bags from the front, and will pick B bags, if he starts picking bags from the back. By picking we mean replacing the bag in his hand with the current one.Now he wonders how many permutations of bags are possible, in which he picks A bags from the front and B bags from back using the above strategy.Since the answer can be very large, output it modulo 998244353.

The only line of input contains three space separated integers N (1 ≤ N ≤ 105), A and B (0 ≤ A, B ≤ N).

Output a single integer — the number of valid permutations modulo 998244353.

NoteIn sample case 1, the only possible permutation is [1]In sample cases 2 and 3, only two permutations of size 2 are possible:{[1, 2], [2, 1]}. The values of a and b for first permutation is 2 and 1, and for the second permutation these values are 1 and 2. In sample case 4, out of 120 permutations of [1, 2, 3, 4, 5] possible, only 22 satisfy the given constraints of a and b.


Magnus decided to play a classic chess game. Though what he saw in his locker shocked him! His favourite chessboard got broken into 4 pieces, each of size n by n, n is always odd. And what's even worse, some squares were of wrong color. j-th square of the i-th row of k-th piece of the board has color ak, i, j; 1 being black and 0 being white. Now Magnus wants to change color of some squares in such a way that he recolors minimum number of squares and obtained pieces form a valid chessboard. Every square has its color different to each of the neightbouring by side squares in a valid board. Its size should be 2n by 2n. You are allowed to move pieces but not allowed to rotate or flip them.

The first line contains odd integer n (1 ≤ n ≤ 100) — the size of all pieces of the board.  Then 4 segments follow, each describes one piece of the board. Each consists of n lines of n characters; j-th one of i-th line is equal to 1 if the square is black initially and 0 otherwise. Segments are separated by an empty line.

Print one number — minimum number of squares Magnus should recolor to be able to obtain a valid chessboard.


Your friend Mishka and you attend a calculus lecture. Lecture lasts n minutes. Lecturer tells ai theorems during the i-th minute.Mishka is really interested in calculus, though it is so hard to stay awake for all the time of lecture. You are given an array t of Mishka's behavior. If Mishka is asleep during the i-th minute of the lecture then ti will be equal to 0, otherwise it will be equal to 1. When Mishka is awake he writes down all the theorems he is being told — ai during the i-th minute. Otherwise he writes nothing.You know some secret technique to keep Mishka awake for k minutes straight. However you can use it only once. You can start using it at the beginning of any minute between 1 and n - k + 1. If you use it on some minute i then Mishka will be awake during minutes j such that  and will write down all the theorems lecturer tells.You task is to calculate the maximum number of theorems Mishka will be able to write down if you use your technique only once to wake him up.

The first line of the input contains two integer numbers n and k (1 ≤ k ≤ n ≤ 105) — the duration of the lecture in minutes and the number of minutes you can keep Mishka awake. The second line of the input contains n integer numbers a1, a2, ... an (1 ≤ ai ≤ 104) — the number of theorems lecturer tells during the i-th minute. The third line of the input contains n integer numbers t1, t2, ... tn (0 ≤ ti ≤ 1) — type of Mishka's behavior at the i-th minute of the lecture.

Print only one integer — the maximum number of theorems Mishka will be able to write down if you use your technique only once to wake him up.

NoteIn the sample case the better way is to use the secret technique at the beginning of the third minute. Then the number of theorems Mishka will be able to write down will be equal to 16.


You are given a string s consisting of n lowercase Latin letters.Let's denote k-substring of s as a string subsk = sksk + 1..sn + 1 - k. Obviously, subs1 = s, and there are exactly  such substrings.Let's call some string t an odd proper suprefix of a string T iff the following conditions are met: |T| > |t|;  |t| is an odd number;  t is simultaneously a prefix and a suffix of T.For evey k-substring () of s you have to calculate the maximum length of its odd proper suprefix.

The first line contains one integer n (2 ≤ n ≤ 106) — the length s. The second line contains the string s consisting of n lowercase Latin letters.

Print  integers. i-th of them should be equal to maximum length of an odd proper suprefix of i-substring of s (or  - 1, if there is no such string that is an odd proper suprefix of i-substring).

NoteThe answer for first sample test is folowing:   1-substring: bcabcabcabcabca  2-substring: cabcabcabcabc  3-substring: abcabcabcab  4-substring: bcabcabca  5-substring: cabcabc  6-substring: abcab  7-substring: bca  8-substring: c


One day Polycarp decided to rewatch his absolute favourite episode of well-known TV series "Tufurama". He was pretty surprised when he got results only for season 7 episode 3 with his search query of "Watch Tufurama season 3 episode 7 online full hd free". This got Polycarp confused — what if he decides to rewatch the entire series someday and won't be able to find the right episodes to watch? Polycarp now wants to count the number of times he will be forced to search for an episode using some different method.TV series have n seasons (numbered 1 through n), the i-th season has ai episodes (numbered 1 through ai). Polycarp thinks that if for some pair of integers x and y (x < y) exist both season x episode y and season y episode x then one of these search queries will include the wrong results. Help Polycarp to calculate the number of such pairs!

The first line contains one integer n (1  ≤ n  ≤  2·105) — the number of seasons. The second line contains n integers separated by space a1, a2, ..., an (1 ≤ ai ≤ 109) — number of episodes in each season.

Print one integer — the number of pairs x and y (x < y) such that there exist both season x episode y and season y episode x.

NotePossible pairs in the second example:  x = 1, y = 2 (season 1 episode 2  season 2 episode 1);  x = 2, y = 3 (season 2 episode 3  season 3 episode 2);  x = 1, y = 3 (season 1 episode 3  season 3 episode 1). In the third example:  x = 1, y = 2 (season 1 episode 2  season 2 episode 1);  x = 1, y = 3 (season 1 episode 3  season 3 episode 1).


You are given a set of n elements indexed from 1 to n. The weight of i-th element is wi. The weight of some subset of a given set is denoted as . The weight of some partition R of a given set into k subsets is  (recall that a partition of a given set is a set of its subsets such that every element of the given set belongs to exactly one subset in partition).Calculate the sum of weights of all partitions of a given set into exactly k non-empty subsets, and print it modulo 109 + 7. Two partitions are considered different iff there exist two elements x and y such that they belong to the same set in one of the partitions, and to different sets in another partition.

The first line contains two integers n and k (1 ≤ k ≤ n ≤ 2·105) — the number of elements and the number of subsets in each partition, respectively. The second line contains n integers wi (1 ≤ wi ≤ 109)— weights of elements of the set.

Print one integer — the sum of weights of all partitions of a given set into k non-empty subsets, taken modulo 109 + 7.


Polycarp has created his own training plan to prepare for the programming contests. He will train for $$$n$$$ days, all days are numbered from $$$1$$$ to $$$n$$$, beginning from the first.On the $$$i$$$-th day Polycarp will necessarily solve $$$a_i$$$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems.Determine the index of day when Polycarp will celebrate the equator.

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 200\,000$$$) — the number of days to prepare for the programming contests. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10\,000$$$), where $$$a_i$$$ equals to the number of problems, which Polycarp will solve on the $$$i$$$-th day.

Print the index of the day when Polycarp will celebrate the equator.

NoteIn the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $$$4$$$ out of $$$7$$$ scheduled problems on four days of the training.In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (inclusive) he will solve $$$6$$$ out of $$$12$$$ scheduled problems on six days of the training.


You are given a positive integer $$$n$$$, written without leading zeroes (for example, the number 04 is incorrect). In one operation you can delete any digit of the given integer so that the result remains a positive integer without leading zeros.Determine the minimum number of operations that you need to consistently apply to the given integer $$$n$$$ to make from it the square of some positive integer or report that it is impossible.An integer $$$x$$$ is the square of some positive integer if and only if $$$x=y^2$$$ for some positive integer $$$y$$$.

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^{9}$$$). The number is given without leading zeroes.

If it is impossible to make the square of some positive integer from $$$n$$$, print -1. In the other case, print the minimal number of operations required to do it.

NoteIn the first example we should delete from $$$8314$$$ the digits $$$3$$$ and $$$4$$$. After that $$$8314$$$ become equals to $$$81$$$, which is the square of the integer $$$9$$$.In the second example the given $$$625$$$ is the square of the integer $$$25$$$, so you should not delete anything. In the third example it is impossible to make the square from $$$333$$$, so the answer is -1.


You are given an array of positive integers. While there are at least two equal elements, we will perform the following operation. We choose the smallest value $$$x$$$ that occurs in the array $$$2$$$ or more times. Take the first two occurrences of $$$x$$$ in this array (the two leftmost occurrences). Remove the left of these two occurrences, and the right one is replaced by the sum of this two values (that is, $$$2 \cdot x$$$).Determine how the array will look after described operations are performed.For example, consider the given array looks like $$$[3, 4, 1, 2, 2, 1, 1]$$$. It will be changed in the following way: $$$[3, 4, 1, 2, 2, 1, 1]~\rightarrow~[3, 4, 2, 2, 2, 1]~\rightarrow~[3, 4, 4, 2, 1]~\rightarrow~[3, 8, 2, 1]$$$.If the given array is look like $$$[1, 1, 3, 1, 1]$$$ it will be changed in the following way: $$$[1, 1, 3, 1, 1]~\rightarrow~[2, 3, 1, 1]~\rightarrow~[2, 3, 2]~\rightarrow~[3, 4]$$$.

The first line contains a single integer $$$n$$$ ($$$2 \le n \le 150\,000$$$) — the number of elements in the array. The second line contains a sequence from $$$n$$$ elements $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^{9}$$$) — the elements of the array.

In the first line print an integer $$$k$$$ — the number of elements in the array after all the performed operations. In the second line print $$$k$$$ integers — the elements of the array after all the performed operations.

NoteThe first two examples were considered in the statement.In the third example all integers in the given array are distinct, so it will not change.


There are $$$n$$$ consecutive seat places in a railway carriage. Each place is either empty or occupied by a passenger.The university team for the Olympiad consists of $$$a$$$ student-programmers and $$$b$$$ student-athletes. Determine the largest number of students from all $$$a+b$$$ students, which you can put in the railway carriage so that:  no student-programmer is sitting next to the student-programmer;  and no student-athlete is sitting next to the student-athlete. In the other words, there should not be two consecutive (adjacent) places where two student-athletes or two student-programmers are sitting.Consider that initially occupied seat places are occupied by jury members (who obviously are not students at all).

The first line contain three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$1 \le n \le 2\cdot10^{5}$$$, $$$0 \le a, b \le 2\cdot10^{5}$$$, $$$a + b > 0$$$) — total number of seat places in the railway carriage, the number of student-programmers and the number of student-athletes. The second line contains a string with length $$$n$$$, consisting of characters "." and "*". The dot means that the corresponding place is empty. The asterisk means that the corresponding place is occupied by the jury member.

Print the largest number of students, which you can put in the railway carriage so that no student-programmer is sitting next to a student-programmer and no student-athlete is sitting next to a student-athlete.

NoteIn the first example you can put all student, for example, in the following way: *.AB*In the second example you can put four students, for example, in the following way: *BAB*BIn the third example you can put seven students, for example, in the following way: B*ABAB**A*BThe letter A means a student-programmer, and the letter B — student-athlete.


The cities of Byteland and Berland are located on the axis $$$Ox$$$. In addition, on this axis there are also disputed cities, which belong to each of the countries in their opinion. Thus, on the line $$$Ox$$$ there are three types of cities:  the cities of Byteland,  the cities of Berland,  disputed cities. Recently, the project BNET has been launched — a computer network of a new generation. Now the task of the both countries is to connect the cities so that the network of this country is connected.The countries agreed to connect the pairs of cities with BNET cables in such a way that:  If you look at the only cities of Byteland and the disputed cities, then in the resulting set of cities, any city should be reachable from any other one by one or more cables,  If you look at the only cities of Berland and the disputed cities, then in the resulting set of cities, any city should be reachable from any other one by one or more cables. Thus, it is necessary to choose a set of pairs of cities to connect by cables in such a way that both conditions are satisfied simultaneously. Cables allow bi-directional data transfer. Each cable connects exactly two distinct cities.The cost of laying a cable from one city to another is equal to the distance between them. Find the minimum total cost of laying a set of cables so that two subsets of cities (Byteland and disputed cities, Berland and disputed cities) are connected.Each city is a point on the line $$$Ox$$$. It is technically possible to connect the cities $$$a$$$ and $$$b$$$ with a cable so that the city $$$c$$$ ($$$a < c < b$$$) is not connected to this cable, where $$$a$$$, $$$b$$$ and $$$c$$$ are simultaneously coordinates of the cities $$$a$$$, $$$b$$$ and $$$c$$$.

The first line contains a single integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^{5}$$$) — the number of cities. The following $$$n$$$ lines contains an integer $$$x_i$$$ and the letter $$$c_i$$$ ($$$-10^{9} \le x_i \le 10^{9}$$$) — the coordinate of the city and its type. If the city belongs to Byteland, $$$c_i$$$ equals to 'B'. If the city belongs to Berland, $$$c_i$$$ equals to «R». If the city is disputed, $$$c_i$$$ equals to 'P'.  All cities have distinct coordinates. Guaranteed, that the cities are given in the increasing order of their coordinates.

Print the minimal total length of such set of cables, that if we delete all Berland cities ($$$c_i$$$='R'), it will be possible to find a way from any remaining city to any other remaining city, moving only by cables. Similarly, if we delete all Byteland cities ($$$c_i$$$='B'), it will be possible to find a way from any remaining city to any other remaining city, moving only by cables.

NoteIn the first example, you should connect the first city with the second, the second with the third, and the third with the fourth. The total length of the cables will be $$$5 + 3 + 4 = 12$$$.In the second example there are no disputed cities, so you need to connect all the neighboring cities of Byteland and all the neighboring cities of Berland. The cities of Berland have coordinates $$$10, 21, 32$$$, so to connect them you need two cables of length $$$11$$$ and $$$11$$$. The cities of Byteland have coordinates $$$14$$$ and $$$16$$$, so to connect them you need one cable of length $$$2$$$. Thus, the total length of all cables is $$$11 + 11 + 2 = 24$$$.


You are given an undirected graph, consisting of $$$n$$$ vertices and $$$m$$$ edges. The graph does not necessarily connected. Guaranteed, that the graph does not contain multiple edges (more than one edges between a pair of vertices) or loops (edges from a vertex to itself).A cycle in a graph is called a simple, if it contains each own vertex exactly once. So simple cycle doesn't allow to visit a vertex more than once in a cycle.Determine the edges, which belong to exactly on one simple cycle.

The first line contain two integers $$$n$$$ and $$$m$$$ $$$(1 \le n \le 100\,000$$$, $$$0 \le m \le \min(n \cdot (n - 1) / 2, 100\,000))$$$ — the number of vertices and the number of edges. Each of the following $$$m$$$ lines contain two integers $$$u$$$ and $$$v$$$ ($$$1 \le u, v \le n$$$, $$$u \neq v$$$) — the description of the edges.

In the first line print the number of edges, which belong to exactly one simple cycle. In the second line print the indices of edges, which belong to exactly one simple cycle, in increasing order. The edges are numbered from one in the same order as they are given in the input.


You are given n points on Cartesian plane. Every point is a lattice point (i. e. both of its coordinates are integers), and all points are distinct.You may draw two straight lines (not necessarily distinct). Is it possible to do this in such a way that every point lies on at least one of these lines?

The first line contains one integer n (1 ≤ n ≤ 105) — the number of points you are given. Then n lines follow, each line containing two integers xi and yi (|xi|, |yi| ≤ 109)— coordinates of i-th point. All n points are distinct.

If it is possible to draw two straight lines in such a way that each of given points belongs to at least one of these lines, print YES. Otherwise, print NO.

NoteIn the first example it is possible to draw two lines, the one containing the points 1, 3 and 5, and another one containing two remaining points.


You are given a tree (a graph with n vertices and n - 1 edges in which it's possible to reach any vertex from any other vertex using only its edges).A vertex can be destroyed if this vertex has even degree. If you destroy a vertex, all edges connected to it are also deleted.Destroy all vertices in the given tree or determine that it is impossible.

The first line contains integer n (1 ≤ n ≤ 2·105) — number of vertices in a tree. The second line contains n integers p1, p2, ..., pn (0 ≤ pi ≤ n). If pi ≠ 0 there is an edge between vertices i and pi. It is guaranteed that the given graph is a tree.

If it's possible to destroy all vertices, print "YES" (without quotes), otherwise print "NO" (without quotes). If it's possible to destroy all vertices, in the next n lines print the indices of the vertices in order you destroy them. If there are multiple correct answers, print any.

NoteIn the first example at first you have to remove the vertex with index 1 (after that, the edges (1, 2) and (1, 4) are removed), then the vertex with index 2 (and edges (2, 3) and (2, 5) are removed). After that there are no edges in the tree, so you can remove remaining vertices in any order.


You are given two integers $$$a$$$ and $$$b$$$. Moreover, you are given a sequence $$$s_0, s_1, \dots, s_{n}$$$. All values in $$$s$$$ are integers $$$1$$$ or $$$-1$$$. It's known that sequence is $$$k$$$-periodic and $$$k$$$ divides $$$n+1$$$. In other words, for each $$$k \leq i \leq n$$$ it's satisfied that $$$s_{i} = s_{i - k}$$$.Find out the non-negative remainder of division of $$$\sum \limits_{i=0}^{n} s_{i} a^{n - i} b^{i}$$$ by $$$10^{9} + 9$$$.Note that the modulo is unusual!

The first line contains four integers $$$n, a, b$$$ and $$$k$$$ $$$(1 \leq n \leq 10^{9}, 1 \leq a, b \leq 10^{9}, 1 \leq k \leq 10^{5})$$$. The second line contains a sequence of length $$$k$$$ consisting of characters '+' and '-'.  If the $$$i$$$-th character (0-indexed) is '+', then $$$s_{i} = 1$$$, otherwise $$$s_{i} = -1$$$. Note that only the first $$$k$$$ members of the sequence are given, the rest can be obtained using the periodicity property.

Output a single integer — value of given expression modulo $$$10^{9} + 9$$$.


A rectangle with sides $$$A$$$ and $$$B$$$ is cut into rectangles with cuts parallel to its sides. For example, if $$$p$$$ horizontal and $$$q$$$ vertical cuts were made, $$$(p + 1) \cdot (q + 1)$$$ rectangles were left after the cutting. After the cutting, rectangles were of $$$n$$$ different types. Two rectangles are different if at least one side of one rectangle isn't equal to the corresponding side of the other. Note that the rectangle can't be rotated, this means that rectangles $$$a \times b$$$ and $$$b \times a$$$ are considered different if $$$a \neq b$$$.For each type of rectangles, lengths of the sides of rectangles are given along with the amount of the rectangles of this type that were left after cutting the initial rectangle.Calculate the amount of pairs $$$(A; B)$$$ such as the given rectangles could be created by cutting the rectangle with sides of lengths $$$A$$$ and $$$B$$$. Note that pairs $$$(A; B)$$$ and $$$(B; A)$$$ are considered different when $$$A \neq B$$$.

The first line consists of a single integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^{5}$$$) — amount of different types of rectangles left after cutting the initial rectangle. The next $$$n$$$ lines each consist of three integers $$$w_{i}, h_{i}, c_{i}$$$ $$$(1 \leq w_{i}, h_{i}, c_{i} \leq 10^{12})$$$ — the lengths of the sides of the rectangles of this type and the amount of the rectangles of this type. It is guaranteed that the rectangles of the different types are different.

Output one integer — the answer to the problem.

NoteIn the first sample there are three suitable pairs: $$$(1; 9)$$$, $$$(3; 3)$$$ and $$$(9; 1)$$$.In the second sample case there are 6 suitable pairs: $$$(2; 220)$$$, $$$(4; 110)$$$, $$$(8; 55)$$$, $$$(10; 44)$$$, $$$(20; 22)$$$ and $$$(40; 11)$$$.Here the sample of cut for $$$(20; 22)$$$.  The third sample has no suitable pairs.


Petya has a polygon consisting of $$$n$$$ vertices. All sides of the Petya's polygon are parallel to the coordinate axes, and each two adjacent sides of the Petya's polygon are perpendicular. It is guaranteed that the polygon is simple, that is, it doesn't have self-intersections and self-touches. All internal area of the polygon (borders are not included) was painted in black color by Petya.Also, Petya has a rectangular window, defined by its coordinates, through which he looks at the polygon. A rectangular window can not be moved. The sides of the rectangular window are parallel to the coordinate axes.    Blue color represents the border of a polygon, red color is the Petya's window. The answer in this case is 2. Determine the number of black connected areas of Petya's polygon, which can be seen through the rectangular window.

The first line contain four integers $$$x_1, y_1, x_2, y_2$$$ ($$$x_1 < x_2$$$, $$$y_2 < y_1$$$) — the coordinates of top-left and bottom-right corners of the rectangular window.  The second line contains a single integer $$$n$$$ ($$$4 \le n \le 15\,000$$$) — the number of vertices in Petya's polygon. Each of the following $$$n$$$ lines contains two integers — the coordinates of vertices of the Petya's polygon in counterclockwise order. Guaranteed, that the given polygon satisfies the conditions described in the statement. All coordinates of the rectangular window and all coordinates of the vertices of the polygon are non-negative and do not exceed $$$15\,000$$$.

Print the number of black connected areas of Petya's polygon, which can be seen through the rectangular window.

NoteThe example corresponds to the picture above.


You are given a string $$$s$$$. You should answer $$$n$$$ queries. The $$$i$$$-th query consists of integer $$$k_i$$$ and string $$$m_i$$$. The answer for this query is the minimum length of such a string $$$t$$$ that $$$t$$$ is a substring of $$$s$$$ and $$$m_i$$$ has at least $$$k_i$$$ occurrences as a substring in $$$t$$$.A substring of a string is a continuous segment of characters of the string.It is guaranteed that for any two queries the strings $$$m_i$$$ from these queries are different.

The first line contains string $$$s$$$ $$$(1 \leq \left | s \right | \leq 10^{5})$$$. The second line contains an integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$). Each of next $$$n$$$ lines contains an integer $$$k_i$$$ $$$(1 \leq k_i \leq |s|)$$$ and a non-empty string $$$m_i$$$ — parameters of the query with number $$$i$$$, in this order. All strings in input consists of lowercase English letters. Sum of length of all strings in input doesn't exceed $$$10^5$$$. All $$$m_i$$$ are distinct.

For each query output the answer for it in a separate line. If a string $$$m_{i}$$$ occurs in $$$s$$$ less that $$$k_{i}$$$ times, output -1.

abbb
7
4 b
1 ab
3 bb
1 abb
2 bbb
1 a
2 abbb


A chip was placed on a field with coordinate system onto point (0, 0).Every second the chip moves randomly. If the chip is currently at a point (x, y), after a second it moves to the point (x - 1, y) with probability p1, to the point (x, y - 1) with probability p2, to the point (x + 1, y) with probability p3 and to the point (x, y + 1) with probability p4. It's guaranteed that p1 + p2 + p3 + p4 = 1. The moves are independent.Find out the expected time after which chip will move away from origin at a distance greater than R (i.e.  will be satisfied).

First line contains five integers R, a1, a2, a3 and a4 (0 ≤ R ≤ 50, 1 ≤ a1, a2, a3, a4 ≤ 1000). Probabilities pi can be calculated using formula .

It can be shown that answer for this problem is always a rational number of form , where . Print P·Q - 1 modulo 109 + 7.

NoteIn the first example initially the chip is located at a distance 0 from origin. In one second chip will move to distance 1 is some direction, so distance to origin will become 1.Answers to the second and the third tests:  and .


Let's define a split of $$$n$$$ as a nonincreasing sequence of positive integers, the sum of which is $$$n$$$. For example, the following sequences are splits of $$$8$$$: $$$[4, 4]$$$, $$$[3, 3, 2]$$$, $$$[2, 2, 1, 1, 1, 1]$$$, $$$[5, 2, 1]$$$.The following sequences aren't splits of $$$8$$$: $$$[1, 7]$$$, $$$[5, 4]$$$, $$$[11, -3]$$$, $$$[1, 1, 4, 1, 1]$$$.The weight of a split is the number of elements in the split that are equal to the first element. For example, the weight of the split $$$[1, 1, 1, 1, 1]$$$ is $$$5$$$, the weight of the split $$$[5, 5, 3, 3, 3]$$$ is $$$2$$$ and the weight of the split $$$[9]$$$ equals $$$1$$$.For a given $$$n$$$, find out the number of different weights of its splits.

The first line contains one integer $$$n$$$ ($$$1 \leq n \leq 10^9$$$).

NoteIn the first sample, there are following possible weights of splits of $$$7$$$:Weight 1: [$$$\textbf 7$$$] Weight 2: [$$$\textbf 3$$$, $$$\textbf 3$$$, 1] Weight 3: [$$$\textbf 2$$$, $$$\textbf 2$$$, $$$\textbf 2$$$, 1] Weight 7: [$$$\textbf 1$$$, $$$\textbf 1$$$, $$$\textbf 1$$$, $$$\textbf 1$$$, $$$\textbf 1$$$, $$$\textbf 1$$$, $$$\textbf 1$$$]


There are n incoming messages for Vasya. The i-th message is going to be received after ti minutes. Each message has a cost, which equals to A initially. After being received, the cost of a message decreases by B each minute (it can become negative). Vasya can read any message after receiving it at any moment of time. After reading the message, Vasya's bank account receives the current cost of this message. Initially, Vasya's bank account is at 0.Also, each minute Vasya's bank account receives C·k, where k is the amount of received but unread messages.Vasya's messages are very important to him, and because of that he wants to have all messages read after T minutes.Determine the maximum amount of money Vasya's bank account can hold after T minutes.

The first line contains five integers n, A, B, C and T (1 ≤ n, A, B, C, T ≤ 1000). The second string contains n integers ti (1 ≤ ti ≤ T).

Output one integer  — the answer to the problem.

NoteIn the first sample the messages must be read immediately after receiving, Vasya receives A points for each message, n·A = 20 in total.In the second sample the messages can be read at any integer moment.In the third sample messages must be read at the moment T. This way Vasya has 1, 2, 3, 4 and 0 unread messages at the corresponding minutes, he gets 40 points for them. When reading messages, he receives (5 - 4·3) + (5 - 3·3) + (5 - 2·3) + (5 - 1·3) + 5 =  - 5 points. This is 35 in total.


Arkady is playing Battleship. The rules of this game aren't really important.There is a field of $$$n \times n$$$ cells. There should be exactly one $$$k$$$-decker on the field, i. e. a ship that is $$$k$$$ cells long oriented either horizontally or vertically. However, Arkady doesn't know where it is located. For each cell Arkady knows if it is definitely empty or can contain a part of the ship.Consider all possible locations of the ship. Find such a cell that belongs to the maximum possible number of different locations of the ship.

The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 100$$$) — the size of the field and the size of the ship. The next $$$n$$$ lines contain the field. Each line contains $$$n$$$ characters, each of which is either '#' (denotes a definitely empty cell) or '.' (denotes a cell that can belong to the ship).

Output two integers — the row and the column of a cell that belongs to the maximum possible number of different locations of the ship. If there are multiple answers, output any of them. In particular, if no ship can be placed on the field, you can output any cell.

NoteThe picture below shows the three possible locations of the ship that contain the cell $$$(3, 2)$$$ in the first sample.


$$$k$$$ people want to split $$$n$$$ candies between them. Each candy should be given to exactly one of them or be thrown away.The people are numbered from $$$1$$$ to $$$k$$$, and Arkady is the first of them. To split the candies, Arkady will choose an integer $$$x$$$ and then give the first $$$x$$$ candies to himself, the next $$$x$$$ candies to the second person, the next $$$x$$$ candies to the third person and so on in a cycle. The leftover (the remainder that is not divisible by $$$x$$$) will be thrown away.Arkady can't choose $$$x$$$ greater than $$$M$$$ as it is considered greedy. Also, he can't choose such a small $$$x$$$ that some person will receive candies more than $$$D$$$ times, as it is considered a slow splitting.Please find what is the maximum number of candies Arkady can receive by choosing some valid $$$x$$$.

The only line contains four integers $$$n$$$, $$$k$$$, $$$M$$$ and $$$D$$$ ($$$2 \le n \le 10^{18}$$$, $$$2 \le k \le n$$$, $$$1 \le M \le n$$$, $$$1 \le D \le \min{(n, 1000)}$$$, $$$M \cdot D \cdot k \ge n$$$) — the number of candies, the number of people, the maximum number of candies given to a person at once, the maximum number of times a person can receive candies.

Print a single integer — the maximum possible number of candies Arkady can give to himself. Note that it is always possible to choose some valid $$$x$$$.

NoteIn the first example Arkady should choose $$$x = 4$$$. He will give $$$4$$$ candies to himself, $$$4$$$ candies to the second person, $$$4$$$ candies to the third person, then $$$4$$$ candies to the fourth person and then again $$$4$$$ candies to himself. No person is given candies more than $$$2$$$ times, and Arkady receives $$$8$$$ candies in total.Note that if Arkady chooses $$$x = 5$$$, he will receive only $$$5$$$ candies, and if he chooses $$$x = 3$$$, he will receive only $$$3 + 3 = 6$$$ candies as well as the second person, the third and the fourth persons will receive $$$3$$$ candies, and $$$2$$$ candies will be thrown away. He can't choose $$$x = 1$$$ nor $$$x = 2$$$ because in these cases he will receive candies more than $$$2$$$ times.In the second example Arkady has to choose $$$x = 4$$$, because any smaller value leads to him receiving candies more than $$$1$$$ time.


To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make $$$s$$$ airplanes.A group of $$$k$$$ people decided to make $$$n$$$ airplanes each. They are going to buy several packs of paper, each of them containing $$$p$$$ sheets, and then distribute the sheets between the people. Each person should have enough sheets to make $$$n$$$ airplanes. How many packs should they buy?

The only line contains four integers $$$k$$$, $$$n$$$, $$$s$$$, $$$p$$$ ($$$1 \le k, n, s, p \le 10^4$$$) — the number of people, the number of airplanes each should make, the number of airplanes that can be made using one sheet and the number of sheets in one pack, respectively.

Print a single integer — the minimum number of packs they should buy.

NoteIn the first sample they have to buy $$$4$$$ packs of paper: there will be $$$12$$$ sheets in total, and giving $$$2$$$ sheets to each person is enough to suit everyone's needs.In the second sample they have to buy a pack for each person as they can't share sheets.


A lot of frogs want to cross a river. A river is $$$w$$$ units width, but frogs can only jump $$$l$$$ units long, where $$$l < w$$$. Frogs can also jump on lengths shorter than $$$l$$$. but can't jump longer. Hopefully, there are some stones in the river to help them.The stones are located at integer distances from the banks. There are $$$a_i$$$ stones at the distance of $$$i$$$ units from the bank the frogs are currently at. Each stone can only be used once by one frog, after that it drowns in the water.What is the maximum number of frogs that can cross the river, given that then can only jump on the stones?

The first line contains two integers $$$w$$$ and $$$l$$$ ($$$1 \le l < w \le 10^5$$$) — the width of the river and the maximum length of a frog's jump. The second line contains $$$w - 1$$$ integers $$$a_1, a_2, \ldots, a_{w-1}$$$ ($$$0 \le a_i \le 10^4$$$), where $$$a_i$$$ is the number of stones at the distance $$$i$$$ from the bank the frogs are currently at.

Print a single integer — the maximum number of frogs that can cross the river.

NoteIn the first sample two frogs can use the different stones at the distance $$$5$$$, and one frog can use the stones at the distances $$$3$$$ and then $$$8$$$.In the second sample although there are two stones at the distance $$$5$$$, that does not help. The three paths are: $$$0 \to 3 \to 6 \to 9 \to 10$$$, $$$0 \to 2 \to 5 \to 8 \to 10$$$, $$$0 \to 1 \to 4 \to 7 \to 10$$$.


Arkady's code contains $$$n$$$ variables. Each variable has a unique name consisting of lowercase English letters only. One day Arkady decided to shorten his code.He wants to replace each variable name with its non-empty prefix so that these new names are still unique (however, a new name of some variable can coincide with some old name of another or same variable). Among such possibilities he wants to find the way with the smallest possible total length of the new names.A string $$$a$$$ is a prefix of a string $$$b$$$ if you can delete some (possibly none) characters from the end of $$$b$$$ and obtain $$$a$$$.Please find this minimum possible total length of new names.

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of variables. The next $$$n$$$ lines contain variable names, one per line. Each name is non-empty and contains only lowercase English letters. The total length of these strings is not greater than $$$10^5$$$. The variable names are distinct.

Print a single integer — the minimum possible total length of new variable names.

NoteIn the first example one of the best options is to shorten the names in the given order as "cod", "co", "c".In the second example we can shorten the last name to "aac" and the first name to "a" without changing the other names.


These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $$$1$$$ minute.He was asked to insert one takeoff in the schedule. The takeoff takes $$$1$$$ minute itself, but for safety reasons there should be a time space between the takeoff and any landing of at least $$$s$$$ minutes from both sides.Find the earliest time when Arkady can insert the takeoff.

The first line of input contains two integers $$$n$$$ and $$$s$$$ ($$$1 \le n \le 100$$$, $$$1 \le s \le 60$$$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff. Each of next $$$n$$$ lines contains two integers $$$h$$$ and $$$m$$$ ($$$0 \le h \le 23$$$, $$$0 \le m \le 59$$$) — the time, in hours and minutes, when a plane will land, starting from current moment (i. e. the current time is $$$0$$$ $$$0$$$). These times are given in increasing order.

Print two integers $$$h$$$ and $$$m$$$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff.

NoteIn the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute.In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than $$$24$$$ hours to insert the takeoff.In the third example Arkady can insert the takeoff even between the first landing.


Arkady wants to water his only flower. Unfortunately, he has a very poor watering system that was designed for $$$n$$$ flowers and so it looks like a pipe with $$$n$$$ holes. Arkady can only use the water that flows from the first hole.Arkady can block some of the holes, and then pour $$$A$$$ liters of water into the pipe. After that, the water will flow out from the non-blocked holes proportionally to their sizes $$$s_1, s_2, \ldots, s_n$$$. In other words, if the sum of sizes of non-blocked holes is $$$S$$$, and the $$$i$$$-th hole is not blocked, $$$\frac{s_i \cdot A}{S}$$$ liters of water will flow out of it.What is the minimum number of holes Arkady should block to make at least $$$B$$$ liters of water flow out of the first hole?

The first line contains three integers $$$n$$$, $$$A$$$, $$$B$$$ ($$$1 \le n \le 100\,000$$$, $$$1 \le B \le A \le 10^4$$$) — the number of holes, the volume of water Arkady will pour into the system, and the volume he wants to get out of the first hole. The second line contains $$$n$$$ integers $$$s_1, s_2, \ldots, s_n$$$ ($$$1 \le s_i \le 10^4$$$) — the sizes of the holes.

Print a single integer — the number of holes Arkady should block.

NoteIn the first example Arkady should block at least one hole. After that, $$$\frac{10 \cdot 2}{6} \approx 3.333$$$ liters of water will flow out of the first hole, and that suits Arkady.In the second example even without blocking any hole, $$$\frac{80 \cdot 3}{10} = 24$$$ liters will flow out of the first hole, that is not less than $$$20$$$.In the third example Arkady has to block all holes except the first to make all water flow out of the first hole.


Mancala is a game famous in the Middle East. It is played on a board that consists of 14 holes.   Initially, each hole has $$$a_i$$$ stones. When a player makes a move, he chooses a hole which contains a positive number of stones. He takes all the stones inside it and then redistributes these stones one by one in the next holes in a counter-clockwise direction.Note that the counter-clockwise order means if the player takes the stones from hole $$$i$$$, he will put one stone in the $$$(i+1)$$$-th hole, then in the $$$(i+2)$$$-th, etc. If he puts a stone in the $$$14$$$-th hole, the next one will be put in the first hole.After the move, the player collects all the stones from holes that contain even number of stones. The number of stones collected by player is the score, according to Resli.Resli is a famous Mancala player. He wants to know the maximum score he can obtain after one move.

The only line contains 14 integers $$$a_1, a_2, \ldots, a_{14}$$$ ($$$0 \leq a_i \leq 10^9$$$) — the number of stones in each hole. It is guaranteed that for any $$$i$$$ ($$$1\leq i \leq 14$$$) $$$a_i$$$ is either zero or odd, and there is at least one stone in the board.

Output one integer, the maximum possible score after one move.

NoteIn the first test case the board after the move from the hole with $$$7$$$ stones will look like 1 2 2 0 0 0 0 0 0 0 1 1 1 1. Then the player collects the even numbers and ends up with a score equal to $$$4$$$.


In Aramic language words can only represent objects.Words in Aramic have special properties:   A word is a root if it does not contain the same letter more than once.  A root and all its permutations represent the same object.  The root $$$x$$$ of a word $$$y$$$ is the word that contains all letters that appear in $$$y$$$ in a way that each letter appears once. For example, the root of "aaaa", "aa", "aaa" is "a", the root of "aabb", "bab", "baabb", "ab" is "ab".  Any word in Aramic represents the same object as its root. You have an ancient script in Aramic. What is the number of different objects mentioned in the script?

The first line contains one integer $$$n$$$ ($$$1 \leq n \leq 10^3$$$) — the number of words in the script. The second line contains $$$n$$$ words $$$s_1, s_2, \ldots, s_n$$$ — the script itself. The length of each string does not exceed $$$10^3$$$. It is guaranteed that all characters of the strings are small latin letters.

Output one integer — the number of different objects mentioned in the given ancient Aramic script.

NoteIn the first test, there are two objects mentioned. The roots that represent them are "a","ab".In the second test, there is only one object, its root is "amer", the other strings are just permutations of "amer".


Hag is a very talented person. He has always had an artist inside him but his father forced him to study mechanical engineering.Yesterday he spent all of his time cutting a giant piece of wood trying to make it look like a goose. Anyway, his dad found out that he was doing arts rather than studying mechanics and other boring subjects. He confronted Hag with the fact that he is a spoiled son that does not care about his future, and if he continues to do arts he will cut his 25 Lira monthly allowance.Hag is trying to prove to his dad that the wooden piece is a project for mechanics subject. He also told his dad that the wooden piece is a strictly convex polygon with $$$n$$$ vertices.Hag brought two pins and pinned the polygon with them in the $$$1$$$-st and $$$2$$$-nd vertices to the wall. His dad has $$$q$$$ queries to Hag of two types.   $$$1$$$ $$$f$$$ $$$t$$$: pull a pin from the vertex $$$f$$$, wait for the wooden polygon to rotate under the gravity force (if it will rotate) and stabilize. And then put the pin in vertex $$$t$$$.  $$$2$$$ $$$v$$$: answer what are the coordinates of the vertex $$$v$$$. Please help Hag to answer his father's queries.You can assume that the wood that forms the polygon has uniform density and the polygon has a positive thickness, same in all points. After every query of the 1-st type Hag's dad tries to move the polygon a bit and watches it stabilize again.

The first line contains two integers $$$n$$$ and $$$q$$$ ($$$3\leq n \leq 10\,000$$$, $$$1 \leq q \leq 200000$$$) — the number of vertices in the polygon and the number of queries. The next $$$n$$$ lines describe the wooden polygon, the $$$i$$$-th line contains two integers $$$x_i$$$ and $$$y_i$$$ ($$$|x_i|, |y_i|\leq 10^8$$$) — the coordinates of the $$$i$$$-th vertex of the polygon. It is guaranteed that polygon is strictly convex and the vertices are given in the counter-clockwise order and all vertices are distinct. The next $$$q$$$ lines describe the queries, one per line. Each query starts with its type $$$1$$$ or $$$2$$$. Each query of the first type continues with two integers $$$f$$$ and $$$t$$$ ($$$1 \le f, t \le n$$$) — the vertex the pin is taken from, and the vertex the pin is put to and the polygon finishes rotating. It is guaranteed that the vertex $$$f$$$ contains a pin. Each query of the second type continues with a single integer $$$v$$$ ($$$1 \le v \le n$$$) — the vertex the coordinates of which Hag should tell his father. It is guaranteed that there is at least one query of the second type.

The output should contain the answer to each query of second type — two numbers in a separate line. Your answer is considered correct, if its absolute or relative error does not exceed $$$10^{-4}$$$. Formally, let your answer be $$$a$$$, and the jury's answer be $$$b$$$. Your answer is considered correct if $$$\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-4}$$$

NoteIn the first test note the initial and the final state of the wooden polygon.   Red Triangle is the initial state and the green one is the triangle after rotation around $$$(2,0)$$$.In the second sample note that the polygon rotates $$$180$$$ degrees counter-clockwise or clockwise direction (it does not matter), because Hag's father makes sure that the polygon is stable and his son does not trick him.


Ghosts live in harmony and peace, they travel the space without any purpose other than scare whoever stands in their way.There are $$$n$$$ ghosts in the universe, they move in the $$$OXY$$$ plane, each one of them has its own velocity that does not change in time: $$$\overrightarrow{V} = V_{x}\overrightarrow{i} + V_{y}\overrightarrow{j}$$$ where $$$V_{x}$$$ is its speed on the $$$x$$$-axis and $$$V_{y}$$$ is on the $$$y$$$-axis.A ghost $$$i$$$ has experience value $$$EX_i$$$, which represent how many ghosts tried to scare him in his past. Two ghosts scare each other if they were in the same cartesian point at a moment of time.As the ghosts move with constant speed, after some moment of time there will be no further scaring (what a relief!) and the experience of ghost kind $$$GX = \sum_{i=1}^{n} EX_i$$$ will never increase.Tameem is a red giant, he took a picture of the cartesian plane at a certain moment of time $$$T$$$, and magically all the ghosts were aligned on a line of the form $$$y = a \cdot x + b$$$. You have to compute what will be the experience index of the ghost kind $$$GX$$$ in the indefinite future, this is your task for today.Note that when Tameem took the picture, $$$GX$$$ may already be greater than $$$0$$$, because many ghosts may have scared one another at any moment between $$$[-\infty, T]$$$.

The first line contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$1 \leq n \leq 200000$$$, $$$1 \leq |a| \leq 10^9$$$, $$$0 \le |b| \le 10^9$$$) — the number of ghosts in the universe and the parameters of the straight line. Each of the next $$$n$$$ lines contains three integers $$$x_i$$$, $$$V_{xi}$$$, $$$V_{yi}$$$ ($$$-10^9 \leq x_i \leq 10^9$$$, $$$-10^9 \leq V_{x i}, V_{y i} \leq 10^9$$$), where $$$x_i$$$ is the current $$$x$$$-coordinate of the $$$i$$$-th ghost (and $$$y_i = a \cdot x_i + b$$$). It is guaranteed that no two ghosts share the same initial position, in other words, it is guaranteed that for all $$$(i,j)$$$ $$$x_i \neq x_j$$$ for $$$i \ne j$$$.

Output one line: experience index of the ghost kind $$$GX$$$ in the indefinite future.

NoteThere are four collisions $$$(1,2,T-0.5)$$$, $$$(1,3,T-1)$$$, $$$(2,4,T+1)$$$, $$$(3,4,T+0.5)$$$, where $$$(u,v,t)$$$ means a collision happened between ghosts $$$u$$$ and $$$v$$$ at moment $$$t$$$. At each collision, each ghost gained one experience point, this means that $$$GX = 4 \cdot 2 = 8$$$.In the second test, all points will collide when $$$t = T + 1$$$.   The red arrow represents the 1-st ghost velocity, orange represents the 2-nd ghost velocity, and blue represents the 3-rd ghost velocity.


String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001".You are given a correct string s.You can perform two different operations on this string:   swap any pair of adjacent characters (for example, "101"  "110");  replace "11" with "1" (for example, "110"  "10"). Let val(s) be such a number that s is its binary representation.Correct string a is less than some other correct string b iff val(a) < val(b).Your task is to find the minimum correct string that you can obtain from the given one using the operations described above. You can use these operations any number of times in any order (or even use no operations at all).

The first line contains integer number n (1 ≤ n ≤ 100) — the length of string s. The second line contains the string s consisting of characters "0" and "1". It is guaranteed that the string s is correct.

Print one string — the minimum correct string that you can obtain from the given one.

NoteIn the first example you can obtain the answer by the following sequence of operations: "1001"  "1010"  "1100"  "100".In the second example you can't obtain smaller answer no matter what operations you use.


Ivar the Boneless is a great leader. He is trying to capture Kattegat from Lagertha. The war has begun and wave after wave Ivar's warriors are falling in battle.Ivar has $$$n$$$ warriors, he places them on a straight line in front of the main gate, in a way that the $$$i$$$-th warrior stands right after $$$(i-1)$$$-th warrior. The first warrior leads the attack.Each attacker can take up to $$$a_i$$$ arrows before he falls to the ground, where $$$a_i$$$ is the $$$i$$$-th warrior's strength.Lagertha orders her warriors to shoot $$$k_i$$$ arrows during the $$$i$$$-th minute, the arrows one by one hit the first still standing warrior. After all Ivar's warriors fall and all the currently flying arrows fly by, Thor smashes his hammer and all Ivar's warriors get their previous strengths back and stand up to fight again. In other words, if all warriors die in minute $$$t$$$, they will all be standing to fight at the end of minute $$$t$$$.The battle will last for $$$q$$$ minutes, after each minute you should tell Ivar what is the number of his standing warriors.

The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n, q \leq 200\,000$$$) — the number of warriors and the number of minutes in the battle. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$) that represent the warriors' strengths. The third line contains $$$q$$$ integers $$$k_1, k_2, \ldots, k_q$$$ ($$$1 \leq k_i \leq 10^{14}$$$), the $$$i$$$-th of them represents Lagertha's order at the $$$i$$$-th minute: $$$k_i$$$ arrows will attack the warriors.

Output $$$q$$$ lines, the $$$i$$$-th of them is the number of standing warriors after the $$$i$$$-th minute.

NoteIn the first example:   after the 1-st minute, the 1-st and 2-nd warriors die.  after the 2-nd minute all warriors die (and all arrows left over are wasted), then they will be revived thus answer is 5 — all warriors are alive.  after the 3-rd minute, the 1-st warrior dies.  after the 4-th minute, the 2-nd warrior takes a hit and his strength decreases by 1.  after the 5-th minute, the 2-nd warrior dies.


You are given a sequence a1, a2, ..., an of one-dimensional segments numbered 1 through n. Your task is to find two distinct indices i and j such that segment ai lies within segment aj.Segment [l1, r1] lies within segment [l2, r2] iff l1 ≥ l2 and r1 ≤ r2.Print indices i and j. If there are multiple answers, print any of them. If no answer exists, print -1 -1.

The first line contains one integer n (1 ≤ n ≤ 3·105) — the number of segments. Each of the next n lines contains two integers li and ri (1 ≤ li ≤ ri ≤ 109) — the i-th segment.

Print two distinct indices i and j such that segment ai lies within segment aj. If there are multiple answers, print any of them. If no answer exists, print -1 -1.

NoteIn the first example the following pairs are considered correct:  (2, 1), (3, 1), (4, 1), (5, 1) — not even touching borders;  (3, 2), (4, 2), (3, 5), (4, 5) — touch one border;  (5, 2), (2, 5) — match exactly.


You are given a sequence of n positive integers d1, d2, ..., dn (d1 < d2 < ... < dn). Your task is to construct an undirected graph such that:  there are exactly dn + 1 vertices;  there are no self-loops;  there are no multiple edges;  there are no more than 106 edges;  its degree set is equal to d. Vertices should be numbered 1 through (dn + 1).Degree sequence is an array a with length equal to the number of vertices in a graph such that ai is the number of vertices adjacent to i-th vertex.Degree set is a sorted in increasing order sequence of all distinct values from the degree sequence.It is guaranteed that there exists such a graph that all the conditions hold, and it contains no more than 106 edges.Print the resulting graph.

The first line contains one integer n (1 ≤ n ≤ 300) — the size of the degree set. The second line contains n integers d1, d2, ..., dn (1 ≤ di ≤ 1000, d1 < d2 < ... < dn) — the degree set.

In the first line print one integer m (1 ≤ m ≤ 106) — the number of edges in the resulting graph. It is guaranteed that there exists such a graph that all the conditions hold and it contains no more than 106 edges. Each of the next m lines should contain two integers vi and ui (1 ≤ vi, ui ≤ dn + 1) — the description of the i-th edge.


You might have heard about the next game in Lara Croft series coming out this year. You also might have watched its trailer. Though you definitely missed the main idea about its plot, so let me lift the veil of secrecy.Lara is going to explore yet another dangerous dungeon. Game designers decided to use good old 2D environment. The dungeon can be represented as a rectangle matrix of n rows and m columns. Cell (x, y) is the cell in the x-th row in the y-th column. Lara can move between the neighbouring by side cells in all four directions.Moreover, she has even chosen the path for herself to avoid all the traps. She enters the dungeon in cell (1, 1), that is top left corner of the matrix. Then she goes down all the way to cell (n, 1) — the bottom left corner. Then she starts moving in the snake fashion — all the way to the right, one cell up, then to the left to the cell in 2-nd column, one cell up. She moves until she runs out of non-visited cells. n and m given are such that she always end up in cell (1, 2).Lara has already moved to a neighbouring cell k times. Can you determine her current position?

The only line contains three integers n, m and k (2 ≤ n, m ≤ 109, n is always even, 0 ≤ k < n·m). Note that k doesn't fit into 32-bit integer type!

Print the cell (the row and the column where the cell is situated) where Lara ends up after she moves k times.


Recently Max has got himself into popular CCG "BrainStone". As "BrainStone" is a pretty intellectual game, Max has to solve numerous hard problems during the gameplay. Here is one of them:Max owns n creatures, i-th of them can be described with two numbers — its health hpi and its damage dmgi. Max also has two types of spells in stock:  Doubles health of the creature (hpi := hpi·2);  Assigns value of health of the creature to its damage (dmgi := hpi). Spell of first type can be used no more than a times in total, of the second type — no more than b times in total. Spell can be used on a certain creature multiple times. Spells can be used in arbitrary order. It isn't necessary to use all the spells.Max is really busy preparing for his final exams, so he asks you to determine what is the maximal total damage of all creatures he can achieve if he uses spells in most optimal way.

The first line contains three integers n, a, b (1 ≤ n ≤ 2·105, 0 ≤ a ≤ 20, 0 ≤ b ≤ 2·105) — the number of creatures, spells of the first type and spells of the second type, respectively. The i-th of the next n lines contain two number hpi and dmgi (1 ≤ hpi, dmgi ≤ 109) — description of the i-th creature.

Print single integer — maximum total damage creatures can deal.

NoteIn the first example Max should use the spell of the first type on the second creature, then the spell of the second type on the same creature. Then total damage will be equal to 15 + 6·2 = 27.In the second example Max should use the spell of the second type on the first creature, then the spell of the second type on the third creature. Total damage will be equal to 10 + 11 + 5 = 26.


You are given a bipartite graph G = (U, V, E), U is the set of vertices of the first part, V is the set of vertices of the second part and E is the set of edges. There might be multiple edges.Let's call some subset of its edges  k-covering iff the graph  has each of its vertices incident to at least k edges. Minimal k-covering is such a k-covering that the size of the subset  is minimal possible.Your task is to find minimal k-covering for each , where minDegree is the minimal degree of any vertex in graph G.

The first line contains three integers n1, n2 and m (1 ≤ n1, n2 ≤ 2000, 0 ≤ m ≤ 2000) — the number of vertices in the first part, the number of vertices in the second part and the number of edges, respectively. The i-th of the next m lines contain two integers ui and vi (1 ≤ ui ≤ n1, 1 ≤ vi ≤ n2) — the description of the i-th edge, ui is the index of the vertex in the first part and vi is the index of the vertex in the second part.

For each  print the subset of edges (minimal k-covering) in separate line. The first integer cntk of the k-th line is the number of edges in minimal k-covering of the graph. Then cntk integers follow — original indices of the edges which belong to the minimal k-covering, these indices should be pairwise distinct. Edges are numbered 1 through m in order they are given in the input.


Kuro is living in a country called Uberland, consisting of $$$n$$$ towns, numbered from $$$1$$$ to $$$n$$$, and $$$n - 1$$$ bidirectional roads connecting these towns. It is possible to reach each town from any other. Each road connects two towns $$$a$$$ and $$$b$$$. Kuro loves walking and he is planning to take a walking marathon, in which he will choose a pair of towns $$$(u, v)$$$ ($$$u \neq v$$$) and walk from $$$u$$$ using the shortest path to $$$v$$$ (note that $$$(u, v)$$$ is considered to be different from $$$(v, u)$$$).Oddly, there are 2 special towns in Uberland named Flowrisa (denoted with the index $$$x$$$) and Beetopia (denoted with the index $$$y$$$). Flowrisa is a town where there are many strong-scent flowers, and Beetopia is another town where many bees live. In particular, Kuro will avoid any pair of towns $$$(u, v)$$$ if on the path from $$$u$$$ to $$$v$$$, he reaches Beetopia after he reached Flowrisa, since the bees will be attracted with the flower smell on Kuro’s body and sting him.Kuro wants to know how many pair of city $$$(u, v)$$$ he can take as his route. Since he’s not really bright, he asked you to help him with this problem.

The first line contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \leq n \leq 3 \cdot 10^5$$$, $$$1 \leq x, y \leq n$$$, $$$x \ne y$$$) - the number of towns, index of the town Flowrisa and index of the town Beetopia, respectively. $$$n - 1$$$ lines follow, each line contains two integers $$$a$$$ and $$$b$$$ ($$$1 \leq a, b \leq n$$$, $$$a \ne b$$$), describes a road connecting two towns $$$a$$$ and $$$b$$$. It is guaranteed that from each town, we can reach every other town in the city using the given roads. That is, the given map of towns and roads is a tree.

A single integer resembles the number of pair of towns $$$(u, v)$$$ that Kuro can use as his walking route.

NoteOn the first example, Kuro can choose these pairs:   $$$(1, 2)$$$: his route would be $$$1 \rightarrow 2$$$,  $$$(2, 3)$$$: his route would be $$$2 \rightarrow 3$$$,  $$$(3, 2)$$$: his route would be $$$3 \rightarrow 2$$$,  $$$(2, 1)$$$: his route would be $$$2 \rightarrow 1$$$,  $$$(3, 1)$$$: his route would be $$$3 \rightarrow 2 \rightarrow 1$$$. Kuro can't choose pair $$$(1, 3)$$$ since his walking route would be $$$1 \rightarrow 2 \rightarrow 3$$$, in which Kuro visits town $$$1$$$ (Flowrisa) and then visits town $$$3$$$ (Beetopia), which is not allowed (note that pair $$$(3, 1)$$$ is still allowed because although Kuro visited Flowrisa and Beetopia, he did not visit them in that order).On the second example, Kuro can choose the following pairs:   $$$(1, 2)$$$: his route would be $$$1 \rightarrow 2$$$,  $$$(2, 1)$$$: his route would be $$$2 \rightarrow 1$$$,  $$$(3, 2)$$$: his route would be $$$3 \rightarrow 1 \rightarrow 2$$$,  $$$(3, 1)$$$: his route would be $$$3 \rightarrow 1$$$.


After the big birthday party, Katie still wanted Shiro to have some more fun. Later, she came up with a game called treasure hunt. Of course, she invited her best friends Kuro and Shiro to play with her.The three friends are very smart so they passed all the challenges very quickly and finally reached the destination. But the treasure can only belong to one cat so they started to think of something which can determine who is worthy of the treasure. Instantly, Kuro came up with some ribbons.A random colorful ribbon is given to each of the cats. Each color of the ribbon can be represented as an uppercase or lowercase Latin letter. Let's call a consecutive subsequence of colors that appears in the ribbon a subribbon. The beauty of a ribbon is defined as the maximum number of times one of its subribbon appears in the ribbon. The more the subribbon appears, the more beautiful is the ribbon. For example, the ribbon aaaaaaa has the beauty of $$$7$$$ because its subribbon a appears $$$7$$$ times, and the ribbon abcdabc has the beauty of $$$2$$$ because its subribbon abc appears twice.The rules are simple. The game will have $$$n$$$ turns. Every turn, each of the cats must change strictly one color (at one position) in his/her ribbon to an arbitrary color which is different from the unchanged one. For example, a ribbon aaab can be changed into acab in one turn. The one having the most beautiful ribbon after $$$n$$$ turns wins the treasure.Could you find out who is going to be the winner if they all play optimally?

The first line contains an integer $$$n$$$ ($$$0 \leq n \leq 10^{9}$$$) — the number of turns. Next 3 lines contain 3 ribbons of Kuro, Shiro and Katie one per line, respectively. Each ribbon is a string which contains no more than $$$10^{5}$$$ uppercase and lowercase Latin letters and is not empty. It is guaranteed that the length of all ribbons are equal for the purpose of fairness. Note that uppercase and lowercase letters are considered different colors.

Print the name of the winner ("Kuro", "Shiro" or "Katie"). If there are at least two cats that share the maximum beauty, print "Draw".

NoteIn the first example, after $$$3$$$ turns, Kuro can change his ribbon into ooooo, which has the beauty of $$$5$$$, while reaching such beauty for Shiro and Katie is impossible (both Shiro and Katie can reach the beauty of at most $$$4$$$, for example by changing Shiro's ribbon into SSiSS and changing Katie's ribbon into Kaaaa). Therefore, the winner is Kuro.In the fourth example, since the length of each of the string is $$$9$$$ and the number of turn is $$$15$$$, everyone can change their ribbons in some way to reach the maximal beauty of $$$9$$$ by changing their strings into zzzzzzzzz after 9 turns, and repeatedly change their strings into azzzzzzzz and then into zzzzzzzzz thrice. Therefore, the game ends in a draw.

7
treasurehunt
threefriends
hiCodeforces


Petya studies at university. The current academic year finishes with $$$n$$$ special days. Petya needs to pass $$$m$$$ exams in those special days. The special days in this problem are numbered from $$$1$$$ to $$$n$$$.There are three values about each exam:  $$$s_i$$$ — the day, when questions for the $$$i$$$-th exam will be published,  $$$d_i$$$ — the day of the $$$i$$$-th exam ($$$s_i < d_i$$$),  $$$c_i$$$ — number of days Petya needs to prepare for the $$$i$$$-th exam. For the $$$i$$$-th exam Petya should prepare in days between $$$s_i$$$ and $$$d_i-1$$$, inclusive. There are three types of activities for Petya in each day: to spend a day doing nothing (taking a rest), to spend a day passing exactly one exam or to spend a day preparing for exactly one exam. So he can't pass/prepare for multiple exams in a day. He can't mix his activities in a day. If he is preparing for the $$$i$$$-th exam in day $$$j$$$, then $$$s_i \le j < d_i$$$.It is allowed to have breaks in a preparation to an exam and to alternate preparations for different exams in consecutive days. So preparation for an exam is not required to be done in consecutive days.Find the schedule for Petya to prepare for all exams and pass them, or report that it is impossible.

The first line contains two integers $$$n$$$ and $$$m$$$ $$$(2 \le n \le 100, 1 \le m \le n)$$$ — the number of days and the number of exams. Each of the following $$$m$$$ lines contains three integers $$$s_i$$$, $$$d_i$$$, $$$c_i$$$ $$$(1 \le s_i < d_i \le n, 1 \le c_i \le n)$$$ — the day, when questions for the $$$i$$$-th exam will be given, the day of the $$$i$$$-th exam, number of days Petya needs to prepare for the $$$i$$$-th exam.  Guaranteed, that all the exams will be in different days. Questions for different exams can be given in the same day. It is possible that, in the day of some exam, the questions for other exams are given.

If Petya can not prepare and pass all the exams, print -1. In case of positive answer, print $$$n$$$ integers, where the $$$j$$$-th number is:   $$$(m + 1)$$$, if the $$$j$$$-th day is a day of some exam (recall that in each day no more than one exam is conducted),  zero, if in the $$$j$$$-th day Petya will have a rest,  $$$i$$$ ($$$1 \le i \le m$$$), if Petya will prepare for the $$$i$$$-th exam in the day $$$j$$$ (the total number of days Petya prepares for each exam should be strictly equal to the number of days needed to prepare for it).Assume that the exams are numbered in order of appearing in the input, starting from $$$1$$$.If there are multiple schedules, print any of them.

NoteIn the first example Petya can, for example, prepare for exam $$$1$$$ in the first day, prepare for exam $$$2$$$ in the second day, pass exam $$$1$$$ in the third day, relax in the fourth day, and pass exam $$$2$$$ in the fifth day. So, he can prepare and pass all exams.In the second example, there are three days and two exams. So, Petya can prepare in only one day (because in two other days he should pass exams). Then Petya can not prepare and pass all exams.


Kuro is currently playing an educational game about numbers. The game focuses on the greatest common divisor (GCD), the XOR value, and the sum of two numbers. Kuro loves the game so much that he solves levels by levels day by day.Sadly, he's going on a vacation for a day, and he isn't able to continue his solving streak on his own. As Katie is a reliable person, Kuro kindly asked her to come to his house on this day to play the game for him.Initally, there is an empty array $$$a$$$. The game consists of $$$q$$$ tasks of two types. The first type asks Katie to add a number $$$u_i$$$ to $$$a$$$. The second type asks Katie to find a number $$$v$$$ existing in $$$a$$$ such that $$$k_i \mid GCD(x_i, v)$$$, $$$x_i + v \leq s_i$$$, and $$$x_i \oplus v$$$ is maximized, where $$$\oplus$$$ denotes the bitwise XOR operation, $$$GCD(c, d)$$$ denotes the greatest common divisor of integers $$$c$$$ and $$$d$$$, and $$$y \mid x$$$ means $$$x$$$ is divisible by $$$y$$$, or report -1 if no such numbers are found.Since you are a programmer, Katie needs you to automatically and accurately perform the tasks in the game to satisfy her dear friend Kuro. Let's help her!

The first line contains one integer $$$q$$$ ($$$2 \leq q \leq 10^{5}$$$) — the number of tasks the game wants you to perform. $$$q$$$ lines follow, each line begins with an integer $$$t_i$$$ — the type of the task:    If $$$t_i = 1$$$, an integer $$$u_i$$$ follow ($$$1 \leq u_i \leq 10^{5}$$$) — you have to add $$$u_i$$$ to the array $$$a$$$.  If $$$t_i = 2$$$, three integers $$$x_i$$$, $$$k_i$$$, and $$$s_i$$$ follow ($$$1 \leq x_i, k_i, s_i \leq 10^{5}$$$) — you must find a number $$$v$$$ existing in the array $$$a$$$ such that $$$k_i \mid GCD(x_i, v)$$$, $$$x_i + v \leq s_i$$$, and $$$x_i \oplus v$$$ is maximized, where $$$\oplus$$$ denotes the XOR operation, or report -1 if no such numbers are found.  It is guaranteed that the type of the first task is type $$$1$$$, and there exists at least one task of type $$$2$$$.

For each task of type $$$2$$$, output on one line the desired number $$$v$$$, or -1 if no such numbers are found.

NoteIn the first example, there are 5 tasks:   The first task requires you to add $$$1$$$ into $$$a$$$. $$$a$$$ is now $$$\left\{1\right\}$$$.  The second task requires you to add $$$2$$$ into $$$a$$$. $$$a$$$ is now $$$\left\{1, 2\right\}$$$.  The third task asks you a question with $$$x = 1$$$, $$$k = 1$$$ and $$$s = 3$$$. Taking both $$$1$$$ and $$$2$$$ as $$$v$$$ satisfies $$$1 \mid GCD(1, v)$$$ and $$$1 + v \leq 3$$$. Because $$$2 \oplus 1 = 3 > 1 \oplus 1 = 0$$$, $$$2$$$ is the answer to this task.  The fourth task asks you a question with $$$x = 1$$$, $$$k = 1$$$ and $$$s = 2$$$. Only $$$v = 1$$$ satisfies $$$1 \mid GCD(1, v)$$$ and $$$1 + v \leq 2$$$, so $$$1$$$ is the answer to this task.  The fifth task asks you a question with $$$x = 1$$$, $$$k = 1$$$ and $$$s = 1$$$. There are no elements in $$$a$$$ that satisfy the conditions, so we report -1 as the answer to this task.


A necklace can be described as a string of links ('-') and pearls ('o'), with the last link or pearl connected to the first one.  You can remove a link or a pearl and insert it between two other existing links or pearls (or between a link and a pearl) on the necklace. This process can be repeated as many times as you like, but you can't throw away any parts.Can you make the number of links between every two adjacent pearls equal? Two pearls are considered to be adjacent if there is no other pearl between them.Note that the final necklace should remain as one circular part of the same length as the initial necklace.

The only line of input contains a string $$$s$$$ ($$$3 \leq |s| \leq 100$$$), representing the necklace, where a dash '-' represents a link and the lowercase English letter 'o' represents a pearl.

Print "YES" if the links and pearls can be rejoined such that the number of links between adjacent pearls is equal. Otherwise print "NO". You can print each letter in any case (upper or lower).


Kuro has recently won the "Most intelligent cat ever" contest. The three friends then decided to go to Katie's home to celebrate Kuro's winning. After a big meal, they took a small break then started playing games.Kuro challenged Katie to create a game with only a white paper, a pencil, a pair of scissors and a lot of arrows (you can assume that the number of arrows is infinite). Immediately, Katie came up with the game called Topological Parity.The paper is divided into $$$n$$$ pieces enumerated from $$$1$$$ to $$$n$$$. Shiro has painted some pieces with some color. Specifically, the $$$i$$$-th piece has color $$$c_{i}$$$ where $$$c_{i} = 0$$$ defines black color, $$$c_{i} = 1$$$ defines white color and $$$c_{i} = -1$$$ means that the piece hasn't been colored yet.The rules of the game is simple. Players must put some arrows between some pairs of different pieces in such a way that for each arrow, the number in the piece it starts from is less than the number of the piece it ends at. Also, two different pieces can only be connected by at most one arrow. After that the players must choose the color ($$$0$$$ or $$$1$$$) for each of the unpainted pieces. The score of a valid way of putting the arrows and coloring pieces is defined as the number of paths of pieces of alternating colors. For example, $$$[1 \to 0 \to 1 \to 0]$$$, $$$[0 \to 1 \to 0 \to 1]$$$, $$$[1]$$$, $$$[0]$$$ are valid paths and will be counted. You can only travel from piece $$$x$$$ to piece $$$y$$$ if and only if there is an arrow from $$$x$$$ to $$$y$$$.But Kuro is not fun yet. He loves parity. Let's call his favorite parity $$$p$$$ where $$$p = 0$$$ stands for "even" and $$$p = 1$$$ stands for "odd". He wants to put the arrows and choose colors in such a way that the score has the parity of $$$p$$$.It seems like there will be so many ways which satisfy Kuro. He wants to count the number of them but this could be a very large number. Let's help him with his problem, but print it modulo $$$10^{9} + 7$$$.

The first line contains two integers $$$n$$$ and $$$p$$$ ($$$1 \leq n \leq 50$$$, $$$0 \leq p \leq 1$$$) — the number of pieces and Kuro's wanted parity. The second line contains $$$n$$$ integers $$$c_{1}, c_{2}, ..., c_{n}$$$ ($$$-1 \leq c_{i} \leq 1$$$) — the colors of the pieces.

Print a single integer — the number of ways to put the arrows and choose colors so the number of valid paths of alternating colors has the parity of $$$p$$$.

NoteIn the first example, there are $$$6$$$ ways to color the pieces and add the arrows, as are shown in the figure below. The scores are $$$3, 3, 5$$$ for the first row and $$$5, 3, 3$$$ for the second row, both from left to right.