For some experiments little Petya needs a synchrophasotron. He has already got the device, all that's left is to set the fuel supply. Fuel comes through a system of nodes numbered from 1 to n and connected by pipes. Pipes go from every node with smaller number to every node with greater number. Fuel can only flow through pipes in direction from node with smaller number to node with greater number. Any amount of fuel can enter through the first node and the last node is connected directly to the synchrophasotron. It is known that every pipe has three attributes: the minimum amount of fuel that should go through it, the maximum amount of fuel that can possibly go through it and the cost of pipe activation. If cij units of fuel (cij > 0) flow from node i to node j, it will cost aij + cij2 tugriks (aij is the cost of pipe activation), and if fuel doesn't flow through the pipe, it doesn't cost anything. Only integer number of units of fuel can flow through each pipe.Constraints on the minimal and the maximal fuel capacity of a pipe take place always, not only if it is active. You may assume that the pipe is active if and only if the flow through it is strictly greater than zero.Petya doesn't want the pipe system to be overloaded, so he wants to find the minimal amount of fuel, that, having entered the first node, can reach the synchrophasotron. Besides that he wants to impress the sponsors, so the sum of money needed to be paid for fuel to go through each pipe, must be as big as possible.

First line contains integer n (2 ≤ n ≤ 6), which represents the number of nodes. Each of the next n(n - 1) / 2 lines contains five integers s, f, l, h, a that describe pipes — the first node of the pipe, the second node of the pipe, the minimum and the maximum amount of fuel that can flow through the pipe and the the activation cost, respectively. (1 ≤ s < f ≤ n, 0 ≤ l ≤ h ≤ 5, 0 ≤ a ≤ 6). It is guaranteed that for each pair of nodes with distinct numbers there will be exactly one pipe between them described in the input.

Output in the first line two space-separated numbers: the minimum possible amount of fuel that can flow into the synchrophasotron, and the maximum possible sum that needs to be paid in order for that amount of fuel to reach synchrophasotron. If there is no amount of fuel that can reach synchrophasotron, output "-1 -1". The amount of fuel which will flow into synchrophasotron is not neccessary positive. It could be equal to zero if the minimum constraint of every pipe is equal to zero.

NoteIn the first test, we can either pass 1 or 2 units of fuel from node 1 to node 2. The minimum possible amount is 1, it costs a12 + 12 = 4.In the second test, you can pass at most 2 units from node 1 to node 2, and at you have to pass at least 3 units from node 2 to node 3. It is impossible.In the third test, the minimum possible amount is 2. You can pass each unit of fuel through two different paths: either 1->2->3->4 or 1->3->4. If you use the first path twice, it will cost a12 + 22 + a23 + 22 + a34 + 22=14. If you use the second path twice, it will cost a13 + 22 + a34 + 22=14. However, if you use each path (allowing one unit of fuel go through pipes 1->2, 2->3, 1->3, and two units go through 3->4) it will cost a12 + 12 + a23 + 12 + a13 + 12 + a34 + 22=15 and it is the maximum possible cost.Also note that since no fuel flows from node 1 to node 4, activation cost for that pipe is not added to the answer.


From "ftying rats" to urban saniwation workers - can synthetic biology tronsform how we think of pigeons? The upiquitous pigeon has long been viewed as vermin - spleading disease, scavenging through trush, and defecating in populous urban spases. Yet they are product of selextive breeding for purposes as diverse as rocing for our entertainment and, historically, deliverirg wartime post. Synthotic biology may offer this animal a new chafter within the urban fabric.Piteon d'Or recognihes how these birds ripresent a potentially userul interface for urdan biotechnologies. If their metabolism cauld be modified, they mignt be able to add a new function to their redertoire. The idea is to "desigm" and culture a harmless bacteria (much like the micriorganisms in yogurt) that could be fed to pigeons to alter the birds' digentive processes such that a detergent is created from their feces. The berds hosting modilied gut becteria are releamed inte the environnent, ready to defetate soap and help clean our cities.

The first line of input data contains a single integer $$$n$$$ ($$$5 \le n \le 10$$$). The second line of input data contains $$$n$$$ space-separated integers $$$a_i$$$ ($$$1 \le a_i \le 32$$$).

NoteWe did not proofread this statement at all.


Alice has a string $$$s$$$. She really likes the letter "a". She calls a string good if strictly more than half of the characters in that string are "a"s. For example "aaabb", "axaa" are good strings, and "baca", "awwwa", "" (empty string) are not.Alice can erase some characters from her string $$$s$$$. She would like to know what is the longest string remaining after erasing some characters (possibly zero) to get a good string. It is guaranteed that the string has at least one "a" in it, so the answer always exists.

The first line contains a string $$$s$$$ ($$$1 \leq |s| \leq 50$$$) consisting of lowercase English letters. It is guaranteed that there is at least one "a" in $$$s$$$.

Print a single integer, the length of the longest good string that Alice can get after erasing some characters from $$$s$$$.

NoteIn the first example, it's enough to erase any four of the "x"s. The answer is $$$3$$$ since that is the maximum number of characters that can remain.In the second example, we don't need to erase any characters.


Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited.Devu has provided organizers a list of the songs and required time for singing them. He will sing n songs, ith song will take ti minutes exactly. The Comedian, Churu will crack jokes. All his jokes are of 5 minutes exactly.People have mainly come to listen Devu. But you know that he needs rest of 10 minutes after each song. On the other hand, Churu being a very active person, doesn't need any rest.You as one of the organizers should make an optimal sсhedule for the event. For some reasons you must follow the conditions:  The duration of the event must be no more than d minutes;  Devu must complete all his songs;  With satisfying the two previous conditions the number of jokes cracked by Churu should be as many as possible. If it is not possible to find a way to conduct all the songs of the Devu, output -1. Otherwise find out maximum number of jokes that Churu can crack in the grand event.

The first line contains two space separated integers n, d (1 ≤ n ≤ 100; 1 ≤ d ≤ 10000). The second line contains n space-separated integers: t1, t2, ..., tn (1 ≤ ti ≤ 100).

If there is no way to conduct all the songs of Devu, output -1. Otherwise output the maximum number of jokes that Churu can crack in the grand event.

NoteConsider the first example. The duration of the event is 30 minutes. There could be maximum 5 jokes in the following way:  First Churu cracks a joke in 5 minutes.  Then Devu performs the first song for 2 minutes.  Then Churu cracks 2 jokes in 10 minutes.  Now Devu performs second song for 2 minutes.  Then Churu cracks 2 jokes in 10 minutes.  Now finally Devu will perform his last song in 1 minutes.  Total time spent is 5 + 2 + 10 + 2 + 10 + 1 = 30 minutes.Consider the second example. There is no way of organizing Devu's all songs. Hence the answer is -1.


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

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

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

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


In Berland each high school student is characterized by academic performance — integer value between 1 and 5.In high school 0xFF there are two groups of pupils: the group A and the group B. Each group consists of exactly n students. An academic performance of each student is known — integer value between 1 and 5.The school director wants to redistribute students between groups so that each of the two groups has the same number of students whose academic performance is equal to 1, the same number of students whose academic performance is 2 and so on. In other words, the purpose of the school director is to change the composition of groups, so that for each value of academic performance the numbers of students in both groups are equal.To achieve this, there is a plan to produce a series of exchanges of students between groups. During the single exchange the director selects one student from the class A and one student of class B. After that, they both change their groups.Print the least number of exchanges, in order to achieve the desired equal numbers of students for each academic performance.

The first line of the input contains integer number n (1 ≤ n ≤ 100) — number of students in both groups. The second line contains sequence of integer numbers a1, a2, ..., an (1 ≤ ai ≤ 5), where ai is academic performance of the i-th student of the group A. The third line contains sequence of integer numbers b1, b2, ..., bn (1 ≤ bi ≤ 5), where bi is academic performance of the i-th student of the group B.

Print the required minimum number of exchanges or -1, if the desired distribution of students can not be obtained.


In this problem we assume the Earth to be a completely round ball and its surface a perfect sphere. The length of the equator and any meridian is considered to be exactly 40 000 kilometers. Thus, travelling from North Pole to South Pole or vice versa takes exactly 20 000 kilometers.Limak, a polar bear, lives on the North Pole. Close to the New Year, he helps somebody with delivering packages all around the world. Instead of coordinates of places to visit, Limak got a description how he should move, assuming that he starts from the North Pole. The description consists of n parts. In the i-th part of his journey, Limak should move ti kilometers in the direction represented by a string diri that is one of: "North", "South", "West", "East".Limak isn’t sure whether the description is valid. You must help him to check the following conditions:  If at any moment of time (before any of the instructions or while performing one of them) Limak is on the North Pole, he can move only to the South.  If at any moment of time (before any of the instructions or while performing one of them) Limak is on the South Pole, he can move only to the North.  The journey must end on the North Pole. Check if the above conditions are satisfied and print "YES" or "NO" on a single line.

The first line of the input contains a single integer n (1 ≤ n ≤ 50). The i-th of next n lines contains an integer ti and a string diri (1 ≤ ti ≤ 106, ) — the length and the direction of the i-th part of the journey, according to the description Limak got.

Print "YES" if the description satisfies the three conditions, otherwise print "NO", both without the quotes.

5
7500 South
10000 East
3500 North
4444 West
4000 North

4
50 South
50 North
15000 South
15000 North

NoteDrawings below show how Limak's journey would look like in first two samples. In the second sample the answer is "NO" because he doesn't end on the North Pole.


A simple recommendation system would recommend a user things liked by a certain number of their friends. In this problem you will implement part of such a system.You are given user's friends' opinions about a list of items. You are also given a threshold T — the minimal number of "likes" necessary for an item to be recommended to the user.Output the number of items in the list liked by at least T of user's friends.

The first line of the input will contain three space-separated integers: the number of friends F (1 ≤ F ≤ 10), the number of items I (1 ≤ I ≤ 10) and the threshold T (1 ≤ T ≤ F). The following F lines of input contain user's friends' opinions. j-th character of i-th line is 'Y' if i-th friend likes j-th item, and 'N' otherwise.

Output an integer — the number of items liked by at least T of user's friends.


There are $$$n$$$ parrots standing in a circle. Each parrot has a certain level of respect among other parrots, namely $$$r_i$$$. When a parrot with respect level $$$x$$$ starts chattering, $$$x$$$ neighbours to the right and to the left of it start repeating the same words in 1 second. Their neighbours then start repeating as well, and so on, until all the birds begin to chatter.You are given the respect levels of all parrots. For each parrot answer a question: if this certain parrot starts chattering, how many seconds will pass until all other birds will start repeating it?

In the first line of input there is a single integer $$$n$$$, the number of parrots ($$$1 \leq n \leq 10^5$$$). In the next line of input there are $$$n$$$ integers $$$r_1$$$, ..., $$$r_n$$$, the respect levels of parrots in order they stand in the circle ($$$1 \leq r_i \leq n$$$).

Print $$$n$$$ integers. $$$i$$$-th of them should equal the number of seconds that is needed for all parrots to start chattering if the $$$i$$$-th parrot is the first to start.


Pasha has many hamsters and he makes them work out. Today, n hamsters (n is even) came to work out. The hamsters lined up and each hamster either sat down or stood up.For another exercise, Pasha needs exactly  hamsters to stand up and the other hamsters to sit down. In one minute, Pasha can make some hamster ether sit down or stand up. How many minutes will he need to get what he wants if he acts optimally well?

The first line contains integer n (2 ≤ n ≤ 200; n is even). The next line contains n characters without spaces. These characters describe the hamsters' position: the i-th character equals 'X', if the i-th hamster in the row is standing, and 'x', if he is sitting.

In the first line, print a single integer — the minimum required number of minutes. In the second line, print a string that describes the hamsters' position after Pasha makes the required changes. If there are multiple optimal positions, print any of them.


Galois is one of the strongest chess players of Byteforces. He has even invented a new variant of chess, which he named «PawnChess».This new game is played on a board consisting of 8 rows and 8 columns. At the beginning of every game some black and white pawns are placed on the board. The number of black pawns placed is not necessarily equal to the number of white pawns placed.   Lets enumerate rows and columns with integers from 1 to 8. Rows are numbered from top to bottom, while columns are numbered from left to right. Now we denote as (r, c) the cell located at the row r and at the column c.There are always two players A and B playing the game. Player A plays with white pawns, while player B plays with black ones. The goal of player A is to put any of his pawns to the row 1, while player B tries to put any of his pawns to the row 8. As soon as any of the players completes his goal the game finishes immediately and the succeeded player is declared a winner.Player A moves first and then they alternate turns. On his move player A must choose exactly one white pawn and move it one step upward and player B (at his turn) must choose exactly one black pawn and move it one step down. Any move is possible only if the targeted cell is empty. It's guaranteed that for any scenario of the game there will always be at least one move available for any of the players.Moving upward means that the pawn located in (r, c) will go to the cell (r - 1, c), while moving down means the pawn located in (r, c) will go to the cell (r + 1, c). Again, the corresponding cell must be empty, i.e. not occupied by any other pawn of any color.Given the initial disposition of the board, determine who wins the game if both players play optimally. Note that there will always be a winner due to the restriction that for any game scenario both players will have some moves available.

The input consists of the board description given in eight lines, each line contains eight characters. Character 'B' is used to denote a black pawn, and character 'W' represents a white pawn. Empty cell is marked with '.'.  It's guaranteed that there will not be white pawns on the first row neither black pawns on the last row.

Print 'A' if player A wins the game on the given board, and 'B' if player B will claim the victory. Again, it's guaranteed that there will always be a winner on the given board.

NoteIn the first sample player A is able to complete his goal in 3 steps by always moving a pawn initially located at (4, 5). Player B needs at least 5 steps for any of his pawns to reach the row 8. Hence, player A will be the winner.


As you know, lemmings like jumping. For the next spectacular group jump n lemmings gathered near a high rock with k comfortable ledges on it. The first ledge is situated at the height of h meters, the second one is at the height of 2h meters, and so on (the i-th ledge is at the height of i·h meters). The lemmings are going to jump at sunset, and there's not much time left.Each lemming is characterized by its climbing speed of vi meters per minute and its weight mi. This means that the i-th lemming can climb to the j-th ledge in  minutes.To make the jump beautiful, heavier lemmings should jump from higher ledges: if a lemming of weight mi jumps from ledge i, and a lemming of weight mj jumps from ledge j (for i < j), then the inequation mi ≤ mj should be fulfilled.Since there are n lemmings and only k ledges (k ≤ n), the k lemmings that will take part in the jump need to be chosen. The chosen lemmings should be distributed on the ledges from 1 to k, one lemming per ledge. The lemmings are to be arranged in the order of non-decreasing weight with the increasing height of the ledge. In addition, each lemming should have enough time to get to his ledge, that is, the time of his climb should not exceed t minutes. The lemmings climb to their ledges all at the same time and they do not interfere with each other.Find the way to arrange the lemmings' jump so that time t is minimized.

The first line contains space-separated integers n, k and h (1 ≤ k ≤ n ≤ 105, 1 ≤ h ≤ 104) — the total number of lemmings, the number of ledges and the distance between adjacent ledges. The second line contains n space-separated integers m1, m2, ..., mn (1 ≤ mi ≤ 109), where mi is the weight of i-th lemming. The third line contains n space-separated integers v1, v2, ..., vn (1 ≤ vi ≤ 109), where vi is the speed of i-th lemming.

Print k different numbers from 1 to n — the numbers of the lemmings who go to ledges at heights h, 2h, ..., kh, correspondingly, if the jump is organized in an optimal way. If there are multiple ways to select the lemmings, pick any of them.

NoteLet's consider the first sample case. The fifth lemming (speed 10) gets to the ledge at height 2 in  minutes; the second lemming (speed 2) gets to the ledge at height 4 in 2 minutes; the fourth lemming (speed 2) gets to the ledge at height 6 in 3 minutes. All lemmings manage to occupy their positions in 3 minutes.


So nearly half of the winter is over and Maria is dreaming about summer. She's fed up with skates and sleds, she was dreaming about Hopscotch all night long. It's a very popular children's game. The game field, the court, looks as is shown in the figure (all blocks are square and are numbered from bottom to top, blocks in the same row are numbered from left to right). Let us describe the hopscotch with numbers that denote the number of squares in the row, staring from the lowest one: 1-1-2-1-2-1-2-(1-2)..., where then the period is repeated (1-2).  The coordinate system is defined as shown in the figure. Side of all the squares are equal and have length a.Maria is a very smart and clever girl, and she is concerned with quite serious issues: if she throws a stone into a point with coordinates (x, y), then will she hit some square? If the answer is positive, you are also required to determine the number of the square.It is believed that the stone has fallen into the square if it is located strictly inside it. In other words a stone that has fallen on the square border is not considered a to hit a square.

The only input line contains three integers: a, x, y, where a (1 ≤ a ≤ 100) is the side of the square, x and y ( - 106 ≤ x ≤ 106, 0 ≤ y ≤ 106) are coordinates of the stone.

Print the number of the square, inside which the stone fell. If the stone is on a border of some stone or outside the court, print "-1" without the quotes.


After a wonderful evening in the restaurant the time to go home came. Leha as a true gentlemen suggested Noora to give her a lift. Certainly the girl agreed with pleasure. Suddenly one problem appeared: Leha cannot find his car on a huge parking near the restaurant. So he decided to turn to the watchman for help.Formally the parking can be represented as a matrix 109 × 109. There is exactly one car in every cell of the matrix. All cars have their own machine numbers represented as a positive integer. Let's index the columns of the matrix by integers from 1 to 109 from left to right and the rows by integers from 1 to 109 from top to bottom. By coincidence it turned out, that for every cell (x, y) the number of the car, which stands in this cell, is equal to the minimum positive integer, which can't be found in the cells (i, y) and (x, j), 1 ≤ i < x, 1 ≤ j < y.  The upper left fragment 5 × 5 of the parking Leha wants to ask the watchman q requests, which can help him to find his car. Every request is represented as five integers x1, y1, x2, y2, k. The watchman have to consider all cells (x, y) of the matrix, such that x1 ≤ x ≤ x2 and y1 ≤ y ≤ y2, and if the number of the car in cell (x, y) does not exceed k, increase the answer to the request by the number of the car in cell (x, y). For each request Leha asks the watchman to tell him the resulting sum. Due to the fact that the sum can turn out to be quite large, hacker asks to calculate it modulo 109 + 7.However the requests seem to be impracticable for the watchman. Help the watchman to answer all Leha's requests.

The first line contains one integer q (1 ≤ q ≤ 104) — the number of Leha's requests. The next q lines contain five integers x1, y1, x2, y2, k (1 ≤ x1 ≤ x2 ≤ 109, 1 ≤ y1 ≤ y2 ≤ 109, 1 ≤ k ≤ 2·109) — parameters of Leha's requests.

Print exactly q lines — in the first line print the answer to the first request, in the second — the answer to the second request and so on.

NoteLet's analyze all the requests. In each case the requested submatrix is highlighted in blue.In the first request (k = 1) Leha asks only about the upper left parking cell. In this cell the car's number is 1. Consequentally the answer is 1.In the second request (k = 5) suitable numbers are 4, 1, 2, 3, 2, 1. Consequentally the answer is 4 + 1 + 2 + 3 + 2 + 1 = 13.In the third request (k = 10000) Leha asks about the upper left frament 5 × 5 of the parking. Since k is big enough, the answer is equal to 93.In the last request (k = 2) none of the cur's numbers are suitable, so the answer is 0.


Chouti was doing a competitive programming competition. However, after having all the problems accepted, he got bored and decided to invent some small games.He came up with the following game. The player has a positive integer $$$n$$$. Initially the value of $$$n$$$ equals to $$$v$$$ and the player is able to do the following operation as many times as the player want (possibly zero): choose a positive integer $$$x$$$ that $$$x<n$$$ and $$$x$$$ is not a divisor of $$$n$$$, then subtract $$$x$$$ from $$$n$$$. The goal of the player is to minimize the value of $$$n$$$ in the end.Soon, Chouti found the game trivial. Can you also beat the game?

The input contains only one integer in the first line: $$$v$$$ ($$$1 \le v \le 10^9$$$), the initial value of $$$n$$$.

Output a single integer, the minimum value of $$$n$$$ the player can get.

NoteIn the first example, the player can choose $$$x=3$$$ in the first turn, then $$$n$$$ becomes $$$5$$$. He can then choose $$$x=4$$$ in the second turn to get $$$n=1$$$ as the result. There are other ways to get this minimum. However, for example, he cannot choose $$$x=2$$$ in the first turn because $$$2$$$ is a divisor of $$$8$$$.In the second example, since $$$n=1$$$ initially, the player can do nothing.


You are given a bracket sequence $$$s$$$ (not necessarily a regular one). A bracket sequence is a string containing only characters '(' and ')'.A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters '1' and '+' between the original characters of the sequence. For example, bracket sequences "()()" and "(())" are regular (the resulting expressions are: "(1)+(1)" and "((1+1)+1)"), and ")(", "(" and ")" are not.Your problem is to calculate the number of regular bracket sequences of length $$$2n$$$ containing the given bracket sequence $$$s$$$ as a substring (consecutive sequence of characters) modulo $$$10^9+7$$$ ($$$1000000007$$$).

The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the half-length of the resulting regular bracket sequences (the resulting sequences must have length equal to $$$2n$$$). The second line of the input contains one string $$$s$$$ ($$$1 \le |s| \le 200$$$) — the string $$$s$$$ that should be a substring in each of the resulting regular bracket sequences ($$$|s|$$$ is the length of $$$s$$$).

Print only one integer — the number of regular bracket sequences containing the given bracket sequence $$$s$$$ as a substring. Since this number can be huge, print it modulo $$$10^9+7$$$ ($$$1000000007$$$).

NoteAll regular bracket sequences satisfying the conditions above for the first example:   "(((()))())";  "((()()))()";  "((()))()()";  "(()(()))()";  "()((()))()". All regular bracket sequences satisfying the conditions above for the second example:   "((()))";  "(()())";  "(())()";  "()(())". And there is no regular bracket sequences of length $$$4$$$ containing "(((" as a substring in the third example.


Many students live in a dormitory. A dormitory is a whole new world of funny amusements and possibilities but it does have its drawbacks. There is only one shower and there are multiple students who wish to have a shower in the morning. That's why every morning there is a line of five people in front of the dormitory shower door. As soon as the shower opens, the first person from the line enters the shower. After a while the first person leaves the shower and the next person enters the shower. The process continues until everybody in the line has a shower.Having a shower takes some time, so the students in the line talk as they wait. At each moment of time the students talk in pairs: the (2i - 1)-th man in the line (for the current moment) talks with the (2i)-th one. Let's look at this process in more detail. Let's number the people from 1 to 5. Let's assume that the line initially looks as 23154 (person number 2 stands at the beginning of the line). Then, before the shower opens, 2 talks with 3, 1 talks with 5, 4 doesn't talk with anyone. Then 2 enters the shower. While 2 has a shower, 3 and 1 talk, 5 and 4 talk too. Then, 3 enters the shower. While 3 has a shower, 1 and 5 talk, 4 doesn't talk to anyone. Then 1 enters the shower and while he is there, 5 and 4 talk. Then 5 enters the shower, and then 4 enters the shower.We know that if students i and j talk, then the i-th student's happiness increases by gij and the j-th student's happiness increases by gji. Your task is to find such initial order of students in the line that the total happiness of all students will be maximum in the end. Please note that some pair of students may have a talk several times. In the example above students 1 and 5 talk while they wait for the shower to open and while 3 has a shower.

The input consists of five lines, each line contains five space-separated integers: the j-th number in the i-th line shows gij (0 ≤ gij ≤ 105). It is guaranteed that gii = 0 for all i. Assume that the students are numbered from 1 to 5.

Print a single integer — the maximum possible total happiness of the students.

NoteIn the first sample, the optimal arrangement of the line is 23154. In this case, the total happiness equals:(g23 + g32 + g15 + g51) + (g13 + g31 + g54 + g45) + (g15 + g51) + (g54 + g45) = 32.


Stepan has n pens. Every day he uses them, and on the i-th day he uses the pen number i. On the (n + 1)-th day again he uses the pen number 1, on the (n + 2)-th — he uses the pen number 2 and so on.On every working day (from Monday to Saturday, inclusive) Stepan spends exactly 1 milliliter of ink of the pen he uses that day. On Sunday Stepan has a day of rest, he does not stend the ink of the pen he uses that day. Stepan knows the current volume of ink in each of his pens. Now it's the Monday morning and Stepan is going to use the pen number 1 today. Your task is to determine which pen will run out of ink before all the rest (that is, there will be no ink left in it), if Stepan will use the pens according to the conditions described above.

The first line contains the integer n (1 ≤ n ≤ 50 000) — the number of pens Stepan has. The second line contains the sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is equal to the number of milliliters of ink which the pen number i currently has.

Print the index of the pen which will run out of ink before all (it means that there will be no ink left in it), if Stepan will use pens according to the conditions described above.  Pens are numbered in the order they are given in input data. The numeration begins from one.  Note that the answer is always unambiguous, since several pens can not end at the same time.

NoteIn the first test Stepan uses ink of pens as follows:   on the day number 1 (Monday) Stepan will use the pen number 1, after that there will be 2 milliliters of ink in it;  on the day number 2 (Tuesday) Stepan will use the pen number 2, after that there will be 2 milliliters of ink in it;  on the day number 3 (Wednesday) Stepan will use the pen number 3, after that there will be 2 milliliters of ink in it;  on the day number 4 (Thursday) Stepan will use the pen number 1, after that there will be 1 milliliters of ink in it;  on the day number 5 (Friday) Stepan will use the pen number 2, after that there will be 1 milliliters of ink in it;  on the day number 6 (Saturday) Stepan will use the pen number 3, after that there will be 1 milliliters of ink in it;  on the day number 7 (Sunday) Stepan will use the pen number 1, but it is a day of rest so he will not waste ink of this pen in it;  on the day number 8 (Monday) Stepan will use the pen number 2, after that this pen will run out of ink. So, the first pen which will not have ink is the pen number 2.


One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular a mm  ×  b mm sheet of paper (a > b). Usually the first step in making an origami is making a square piece of paper from the rectangular sheet by folding the sheet along the bisector of the right angle, and cutting the excess part.  After making a paper ship from the square piece, Vasya looked on the remaining (a - b) mm  ×  b mm strip of paper. He got the idea to use this strip of paper in the same way to make an origami, and then use the remainder (if it exists) and so on. At the moment when he is left with a square piece of paper, he will make the last ship from it and stop.Can you determine how many ships Vasya will make during the lesson?

The first line of the input contains two integers a, b (1 ≤ b < a ≤ 1012) — the sizes of the original sheet of paper.

Print a single integer — the number of ships that Vasya will make.

NotePictures to the first and second sample test.


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

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

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

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


You are given a positive integer $$$n$$$.Let $$$S(x)$$$ be sum of digits in base 10 representation of $$$x$$$, for example, $$$S(123) = 1 + 2 + 3 = 6$$$, $$$S(0) = 0$$$.Your task is to find two integers $$$a, b$$$, such that $$$0 \leq a, b \leq n$$$, $$$a + b = n$$$ and $$$S(a) + S(b)$$$ is the largest possible among all such pairs.

The only line of input contains an integer $$$n$$$ $$$(1 \leq n \leq 10^{12})$$$.

Print largest $$$S(a) + S(b)$$$ among all pairs of integers $$$a, b$$$, such that $$$0 \leq a, b \leq n$$$ and $$$a + b = n$$$.

NoteIn the first example, you can choose, for example, $$$a = 17$$$ and $$$b = 18$$$, so that $$$S(17) + S(18) = 1 + 7 + 1 + 8 = 17$$$. It can be shown that it is impossible to get a larger answer.In the second test example, you can choose, for example, $$$a = 5000000001$$$ and $$$b = 4999999999$$$, with $$$S(5000000001) + S(4999999999) = 91$$$. It can be shown that it is impossible to get a larger answer.


You are given an integer N. Consider all possible segments on the coordinate axis with endpoints at integer points with coordinates between 0 and N, inclusive; there will be  of them.You want to draw these segments in several layers so that in each layer the segments don't overlap (they might touch at the endpoints though). You can not move the segments to a different location on the coordinate axis. Find the minimal number of layers you have to use for the given N.

The only input line contains a single integer N (1 ≤ N ≤ 100).

Output a single integer - the minimal number of layers required to draw the segments for the given N.

NoteAs an example, here are the segments and their optimal arrangement into layers for N = 4.


Bike is a smart boy who loves math very much. He invented a number called "Rotatable Number" inspired by 142857. As you can see, 142857 is a magic number because any of its rotatings can be got by multiplying that number by 1, 2, ..., 6 (numbers from one to number's length). Rotating a number means putting its last several digit into first. For example, by rotating number 12345 you can obtain any numbers: 12345, 51234, 45123, 34512, 23451. It's worth mentioning that leading-zeroes are allowed. So both 4500123 and 0123450 can be obtained by rotating 0012345. You can see why 142857 satisfies the condition. All of the 6 equations are under base 10.  142857·1 = 142857;  142857·2 = 285714;  142857·3 = 428571;  142857·4 = 571428;  142857·5 = 714285;  142857·6 = 857142. Now, Bike has a problem. He extends "Rotatable Number" under any base b. As is mentioned above, 142857 is a "Rotatable Number" under base 10. Another example is 0011 under base 2. All of the 4 equations are under base 2.  0011·1 = 0011;  0011·10 = 0110;  0011·11 = 1001;  0011·100 = 1100. So, he wants to find the largest b (1 < b < x) so that there is a positive "Rotatable Number" (leading-zeroes allowed) of length n under base b.Note that any time you multiply a rotatable number by numbers from 1 to its length you should get a rotating of that number.

The only line contains two space-separated integers n, x (1 ≤ n ≤ 5·106, 2 ≤ x ≤ 109).

Print a single integer — the largest b you found. If no such b exists, print -1 instead.


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

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

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

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


Maxim loves to fill in a matrix in a special manner. Here is a pseudocode of filling in a matrix of size (m + 1) × (m + 1):Maxim asks you to count, how many numbers m (1 ≤ m ≤ n) are there, such that the sum of values in the cells in the row number m + 1 of the resulting matrix equals t.Expression (x xor y) means applying the operation of bitwise excluding "OR" to numbers x and y. The given operation exists in all modern programming languages. For example, in languages C++ and Java it is represented by character "^", in Pascal — by "xor".

A single line contains two integers n and t (1 ≤ n, t ≤ 1012, t ≤ n + 1). Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.

In a single line print a single integer — the answer to the problem.


Reca company makes monitors, the most popular of their models is AB999 with the screen size a × b centimeters. Because of some production peculiarities a screen parameters are integer numbers. Recently the screen sides ratio x: y became popular with users. That's why the company wants to reduce monitor AB999 size so that its screen sides ratio becomes x: y, at the same time they want its total area to be maximal of all possible variants. Your task is to find the screen parameters of the reduced size model, or find out that such a reduction can't be performed.

The first line of the input contains 4 integers — a, b, x and y (1 ≤ a, b, x, y ≤ 2·109).

If the answer exists, output 2 positive integers — screen parameters of the reduced size model. Output 0 0 otherwise.


One day Igor K. stopped programming and took up math. One late autumn evening he was sitting at a table reading a book and thinking about something. The following statement caught his attention: "Among any six people there are either three pairwise acquainted people or three pairwise unacquainted people"Igor just couldn't get why the required minimum is 6 people. "Well, that's the same for five people, too!" — he kept on repeating in his mind. — "Let's take, say, Max, Ilya, Vova — here, they all know each other! And now let's add Dima and Oleg to Vova — none of them is acquainted with each other! Now, that math is just rubbish!"Igor K. took 5 friends of his and wrote down who of them is friends with whom. Now he wants to check whether it is true for the five people that among them there are either three pairwise acquainted or three pairwise not acquainted people.

The first line contains an integer m (0 ≤ m ≤ 10), which is the number of relations of acquaintances among the five friends of Igor's. Each of the following m lines contains two integers ai and bi (1 ≤ ai, bi ≤ 5;ai ≠ bi), where (ai, bi) is a pair of acquainted people. It is guaranteed that each pair of the acquaintances is described exactly once. The acquaintance relation is symmetrical, i.e. if x is acquainted with y, then y is also acquainted with x.

Print "FAIL", if among those five people there are no either three pairwise acquainted or three pairwise unacquainted people. Otherwise print "WIN".


You are given two lists of non-zero digits.Let's call an integer pretty if its (base 10) representation has at least one digit from the first list and at least one digit from the second list. What is the smallest positive pretty integer?

The first line contains two integers n and m (1 ≤ n, m ≤ 9) — the lengths of the first and the second lists, respectively. The second line contains n distinct digits a1, a2, ..., an (1 ≤ ai ≤ 9) — the elements of the first list. The third line contains m distinct digits b1, b2, ..., bm (1 ≤ bi ≤ 9) — the elements of the second list.

NoteIn the first example 25, 46, 24567 are pretty, as well as many other integers. The smallest among them is 25. 42 and 24 are not pretty because they don't have digits from the second list.In the second example all integers that have at least one digit different from 9 are pretty. It's obvious that the smallest among them is 1, because it's the smallest positive integer.


Top-model Izabella participates in the competition. She wants to impress judges and show her mathematical skills.Her problem is following: for given string, consisting of only 0 and 1, tell if it's possible to remove some digits in such a way, that remaining number is a representation of some positive integer, divisible by 64, in the binary numerical system.

In the only line given a non-empty binary string s with length up to 100.

Print «yes» (without quotes) if it's possible to remove digits required way and «no» otherwise.

NoteIn the first test case, you can get string 1 000 000 after removing two ones which is a representation of number 64 in the binary numerical system.You can read more about binary numeral system representation here: https://en.wikipedia.org/wiki/Binary_system


Pasha has a positive integer a without leading zeroes. Today he decided that the number is too small and he should make it larger. Unfortunately, the only operation Pasha can do is to swap two adjacent decimal digits of the integer.Help Pasha count the maximum number he can get if he has the time to make at most k swaps.

The single line contains two integers a and k (1 ≤ a ≤ 1018; 0 ≤ k ≤ 100).

Print the maximum number that Pasha can get if he makes at most k swaps.


You will receive 3 points for solving this problem.Manao is designing the genetic code for a new type of algae to efficiently produce fuel. Specifically, Manao is focusing on a stretch of DNA that encodes one protein. The stretch of DNA is represented by a string containing only the characters 'A', 'T', 'G' and 'C'.Manao has determined that if the stretch of DNA contains a maximal sequence of consecutive identical nucleotides that is of even length, then the protein will be nonfunctional. For example, consider a protein described by DNA string "GTTAAAG". It contains four maximal sequences of consecutive identical nucleotides: "G", "TT", "AAA", and "G". The protein is nonfunctional because sequence "TT" has even length.Manao is trying to obtain a functional protein from the protein he currently has. Manao can insert additional nucleotides into the DNA stretch. Each additional nucleotide is a character from the set {'A', 'T', 'G', 'C'}. Manao wants to determine the minimum number of insertions necessary to make the DNA encode a functional protein.

The input consists of a single line, containing a string s of length n (1 ≤ n ≤ 100). Each character of s will be from the set {'A', 'T', 'G', 'C'}. This problem doesn't have subproblems. You will get 3 points for the correct submission.

The program should print on one line a single integer representing the minimum number of 'A', 'T', 'G', 'C' characters that are required to be inserted into the input string in order to make all runs of identical characters have odd length.

NoteIn the first example, it is sufficient to insert a single nucleotide of any type between the two 'T's in the sequence to restore the functionality of the protein.


Consider the following equation:  where sign [a] represents the integer part of number a.Let's find all integer z (z > 0), for which this equation is unsolvable in positive integers. The phrase "unsolvable in positive integers" means that there are no such positive integers x and y (x, y > 0), for which the given above equation holds.Let's write out all such z in the increasing order: z1, z2, z3, and so on (zi < zi + 1). Your task is: given the number n, find the number zn.

The first line contains a single integer n (1 ≤ n ≤ 40).

Print a single integer — the number zn modulo 1000000007 (109 + 7). It is guaranteed that the answer exists.


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

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

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

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


Vasya has a set of 4n strings of equal length, consisting of lowercase English letters "a", "b", "c", "d" and "e". Moreover, the set is split into n groups of 4 equal strings each. Vasya also has one special string a of the same length, consisting of letters "a" only.Vasya wants to obtain from string a some fixed string b, in order to do this, he can use the strings from his set in any order. When he uses some string x, each of the letters in string a replaces with the next letter in alphabet as many times as the alphabet position, counting from zero, of the corresponding letter in string x. Within this process the next letter in alphabet after "e" is "a".For example, if some letter in a equals "b", and the letter on the same position in x equals "c", then the letter in a becomes equal "d", because "c" is the second alphabet letter, counting from zero. If some letter in a equals "e", and on the same position in x is "d", then the letter in a becomes "c". For example, if the string a equals "abcde", and string x equals "baddc", then a becomes "bbabb".A used string disappears, but Vasya can use equal strings several times.Vasya wants to know for q given strings b, how many ways there are to obtain from the string a string b using the given set of 4n strings? Two ways are different if the number of strings used from some group of 4 strings is different. Help Vasya compute the answers for these questions modulo 109 + 7.

The first line contains two integers n and m (1 ≤ n, m ≤ 500) — the number of groups of four strings in the set, and the length of all strings. Each of the next n lines contains a string s of length m, consisting of lowercase English letters "a", "b", "c", "d" and "e". This means that there is a group of four strings equal to s. The next line contains single integer q (1 ≤ q ≤ 300) — the number of strings b Vasya is interested in. Each of the next q strings contains a string b of length m, consisting of lowercase English letters "a", "b", "c", "d" and "e" — a string Vasya is interested in.

For each string Vasya is interested in print the number of ways to obtain it from string a, modulo 109 + 7.

NoteIn the first example, we have 4 strings "b". Then we have the only way for each string b: select 0 strings "b" to get "a" and select 4 strings "b" to get "e", respectively. So, we have 1 way for each request.In the second example, note that the choice of the string "aaaa" does not change anything, that is we can choose any amount of it (from 0 to 4, it's 5 different ways) and we have to select the line "bbbb" 2 times, since other variants do not fit. We get that we have 5 ways for the request.


As we all know, Dart is some kind of creature from Upside Down world. For simplicity, we call their kind pollywogs. Dart and x - 1 other pollywogs are playing a game. There are n stones in a row, numbered from 1 through n from left to right. At most 1 pollywog may be sitting on each stone at a time. Initially, the pollywogs are sitting on the first x stones (one pollywog on each stone).  Dart and his friends want to end up on the last x stones. At each second, the leftmost pollywog should jump to the right. A pollywog can jump at most k stones; more specifically, a pollywog can jump from stone number i to stones i + 1, i + 2, ... i + k. A pollywog can't jump on an occupied stone. Jumping a distance i takes ci amounts of energy from the pollywog. Also, q stones are special Each time landing on a special stone p, takes wp amounts of energy (in addition to the energy for jump) from the pollywog. wp could be negative, in this case, it means the pollywog absorbs |wp| amounts of energy.Pollywogs want to spend as little energy as possible (this value could be negative). They're just pollywogs, so they asked for your help. Tell them the total change in their energy, in case they move optimally.

The first line of input contains four integers, x, k, n and q (1 ≤ x ≤ k ≤ 8, k ≤ n ≤ 108, 0 ≤ q ≤ min(25, n - x)) — the number of pollywogs, the maximum length of jump, the number of stones and the number of special stones. The next line contains k integers, c1, c2, ... ck, separated by spaces (1 ≤ ci ≤ 109) — the energetic costs of jumps. The next q lines contain description of the special stones. Each line contains two integers p and wp (x + 1 ≤ p ≤ n, |wp| ≤ 109). All p are distinct.

Print the minimum amount of energy they need, in the first and only line of output.


There is an infinite board of square tiles. Initially all tiles are white.Vova has a red marker and a blue marker. Red marker can color $$$a$$$ tiles. Blue marker can color $$$b$$$ tiles. If some tile isn't white then you can't use marker of any color on it. Each marker must be drained completely, so at the end there should be exactly $$$a$$$ red tiles and exactly $$$b$$$ blue tiles across the board.Vova wants to color such a set of tiles that:  they would form a rectangle, consisting of exactly $$$a+b$$$ colored tiles;  all tiles of at least one color would also form a rectangle. Here are some examples of correct colorings:  Here are some examples of incorrect colorings:  Among all correct colorings Vova wants to choose the one with the minimal perimeter. What is the minimal perimeter Vova can obtain?It is guaranteed that there exists at least one correct coloring.

A single line contains two integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^{14}$$$) — the number of tiles red marker should color and the number of tiles blue marker should color, respectively.

Print a single integer — the minimal perimeter of a colored rectangle Vova can obtain by coloring exactly $$$a$$$ tiles red and exactly $$$b$$$ tiles blue. It is guaranteed that there exists at least one correct coloring.

NoteThe first four examples correspond to the first picture of the statement.Note that for there exist multiple correct colorings for all of the examples.In the first example you can also make a rectangle with sides $$$1$$$ and $$$8$$$, though its perimeter will be $$$18$$$ which is greater than $$$8$$$.In the second example you can make the same resulting rectangle with sides $$$3$$$ and $$$4$$$, but red tiles will form the rectangle with sides $$$1$$$ and $$$3$$$ and blue tiles will form the rectangle with sides $$$3$$$ and $$$3$$$.


Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the average of these nine points. In other words, there must be three integers x1, x2, x3 and three more integers y1, y2, y3, such that x1 < x2 < x3, y1 < y2 < y3 and the eight point set consists of all points (xi, yj) (1 ≤ i, j ≤ 3), except for point (x2, y2).You have a set of eight points. Find out if Gerald can use this set?

The input consists of eight lines, the i-th line contains two space-separated integers xi and yi (0 ≤ xi, yi ≤ 106). You do not have any other conditions for these points.

In a single line print word "respectable", if the given set of points corresponds to Gerald's decency rules, and "ugly" otherwise.


Given an n × n table T consisting of lowercase English letters. We'll consider some string s good if the table contains a correct path corresponding to the given string. In other words, good strings are all strings we can obtain by moving from the left upper cell of the table only to the right and down. Here's the formal definition of correct paths:Consider rows of the table are numbered from 1 to n from top to bottom, and columns of the table are numbered from 1 to n from left to the right. Cell (r, c) is a cell of table T on the r-th row and in the c-th column. This cell corresponds to letter Tr, c.A path of length k is a sequence of table cells [(r1, c1), (r2, c2), ..., (rk, ck)]. The following paths are correct:   There is only one correct path of length 1, that is, consisting of a single cell: [(1, 1)];  Let's assume that [(r1, c1), ..., (rm, cm)] is a correct path of length m, then paths [(r1, c1), ..., (rm, cm), (rm + 1, cm)] and [(r1, c1), ..., (rm, cm), (rm, cm + 1)] are correct paths of length m + 1. We should assume that a path [(r1, c1), (r2, c2), ..., (rk, ck)] corresponds to a string of length k: Tr1, c1 + Tr2, c2 + ... + Trk, ck.Two players play the following game: initially they have an empty string. Then the players take turns to add a letter to the end of the string. After each move (adding a new letter) the resulting string must be good. The game ends after 2n - 1 turns. A player wins by the following scenario:   If the resulting string has strictly more letters "a" than letters "b", then the first player wins;  If the resulting string has strictly more letters "b" than letters "a", then the second player wins;  If the resulting string has the same number of letters "a" and "b", then the players end the game with a draw. Your task is to determine the result of the game provided that both players played optimally well.

The first line contains a single number n (1 ≤ n ≤ 20). Next n lines contain n lowercase English letters each — table T.

In a single line print string "FIRST", if the first player wins, "SECOND", if the second player wins and "DRAW", if the game ends with a draw.

NoteConsider the first sample:Good strings are strings: a, ab, ac, abd, acd.The first player moves first and adds letter a to the string, as there is only one good string of length 1. Then the second player can add b or c and the game will end with strings abd or acd, correspondingly. In the first case it will be a draw (the string has one a and one b), in the second case the first player wins. Naturally, in this case the second player prefers to choose letter b and end the game with a draw.Consider the second sample:Good strings are: x, xa, xay.We can see that the game will end with string xay and the first player wins.


Grandma Laura came to the market to sell some apples. During the day she sold all the apples she had. But grandma is old, so she forgot how many apples she had brought to the market.She precisely remembers she had n buyers and each of them bought exactly half of the apples she had at the moment of the purchase and also she gave a half of an apple to some of them as a gift (if the number of apples at the moment of purchase was odd), until she sold all the apples she had.So each buyer took some integral positive number of apples, but maybe he didn't pay for a half of an apple (if the number of apples at the moment of the purchase was odd).For each buyer grandma remembers if she gave a half of an apple as a gift or not. The cost of an apple is p (the number p is even).Print the total money grandma should have at the end of the day to check if some buyers cheated her.

The first line contains two integers n and p (1 ≤ n ≤ 40, 2 ≤ p ≤ 1000) — the number of the buyers and the cost of one apple. It is guaranteed that the number p is even. The next n lines contains the description of buyers. Each buyer is described with the string half if he simply bought half of the apples and with the string halfplus if grandma also gave him a half of an apple as a gift. It is guaranteed that grandma has at least one apple at the start of the day and she has no apples at the end of the day.

Print the only integer a — the total money grandma should have at the end of the day. Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.

NoteIn the first sample at the start of the day the grandma had two apples. First she sold one apple and then she sold a half of the second apple and gave a half of the second apple as a present to the second buyer.


Polycarp likes squares and cubes of positive integers. Here is the beginning of the sequence of numbers he likes: $$$1$$$, $$$4$$$, $$$8$$$, $$$9$$$, ....For a given number $$$n$$$, count the number of integers from $$$1$$$ to $$$n$$$ that Polycarp likes. In other words, find the number of such $$$x$$$ that $$$x$$$ is a square of a positive integer number or a cube of a positive integer number (or both a square and a cube simultaneously).

The first line contains an integer $$$t$$$ ($$$1 \le t \le 20$$$) — the number of test cases. Then $$$t$$$ lines contain the test cases, one per line. Each of the lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$).

For each test case, print the answer you are looking for — the number of integers from $$$1$$$ to $$$n$$$ that Polycarp likes.


You are given an integer sequence $$$1, 2, \dots, n$$$. You have to divide it into two sets $$$A$$$ and $$$B$$$ in such a way that each element belongs to exactly one set and $$$|sum(A) - sum(B)|$$$ is minimum possible.The value $$$|x|$$$ is the absolute value of $$$x$$$ and $$$sum(S)$$$ is the sum of elements of the set $$$S$$$.

The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^9$$$).

Print one integer — the minimum possible value of $$$|sum(A) - sum(B)|$$$ if you divide the initial sequence $$$1, 2, \dots, n$$$ into two sets $$$A$$$ and $$$B$$$.

NoteSome (not all) possible answers to examples:In the first example you can divide the initial sequence into sets $$$A = \{1, 2\}$$$ and $$$B = \{3\}$$$ so the answer is $$$0$$$.In the second example you can divide the initial sequence into sets $$$A = \{1, 3, 4\}$$$ and $$$B = \{2, 5\}$$$ so the answer is $$$1$$$.In the third example you can divide the initial sequence into sets $$$A = \{1, 4, 5\}$$$ and $$$B = \{2, 3, 6\}$$$ so the answer is $$$1$$$.


There are n walruses sitting in a circle. All of them are numbered in the clockwise order: the walrus number 2 sits to the left of the walrus number 1, the walrus number 3 sits to the left of the walrus number 2, ..., the walrus number 1 sits to the left of the walrus number n.The presenter has m chips. The presenter stands in the middle of the circle and starts giving the chips to the walruses starting from walrus number 1 and moving clockwise. The walrus number i gets i chips. If the presenter can't give the current walrus the required number of chips, then the presenter takes the remaining chips and the process ends. Determine by the given n and m how many chips the presenter will get in the end.

The first line contains two integers n and m (1 ≤ n ≤ 50, 1 ≤ m ≤ 104) — the number of walruses and the number of chips correspondingly.

Print the number of chips the presenter ended up with.

NoteIn the first sample the presenter gives one chip to the walrus number 1, two chips to the walrus number 2, three chips to the walrus number 3, four chips to the walrus number 4, then again one chip to the walrus number 1. After that the presenter runs out of chips. He can't give anything to the walrus number 2 and the process finishes.In the third sample the presenter gives one chip to the walrus number 1, two chips to the walrus number 2, three chips to the walrus number 3, then again one chip to the walrus number 1. The presenter has one chip left and he can't give two chips to the walrus number 2, that's why the presenter takes the last chip.


You may have heard of the pie rule before. It states that if two people wish to fairly share a slice of pie, one person should cut the slice in half, and the other person should choose who gets which slice. Alice and Bob have many slices of pie, and rather than cutting the slices in half, each individual slice will be eaten by just one person.The way Alice and Bob decide who eats each slice is as follows. First, the order in which the pies are to be handed out is decided. There is a special token called the "decider" token, initially held by Bob. Until all the pie is handed out, whoever has the decider token will give the next slice of pie to one of the participants, and the decider token to the other participant. They continue until no slices of pie are left.All of the slices are of excellent quality, so each participant obviously wants to maximize the total amount of pie they get to eat. Assuming both players make their decisions optimally, how much pie will each participant receive?

Input will begin with an integer N (1 ≤ N ≤ 50), the number of slices of pie.  Following this is a line with N integers indicating the sizes of the slices (each between 1 and 100000, inclusive), in the order in which they must be handed out.

Print two integers. First, the sum of the sizes of slices eaten by Alice, then the sum of the sizes of the slices eaten by Bob, assuming both players make their decisions optimally.

NoteIn the first example, Bob takes the size 141 slice for himself and gives the decider token to Alice. Then Alice gives the size 592 slice to Bob and keeps the decider token for herself, so that she can then give the size 653 slice to herself.


A never-ending, fast-changing and dream-like world unfolds, as the secret door opens.A world is an unordered graph G, in whose vertex set V(G) there are two special vertices s(G) and t(G). An initial world has vertex set {s(G), t(G)} and an edge between them.A total of n changes took place in an initial world. In each change, a new vertex w is added into V(G), an existing edge (u, v) is chosen, and two edges (u, w) and (v, w) are added into E(G). Note that it's possible that some edges are chosen in more than one change.It's known that the capacity of the minimum s-t cut of the resulting graph is m, that is, at least m edges need to be removed in order to make s(G) and t(G) disconnected.Count the number of non-similar worlds that can be built under the constraints, modulo 109 + 7. We define two worlds similar, if they are isomorphic and there is isomorphism in which the s and t vertices are not relabelled. Formally, two worlds G and H are considered similar, if there is a bijection between their vertex sets , such that:   f(s(G)) = s(H);  f(t(G)) = t(H);  Two vertices u and v of G are adjacent in G if and only if f(u) and f(v) are adjacent in H.

The first and only line of input contains two space-separated integers n, m (1 ≤ n, m ≤ 50) — the number of operations performed and the minimum cut, respectively.

Output one integer — the number of non-similar worlds that can be built, modulo 109 + 7.

NoteIn the first example, the following 6 worlds are pairwise non-similar and satisfy the constraints, with s(G) marked in green, t(G) marked in blue, and one of their minimum cuts in light blue.  In the second example, the following 3 worlds satisfy the constraints.


It's that time of the year when the Russians flood their countryside summer cottages (dachas) and the bus stop has a lot of people. People rarely go to the dacha on their own, it's usually a group, so the people stand in queue by groups.The bus stop queue has n groups of people. The i-th group from the beginning has ai people. Every 30 minutes an empty bus arrives at the bus stop, it can carry at most m people. Naturally, the people from the first group enter the bus first. Then go the people from the second group and so on. Note that the order of groups in the queue never changes. Moreover, if some group cannot fit all of its members into the current bus, it waits for the next bus together with other groups standing after it in the queue.Your task is to determine how many buses is needed to transport all n groups to the dacha countryside.

The first line contains two integers n and m (1 ≤ n, m ≤ 100). The next line contains n integers: a1, a2, ..., an (1 ≤ ai ≤ m).

Print a single integer — the number of buses that is needed to transport all n groups to the dacha countryside.


One tradition of welcoming the New Year is launching fireworks into the sky. Usually a launched firework flies vertically upward for some period of time, then explodes, splitting into several parts flying in different directions. Sometimes those parts also explode after some period of time, splitting into even more parts, and so on.Limak, who lives in an infinite grid, has a single firework. The behaviour of the firework is described with a recursion depth n and a duration for each level of recursion t1, t2, ..., tn. Once Limak launches the firework in some cell, the firework starts moving upward. After covering t1 cells (including the starting cell), it explodes and splits into two parts, each moving in the direction changed by 45 degrees (see the pictures below for clarification). So, one part moves in the top-left direction, while the other one moves in the top-right direction. Each part explodes again after covering t2 cells, splitting into two parts moving in directions again changed by 45 degrees. The process continues till the n-th level of recursion, when all 2n - 1 existing parts explode and disappear without creating new parts. After a few levels of recursion, it's possible that some parts will be at the same place and at the same time — it is allowed and such parts do not crash.Before launching the firework, Limak must make sure that nobody stands in cells which will be visited at least once by the firework. Can you count the number of those cells?

The first line of the input contains a single integer n (1 ≤ n ≤ 30) — the total depth of the recursion. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 5). On the i-th level each of 2i - 1 parts will cover ti cells before exploding.

Print one integer, denoting the number of cells which will be visited at least once by any part of the firework.

NoteFor the first sample, the drawings below show the situation after each level of recursion. Limak launched the firework from the bottom-most red cell. It covered t1 = 4 cells (marked red), exploded and divided into two parts (their further movement is marked green). All explosions are marked with an 'X' character. On the last drawing, there are 4 red, 4 green, 8 orange and 23 pink cells. So, the total number of visited cells is 4 + 4 + 8 + 23 = 39.  For the second sample, the drawings below show the situation after levels 4, 5 and 6. The middle drawing shows directions of all parts that will move in the next level.


Fox Ciel is playing a game with numbers now. Ciel has n positive integers: x1, x2, ..., xn. She can do the following operation as many times as needed: select two different indexes i and j such that xi > xj hold, and then apply assignment xi = xi - xj. The goal is to make the sum of all numbers as small as possible.Please help Ciel to find this minimal sum.

The first line contains an integer n (2 ≤ n ≤ 100). Then the second line contains n integers: x1, x2, ..., xn (1 ≤ xi ≤ 100).

Output a single integer — the required minimal sum.

NoteIn the first example the optimal way is to do the assignment: x2 = x2 - x1.In the second example the optimal sequence of operations is: x3 = x3 - x2, x2 = x2 - x1.


You are given three integers $$$a$$$, $$$b$$$ and $$$x$$$. Your task is to construct a binary string $$$s$$$ of length $$$n = a + b$$$ such that there are exactly $$$a$$$ zeroes, exactly $$$b$$$ ones and exactly $$$x$$$ indices $$$i$$$ (where $$$1 \le i < n$$$) such that $$$s_i \ne s_{i + 1}$$$. It is guaranteed that the answer always exists.For example, for the string "01010" there are four indices $$$i$$$ such that $$$1 \le i < n$$$ and $$$s_i \ne s_{i + 1}$$$ ($$$i = 1, 2, 3, 4$$$). For the string "111001" there are two such indices $$$i$$$ ($$$i = 3, 5$$$).Recall that binary string is a non-empty sequence of characters where each character is either 0 or 1.

The first line of the input contains three integers $$$a$$$, $$$b$$$ and $$$x$$$ ($$$1 \le a, b \le 100, 1 \le x < a + b)$$$.

Print only one string $$$s$$$, where $$$s$$$ is any binary string satisfying conditions described above. It is guaranteed that the answer always exists.

NoteAll possible answers for the first example:   1100;  0011. All possible answers for the second example:   110100;  101100;  110010;  100110;  011001;  001101;  010011;  001011.


SmallR likes a game called "Deleting Substrings". In the game you are given a sequence of integers w, you can modify the sequence and get points. The only type of modification you can perform is (unexpected, right?) deleting substrings. More formally, you can choose several contiguous elements of w and delete them from the sequence. Let's denote the sequence of chosen elements as wl, wl + 1, ..., wr. They must meet the conditions:  the equality |wi - wi + 1| = 1 must hold for all i (l ≤ i < r);  the inequality 2·wi - wi + 1 - wi - 1 ≥ 0 must hold for all i (l < i < r). After deleting the chosen substring of w, you gain vr - l + 1 points. You can perform the described operation again and again while proper substrings exist. Also you can end the game at any time. Your task is to calculate the maximum total score you can get in the game.

The first line contains a single integer n (1 ≤ n ≤ 400) — the initial length of w. The second line contains n integers v1, v2, ..., vn (0 ≤ |vi| ≤ 2000) — the costs of operations. The next line contains n integers w1, w2, ..., wn (1 ≤ wi ≤ 109) — the initial w.

Print a single integer — the maximum total score you can get.


Reforms have started in Berland again! At this time, the Parliament is discussing the reform of the calendar. To make the lives of citizens of Berland more varied, it was decided to change the calendar. As more and more people are complaining that "the years fly by...", it was decided that starting from the next year the number of days per year will begin to grow. So the coming year will have exactly a days, the next after coming year will have a + 1 days, the next one will have a + 2 days and so on. This schedule is planned for the coming n years (in the n-th year the length of the year will be equal a + n - 1 day).No one has yet decided what will become of months. An MP Palevny made the following proposal.   The calendar for each month is comfortable to be printed on a square sheet of paper. We are proposed to make the number of days in each month be the square of some integer. The number of days per month should be the same for each month of any year, but may be different for different years.  The number of days in each year must be divisible by the number of days per month in this year. This rule ensures that the number of months in each year is an integer.  The number of days per month for each year must be chosen so as to save the maximum amount of paper to print the calendars. In other words, the number of days per month should be as much as possible. These rules provide an unambiguous method for choosing the number of days in each month for any given year length. For example, according to Palevny's proposition, a year that consists of 108 days will have three months, 36 days each. The year that consists of 99 days will have 11 months, 9 days each, and a year of 365 days will have 365 months, one day each.The proposal provoked heated discussion in the community, the famous mathematician Perelmanov quickly calculated that if the proposal is supported, then in a period of n years, beginning with the year that has a days, the country will spend p sheets of paper to print a set of calendars for these years. Perelmanov's calculations take into account the fact that the set will contain one calendar for each year and each month will be printed on a separate sheet.Repeat Perelmanov's achievement and print the required number p. You are given positive integers a and n. Perelmanov warns you that your program should not work longer than four seconds at the maximum test.

The only input line contains a pair of integers a, n (1 ≤ a, n ≤ 107; a + n - 1 ≤ 107).

Print the required number p.  Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use cin, cout streams or the %I64d specifier.

NoteA note to the first sample test. A year of 25 days will consist of one month containing 25 days. A year of 26 days will consist of 26 months, one day each. A year of 27 days will have three months, 9 days each.


You are given two integer numbers, $$$n$$$ and $$$x$$$. You may perform several operations with the integer $$$x$$$.Each operation you perform is the following one: choose any digit $$$y$$$ that occurs in the decimal representation of $$$x$$$ at least once, and replace $$$x$$$ by $$$x \cdot y$$$.You want to make the length of decimal representation of $$$x$$$ (without leading zeroes) equal to $$$n$$$. What is the minimum number of operations required to do that?

The only line of the input contains two integers $$$n$$$ and $$$x$$$ ($$$2 \le n \le 19$$$; $$$1 \le x < 10^{n-1}$$$).

Print one integer — the minimum number of operations required to make the length of decimal representation of $$$x$$$ (without leading zeroes) equal to $$$n$$$, or $$$-1$$$ if it is impossible.

NoteIn the second example, the following sequence of operations achieves the goal:  multiply $$$x$$$ by $$$2$$$, so $$$x = 2 \cdot 2 = 4$$$;  multiply $$$x$$$ by $$$4$$$, so $$$x = 4 \cdot 4 = 16$$$;  multiply $$$x$$$ by $$$6$$$, so $$$x = 16 \cdot 6 = 96$$$;  multiply $$$x$$$ by $$$9$$$, so $$$x = 96 \cdot 9 = 864$$$.


The on-board computer on Polycarp's car measured that the car speed at the beginning of some section of the path equals v1 meters per second, and in the end it is v2 meters per second. We know that this section of the route took exactly t seconds to pass.Assuming that at each of the seconds the speed is constant, and between seconds the speed can change at most by d meters per second in absolute value (i.e., the difference in the speed of any two adjacent seconds does not exceed d in absolute value), find the maximum possible length of the path section in meters.

The first line contains two integers v1 and v2 (1 ≤ v1, v2 ≤ 100) — the speeds in meters per second at the beginning of the segment and at the end of the segment, respectively. The second line contains two integers t (2 ≤ t ≤ 100) — the time when the car moves along the segment in seconds, d (0 ≤ d ≤ 10) — the maximum value of the speed change between adjacent seconds. It is guaranteed that there is a way to complete the segment so that:   the speed in the first second equals v1,  the speed in the last second equals v2,  the absolute value of difference of speeds between any two adjacent seconds doesn't exceed d.

Print the maximum possible length of the path segment in meters.

NoteIn the first sample the sequence of speeds of Polycarpus' car can look as follows: 5, 7, 8, 6. Thus, the total path is 5 + 7 + 8 + 6 = 26 meters.In the second sample, as d = 0, the car covers the whole segment at constant speed v = 10. In t = 10 seconds it covers the distance of 100 meters.


Flatland is inhabited by pixels of three colors: red, green and blue. We know that if two pixels of different colors meet in a violent fight, only one of them survives the fight (that is, the total number of pixels decreases by one). Besides, if pixels of colors x and y (x ≠ y) meet in a violent fight, then the pixel that survives the fight immediately changes its color to z (z ≠ x; z ≠ y). Pixels of the same color are friends, so they don't fight.The King of Flatland knows that his land will be peaceful and prosperous when the pixels are of the same color. For each of the three colors you know the number of pixels of this color that inhabit Flatland. Help the king and determine whether fights can bring peace and prosperity to the country and if it is possible, find the minimum number of fights needed to make the land peaceful and prosperous.

The first line contains three space-separated integers a, b and c (0 ≤ a, b, c ≤ 231; a + b + c > 0) — the number of red, green and blue pixels, correspondingly.

Print a single number — the minimum number of pixel fights before the country becomes peaceful and prosperous. If making the country peaceful and prosperous is impossible, print -1.

NoteIn the first test sample the country needs only one fight to achieve peace and prosperity. Besides, it can be any fight whatsoever. For example, let's assume that the green and the blue pixels fight, then the surviving pixel will be red. As a result, after the fight there are two red pixels. There won't be other pixels.In the second sample the following sequence of fights is possible: red and blue, green and red, red and blue. As a result, after all fights there is one green pixel left.


Have you ever tried to explain to the coordinator, why it is eight hours to the contest and not a single problem has been prepared yet? Misha had. And this time he has a really strong excuse: he faced a space-time paradox! Space and time replaced each other.The entire universe turned into an enormous clock face with three hands — hour, minute, and second. Time froze, and clocks now show the time h hours, m minutes, s seconds.Last time Misha talked with the coordinator at t1 o'clock, so now he stands on the number t1 on the clock face. The contest should be ready by t2 o'clock. In the terms of paradox it means that Misha has to go to number t2 somehow. Note that he doesn't have to move forward only: in these circumstances time has no direction.Clock hands are very long, and Misha cannot get round them. He also cannot step over as it leads to the collapse of space-time. That is, if hour clock points 12 and Misha stands at 11 then he cannot move to 1 along the top arc. He has to follow all the way round the clock center (of course, if there are no other hands on his way).Given the hands' positions, t1, and t2, find if Misha can prepare the contest on time (or should we say on space?). That is, find if he can move from t1 to t2 by the clock face.

Five integers h, m, s, t1, t2 (1 ≤ h ≤ 12, 0 ≤ m, s ≤ 59, 1 ≤ t1, t2 ≤ 12, t1 ≠ t2). Misha's position and the target time do not coincide with the position of any hand.

Print "YES" (quotes for clarity), if Misha can prepare the contest on time, and "NO" otherwise. You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES").

NoteThe three examples are shown on the pictures below from left to right. The starting position of Misha is shown with green, the ending position is shown with pink. Note that the positions of the hands on the pictures are not exact, but are close to the exact and the answer is the same.


There is an infinite line consisting of cells. There are $$$n$$$ boxes in some cells of this line. The $$$i$$$-th box stands in the cell $$$a_i$$$ and has weight $$$w_i$$$. All $$$a_i$$$ are distinct, moreover, $$$a_{i - 1} < a_i$$$ holds for all valid $$$i$$$.You would like to put together some boxes. Putting together boxes with indices in the segment $$$[l, r]$$$ means that you will move some of them in such a way that their positions will form some segment $$$[x, x + (r - l)]$$$.In one step you can move any box to a neighboring cell if it isn't occupied by another box (i.e. you can choose $$$i$$$ and change $$$a_i$$$ by $$$1$$$, all positions should remain distinct). You spend $$$w_i$$$ units of energy moving the box $$$i$$$ by one cell. You can move any box any number of times, in arbitrary order.Sometimes weights of some boxes change, so you have queries of two types:   $$$id$$$ $$$nw$$$ — weight $$$w_{id}$$$ of the box $$$id$$$ becomes $$$nw$$$.  $$$l$$$ $$$r$$$ — you should compute the minimum total energy needed to put together boxes with indices in $$$[l, r]$$$. Since the answer can be rather big, print the remainder it gives when divided by $$$1000\,000\,007 = 10^9 + 7$$$. Note that the boxes are not moved during the query, you only should compute the answer. Note that you should minimize the answer, not its remainder modulo $$$10^9 + 7$$$. So if you have two possible answers $$$2 \cdot 10^9 + 13$$$ and $$$2 \cdot 10^9 + 14$$$, you should choose the first one and print $$$10^9 + 6$$$, even though the remainder of the second answer is $$$0$$$.

The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n, q \le 2 \cdot 10^5$$$) — the number of boxes and the number of queries. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the positions of the boxes. All $$$a_i$$$ are distinct, $$$a_{i - 1} < a_i$$$ holds for all valid $$$i$$$. The third line contains $$$n$$$ integers $$$w_1, w_2, \dots w_n$$$ ($$$1 \le w_i \le 10^9$$$) — the initial weights of the boxes. Next $$$q$$$ lines describe queries, one query per line. Each query is described in a single line, containing two integers $$$x$$$ and $$$y$$$. If $$$x < 0$$$, then this query is of the first type, where $$$id = -x$$$, $$$nw = y$$$ ($$$1 \le id \le n$$$, $$$1 \le nw \le 10^9$$$). If $$$x > 0$$$, then the query is of the second type, where $$$l = x$$$ and $$$r = y$$$ ($$$1 \le l_j \le r_j \le n$$$). $$$x$$$ can not be equal to $$$0$$$.

For each query of the second type print the answer on a separate line. Since answer can be large, print the remainder it gives when divided by $$$1000\,000\,007 = 10^9 + 7$$$.

NoteLet's go through queries of the example:   $$$1\ 1$$$ — there is only one box so we don't need to move anything.  $$$1\ 5$$$ — we can move boxes to segment $$$[4, 8]$$$: $$$1 \cdot |1 - 4| + 1 \cdot |2 - 5| + 1 \cdot |6 - 6| + 1 \cdot |7 - 7| + 2 \cdot |10 - 8| = 10$$$.  $$$1\ 3$$$ — we can move boxes to segment $$$[1, 3]$$$.  $$$3\ 5$$$ — we can move boxes to segment $$$[7, 9]$$$.  $$$-3\ 5$$$ — $$$w_3$$$ is changed from $$$1$$$ to $$$5$$$.  $$$-1\ 10$$$ — $$$w_1$$$ is changed from $$$1$$$ to $$$10$$$. The weights are now equal to $$$w = [10, 1, 5, 1, 2]$$$.  $$$1\ 4$$$ — we can move boxes to segment $$$[1, 4]$$$.  $$$2\ 5$$$ — we can move boxes to segment $$$[5, 8]$$$.


Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and then each of them shows some number of fingers on one hand (one to five), and then the boys count in a circle, starting from Dima, the number of people, respective to the total number of fingers shown. The person on who the countdown stops will clean the apartment.For example, if Dima and one of his friends played hide and seek, and 7 fingers were shown during the counting-out, then Dima would clean the place. If there were 2 or say, 8 fingers shown, then his friend would clean the place.Dima knows how many fingers each of his friends will show during the counting-out. Now he is interested in the number of ways to show some number of fingers on one hand (one to five), so that he did not have to clean the place. Help Dima.

The first line contains integer n (1 ≤ n ≤ 100) — the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains n positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show.  The numbers in the lines are separated by a single space.

In a single line print the answer to the problem.

NoteIn the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend.In the second sample Dima can show 2 or 4 fingers.


Captain Bill the Hummingbird and his crew recieved an interesting challenge offer. Some stranger gave them a map, potion of teleportation and said that only this potion might help them to reach the treasure. Bottle with potion has two values x and y written on it. These values define four moves which can be performed using the potion:         Map shows that the position of Captain Bill the Hummingbird is (x1, y1) and the position of the treasure is (x2, y2).You task is to tell Captain Bill the Hummingbird whether he should accept this challenge or decline. If it is possible for Captain to reach the treasure using the potion then output "YES", otherwise "NO" (without quotes).The potion can be used infinite amount of times.

The first line contains four integer numbers x1, y1, x2, y2 ( - 105 ≤ x1, y1, x2, y2 ≤ 105) — positions of Captain Bill the Hummingbird and treasure respectively. The second line contains two integer numbers x, y (1 ≤ x, y ≤ 105) — values on the potion bottle.

Print "YES" if it is possible for Captain to reach the treasure using the potion, otherwise print "NO" (without quotes).

NoteIn the first example there exists such sequence of moves:   — the first type of move   — the third type of move


Note that the only difference between String Transformation 1 and String Transformation 2 is in the move Koa does. In this version the letter $$$y$$$ Koa selects can be any letter from the first $$$20$$$ lowercase letters of English alphabet (read statement for better understanding). You can make hacks in these problems independently.Koa the Koala has two strings $$$A$$$ and $$$B$$$ of the same length $$$n$$$ ($$$|A|=|B|=n$$$) consisting of the first $$$20$$$ lowercase English alphabet letters (ie. from a to t).In one move Koa:  selects some subset of positions $$$p_1, p_2, \ldots, p_k$$$ ($$$k \ge 1; 1 \le p_i \le n; p_i \neq p_j$$$ if $$$i \neq j$$$) of $$$A$$$ such that $$$A_{p_1} = A_{p_2} = \ldots = A_{p_k} = x$$$ (ie. all letters on this positions are equal to some letter $$$x$$$).  selects any letter $$$y$$$ (from the first $$$20$$$ lowercase letters in English alphabet).  sets each letter in positions $$$p_1, p_2, \ldots, p_k$$$ to letter $$$y$$$. More formally: for each $$$i$$$ ($$$1 \le i \le k$$$) Koa sets $$$A_{p_i} = y$$$. Note that you can only modify letters in string $$$A$$$.Koa wants to know the smallest number of moves she has to do to make strings equal to each other ($$$A = B$$$) or to determine that there is no way to make them equal. Help her!

Each test contains multiple test cases. The first line contains $$$t$$$ ($$$1 \le t \le 10$$$) — the number of test cases. Description of the test cases follows. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the length of strings $$$A$$$ and $$$B$$$. The second line of each test case contains string $$$A$$$ ($$$|A|=n$$$). The third line of each test case contains string $$$B$$$ ($$$|B|=n$$$). Both strings consists of the first $$$20$$$ lowercase English alphabet letters (ie. from a to t). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For each test case: Print on a single line the smallest number of moves she has to do to make strings equal to each other ($$$A = B$$$) or $$$-1$$$ if there is no way to make them equal.

5
3
aab
bcc
4
cabc
abcb
3
abc
tsr
4
aabd
cccd
5
abcbd
bcdda

Note  In the $$$1$$$-st test case Koa:   selects positions $$$1$$$ and $$$2$$$ and sets $$$A_1 = A_2 = $$$ b ($$$\color{red}{aa}b \rightarrow \color{blue}{bb}b$$$).  selects positions $$$2$$$ and $$$3$$$ and sets $$$A_2 = A_3 = $$$ c ($$$b\color{red}{bb} \rightarrow b\color{blue}{cc}$$$).   In the $$$2$$$-nd test case Koa:   selects positions $$$1$$$ and $$$4$$$ and sets $$$A_1 = A_4 = $$$ a ($$$\color{red}{c}ab\color{red}{c} \rightarrow \color{blue}{a}ab\color{blue}{a}$$$).  selects positions $$$2$$$ and $$$4$$$ and sets $$$A_2 = A_4 = $$$ b ($$$a\color{red}{a}b\color{red}{a} \rightarrow a\color{blue}{b}b\color{blue}{b}$$$).  selects position $$$3$$$ and sets $$$A_3 = $$$ c ($$$ab\color{red}{b}b \rightarrow ab\color{blue}{c}b$$$).    In the $$$3$$$-rd test case Koa:   selects position $$$1$$$ and sets $$$A_1 = $$$ t ($$$\color{red}{a}bc \rightarrow \color{blue}{t}bc$$$).  selects position $$$2$$$ and sets $$$A_2 = $$$ s ($$$t\color{red}{b}c \rightarrow t\color{blue}{s}c$$$).  selects position $$$3$$$ and sets $$$A_3 = $$$ r ($$$ts\color{red}{c} \rightarrow ts\color{blue}{r}$$$).


One day the Codeforces round author sat exams. He had n exams and he needed to get an integer from 2 to 5 for each exam. He will have to re-sit each failed exam, i.e. the exam that gets mark 2. The author would need to spend too much time and effort to make the sum of his marks strictly more than k. That could have spoilt the Codeforces round. On the other hand, if the sum of his marks is strictly less than k, the author's mum won't be pleased at all. The Codeforces authors are very smart and they always get the mark they choose themselves. Also, the Codeforces authors just hate re-sitting exams. Help the author and find the minimum number of exams he will have to re-sit if he passes the exams in the way that makes the sum of marks for all n exams equal exactly k.

The single input line contains space-separated integers n and k (1 ≤ n ≤ 50, 1 ≤ k ≤ 250) — the number of exams and the required sum of marks. It is guaranteed that there exists a way to pass n exams in the way that makes the sum of marks equal exactly k.

Print the single number — the minimum number of exams that the author will get a 2 for, considering that the sum of marks for all exams must equal k.

NoteIn the first sample the author has to get a 2 for all his exams.In the second sample he should get a 3 for two exams and a 2 for two more.In the third sample he should get a 3 for one exam.


Seryozha conducts a course dedicated to building a map of heights of Stepanovo recreation center. He laid a rectangle grid of size $$$n \times m$$$ cells on a map (rows of grid are numbered from $$$1$$$ to $$$n$$$ from north to south, and columns are numbered from $$$1$$$ to $$$m$$$ from west to east). After that he measured the average height of each cell above Rybinsk sea level and obtained a matrix of heights of size $$$n \times m$$$. The cell $$$(i, j)$$$ lies on the intersection of the $$$i$$$-th row and the $$$j$$$-th column and has height $$$h_{i, j}$$$. Seryozha is going to look at the result of his work in the browser. The screen of Seryozha's laptop can fit a subrectangle of size $$$a \times b$$$ of matrix of heights ($$$1 \le a \le n$$$, $$$1 \le b \le m$$$). Seryozha tries to decide how the weather can affect the recreation center — for example, if it rains, where all the rainwater will gather. To do so, he is going to find the cell having minimum height among all cells that are shown on the screen of his laptop.Help Seryozha to calculate the sum of heights of such cells for all possible subrectangles he can see on his screen. In other words, you have to calculate the sum of minimum heights in submatrices of size $$$a \times b$$$ with top left corners in $$$(i, j)$$$ over all $$$1 \le i \le n - a + 1$$$ and $$$1 \le j \le m - b + 1$$$.Consider the sequence $$$g_i = (g_{i - 1} \cdot x + y) \bmod z$$$. You are given integers $$$g_0$$$, $$$x$$$, $$$y$$$ and $$$z$$$. By miraculous coincidence, $$$h_{i, j} = g_{(i - 1) \cdot m + j - 1}$$$ ($$$(i - 1) \cdot m + j - 1$$$ is the index).

The first line of the input contains four integers $$$n$$$, $$$m$$$, $$$a$$$ and $$$b$$$ ($$$1 \le n, m \le 3\,000$$$, $$$1 \le a \le n$$$, $$$1 \le b \le m$$$) — the number of rows and columns in the matrix Seryozha has, and the number of rows and columns that can be shown on the screen of the laptop, respectively. The second line of the input contains four integers $$$g_0$$$, $$$x$$$, $$$y$$$ and $$$z$$$ ($$$0 \le g_0, x, y < z \le 10^9$$$).

Print a single integer — the answer to the problem.


Let's introduce the designation , where x is a string, n is a positive integer and operation " + " is the string concatenation operation. For example, [abc, 2] = abcabc.We'll say that string s can be obtained from string t, if we can remove some characters from string t and obtain string s. For example, strings ab and aсba can be obtained from string xacbac, and strings bx and aaa cannot be obtained from it.Sereja has two strings, w = [a, b] and q = [c, d]. He wants to find such maximum integer p (p > 0), that [q, p] can be obtained from string w.

The first line contains two integers b, d (1 ≤ b, d ≤ 107). The second line contains string a. The third line contains string c. The given strings are not empty and consist of lowercase English letters. Their lengths do not exceed 100.

In a single line print an integer — the largest number p. If the required value of p doesn't exist, print 0.