The only difference between easy and hard versions is on constraints. In this version constraints are lower. You can make hacks only if all versions of the problem are solved.Koa the Koala is at the beach!The beach consists (from left to right) of a shore, $$$n+1$$$ meters of sea and an island at $$$n+1$$$ meters from the shore.She measured the depth of the sea at $$$1, 2, \dots, n$$$ meters from the shore and saved them in array $$$d$$$. $$$d_i$$$ denotes the depth of the sea at $$$i$$$ meters from the shore for $$$1 \le i \le n$$$.Like any beach this one has tide, the intensity of the tide is measured by parameter $$$k$$$ and affects all depths from the beginning at time $$$t=0$$$ in the following way:  For a total of $$$k$$$ seconds, each second, tide increases all depths by $$$1$$$.  Then, for a total of $$$k$$$ seconds, each second, tide decreases all depths by $$$1$$$.  This process repeats again and again (ie. depths increase for $$$k$$$ seconds then decrease for $$$k$$$ seconds and so on ...).Formally, let's define $$$0$$$-indexed array $$$p = [0, 1, 2, \ldots, k - 2, k - 1, k, k - 1, k - 2, \ldots, 2, 1]$$$ of length $$$2k$$$. At time $$$t$$$ ($$$0 \le t$$$) depth at $$$i$$$ meters from the shore equals $$$d_i + p[t \bmod 2k]$$$ ($$$t \bmod 2k$$$ denotes the remainder of the division of $$$t$$$ by $$$2k$$$). Note that the changes occur instantaneously after each second, see the notes for better understanding. At time $$$t=0$$$ Koa is standing at the shore and wants to get to the island. Suppose that at some time $$$t$$$ ($$$0 \le t$$$) she is at $$$x$$$ ($$$0 \le x \le n$$$) meters from the shore:  In one second Koa can swim $$$1$$$ meter further from the shore ($$$x$$$ changes to $$$x+1$$$) or not swim at all ($$$x$$$ stays the same), in both cases $$$t$$$ changes to $$$t+1$$$.  As Koa is a bad swimmer, the depth of the sea at the point where she is can't exceed $$$l$$$ at integer points of time (or she will drown). More formally, if Koa is at $$$x$$$ ($$$1 \le x \le n$$$) meters from the shore at the moment $$$t$$$ (for some integer $$$t\ge 0$$$), the depth of the sea at this point  — $$$d_x + p[t \bmod 2k]$$$  — can't exceed $$$l$$$. In other words, $$$d_x + p[t \bmod 2k] \le l$$$ must hold always.  Once Koa reaches the island at $$$n+1$$$ meters from the shore, she stops and can rest.Note that while Koa swims tide doesn't have effect on her (ie. she can't drown while swimming). Note that Koa can choose to stay on the shore for as long as she needs and neither the shore or the island are affected by the tide (they are solid ground and she won't drown there). Koa wants to know whether she can go from the shore to the island. Help her!

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$)  — the number of test cases. Description of the test cases follows. The first line of each test case contains three integers $$$n$$$, $$$k$$$ and $$$l$$$ ($$$1 \le n \le 100; 1 \le k \le 100; 1 \le l \le 100$$$) — the number of meters of sea Koa measured and parameters $$$k$$$ and $$$l$$$. The second line of each test case contains $$$n$$$ integers $$$d_1, d_2, \ldots, d_n$$$ ($$$0 \le d_i \le 100$$$)  — the depths of each meter of sea Koa measured. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$100$$$.

For each test case: Print Yes if Koa can get from the shore to the island, and No otherwise. You may print each letter in any case (upper or lower).

NoteIn the following $$$s$$$ denotes the shore, $$$i$$$ denotes the island, $$$x$$$ denotes distance from Koa to the shore, the underline denotes the position of Koa, and values in the array below denote current depths, affected by tide, at $$$1, 2, \dots, n$$$ meters from the shore.In test case $$$1$$$ we have $$$n = 2, k = 1, l = 1, p = [ 0, 1 ]$$$.Koa wants to go from shore (at $$$x = 0$$$) to the island (at $$$x = 3$$$). Let's describe a possible solution:  Initially at $$$t = 0$$$ the beach looks like this: $$$[\underline{s}, 1, 0, i]$$$.  At $$$t = 0$$$ if Koa would decide to swim to $$$x = 1$$$, beach would look like: $$$[s, \underline{2}, 1, i]$$$ at $$$t = 1$$$, since $$$2 > 1$$$ she would drown. So Koa waits $$$1$$$ second instead and beach looks like $$$[\underline{s}, 2, 1, i]$$$ at $$$t = 1$$$.  At $$$t = 1$$$ Koa swims to $$$x = 1$$$, beach looks like $$$[s, \underline{1}, 0, i]$$$ at $$$t = 2$$$. Koa doesn't drown because $$$1 \le 1$$$.  At $$$t = 2$$$ Koa swims to $$$x = 2$$$, beach looks like $$$[s, 2, \underline{1}, i]$$$ at $$$t = 3$$$. Koa doesn't drown because $$$1 \le 1$$$.  At $$$t = 3$$$ Koa swims to $$$x = 3$$$, beach looks like $$$[s, 1, 0, \underline{i}]$$$ at $$$t = 4$$$.  At $$$t = 4$$$ Koa is at $$$x = 3$$$ and she made it! We can show that in test case $$$2$$$ Koa can't get to the island.


You are given a figure on a grid representing stairs consisting of 7 steps. The width of the stair on height i is wi squares. Formally, the figure is created by consecutively joining rectangles of size wi × i so that the wi sides lie on one straight line. Thus, for example, if all wi = 1, the figure will look like that (different colors represent different rectangles):  And if w = {5, 1, 0, 3, 0, 0, 1}, then it looks like that:  Find the number of ways to color some borders of the figure's inner squares so that no square had all four borders colored. The borders of the squares lying on the border of the figure should be considered painted. The ways that differ with the figure's rotation should be considered distinct.

The single line of the input contains 7 numbers w1, w2, ..., w7 (0 ≤ wi ≤ 105). It is guaranteed that at least one of the wi's isn't equal to zero.

In the single line of the output display a single number — the answer to the problem modulo 109 + 7.

NoteAll the possible ways of painting the third sample are given below:


Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number n. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova that n is the answer to the arithmetic task for first-graders. In the textbook, a certain positive integer x was given. The task was to add x to the sum of the digits of the number x written in decimal numeral system.Since the number n on the board was small, Vova quickly guessed which x could be in the textbook. Now he wants to get a program which will search for arbitrary values of the number n for all suitable values of x or determine that such x does not exist. Write such a program for Vova.

The first line contains integer n (1 ≤ n ≤ 109).

In the first line print one integer k — number of different values of x satisfying the condition.  In next k lines print these values in ascending order.

NoteIn the first test case x = 15 there is only one variant: 15 + 1 + 5 = 21.In the second test case there are no such x.


In Pavlopolis University where Noora studies it was decided to hold beauty contest "Miss Pavlopolis University". Let's describe the process of choosing the most beautiful girl in the university in more detail.The contest is held in several stages. Suppose that exactly n girls participate in the competition initially. All the participants are divided into equal groups, x participants in each group. Furthermore the number x is chosen arbitrarily, i. e. on every stage number x can be different. Within each group the jury of the contest compares beauty of the girls in the format "each with each". In this way, if group consists of x girls, then  comparisons occur. Then, from each group, the most beautiful participant is selected. Selected girls enter the next stage of the competition. Thus if n girls were divided into groups, x participants in each group, then exactly  participants will enter the next stage. The contest continues until there is exactly one girl left who will be "Miss Pavlopolis University"But for the jury this contest is a very tedious task. They would like to divide the girls into groups in each stage so that the total number of pairwise comparisons of the girls is as few as possible. Let f(n) be the minimal total number of comparisons that should be made to select the most beautiful participant, if we admit n girls to the first stage.The organizers of the competition are insane. They give Noora three integers t, l and r and ask the poor girl to calculate the value of the following expression: t0·f(l) + t1·f(l + 1) + ... + tr - l·f(r). However, since the value of this expression can be quite large the organizers ask her to calculate it modulo 109 + 7. If Noora can calculate the value of this expression the organizers promise her to help during the beauty contest. But the poor girl is not strong in mathematics, so she turned for help to Leha and he turned to you.

The first and single line contains three integers t, l and r (1 ≤ t < 109 + 7, 2 ≤ l ≤ r ≤ 5·106).

In the first line print single integer — the value of the expression modulo 109 + 7.

NoteConsider the sample.It is necessary to find the value of .f(2) = 1. From two girls you can form only one group of two people, in which there will be one comparison.f(3) = 3. From three girls you can form only one group of three people, in which there will be three comparisons.f(4) = 3. From four girls you can form two groups of two girls each. Then at the first stage there will be two comparisons, one in each of the two groups. In the second stage there will be two girls and there will be one comparison between them. Total 2 + 1 = 3 comparisons. You can also leave all girls in same group in the first stage. Then  comparisons will occur. Obviously, it's better to split girls into groups in the first way.Then the value of the expression is .


Recently Anton found a box with digits in his room. There are k2 digits 2, k3 digits 3, k5 digits 5 and k6 digits 6.Anton's favorite integers are 32 and 256. He decided to compose this integers from digits he has. He wants to make the sum of these integers as large as possible. Help him solve this task!Each digit can be used no more than once, i.e. the composed integers should contain no more than k2 digits 2, k3 digits 3 and so on. Of course, unused digits are not counted in the sum.

The only line of the input contains four integers k2, k3, k5 and k6 — the number of digits 2, 3, 5 and 6 respectively (0 ≤ k2, k3, k5, k6 ≤ 5·106).

Print one integer — maximum possible sum of Anton's favorite integers that can be composed using digits from the box.

NoteIn the first sample, there are five digits 2, one digit 3, three digits 5 and four digits 6. Anton can compose three integers 256 and one integer 32 to achieve the value 256 + 256 + 256 + 32 = 800. Note, that there is one unused integer 2 and one unused integer 6. They are not counted in the answer.In the second sample, the optimal answer is to create on integer 256, thus the answer is 256.


You are given a tetrahedron. Let's mark its vertices with letters A, B, C and D correspondingly.  An ant is standing in the vertex D of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each moment of time he makes a step from one vertex to another one along some edge of the tetrahedron. The ant just can't stand on one place.You do not have to do much to solve the problem: your task is to count the number of ways in which the ant can go from the initial vertex D to itself in exactly n steps. In other words, you are asked to find out the number of different cyclic paths with the length of n from vertex D to itself. As the number can be quite large, you should print it modulo 1000000007 (109 + 7).

The first line contains the only integer n (1 ≤ n ≤ 107) — the required length of the cyclic path.

Print the only integer — the required number of ways modulo 1000000007 (109 + 7).

NoteThe required paths in the first sample are:   D - A - D  D - B - D  D - C - D


Farmer John is obsessed with making Bessie exercise more!Bessie is out grazing on the farm, which consists of $$$n$$$ fields connected by $$$m$$$ directed roads. Each road takes some time $$$w_i$$$ to cross. She is currently at field $$$1$$$ and will return to her home at field $$$n$$$ at the end of the day.Farmer John has plans to increase the time it takes to cross certain roads. He can increase the time it takes to cross each road by a nonnegative amount, but the total increase cannot exceed $$$x_i$$$ for the $$$i$$$-th plan. Determine the maximum he can make the shortest path from $$$1$$$ to $$$n$$$ for each of the $$$q$$$ independent plans.

The first line contains integers $$$n$$$ and $$$m$$$ ($$$2 \le n \le 50$$$, $$$1 \le m \le n \cdot (n-1)$$$) — the number of fields and number of roads, respectively. Each of the following $$$m$$$ lines contains $$$3$$$ integers, $$$u_i$$$, $$$v_i$$$, and $$$w_i$$$ ($$$1 \le u_i, v_i \le n$$$, $$$1 \le w_i \le 10^6$$$), meaning there is an road from field $$$u_i$$$ to field $$$v_i$$$ that takes $$$w_i$$$ time to cross. It is guaranteed that there exists a way to get to field $$$n$$$ from field $$$1$$$. It is guaranteed that the graph does not contain self-loops or parallel edges. It is possible to have a road from $$$u$$$ to $$$v$$$ and a road from $$$v$$$ to $$$u$$$. The next line contains a single integer $$$q$$$ ($$$1 \le q \le 10^5$$$), the number of plans. Each of the following $$$q$$$ lines contains a single integer $$$x_i$$$, the query ($$$0 \le x_i \le 10^5$$$).

For each query, output the maximum Farmer John can make the shortest path if the total increase does not exceed $$$x_i$$$. Your answer is considered correct if its absolute or relative error does not exceed $$$10^{-6}$$$. Formally, let your answer be $$$a$$$, and the jury's answer be $$$b$$$. Your answer is accepted if and only if $$$\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$$$.


Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.One day Petya came across an interval of numbers [a, a + l - 1]. Let F(x) be the number of lucky digits of number x. Find the minimum b (a < b) such, that F(a) = F(b), F(a + 1) = F(b + 1), ..., F(a + l - 1) = F(b + l - 1).

The single line contains two integers a and l (1 ≤ a, l ≤ 109) — the interval's first number and the interval's length correspondingly.

On the single line print number b — the answer to the problem.

NoteConsider that [a, b] denotes an interval of integers; this interval includes the boundaries. That is,


One day Petya was solving a very interesting problem. But although he used many optimization techniques, his solution still got Time limit exceeded verdict. Petya conducted a thorough analysis of his program and found out that his function for finding maximum element in an array of n positive integers was too slow. Desperate, Petya decided to use a somewhat unexpected optimization using parameter k, so now his function contains the following code:int fast_max(int n, int a[]) {     int ans = 0;    int offset = 0;    for (int i = 0; i < n; ++i)        if (ans < a[i]) {            ans = a[i];            offset = 0;        } else {            offset = offset + 1;            if (offset == k)                return ans;        }    return ans;}That way the function iteratively checks array elements, storing the intermediate maximum, and if after k consecutive iterations that maximum has not changed, it is returned as the answer.Now Petya is interested in fault rate of his function. He asked you to find the number of permutations of integers from 1 to n such that the return value of his function on those permutations is not equal to n. Since this number could be very big, output the answer modulo 109 + 7.

The only line contains two integers n and k (1 ≤ n, k ≤ 106), separated by a space — the length of the permutations and the parameter k.

Output the answer to the problem modulo 109 + 7.


In the city of Ultima Thule job applicants are often offered an IQ test. The test is as follows: the person gets a piece of squared paper with a 4 × 4 square painted on it. Some of the square's cells are painted black and others are painted white. Your task is to repaint at most one cell the other color so that the picture has a 2 × 2 square, completely consisting of cells of the same color. If the initial picture already has such a square, the person should just say so and the test will be completed. Your task is to write a program that determines whether it is possible to pass the test. You cannot pass the test if either repainting any cell or no action doesn't result in a 2 × 2 square, consisting of cells of the same color.

Four lines contain four characters each: the j-th character of the i-th line equals "." if the cell in the i-th row and the j-th column of the square is painted white, and "#", if the cell is black.

Print "YES" (without the quotes), if the test can be passed and "NO" (without the quotes) otherwise.

NoteIn the first test sample it is enough to repaint the first cell in the second row. After such repainting the required 2 × 2 square is on the intersection of the 1-st and 2-nd row with the 1-st and 2-nd column.


Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies.At first, Arya and Bran have 0 Candies. There are n days, at the i-th day, Arya finds ai candies in a box, that is given by the Many-Faced God. Every day she can give Bran at most 8 of her candies. If she don't give him the candies at the same day, they are saved for her and she can give them to him later.Your task is to find the minimum number of days Arya needs to give Bran k candies before the end of the n-th day. Formally, you need to output the minimum day index to the end of which k candies will be given out (the days are indexed from 1 to n).Print -1 if she can't give him k candies during n given days.

The first line contains two integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 10000). The second line contains n integers a1, a2, a3, ..., an (1 ≤ ai ≤ 100).

If it is impossible for Arya to give Bran k candies within n days, print -1. Otherwise print a single integer — the minimum number of days Arya needs to give Bran k candies before the end of the n-th day.

NoteIn the first sample, Arya can give Bran 3 candies in 2 days.In the second sample, Arya can give Bran 17 candies in 3 days, because she can give him at most 8 candies per day.In the third sample, Arya can't give Bran 9 candies, because she can give him at most 8 candies per day and she must give him the candies within 1 day.


Polycarpus has recently got interested in sequences of pseudorandom numbers. He learned that many programming languages generate such sequences in a similar way:  (for i ≥ 1). Here a, b, m are constants, fixed for the given realization of the pseudorandom numbers generator, r0 is the so-called randseed (this value can be set from the program using functions like RandSeed(r) or srand(n)), and  denotes the operation of taking the remainder of division.For example, if a = 2, b = 6, m = 12, r0 = 11, the generated sequence will be: 4, 2, 10, 2, 10, 2, 10, 2, 10, 2, 10, ....Polycarpus realized that any such sequence will sooner or later form a cycle, but the cycle may occur not in the beginning, so there exist a preperiod and a period. The example above shows a preperiod equal to 1 and a period equal to 2.Your task is to find the period of a sequence defined by the given values of a, b, m and r0. Formally, you have to find such minimum positive integer t, for which exists such positive integer k, that for any i ≥ k: ri = ri + t.

The single line of the input contains four integers a, b, m and r0 (1 ≤ m ≤ 105, 0 ≤ a, b ≤ 1000, 0 ≤ r0 < m), separated by single spaces.

Print a single integer — the period of the sequence.

NoteThe first sample is described above. In the second sample the sequence is (starting from the first element): 0, 3, 4, 1, 0, 3, 4, 1, 0, ...In the third sample the sequence is (starting from the first element): 33, 24, 78, 78, 78, 78, ...


Numbers k-bonacci (k is integer, k > 1) are a generalization of Fibonacci numbers and are determined as follows:  F(k, n) = 0, for integer n, 1 ≤ n < k;  F(k, k) = 1;  F(k, n) = F(k, n - 1) + F(k, n - 2) + ... + F(k, n - k), for integer n, n > k. Note that we determine the k-bonacci numbers, F(k, n), only for integer values of n and k.You've got a number s, represent it as a sum of several (at least two) distinct k-bonacci numbers.

The first line contains two integers s and k (1 ≤ s, k ≤ 109; k > 1).

In the first line print an integer m (m ≥ 2) that shows how many numbers are in the found representation. In the second line print m distinct integers a1, a2, ..., am. Each printed integer should be a k-bonacci number. The sum of printed integers must equal s. It is guaranteed that the answer exists. If there are several possible answers, print any of them.


You have $$$n \times n$$$ square grid and an integer $$$k$$$. Put an integer in each cell while satisfying the conditions below.  All numbers in the grid should be between $$$1$$$ and $$$k$$$ inclusive.  Minimum number of the $$$i$$$-th row is $$$1$$$ ($$$1 \le i \le n$$$).  Minimum number of the $$$j$$$-th column is $$$1$$$ ($$$1 \le j \le n$$$). Find the number of ways to put integers in the grid. Since the answer can be very large, find the answer modulo $$$(10^{9} + 7)$$$.  These are the examples of valid and invalid grid when $$$n=k=2$$$.

The only line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 250$$$, $$$1 \le k \le 10^{9}$$$).

Print the answer modulo $$$(10^{9} + 7)$$$.

NoteIn the first example, following $$$7$$$ cases are possible.  In the second example, make sure you print the answer modulo $$$(10^{9} + 7)$$$.


A new delivery of clothing has arrived today to the clothing store. This delivery consists of $$$a$$$ ties, $$$b$$$ scarves, $$$c$$$ vests and $$$d$$$ jackets.The store does not sell single clothing items — instead, it sells suits of two types:  a suit of the first type consists of one tie and one jacket;  a suit of the second type consists of one scarf, one vest and one jacket. Each suit of the first type costs $$$e$$$ coins, and each suit of the second type costs $$$f$$$ coins.Calculate the maximum possible cost of a set of suits that can be composed from the delivered clothing items. Note that one item cannot be used in more than one suit (though some items may be left unused).

The first line contains one integer $$$a$$$ $$$(1 \le a \le 100\,000)$$$ — the number of ties. The second line contains one integer $$$b$$$ $$$(1 \le b \le 100\,000)$$$ — the number of scarves. The third line contains one integer $$$c$$$ $$$(1 \le c \le 100\,000)$$$ — the number of vests. The fourth line contains one integer $$$d$$$ $$$(1 \le d \le 100\,000)$$$ — the number of jackets. The fifth line contains one integer $$$e$$$ $$$(1 \le e \le 1\,000)$$$ — the cost of one suit of the first type. The sixth line contains one integer $$$f$$$ $$$(1 \le f \le 1\,000)$$$ — the cost of one suit of the second type.

Print one integer — the maximum total cost of some set of suits that can be composed from the delivered items.

NoteIt is possible to compose three suits of the second type in the first example, and their total cost will be $$$6$$$. Since all jackets will be used, it's impossible to add anything to this set.The best course of action in the second example is to compose nine suits of the first type and eleven suits of the second type. The total cost is $$$9 \cdot 4 + 11 \cdot 6 = 102$$$.


The Professor has lost his home robot yet again. After some thinking Professor understood that he had left the robot in the basement.The basement in Professor's house is represented by a rectangle n × m, split into 1 × 1 squares. Some squares are walls which are impassable; other squares are passable. You can get from any passable square to any other passable square moving through edge-adjacent passable squares. One passable square is the exit from the basement. The robot is placed exactly in one passable square. Also the robot may be placed in the exit square.Professor is scared of going to the dark basement looking for the robot at night. However, he has a basement plan and the robot's remote control. Using the remote, Professor can send signals to the robot to shift one square left, right, up or down. When the robot receives a signal, it moves in the required direction if the robot's neighboring square in the given direction is passable. Otherwise, the robot stays idle.Professor wrote a sequence of k commands on a piece of paper. He thinks that the sequence can lead the robot out of the basement, wherever it's initial position might be. Professor programmed another robot to press the required buttons on the remote according to the notes on the piece of paper. Professor was just about to run the program and go to bed, when he had an epiphany.Executing each command takes some energy and Professor doesn't want to get huge electricity bill at the end of the month. That's why he wants to find in the sequence he has written out the minimal possible prefix that would guarantee to lead the robot out to the exit after the prefix is fulfilled. And that's the problem Professor challenges you with at this late hour.

The first line contains three integers n, m and k (3 ≤ n, m ≤ 150, 1 ≤ k ≤ 105). Next n lines contain m characters each — that is the Professor's basement's description: "#" stands for a wall, "." stands for a passable square and "E" stands for the exit from the basement (this square also is passable). It is possible to get from each passable square to the exit, all squares located by the n × m rectangle's perimeter are the walls. Exactly one square is the exit from the basement. The last line contains k characters, the description of the sequence of commands that Professor has written out on a piece of paper. "L", "R", "U", "D" stand for commands left, right, up and down correspondingly.

Print in the output file the length of the smallest possible prefix that will lead the robot to the exit square. In other words, wherever the robot had been positioned initially, it should be positioned in the exit square after all the commands from the prefix are fulfilled (during doing commands the robot can come and leave the exit square, but only the last position of the robot is interesting for us). If Professor is mistaken and no prefix (including the whole sequence) can bring the robot to the exit, print "-1" (without the quotes). If there is the only passable square and it is the exit, print "0" (without the quotes).


Makoto has a big blackboard with a positive integer $$$n$$$ written on it. He will perform the following action exactly $$$k$$$ times:Suppose the number currently written on the blackboard is $$$v$$$. He will randomly pick one of the divisors of $$$v$$$ (possibly $$$1$$$ and $$$v$$$) and replace $$$v$$$ with this divisor. As Makoto uses his famous random number generator (RNG) and as he always uses $$$58$$$ as his generator seed, each divisor is guaranteed to be chosen with equal probability.He now wonders what is the expected value of the number written on the blackboard after $$$k$$$ steps.It can be shown that this value can be represented as $$$\frac{P}{Q}$$$ where $$$P$$$ and $$$Q$$$ are coprime integers and $$$Q \not\equiv 0 \pmod{10^9+7}$$$. Print the value of $$$P \cdot Q^{-1}$$$ modulo $$$10^9+7$$$.

The only line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 10^{15}$$$, $$$1 \leq k \leq 10^4$$$).

Print a single integer — the expected value of the number on the blackboard after $$$k$$$ steps as $$$P \cdot Q^{-1} \pmod{10^9+7}$$$ for $$$P$$$, $$$Q$$$ defined above.

NoteIn the first example, after one step, the number written on the blackboard is $$$1$$$, $$$2$$$, $$$3$$$ or $$$6$$$ — each occurring with equal probability. Hence, the answer is $$$\frac{1+2+3+6}{4}=3$$$.In the second example, the answer is equal to $$$1 \cdot \frac{9}{16}+2 \cdot \frac{3}{16}+3 \cdot \frac{3}{16}+6 \cdot \frac{1}{16}=\frac{15}{8}$$$.


InputThe only line of the input is a string of 7 characters. The first character is letter A, followed by 6 digits. The input is guaranteed to be valid (for certain definition of "valid").OutputOutput a single integer.ExamplesInputA221033Output21InputA223635Output22InputA232726Output23


Fox Ciel studies number theory.She thinks a non-empty set S contains non-negative integers is perfect if and only if for any  (a can be equal to b), . Where operation xor means exclusive or operation (http://en.wikipedia.org/wiki/Exclusive_or).Please calculate the number of perfect sets consisting of integers not greater than k. The answer can be very large, so print it modulo 1000000007 (109 + 7).

The first line contains an integer k (0 ≤ k ≤ 109).

Print a single integer — the number of required sets modulo 1000000007 (109 + 7).

NoteIn example 1, there are 2 such sets: {0} and {0, 1}. Note that {1} is not a perfect set since 1 xor 1 = 0 and {1} doesn't contain zero.In example 4, there are 6 such sets: {0}, {0, 1}, {0, 2}, {0, 3}, {0, 4} and {0, 1, 2, 3}.


Gerald bought two very rare paintings at the Sotheby's auction and he now wants to hang them on the wall. For that he bought a special board to attach it to the wall and place the paintings on the board. The board has shape of an a1 × b1 rectangle, the paintings have shape of a a2 × b2 and a3 × b3 rectangles.Since the paintings are painted in the style of abstract art, it does not matter exactly how they will be rotated, but still, one side of both the board, and each of the paintings must be parallel to the floor. The paintings can touch each other and the edges of the board, but can not overlap or go beyond the edge of the board. Gerald asks whether it is possible to place the paintings on the board, or is the board he bought not large enough?

The first line contains two space-separated numbers a1 and b1 — the sides of the board. Next two lines contain numbers a2, b2, a3 and b3 — the sides of the paintings. All numbers ai, bi in the input are integers and fit into the range from 1 to 1000.

If the paintings can be placed on the wall, print "YES" (without the quotes), and if they cannot, print "NO" (without the quotes).

NoteThat's how we can place the pictures in the first test:And that's how we can do it in the third one.


Uncle Fyodor, Matroskin the Cat and Sharic the Dog live their simple but happy lives in Prostokvashino. Sometimes they receive parcels from Uncle Fyodor’s parents and sometimes from anonymous benefactors, in which case it is hard to determine to which one of them the package has been sent. A photographic rifle is obviously for Sharic who loves hunting and fish is for Matroskin, but for whom was a new video game console meant? Every one of the three friends claimed that the present is for him and nearly quarreled. Uncle Fyodor had an idea how to solve the problem justly: they should suppose that the console was sent to all three of them and play it in turns. Everybody got relieved but then yet another burning problem popped up — who will play first? This time Matroskin came up with a brilliant solution, suggesting the most fair way to find it out: play rock-paper-scissors together. The rules of the game are very simple. On the count of three every player shows a combination with his hand (or paw). The combination corresponds to one of three things: a rock, scissors or paper. Some of the gestures win over some other ones according to well-known rules: the rock breaks the scissors, the scissors cut the paper, and the paper gets wrapped over the stone. Usually there are two players. Yet there are three friends, that’s why they decided to choose the winner like that: If someone shows the gesture that wins over the other two players, then that player wins. Otherwise, another game round is required. Write a program that will determine the winner by the gestures they have shown.

The first input line contains the name of the gesture that Uncle Fyodor showed, the second line shows which gesture Matroskin showed and the third line shows Sharic’s gesture.

Print "F" (without quotes) if Uncle Fyodor wins. Print "M" if Matroskin wins and "S" if Sharic wins. If it is impossible to find the winner, print "?".


You are given a tree with $$$n$$$ nodes. You have to write non-negative integers on its edges so that the following condition would be satisfied:For every two nodes $$$i$$$, $$$j$$$, look at the path between them and count the sum of numbers on the edges of this path. Write all obtained sums on the blackboard. Then every integer from $$$1$$$ to $$$\lfloor \frac{2n^2}{9} \rfloor$$$ has to be written on the blackboard at least once. It is guaranteed that such an arrangement exists.

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of nodes. Each of the next $$$n-1$$$ lines contains two integers $$$u$$$ and $$$v$$$ ($$$1 \le u, v \le n$$$, $$$u \neq v$$$), meaning that there is an edge between nodes $$$u$$$ and $$$v$$$. It is guaranteed that these edges form a tree.

Output $$$n-1$$$ lines, each of form $$$u$$$ $$$v$$$ $$$x$$$ ($$$0 \le x \le 10^6$$$), which will mean that you wrote number $$$x$$$ on the edge between $$$u$$$, $$$v$$$.  Set of edges $$$(u, v)$$$ has to coincide with the set of edges of the input graph, but you can output edges in any order. You can also output ends of edges in an order different from the order in input.

NoteIn the first example, distance between nodes $$$1$$$ and $$$2$$$ is equal to $$$2$$$, between nodes $$$2$$$ and $$$3$$$ to $$$1$$$, between $$$1$$$ and $$$3$$$ to $$$3$$$.In the third example, numbers from $$$1$$$ to $$$9$$$ (inclusive) will be written on the blackboard, while we need just from $$$1$$$ to $$$5$$$ to pass the test.


Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place.But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams.Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania.It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win.

The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls.

Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1».

NoteDot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points.


Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet.

The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes).

Output the decoded ternary number. It can have leading zeroes.


John Doe has recently found a "Free Market" in his city — that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that each item is one of a kind and that means that you cannot exchange set {a, b} for set {v, a}. However, you can always exchange set x for any set y, unless there is item p, such that p occurs in x and p occurs in y.For each item, John knows its value ci. John's sense of justice doesn't let him exchange a set of items x for a set of items y, if s(x) + d < s(y) (s(x) is the total price of items in the set x). During one day John can exchange only one set of items for something else. Initially, he has no items. John wants to get a set of items with the maximum total price. Find the cost of such set and the minimum number of days John can get it in.

The first line contains two space-separated integers n, d (1 ≤ n ≤ 50, 1 ≤ d ≤ 104) — the number of items on the market and John's sense of justice value, correspondingly. The second line contains n space-separated integers ci (1 ≤ ci ≤ 104).

Print two space-separated integers: the maximum possible price in the set of items John can get and the minimum number of days needed to get such set.

NoteIn the first sample John can act like this:   Take the first item (1 - 0 ≤ 2).  Exchange the first item for the second one (3 - 1 ≤ 2).  Take the first item (1 - 0 ≤ 2).


Karen is getting ready for a new school day!  It is currently hh:mm, given in a 24-hour format. As you know, Karen loves palindromes, and she believes that it is good luck to wake up when the time is a palindrome.What is the minimum number of minutes she should sleep, such that, when she wakes up, the time is a palindrome?Remember that a palindrome is a string that reads the same forwards and backwards. For instance, 05:39 is not a palindrome, because 05:39 backwards is 93:50. On the other hand, 05:50 is a palindrome, because 05:50 backwards is 05:50.

The first and only line of input contains a single string in the format hh:mm (00 ≤  hh  ≤ 23, 00 ≤  mm  ≤ 59).

Output a single integer on a line by itself, the minimum number of minutes she should sleep, such that, when she wakes up, the time is a palindrome.

NoteIn the first test case, the minimum number of minutes Karen should sleep for is 11. She can wake up at 05:50, when the time is a palindrome.In the second test case, Karen can wake up immediately, as the current time, 13:31, is already a palindrome.In the third test case, the minimum number of minutes Karen should sleep for is 1 minute. She can wake up at 00:00, when the time is a palindrome.


Misha and Vasya participated in a Codeforces contest. Unfortunately, each of them solved only one problem, though successfully submitted it at the first attempt. Misha solved the problem that costs a points and Vasya solved the problem that costs b points. Besides, Misha submitted the problem c minutes after the contest started and Vasya submitted the problem d minutes after the contest started. As you know, on Codeforces the cost of a problem reduces as a round continues. That is, if you submit a problem that costs p points t minutes after the contest started, you get  points. Misha and Vasya are having an argument trying to find out who got more points. Help them to find out the truth.

The first line contains four integers a, b, c, d (250 ≤ a, b ≤ 3500, 0 ≤ c, d ≤ 180).  It is guaranteed that numbers a and b are divisible by 250 (just like on any real Codeforces round).

Output on a single line:  "Misha" (without the quotes), if Misha got more points than Vasya. "Vasya" (without the quotes), if Vasya got more points than Misha. "Tie" (without the quotes), if both of them got the same number of points.


Alice has a lovely piece of cloth. It has the shape of a square with a side of length $$$a$$$ centimeters. Bob also wants such piece of cloth. He would prefer a square with a side of length $$$b$$$ centimeters (where $$$b < a$$$). Alice wanted to make Bob happy, so she cut the needed square out of the corner of her piece and gave it to Bob. Now she is left with an ugly L shaped cloth (see pictures below).Alice would like to know whether the area of her cloth expressed in square centimeters is prime. Could you help her to determine it?

The first line contains a number $$$t$$$ ($$$1 \leq t \leq 5$$$) — the number of test cases. Each of the next $$$t$$$ lines describes the $$$i$$$-th test case. It contains two integers $$$a$$$ and $$$b~(1 \leq b < a \leq 10^{11})$$$ — the side length of Alice's square and the side length of the square that Bob wants.

Print $$$t$$$ lines, where the $$$i$$$-th line is the answer to the $$$i$$$-th test case. Print "YES" (without quotes) if the area of the remaining piece of cloth is prime, otherwise print "NO". You can print each letter in an arbitrary case (upper or lower).

NoteThe figure below depicts the first test case. The blue part corresponds to the piece which belongs to Bob, and the red part is the piece that Alice keeps for herself. The area of the red part is $$$6^2 - 5^2 = 36 - 25 = 11$$$, which is prime, so the answer is "YES".  In the second case, the area is $$$16^2 - 13^2 = 87$$$, which is divisible by $$$3$$$.  In the third case, the area of the remaining piece is $$$61690850361^2 - 24777622630^2 = 3191830435068605713421$$$. This number is not prime because $$$3191830435068605713421 = 36913227731 \cdot 86468472991 $$$.In the last case, the area is $$$34^2 - 33^2 = 67$$$.


This problem is same as the previous one, but has larger constraints.Aki is playing a new video game. In the video game, he will control Neko, the giant cat, to fly between planets in the Catniverse.There are $$$n$$$ planets in the Catniverse, numbered from $$$1$$$ to $$$n$$$. At the beginning of the game, Aki chooses the planet where Neko is initially located. Then Aki performs $$$k - 1$$$ moves, where in each move Neko is moved from the current planet $$$x$$$ to some other planet $$$y$$$ such that:  Planet $$$y$$$ is not visited yet.  $$$1 \leq y \leq x + m$$$ (where $$$m$$$ is a fixed constant given in the input) This way, Neko will visit exactly $$$k$$$ different planets. Two ways of visiting planets are called different if there is some index $$$i$$$ such that, the $$$i$$$-th planet visited in the first way is different from the $$$i$$$-th planet visited in the second way.What is the total number of ways to visit $$$k$$$ planets this way? Since the answer can be quite large, print it modulo $$$10^9 + 7$$$.

The only line contains three integers $$$n$$$, $$$k$$$ and $$$m$$$ ($$$1 \le n \le 10^9$$$, $$$1 \le k \le \min(n, 12)$$$, $$$1 \le m \le 4$$$) — the number of planets in the Catniverse, the number of planets Neko needs to visit and the said constant $$$m$$$.

Print exactly one integer — the number of different ways Neko can visit exactly $$$k$$$ planets. Since the answer can be quite large, print it modulo $$$10^9 + 7$$$.

NoteIn the first example, there are $$$4$$$ ways Neko can visit all the planets:  $$$1 \rightarrow 2 \rightarrow 3$$$  $$$2 \rightarrow 3 \rightarrow 1$$$  $$$3 \rightarrow 1 \rightarrow 2$$$  $$$3 \rightarrow 2 \rightarrow 1$$$ In the second example, there are $$$9$$$ ways Neko can visit exactly $$$2$$$ planets:  $$$1 \rightarrow 2$$$  $$$2 \rightarrow 1$$$  $$$2 \rightarrow 3$$$  $$$3 \rightarrow 1$$$  $$$3 \rightarrow 2$$$  $$$3 \rightarrow 4$$$  $$$4 \rightarrow 1$$$  $$$4 \rightarrow 2$$$  $$$4 \rightarrow 3$$$ In the third example, with $$$m = 4$$$, Neko can visit all the planets in any order, so there are $$$5! = 120$$$ ways Neko can visit all the planets.In the fourth example, Neko only visit exactly $$$1$$$ planet (which is also the planet he initially located), and there are $$$100$$$ ways to choose the starting planet for Neko.


Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are "a", "o", "u", "i", and "e". Other letters are consonant.In Berlanese, there has to be a vowel after every consonant, but there can be any letter after any vowel. The only exception is a consonant "n"; after this letter, there can be any letter (not only a vowel) or there can be no letter at all. For example, the words "harakiri", "yupie", "man", and "nbo" are Berlanese while the words "horse", "king", "my", and "nz" are not.Help Vitya find out if a word $$$s$$$ is Berlanese.

The first line of the input contains the string $$$s$$$ consisting of $$$|s|$$$ ($$$1\leq |s|\leq 100$$$) lowercase Latin letters.

Print "YES" (without quotes) if there is a vowel after every consonant except "n", otherwise print "NO". You can print each letter in any case (upper or lower).

NoteIn the first and second samples, a vowel goes after each consonant except "n", so the word is Berlanese.In the third sample, the consonant "c" goes after the consonant "r", and the consonant "s" stands on the end, so the word is not Berlanese.


Gerald got a very curious hexagon for his birthday. The boy found out that all the angles of the hexagon are equal to . Then he measured the length of its sides, and found that each of them is equal to an integer number of centimeters. There the properties of the hexagon ended and Gerald decided to draw on it.He painted a few lines, parallel to the sides of the hexagon. The lines split the hexagon into regular triangles with sides of 1 centimeter. Now Gerald wonders how many triangles he has got. But there were so many of them that Gerald lost the track of his counting. Help the boy count the triangles.

The first and the single line of the input contains 6 space-separated integers a1, a2, a3, a4, a5 and a6 (1 ≤ ai ≤ 1000) — the lengths of the sides of the hexagons in centimeters in the clockwise order. It is guaranteed that the hexagon with the indicated properties and the exactly such sides exists.

Print a single integer — the number of triangles with the sides of one 1 centimeter, into which the hexagon is split.

NoteThis is what Gerald's hexagon looks like in the first sample:And that's what it looks like in the second sample:


Unlucky year in Berland is such a year that its number n can be represented as n = xa + yb, where a and b are non-negative integer numbers. For example, if x = 2 and y = 3 then the years 4 and 17 are unlucky (4 = 20 + 31, 17 = 23 + 32 = 24 + 30) and year 18 isn't unlucky as there is no such representation for it.Such interval of years that there are no unlucky years in it is called The Golden Age.You should write a program which will find maximum length of The Golden Age which starts no earlier than the year l and ends no later than the year r. If all years in the interval [l, r] are unlucky then the answer is 0.

The first line contains four integer numbers x, y, l and r (2 ≤ x, y ≤ 1018, 1 ≤ l ≤ r ≤ 1018).

Print the maximum length of The Golden Age within the interval [l, r]. If all years in the interval [l, r] are unlucky then print 0.

NoteIn the first example the unlucky years are 2, 3, 4, 5, 7, 9 and 10. So maximum length of The Golden Age is achived in the intervals [1, 1], [6, 6] and [8, 8].In the second example the longest Golden Age is the interval [15, 22].


qd ucyhf yi q fhycu dkcruh mxeiu huluhiu yi q tyvvuhudj fhycu dkcruh. oekh jqia yi je vydt jxu djx ucyhf.

jxu ydfkj sediyiji ev q iydwbu ydjuwuh d (1 ≤ d ≤ 11184) — jxu edu-rqiut ydtun ev jxu ucyhf je vydt.


Having problems with tram routes in the morning, Arkady decided to return home by metro. Fortunately for Arkady, there is only one metro line in the city.Unfortunately for Arkady, the line is circular. It means that the stations are enumerated from $$$1$$$ to $$$n$$$ and there is a tunnel between any pair of consecutive stations as well as between the station $$$1$$$ and the station $$$n$$$. Trains that go in clockwise direction visit the stations in order $$$1 \to 2 \to 3 \to \ldots \to n \to 1$$$ while the trains that go in the counter-clockwise direction visit the stations in the reverse order.The stations that have numbers from $$$1$$$ to $$$m$$$ have interior mostly in red colors while the stations that have numbers from $$$m + 1$$$ to $$$n$$$ have blue interior. Arkady entered the metro at station $$$s$$$ and decided to use the following algorithm to choose his way home.  Initially he has a positive integer $$$t$$$ in his mind.  If the current station has red interior, he takes a clockwise-directed train, otherwise he takes a counter-clockwise-directed train.  He rides exactly $$$t$$$ stations on the train and leaves the train.  He decreases $$$t$$$ by one. If $$$t$$$ is still positive, he returns to step $$$2$$$. Otherwise he exits the metro. You have already realized that this algorithm most probably won't bring Arkady home. Find the station he will exit the metro at so that you can continue helping him.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$3 \le n \le 10^5$$$, $$$1 \le m < n$$$) — the total number of stations and the number of stations that have red interior. The second line contains two integers $$$s$$$ and $$$t$$$ ($$$1 \le s \le n$$$, $$$1 \le t \le 10^{12}$$$) — the starting station and the initial value of $$$t$$$.

Output the only integer — the station where Arkady will exit the metro.

NoteConsider the first example. There are $$$10$$$ stations and the first $$$4$$$ of them are red. Arkady starts at station $$$3$$$ with value $$$t = 1$$$, so just rides $$$1$$$ station in clockwise direction and ends up on the station $$$4$$$.In the second example the metro is same as in the first example, but Arkady starts at station $$$3$$$ with value $$$t = 5$$$.   It is a red station so he rides $$$5$$$ stations in clockwise direction and leaves the train at station $$$8$$$.  It is a blue station, so he rides $$$4$$$ stations in counter-clockwise direction and leaves at station $$$4$$$.  It is a red station, so he rides $$$3$$$ stations in clockwise direction and leaves at station $$$7$$$.  It is a blue station, so he rides $$$2$$$ stations in counter-clockwise direction and leaves at station $$$5$$$.  It is a blue station, so he rides $$$1$$$ station in counter-clockwise direction and leaves at station $$$4$$$.  Now $$$t = 0$$$, so Arkady exits metro at the station $$$4$$$.


Noora is a student of one famous high school. It's her final year in school — she is going to study in university next year. However, she has to get an «A» graduation certificate in order to apply to a prestigious one.In school, where Noora is studying, teachers are putting down marks to the online class register, which are integers from 1 to k. The worst mark is 1, the best is k. Mark that is going to the certificate, is calculated as an average of all the marks, rounded to the closest integer. If several answers are possible, rounding up is produced. For example, 7.3 is rounded to 7, but 7.5 and 7.8784 — to 8. For instance, if Noora has marks [8, 9], then the mark to the certificate is 9, because the average is equal to 8.5 and rounded to 9, but if the marks are [8, 8, 9], Noora will have graduation certificate with 8.To graduate with «A» certificate, Noora has to have mark k.Noora got n marks in register this year. However, she is afraid that her marks are not enough to get final mark k. Noora decided to ask for help in the internet, where hacker Leha immediately responded to her request. He is ready to hack class register for Noora and to add Noora any number of additional marks from 1 to k. At the same time, Leha want his hack be unseen to everyone, so he decided to add as less as possible additional marks. Please help Leha to calculate the minimal number of marks he has to add, so that final Noora's mark will become equal to k.

The first line contains two integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 100) denoting the number of marks, received by Noora and the value of highest possible mark. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ k) denoting marks received by Noora before Leha's hack.

Print a single integer — minimal number of additional marks, that Leha has to add in order to change Noora's final mark to k.

NoteConsider the first example testcase.Maximal mark is 10, Noora received two marks — 8 and 9, so current final mark is 9. To fix it, Leha can add marks [10, 10, 10, 10] (4 marks in total) to the registry, achieving Noora having average mark equal to . Consequently, new final mark is 10. Less number of marks won't fix the situation.In the second example Leha can add [5, 5, 5] to the registry, so that making average mark equal to 4.5, which is enough to have 5 in the certificate.


InputThe first line of the input contains a single integer $$$N$$$ ($$$1 \le N \le 24$$$). The next $$$N$$$ lines contain $$$5$$$ space-separated integers each. The first three integers will be between 0 and 2, inclusive. The last two integers will be between 0 and 3, inclusive. The sum of the first three integers will be equal to the sum of the last two integers.OutputOutput the result – a string of lowercase English letters.ExamplesInput
1
1 0 0 1 0
Output
a
Input
10
2 0 0 1 1
1 1 1 2 1
2 1 0 1 2
1 1 0 1 1
2 1 0 2 1
1 1 1 2 1
1 2 1 3 1
2 0 0 1 1
1 1 0 1 1
1 1 2 2 2
Output
codeforcez


Nastya received a gift on New Year — a magic wardrobe. It is magic because in the end of each month the number of dresses in it doubles (i.e. the number of dresses becomes twice as large as it is in the beginning of the month).Unfortunately, right after the doubling the wardrobe eats one of the dresses (if any) with the 50% probability. It happens every month except the last one in the year. Nastya owns x dresses now, so she became interested in the expected number of dresses she will have in one year. Nastya lives in Byteland, so the year lasts for k + 1 months.Nastya is really busy, so she wants you to solve this problem. You are the programmer, after all. Also, you should find the answer modulo 109 + 7, because it is easy to see that it is always integer.

The only line contains two integers x and k (0 ≤ x, k ≤ 1018), where x is the initial number of dresses and k + 1 is the number of months in a year in Byteland.

In the only line print a single integer — the expected number of dresses Nastya will own one year later modulo 109 + 7.

NoteIn the first example a year consists on only one month, so the wardrobe does not eat dresses at all.In the second example after the first month there are 3 dresses with 50% probability and 4 dresses with 50% probability. Thus, in the end of the year there are 6 dresses with 50% probability and 8 dresses with 50% probability. This way the answer for this test is (6 + 8) / 2 = 7.


This is an easier version of the problem. In this version, $$$n \le 6$$$.Marek is working hard on creating strong testcases to his new algorithmic problem. You want to know what it is? Nah, we're not telling you. However, we can tell you how he generates the testcases.Marek chooses an integer $$$n$$$ and $$$n^2$$$ integers $$$p_{ij}$$$ ($$$1 \le i \le n$$$, $$$1 \le j \le n$$$). He then generates a random bipartite graph with $$$2n$$$ vertices. There are $$$n$$$ vertices on the left side: $$$\ell_1, \ell_2, \dots, \ell_n$$$, and $$$n$$$ vertices on the right side: $$$r_1, r_2, \dots, r_n$$$. For each $$$i$$$ and $$$j$$$, he puts an edge between vertices $$$\ell_i$$$ and $$$r_j$$$ with probability $$$p_{ij}$$$ percent.It turns out that the tests will be strong only if a perfect matching exists in the generated graph. What is the probability that this will occur?It can be shown that this value can be represented as $$$\frac{P}{Q}$$$ where $$$P$$$ and $$$Q$$$ are coprime integers and $$$Q \not\equiv 0 \pmod{10^9+7}$$$. Let $$$Q^{-1}$$$ be an integer for which $$$Q \cdot Q^{-1} \equiv 1 \pmod{10^9+7}$$$. Print the value of $$$P \cdot Q^{-1}$$$ modulo $$$10^9+7$$$.

The first line of the input contains a single integer $$$n$$$ ($$$\mathbf{1 \le n \le 6}$$$). The following $$$n$$$ lines describe the probabilities of each edge appearing in the graph. The $$$i$$$-th of the lines contains $$$n$$$ integers $$$p_{i1}, p_{i2}, \dots, p_{in}$$$ ($$$0 \le p_{ij} \le 100$$$); $$$p_{ij}$$$ denotes the probability, in percent, of an edge appearing between $$$\ell_i$$$ and $$$r_j$$$.

Print a single integer — the probability that the perfect matching exists in the bipartite graph, written as $$$P \cdot Q^{-1} \pmod{10^9+7}$$$ for $$$P$$$, $$$Q$$$ defined above.

NoteIn the first sample test, each of the $$$16$$$ graphs below is equally probable. Out of these, $$$7$$$ have a perfect matching:  Therefore, the probability is equal to $$$\frac{7}{16}$$$. As $$$16 \cdot 562\,500\,004 = 1 \pmod{10^9+7}$$$, the answer to the testcase is $$$7 \cdot 562\,500\,004 \mod{(10^9+7)} = 937\,500\,007$$$.


You are given two set of points. The first set is determined by the equation A1x + B1y + C1 = 0, and the second one is determined by the equation A2x + B2y + C2 = 0.Write the program which finds the number of points in the intersection of two given sets.

The first line of the input contains three integer numbers A1, B1, C1 separated by space. The second line contains three integer numbers A2, B2, C2 separated by space. All the numbers are between -100 and 100, inclusive.

Print the number of points in the intersection or -1 if there are infinite number of points.


Real Cosmic Communications is the largest telecommunication company on a far far away planet, located at the very edge of the universe. RCC launches communication satellites.The planet is at the very edge of the universe, so its form is half of a circle. Its radius is r, the ends of its diameter are points A and B. The line AB is the edge of the universe, so one of the half-planes contains nothing, neither the planet, nor RCC satellites, nor anything else. Let us introduce coordinates in the following way: the origin is at the center of AB segment, OX axis coincides with line AB, the planet is completely in y > 0 half-plane.The satellite can be in any point of the universe, except the planet points. Satellites are never located beyond the edge of the universe, nor on the edge itself — that is, they have coordinate y > 0. Satellite antennas are directed in such way that they cover the angle with the vertex in the satellite, and edges directed to points A and B. Let us call this area the satellite coverage area. The picture below shows coordinate system and coverage area of a satellite.  When RCC was founded there were no satellites around the planet. Since then there have been several events of one of the following types:   1 x y — launch the new satellite and put it to the point (x, y). Satellites never move and stay at the point they were launched. Let us assign the number i to the i-th satellite in order of launching, starting from one.  2 i — remove satellite number i.  3 i j — make an attempt to create a communication channel between satellites i and j. To create a communication channel a repeater is required. It must not be located inside the planet, but can be located at its half-circle border, or above it. Repeater must be in coverage area of both satellites i and j. To avoid signal interference, it must not be located in coverage area of any other satellite. Of course, the repeater must be within the universe, it must have a coordinate y > 0. For each attempt to create a communication channel you must find out whether it is possible.Sample test has the following satellites locations:

The first line of input data contains integers r and n — radius of the planet and the number of events (1 ≤ r ≤ 109, 1 ≤ n ≤ 5·105). Each of the following n lines describe events in the specified format. Satellite coordinates are integer, the satisfy the following constraints |x| ≤ 109, 0 < y ≤ 109. No two satellites that simultaneously exist can occupy the same point. Distance from each satellite to the center of the planet is strictly greater than r. It is guaranteed that events of types 2 and 3 only refer to satellites that exist at the moment. For all events of type 3 the inequality i ≠ j is satisfied.

For each event of type 3 print «YES» on a separate line, if it is possible to create a communication channel, or «NO» if it is impossible.


Meg the Rabbit decided to do something nice, specifically — to determine the shortest distance between two points on the surface of our planet. But Meg... what can you say, she wants everything simple. So, she already regards our planet as a two-dimensional circle. No, wait, it's even worse — as a square of side n. Thus, the task has been reduced to finding the shortest path between two dots on a square (the path should go through the square sides). To simplify the task let us consider the vertices of the square to lie at points whose coordinates are: (0, 0), (n, 0), (0, n) and (n, n).

The single line contains 5 space-separated integers: n, x1, y1, x2, y2 (1 ≤ n ≤ 1000, 0 ≤ x1, y1, x2, y2 ≤ n) which correspondingly represent a side of the square, the coordinates of the first point and the coordinates of the second point. It is guaranteed that the points lie on the sides of the square.

You must print on a single line the shortest distance between the points.


The Smart Beaver from ABBYY came up with another splendid problem for the ABBYY Cup participants! This time the Beaver invites the contest participants to check out a problem on sorting documents by their subjects. Let's describe the problem:You've got some training set of documents. For each document you know its subject. The subject in this problem is an integer from 1 to 3. Each of these numbers has a physical meaning. For instance, all documents with subject 3 are about trade.You can download the training set of documents at the following link: http://download4.abbyy.com/a2/X2RZ2ZWXBG5VYWAL61H76ZQM/train.zip. The archive contains three directories with names "1", "2", "3". Directory named "1" contains documents on the 1-st subject, directory "2" contains documents on the 2-nd subject, and directory "3" contains documents on the 3-rd subject. Each document corresponds to exactly one file from some directory.All documents have the following format: the first line contains the document identifier, the second line contains the name of the document, all subsequent lines contain the text of the document. The document identifier is used to make installing the problem more convenient and has no useful information for the participants.You need to write a program that should indicate the subject for a given document. It is guaranteed that all documents given as input to your program correspond to one of the three subjects of the training set.

The first line contains integer id (0 ≤ id ≤ 106) — the document identifier. The second line contains the name of the document. The third and the subsequent lines contain the text of the document. It is guaranteed that the size of any given document will not exceed 10 kilobytes. The tests for this problem are divided into 10 groups. Documents of groups 1 and 2 are taken from the training set, but their identifiers will not match the identifiers specified in the training set. Groups from the 3-rd to the 10-th are roughly sorted by the author in ascending order of difficulty (these groups contain documents which aren't present in the training set).

Print an integer from 1 to 3, inclusive — the number of the subject the given document corresponds to.


The weather is fine today and hence it's high time to climb the nearby pine and enjoy the landscape.The pine's trunk includes several branches, located one above another and numbered from 2 to y. Some of them (more precise, from 2 to p) are occupied by tiny vile grasshoppers which you're at war with. These grasshoppers are known for their awesome jumping skills: the grasshopper at branch x can jump to branches .Keeping this in mind, you wisely decided to choose such a branch that none of the grasshoppers could interrupt you. At the same time you wanna settle as high as possible since the view from up there is simply breathtaking.In other words, your goal is to find the highest branch that cannot be reached by any of the grasshoppers or report that it's impossible.

The only line contains two integers p and y (2 ≤ p ≤ y ≤ 109).

Output the number of the highest suitable branch. If there are none, print -1 instead.

NoteIn the first sample case grasshopper from branch 2 reaches branches 2, 4 and 6 while branch 3 is initially settled by another grasshopper. Therefore the answer is 5.It immediately follows that there are no valid branches in second sample case.


Emuskald is an innovative musician and always tries to push the boundaries of music production. Now he has come up with an idea for a revolutionary musical instrument — a rectangular harp.A rectangular harp is a rectangle n × m consisting of n rows and m columns. The rows are numbered 1 to n from top to bottom. Similarly the columns are numbered 1 to m from left to right. String pins are spaced evenly across every side, one per unit. Thus there are n pins on the left and right sides of the harp and m pins on its top and bottom. The harp has exactly n + m different strings, each string connecting two different pins, each on a different side of the harp.Emuskald has ordered his apprentice to construct the first ever rectangular harp. However, he didn't mention that no two strings can cross, otherwise it would be impossible to play the harp. Two strings cross if the segments connecting their pins intersect. To fix the harp, Emuskald can perform operations of two types:   pick two different columns and swap their pins on each side of the harp, not changing the pins that connect each string;  pick two different rows and swap their pins on each side of the harp, not changing the pins that connect each string; In the following example, he can fix the harp by swapping two columns:   Help Emuskald complete his creation and find the permutations how the rows and columns of the harp need to be rearranged, or tell that it is impossible to do so. He can detach and reattach each string to its pins, so the physical layout of the strings doesn't matter.

The first line of input contains two space-separated integers numbers n and m (1 ≤ n, m ≤ 105), the height and width of the harp in units. Each of the following n + m lines contains 4 space-separated tokens, describing a single string: two symbols ai, bi and two integer numbers pi, qi. The pair ai, pi describes the first pin, and the pair bi, qi describes the second pin of the string; A pair s, x describes the position of a single pin in a following way:    s is equal to one of the symbols "L", "T", "R" or "B" (without quotes), which means that the pin is positioned on the left, top, right or bottom side of the harp accordingly;  x is equal to the number of the row, if the pin is on the left or right border of the harp, and to the number of the column, if the pin is on the top or bottom border of the harp.  It is guaranteed that no two different strings are connected to the same pin.

If it is possible to rearrange the rows and columns to fix the harp, on the first line output n space-separated integers — the old numbers of rows now placed from top to bottom in the fixed harp. On the second line, output m space-separated integers — the old numbers of columns now placed from left to right in the fixed harp. If it is impossible to rearrange the rows and columns to fix the harp, output "No solution" (without quotes).


Let's define the transformation P of a sequence of integers a1, a2, ..., an as b1, b2, ..., bn, where bi = a1 | a2 | ... | ai for all i = 1, 2, ..., n, where | is the bitwise OR operation.Vasya consequently applies the transformation P to all sequences of length n consisting of integers from 1 to 2k - 1 inclusive. He wants to know how many of these sequences have such property that their transformation is a strictly increasing sequence. Help him to calculate this number modulo 109 + 7.

The only line of the input contains two integers n and k (1 ≤ n ≤ 1018, 1 ≤ k ≤ 30 000).

Print a single integer — the answer to the problem modulo 109 + 7.


A New Year party is not a New Year party without lemonade! As usual, you are expecting a lot of guests, and buying lemonade has already become a pleasant necessity.Your favorite store sells lemonade in bottles of n different volumes at different costs. A single bottle of type i has volume 2i - 1 liters and costs ci roubles. The number of bottles of each type in the store can be considered infinite.You want to buy at least L liters of lemonade. How many roubles do you have to spend?

The first line contains two integers n and L (1 ≤ n ≤ 30; 1 ≤ L ≤ 109) — the number of types of bottles in the store and the required amount of lemonade in liters, respectively. The second line contains n integers c1, c2, ..., cn (1 ≤ ci ≤ 109) — the costs of bottles of different types.

Output a single integer — the smallest number of roubles you have to pay in order to buy at least L liters of lemonade.

NoteIn the first example you should buy one 8-liter bottle for 90 roubles and two 2-liter bottles for 30 roubles each. In total you'll get 12 liters of lemonade for just 150 roubles.In the second example, even though you need only 3 liters, it's cheaper to buy a single 8-liter bottle for 10 roubles.In the third example it's best to buy three 1-liter bottles for 10 roubles each, getting three liters for 30 roubles.


Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Being a dutiful student, he immediately learns how to spell the word.Hongcow has decided to try to make new words from this one. He starts by taking the word he just learned how to spell, and moves the last character of the word to the beginning of the word. He calls this a cyclic shift. He can apply cyclic shift many times. For example, consecutively applying cyclic shift operation to the word "abracadabra" Hongcow will get words "aabracadabr", "raabracadab" and so on.Hongcow is now wondering how many distinct words he can generate by doing the cyclic shift arbitrarily many times. The initial string is also counted.

The first line of input will be a single string s (1 ≤ |s| ≤ 50), the word Hongcow initially learns how to spell. The string s consists only of lowercase English letters ('a'–'z').

Output a single integer equal to the number of distinct strings that Hongcow can obtain by applying the cyclic shift arbitrarily many times to the given string.

NoteFor the first sample, the strings Hongcow can generate are "abcd", "dabc", "cdab", and "bcda".For the second sample, no matter how many times Hongcow does the cyclic shift, Hongcow can only generate "bbb".For the third sample, the two strings Hongcow can generate are "yzyz" and "zyzy".


Little Johnny has recently learned about set theory. Now he is studying binary relations. You've probably heard the term "equivalence relation". These relations are very important in many areas of mathematics. For example, the equality of the two numbers is an equivalence relation.A set ρ of pairs (a, b) of elements of some set A is called a binary relation on set A. For two elements a and b of the set A we say that they are in relation ρ, if pair , in this case we use a notation .Binary relation is equivalence relation, if: It is reflexive (for any a it is true that ); It is symmetric (for any a, b it is true that if , then ); It is transitive (if  and , than ).Little Johnny is not completely a fool and he noticed that the first condition is not necessary! Here is his "proof":Take any two elements, a and b. If , then  (according to property (2)), which means  (according to property (3)).It's very simple, isn't it? However, you noticed that Johnny's "proof" is wrong, and decided to show him a lot of examples that prove him wrong.Here's your task: count the number of binary relations over a set of size n such that they are symmetric, transitive, but not an equivalence relations (i.e. they are not reflexive).Since their number may be very large (not 0, according to Little Johnny), print the remainder of integer division of this number by 109 + 7.

A single line contains a single integer n (1 ≤ n ≤ 4000).

In a single line print the answer to the problem modulo 109 + 7.

NoteIf n = 1 there is only one such relation — an empty one, i.e. . In other words, for a single element x of set A the following is hold: .If n = 2 there are three such relations. Let's assume that set A consists of two elements, x and y. Then the valid relations are , ρ = {(x, x)}, ρ = {(y, y)}. It is easy to see that the three listed binary relations are symmetric and transitive relations, but they are not equivalence relations.


Once upon a time in the Kingdom of Far Far Away lived Sir Lancelot, the chief Royal General. He was very proud of his men and he liked to invite the King to come and watch drill exercises which demonstrated the fighting techniques and tactics of the squad he was in charge of. But time went by and one day Sir Lancelot had a major argument with the Fairy Godmother (there were rumors that the argument occurred after the general spoke badly of the Godmother's flying techniques. That seemed to hurt the Fairy Godmother very deeply). As the result of the argument, the Godmother put a rather strange curse upon the general. It sounded all complicated and quite harmless: "If the squared distance between some two soldiers equals to 5, then those soldiers will conflict with each other!"The drill exercises are held on a rectangular n × m field, split into nm square 1 × 1 segments for each soldier. Thus, the square of the distance between the soldiers that stand on squares (x1, y1) and (x2, y2) equals exactly (x1 - x2)2 + (y1 - y2)2. Now not all nm squad soldiers can participate in the drill exercises as it was before the Fairy Godmother's curse. Unless, of course, the general wants the soldiers to fight with each other or even worse... For example, if he puts a soldier in the square (2, 2), then he cannot put soldiers in the squares (1, 4), (3, 4), (4, 1) and (4, 3) — each of them will conflict with the soldier in the square (2, 2).Your task is to help the general. You are given the size of the drill exercise field. You are asked to calculate the maximum number of soldiers that can be simultaneously positioned on this field, so that no two soldiers fall under the Fairy Godmother's curse.

The single line contains space-separated integers n and m (1 ≤ n, m ≤ 1000) that represent the size of the drill exercise field.

Print the desired maximum number of warriors.

NoteIn the first sample test Sir Lancelot can place his 4 soldiers on the 2 × 4 court as follows (the soldiers' locations are marked with gray circles on the scheme):  In the second sample test he can place 6 soldiers on the 3 × 4 site in the following manner:


Every summer Vitya comes to visit his grandmother in the countryside. This summer, he got a huge wart. Every grandma knows that one should treat warts when the moon goes down. Thus, Vitya has to catch the moment when the moon is down.Moon cycle lasts 30 days. The size of the visible part of the moon (in Vitya's units) for each day is 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, and then cycle repeats, thus after the second 1 again goes 0.As there is no internet in the countryside, Vitya has been watching the moon for n consecutive days and for each of these days he wrote down the size of the visible part of the moon. Help him find out whether the moon will be up or down next day, or this cannot be determined by the data he has.

The first line of the input contains a single integer n (1 ≤ n ≤ 92) — the number of consecutive days Vitya was watching the size of the visible part of the moon.  The second line contains n integers ai (0 ≤ ai ≤ 15) — Vitya's records. It's guaranteed that the input data is consistent.

If Vitya can be sure that the size of visible part of the moon on day n + 1 will be less than the size of the visible part on day n, then print "DOWN" at the only line of the output. If he might be sure that the size of the visible part will increase, then print "UP". If it's impossible to determine what exactly will happen with the moon, print -1.

NoteIn the first sample, the size of the moon on the next day will be equal to 8, thus the answer is "UP".In the second sample, the size of the moon on the next day will be 11, thus the answer is "DOWN".In the third sample, there is no way to determine whether the size of the moon on the next day will be 7 or 9, thus the answer is -1.


Polycarpus is an amateur businessman. Recently he was surprised to find out that the market for paper scissors is completely free! Without further ado, Polycarpus decided to start producing and selling such scissors.Polycaprus calculated that the optimal celling price for such scissors would be p bourles. However, he read somewhere that customers are attracted by prices that say something like "Special Offer! Super price 999 bourles!". So Polycarpus decided to lower the price a little if it leads to the desired effect.Polycarpus agrees to lower the price by no more than d bourles so that the number of nines at the end of the resulting price is maximum. If there are several ways to do it, he chooses the maximum possible price.Note, Polycarpus counts only the trailing nines in a price.

The first line contains two integers p and d (1 ≤ p ≤ 1018; 0 ≤ d < p) — the initial price of scissors and the maximum possible price reduction. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.

Print the required price — the maximum price that ends with the largest number of nines and that is less than p by no more than d. The required number shouldn't have leading zeroes.


The only difference between easy and hard versions is constraints.The BerTV channel every day broadcasts one episode of one of the $$$k$$$ TV shows. You know the schedule for the next $$$n$$$ days: a sequence of integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le k$$$), where $$$a_i$$$ is the show, the episode of which will be shown in $$$i$$$-th day.The subscription to the show is bought for the entire show (i.e. for all its episodes), for each show the subscription is bought separately.How many minimum subscriptions do you need to buy in order to have the opportunity to watch episodes of purchased shows $$$d$$$ ($$$1 \le d \le n$$$) days in a row? In other words, you want to buy the minimum number of TV shows so that there is some segment of $$$d$$$ consecutive days in which all episodes belong to the purchased shows.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then $$$t$$$ test case descriptions follow. The first line of each test case contains three integers $$$n, k$$$ and $$$d$$$ ($$$1 \le n \le 100$$$, $$$1 \le k \le 100$$$, $$$1 \le d \le n$$$). The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le k$$$), where $$$a_i$$$ is the show that is broadcasted on the $$$i$$$-th day. It is guaranteed that the sum of the values of $$$n$$$ for all test cases in the input does not exceed $$$100$$$.

Print $$$t$$$ integers — the answers to the test cases in the input in the order they follow. The answer to a test case is the minimum number of TV shows for which you need to purchase a subscription so that you can watch episodes of the purchased TV shows on BerTV for $$$d$$$ consecutive days. Please note that it is permissible that you will be able to watch more than $$$d$$$ days in a row.

NoteIn the first test case to have an opportunity to watch shows for two consecutive days, you need to buy a subscription on show $$$1$$$ and on show $$$2$$$. So the answer is two.In the second test case, you can buy a subscription to any show because for each show you can find a segment of three consecutive days, consisting only of episodes of this show.In the third test case in the unique segment of four days, you have four different shows, so you need to buy a subscription to all these four shows.In the fourth test case, you can buy subscriptions to shows $$$3,5,7,8,9$$$, and you will be able to watch shows for the last eight days.


Vadim is really keen on travelling. Recently he heard about kayaking activity near his town and became very excited about it, so he joined a party of kayakers.Now the party is ready to start its journey, but firstly they have to choose kayaks. There are 2·n people in the group (including Vadim), and they have exactly n - 1 tandem kayaks (each of which, obviously, can carry two people) and 2 single kayaks. i-th person's weight is wi, and weight is an important matter in kayaking — if the difference between the weights of two people that sit in the same tandem kayak is too large, then it can crash. And, of course, people want to distribute their seats in kayaks in order to minimize the chances that kayaks will crash.Formally, the instability of a single kayak is always 0, and the instability of a tandem kayak is the absolute difference between weights of the people that are in this kayak. Instability of the whole journey is the total instability of all kayaks.Help the party to determine minimum possible total instability!

The first line contains one number n (2 ≤ n ≤ 50). The second line contains 2·n integer numbers w1, w2, ..., w2n, where wi is weight of person i (1 ≤ wi ≤ 1000).

Print minimum possible total instability.


Polycarp takes part in a math show. He is given n tasks, each consists of k subtasks, numbered 1 through k. It takes him tj minutes to solve the j-th subtask of any task. Thus, time required to solve a subtask depends only on its index, but not on the task itself. Polycarp can solve subtasks in any order.By solving subtask of arbitrary problem he earns one point. Thus, the number of points for task is equal to the number of solved subtasks in it. Moreover, if Polycarp completely solves the task (solves all k of its subtasks), he recieves one extra point. Thus, total number of points he recieves for the complete solution of the task is k + 1.Polycarp has M minutes of time. What is the maximum number of points he can earn?

The first line contains three integer numbers n, k and M (1 ≤ n ≤ 45, 1 ≤ k ≤ 45, 0 ≤ M ≤ 2·109). The second line contains k integer numbers, values tj (1 ≤ tj ≤ 1000000), where tj is the time in minutes required to solve j-th subtask of any task.

Print the maximum amount of points Polycarp can earn in M minutes.

NoteIn the first example Polycarp can complete the first task and spend 1 + 2 + 3 + 4 = 10 minutes. He also has the time to solve one subtask of the second task in one minute.In the second example Polycarp can solve the first subtask of all five tasks and spend 5·1 = 5 minutes. Also he can solve the second subtasks of two tasks and spend 2·2 = 4 minutes. Thus, he earns 5 + 2 = 7 points in total.


One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. Vasya weighed all the three pairs of coins on pan balance scales and told you the results. Find out how the deminations of the coins differ or if Vasya has a mistake in the weighting results. No two coins are equal.

The input data contains the results of all the weighting, one result on each line. It is guaranteed that every coin pair was weighted exactly once. Vasya labelled the coins with letters «A», «B» and «C». Each result is a line that appears as (letter)(> or < sign)(letter). For example, if coin "A" proved lighter than coin "B", the result of the weighting is A<B.

It the results are contradictory, print Impossible. Otherwise, print without spaces the rearrangement of letters «A», «B» and «C» which represent the coins in the increasing order of their weights.


Lengths are measures in Baden in inches and feet. To a length from centimeters it is enough to know that an inch equals three centimeters in Baden and one foot contains 12 inches.You are given a length equal to n centimeters. Your task is to convert it to feet and inches so that the number of feet was maximum. The result should be an integer rounded to the closest value containing an integral number of inches.Note that when you round up, 1 cm rounds up to 0 inches and 2 cm round up to 1 inch.

The only line contains an integer n (1 ≤ n ≤ 10000).

Print two non-negative space-separated integers a and b, where a is the numbers of feet and b is the number of inches.


Amr doesn't like Maths as he finds it really boring, so he usually sleeps in Maths lectures. But one day the teacher suspected that Amr is sleeping and asked him a question to make sure he wasn't.First he gave Amr two positive integers n and k. Then he asked Amr, how many integer numbers x > 0 exist such that:  Decimal representation of x (without leading zeroes) consists of exactly n digits;  There exists some integer y > 0 such that:   ;  decimal representation of y is a suffix of decimal representation of x.  As the answer to this question may be pretty huge the teacher asked Amr to output only its remainder modulo a number m.Can you help Amr escape this embarrassing situation?

Input consists of three integers n, k, m (1 ≤ n ≤ 1000, 1 ≤ k ≤ 100, 1 ≤ m ≤ 109).

NoteA suffix of a string S is a non-empty string that can be obtained by removing some number (possibly, zero) of first characters from S.


You are given an array of $$$n$$$ integers: $$$a_1, a_2, \ldots, a_n$$$. Your task is to find some non-zero integer $$$d$$$ ($$$-10^3 \leq d \leq 10^3$$$) such that, after each number in the array is divided by $$$d$$$, the number of positive numbers that are presented in the array is greater than or equal to half of the array size (i.e., at least $$$\lceil\frac{n}{2}\rceil$$$). Note that those positive numbers do not need to be an integer (e.g., a $$$2.5$$$ counts as a positive number). If there are multiple values of $$$d$$$ that satisfy the condition, you may print any of them. In case that there is no such $$$d$$$, print a single integer $$$0$$$.Recall that $$$\lceil x \rceil$$$ represents the smallest integer that is not less than $$$x$$$ and that zero ($$$0$$$) is neither positive nor negative.

The first line contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the number of elements in the array. The second line contains $$$n$$$ space-separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-10^3 \le a_i \le 10^3$$$).

Print one integer $$$d$$$ ($$$-10^3 \leq d \leq 10^3$$$ and $$$d \neq 0$$$) that satisfies the given condition. If there are multiple values of $$$d$$$ that satisfy the condition, you may print any of them. In case that there is no such $$$d$$$, print a single integer $$$0$$$.

NoteIn the first sample, $$$n = 5$$$, so we need at least $$$\lceil\frac{5}{2}\rceil = 3$$$ positive numbers after division. If $$$d = 4$$$, the array after division is $$$[2.5, 0, -1.75, 0.5, 1.5]$$$, in which there are $$$3$$$ positive numbers (namely: $$$2.5$$$, $$$0.5$$$, and $$$1.5$$$).In the second sample, there is no valid $$$d$$$, so $$$0$$$ should be printed.


A triangular number is the number of dots in an equilateral triangle uniformly filled with dots. For example, three dots can be arranged in a triangle; thus three is a triangular number. The n-th triangular number is the number of dots in a triangle with n dots on a side. . You can learn more about these numbers from Wikipedia (http://en.wikipedia.org/wiki/Triangular_number).Your task is to find out if a given integer is a triangular number.

The first line contains the single number n (1 ≤ n ≤ 500) — the given integer.

If the given integer is a triangular number output YES, otherwise output NO.


Anna's got a birthday today. She invited many guests and cooked a huge (nearly infinite) birthday cake decorated by n banana circles of different sizes. Maria's birthday is about to start in 7 minutes too, and while Anna is older, she decided to play the boss a little. She told Maria to cut the cake by k straight-line cuts (the cutting lines can intersect) to divide banana circles into banana pieces. Anna has many guests and she wants everyone to get at least one banana piece. That's why she told Maria to make the total number of banana pieces maximum. It's not a problem if some banana pieces end up on the same cake piece — the key is to make the maximum number of banana pieces. Determine what result Maria will achieve.

The first line contains two integers n and k — the number of banana circles and the number of cuts Maria should perform (1 ≤ n ≤ 1000, 1 ≤ k ≤ 105). Next n lines contain the positions and sizes of the banana circles (all banana circles are round). On the cake the Cartesian coordinate system is defined. Each line contains three integers x, y and r — the coordinates of the center of the corresponding banana piece and its radius ( - 1000 ≤ x, y ≤ 1000, 1 ≤ r ≤ 1000). It is guaranteed that the banana circles do not intersect, do not touch each other and do not overlap with each other. Pretest 10 is big test with n = k = 1000.

Print the only integer — the largest number of banana pieces that Maria can get after she performs the k straight-line cuts. Please do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specificator.


One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems.But there are too many problems, to do it manually. Alex asks you to write a program, which will determine if a problem is from this contest by its name.It is known, that problem is from this contest if and only if its name contains one of Alex's friends' name exactly once. His friends' names are "Danil", "Olya", "Slava", "Ann" and "Nikita".Names are case sensitive.

The only line contains string from lowercase and uppercase letters and "_" symbols of length, not more than 100 — the name of the problem.

Print "YES", if problem is from this contest, and "NO" otherwise.


Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that there are only three decent ingredients to make hamburgers from: a bread, sausage and cheese. He writes down the recipe of his favorite "Le Hamburger de Polycarpus" as a string of letters 'B' (bread), 'S' (sausage) и 'C' (cheese). The ingredients in the recipe go from bottom to top, for example, recipe "ВSCBS" represents the hamburger where the ingredients go from bottom to top as bread, sausage, cheese, bread and sausage again.Polycarpus has nb pieces of bread, ns pieces of sausage and nc pieces of cheese in the kitchen. Besides, the shop nearby has all three ingredients, the prices are pb rubles for a piece of bread, ps for a piece of sausage and pc for a piece of cheese.Polycarpus has r rubles and he is ready to shop on them. What maximum number of hamburgers can he cook? You can assume that Polycarpus cannot break or slice any of the pieces of bread, sausage or cheese. Besides, the shop has an unlimited number of pieces of each ingredient.

The first line of the input contains a non-empty string that describes the recipe of "Le Hamburger de Polycarpus". The length of the string doesn't exceed 100, the string contains only letters 'B' (uppercase English B), 'S' (uppercase English S) and 'C' (uppercase English C). The second line contains three integers nb, ns, nc (1 ≤ nb, ns, nc ≤ 100) — the number of the pieces of bread, sausage and cheese on Polycarpus' kitchen. The third line contains three integers pb, ps, pc (1 ≤ pb, ps, pc ≤ 100) — the price of one piece of bread, sausage and cheese in the shop. Finally, the fourth line contains integer r (1 ≤ r ≤ 1012) — the number of rubles Polycarpus has. Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

Print the maximum number of hamburgers Polycarpus can make. If he can't make any hamburger, print 0.


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

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

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

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


After finishing eating her bun, Alyona came up with two integers n and m. She decided to write down two columns of integers — the first column containing integers from 1 to n and the second containing integers from 1 to m. Now the girl wants to count how many pairs of integers she can choose, one from the first column and the other from the second column, such that their sum is divisible by 5.Formally, Alyona wants to count the number of pairs of integers (x, y) such that 1 ≤ x ≤ n, 1 ≤ y ≤ m and  equals 0.As usual, Alyona has some troubles and asks you to help.

The only line of the input contains two integers n and m (1 ≤ n, m ≤ 1 000 000).

Print the only integer — the number of pairs of integers (x, y) such that 1 ≤ x ≤ n, 1 ≤ y ≤ m and (x + y) is divisible by 5.

NoteFollowing pairs are suitable in the first sample case:   for x = 1 fits y equal to 4 or 9;  for x = 2 fits y equal to 3 or 8;  for x = 3 fits y equal to 2, 7 or 12;  for x = 4 fits y equal to 1, 6 or 11;  for x = 5 fits y equal to 5 or 10;  for x = 6 fits y equal to 4 or 9. Only the pair (1, 4) is suitable in the third sample case.


We've got no test cases. A big olympiad is coming up. But the problemsetters' number one priority should be adding another problem to the round. The diameter of a multiset of points on the line is the largest distance between two points from this set. For example, the diameter of the multiset {1, 3, 2, 1} is 2.Diameter of multiset consisting of one point is 0.You are given n points on the line. What is the minimum number of points you have to remove, so that the diameter of the multiset of the remaining points will not exceed d?

The first line contains two integers n and d (1 ≤ n ≤ 100, 0 ≤ d ≤ 100) — the amount of points and the maximum allowed diameter respectively. The second line contains n space separated integers (1 ≤ xi ≤ 100) — the coordinates of the points.

Output a single integer — the minimum number of points you have to remove.

NoteIn the first test case the optimal strategy is to remove the point with coordinate 4. The remaining points will have coordinates 1 and 2, so the diameter will be equal to 2 - 1 = 1.In the second test case the diameter is equal to 0, so its is unnecessary to remove any points. In the third test case the optimal strategy is to remove points with coordinates 1, 9 and 10. The remaining points will have coordinates 3, 4 and 6, so the diameter will be equal to 6 - 3 = 3.


You have a map as a rectangle table. Each cell of the table is either an obstacle, or a treasure with a certain price, or a bomb, or an empty cell. Your initial position is also given to you.You can go from one cell of the map to a side-adjacent one. At that, you are not allowed to go beyond the borders of the map, enter the cells with treasures, obstacles and bombs. To pick the treasures, you need to build a closed path (starting and ending in the starting cell). The closed path mustn't contain any cells with bombs inside. Let's assume that the sum of the treasures' values that are located inside the closed path equals v, and besides, you've made k single moves (from one cell to another) while you were going through the path, then such path brings you the profit of v - k rubles.Your task is to build a closed path that doesn't contain any bombs and brings maximum profit.Note that the path can have self-intersections. In order to determine if a cell lies inside a path or not, use the following algorithm:  Assume that the table cells are points on the plane (the table cell on the intersection of the i-th column and the j-th row is point (i, j)). And the given path is a closed polyline that goes through these points.  You need to find out if the point p of the table that is not crossed by the polyline lies inside the polyline.  Let's draw a ray that starts from point p and does not intersect other points of the table (such ray must exist).  Let's count the number of segments of the polyline that intersect the painted ray. If this number is odd, we assume that point p (and consequently, the table cell) lie inside the polyline (path). Otherwise, we assume that it lies outside.

The first line contains two integers n and m (1 ≤ n, m ≤ 20) — the sizes of the table. Next n lines each contains m characters — the description of the table. The description means the following:   character "B" is a cell with a bomb;  character "S" is the starting cell, you can assume that it's empty;  digit c (1-8) is treasure with index c;  character "." is an empty cell;  character "#" is an obstacle.  Assume that the map has t treasures. Next t lines contain the prices of the treasures. The i-th line contains the price of the treasure with index i, vi ( - 200 ≤ vi ≤ 200). It is guaranteed that the treasures are numbered from 1 to t. It is guaranteed that the map has not more than 8 objects in total. Objects are bombs and treasures. It is guaranteed that the map has exactly one character "S".

Print a single integer — the maximum possible profit you can get.

NoteIn the first example the answer will look as follows.  In the second example the answer will look as follows.  In the third example you cannot get profit.In the fourth example you cannot get profit as you cannot construct a closed path with more than one cell.


Two chess pieces, a rook and a knight, stand on a standard chessboard 8 × 8 in size. The positions in which they are situated are known. It is guaranteed that none of them beats the other one.Your task is to find the number of ways to place another knight on the board so that none of the three pieces on the board beat another one. A new piece can only be placed on an empty square.

The first input line contains the description of the rook's position on the board. This description is a line which is 2 in length. Its first symbol is a lower-case Latin letter from a to h, and its second symbol is a number from 1 to 8. The second line contains the description of the knight's position in a similar way. It is guaranteed that their positions do not coincide.

Print a single number which is the required number of ways.