Petya is having a party soon, and he has decided to invite his $$$n$$$ friends.
He wants to make invitations in the form of origami. For each invitation, he needs two red sheets, five green sheets, and eight blue sheets. The store sells an infinite number of notebooks of each color, but each notebook consists of only one color with $$$k$$$ sheets. That is, each notebook contains $$$k$$$ sheets of either red, green, or blue.
Find the minimum number of notebooks that Petya needs to buy to invite all $$$n$$$ of his friends.
The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1\leq n, k\leq 10^8$$$) — the number of Petya's friends and the number of sheets in each notebook respectively.
Print one number — the minimum number of notebooks that Petya needs to buy.
3 5
10
15 6
38
In the first example, we need $$$2$$$ red notebooks, $$$3$$$ green notebooks, and $$$5$$$ blue notebooks.
In the second example, we need $$$5$$$ red notebooks, $$$13$$$ green notebooks, and $$$20$$$ blue notebooks.
Little girl Margarita is a big fan of competitive programming. She especially loves problems about arrays and queries on them.
Recently, she was presented with an array $$$a$$$ of the size of $$$10^9$$$ elements that is filled as follows:
That is, the value of the $$$i$$$-th element of the array $$$a$$$ is calculated using the formula $$$a_i = i \cdot (-1)^i$$$.
She immediately came up with $$$q$$$ queries on this array. Each query is described with two numbers: $$$l$$$ and $$$r$$$. The answer to a query is the sum of all the elements of the array at positions from $$$l$$$ to $$$r$$$ inclusive.
Margarita really wants to know the answer to each of the requests. She doesn't want to count all this manually, but unfortunately, she couldn't write the program that solves the problem either. She has turned to you — the best programmer.
Help her find the answers!
The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^3$$$) — the number of the queries.
Each of the next $$$q$$$ lines contains two integers $$$l$$$ and $$$r$$$ ($$$1 \le l \le r \le 10^9$$$) — the descriptions of the queries.
Print $$$q$$$ lines, each containing one number — the answer to the query.
5 1 3 2 5 5 5 4 4 2 3
-2 -2 -5 4 -1
In the first query, you need to find the sum of the elements of the array from position $$$1$$$ to position $$$3$$$. The sum is equal to $$$a_1 + a_2 + a_3 = -1 + 2 -3 = -2$$$.
In the second query, you need to find the sum of the elements of the array from position $$$2$$$ to position $$$5$$$. The sum is equal to $$$a_2 + a_3 + a_4 + a_5 = 2 -3 + 4 - 5 = -2$$$.
In the third query, you need to find the sum of the elements of the array from position $$$5$$$ to position $$$5$$$. The sum is equal to $$$a_5 = -5$$$.
In the fourth query, you need to find the sum of the elements of the array from position $$$4$$$ to position $$$4$$$. The sum is equal to $$$a_4 = 4$$$.
In the fifth query, you need to find the sum of the elements of the array from position $$$2$$$ to position $$$3$$$. The sum is equal to $$$a_2 + a_3 = 2 - 3 = -1$$$.
Recently, Masha was presented with a chessboard with a height of $$$n$$$ and a width of $$$m$$$.
The rows on the chessboard are numbered from $$$1$$$ to $$$n$$$ from bottom to top. The columns are numbered from $$$1$$$ to $$$m$$$ from left to right. Therefore, each cell can be specified with the coordinates $$$(x,y)$$$, where $$$x$$$ is the column number, and $$$y$$$ is the row number (do not mix up).
Let us call a rectangle with coordinates $$$(a,b,c,d)$$$ a rectangle lower left point of which has coordinates $$$(a,b)$$$, and the upper right one — $$$(c,d)$$$.
The chessboard is painted black and white as follows:
Masha was very happy with the gift and, therefore, invited her friends Maxim and Denis to show off. The guys decided to make her a treat — they bought her a can of white and a can of black paint, so that if the old board deteriorates, it can be repainted. When they came to Masha, something unpleasant happened: first, Maxim went over the threshold and spilled white paint on the rectangle $$$(x_1,y_1,x_2,y_2)$$$. Then after him Denis spilled black paint on the rectangle $$$(x_3,y_3,x_4,y_4)$$$.
To spill paint of color $$$color$$$ onto a certain rectangle means that all the cells that belong to the given rectangle become $$$color$$$. The cell dyeing is superimposed on each other (if at first some cell is spilled with white paint and then with black one, then its color will be black).
Masha was shocked! She drove away from the guests and decided to find out how spoiled the gift was. For this, she needs to know the number of cells of white and black color. Help her find these numbers!
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^3$$$) — the number of test cases.
Each of them is described in the following format:
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n,m \le 10^9$$$) — the size of the board.
The second line contains four integers $$$x_1$$$, $$$y_1$$$, $$$x_2$$$, $$$y_2$$$ ($$$1 \le x_1 \le x_2 \le m, 1 \le y_1 \le y_2 \le n$$$) — the coordinates of the rectangle, the white paint was spilled on.
The third line contains four integers $$$x_3$$$, $$$y_3$$$, $$$x_4$$$, $$$y_4$$$ ($$$1 \le x_3 \le x_4 \le m, 1 \le y_3 \le y_4 \le n$$$) — the coordinates of the rectangle, the black paint was spilled on.
Output $$$t$$$ lines, each of which contains two numbers — the number of white and black cells after spilling paint, respectively.
5 2 2 1 1 2 2 1 1 2 2 3 4 2 2 3 2 3 1 4 3 1 5 1 1 5 1 3 1 5 1 4 4 1 1 4 2 1 3 4 4 3 4 1 2 4 2 2 1 3 3
0 4 3 9 2 3 8 8 4 8
Explanation for examples:
The first picture of each illustration shows how the field looked before the dyes were spilled. The second picture of each illustration shows how the field looked after Maxim spoiled white dye (the rectangle on which the dye was spilled is highlighted with red). The third picture in each illustration shows how the field looked after Denis spoiled black dye (the rectangle on which the dye was spilled is highlighted with red).
In the first test, the paint on the field changed as follows:
In the second test, the paint on the field changed as follows:
In the third test, the paint on the field changed as follows:
In the fourth test, the paint on the field changed as follows:
In the fifth test, the paint on the field changed as follows:
Recently, Olya received a magical square with the size of $$$2^n\times 2^n$$$.
It seems to her sister that one square is boring. Therefore, she asked Olya to perform exactly $$$k$$$ splitting operations.
A Splitting operation is an operation during which Olya takes a square with side $$$a$$$ and cuts it into 4 equal squares with side $$$\dfrac{a}{2}$$$. If the side of the square is equal to $$$1$$$, then it is impossible to apply a splitting operation to it (see examples for better understanding).
Olya is happy to fulfill her sister's request, but she also wants the condition of Olya's happiness to be satisfied after all operations.
The condition of Olya's happiness will be satisfied if the following statement is fulfilled:
Let the length of the side of the lower left square be equal to $$$a$$$, then the length of the side of the right upper square should also be equal to $$$a$$$. There should also be a path between them that consists only of squares with the side of length $$$a$$$. All consecutive squares on a path should have a common side.
Obviously, as long as we have one square, these conditions are met. So Olya is ready to fulfill her sister's request only under the condition that she is satisfied too. Tell her: is it possible to perform exactly $$$k$$$ splitting operations in a certain order so that the condition of Olya's happiness is satisfied? If it is possible, tell also the size of the side of squares of which the path from the lower left square to the upper right one will consist.
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^3$$$) — the number of tests.
Each of the following $$$t$$$ lines contains two integers $$$n_i$$$ and $$$k_i$$$ ($$$1 \le n_i \le 10^9, 1 \le k_i \le 10^{18}$$$) — the description of the $$$i$$$-th test, which means that initially Olya's square has size of $$$2^{n_i}\times 2^{n_i}$$$ and Olya's sister asks her to do exactly $$$k_i$$$ splitting operations.
Print $$$t$$$ lines, where in the $$$i$$$-th line you should output "YES" if it is possible to perform $$$k_i$$$ splitting operations in the $$$i$$$-th test in such a way that the condition of Olya's happiness is satisfied or print "NO" otherwise. If you printed "YES", then also print the $$$log_2$$$ of the length of the side of the squares through space, along which you can build a path from the lower left square to the upper right one.
You can output each letter in any case (lower or upper).
If there are multiple answers, print any.
3 1 1 2 2 2 12
YES 0 YES 1 NO
In each of the illustrations, the pictures are shown in order in which Olya applied the operations. The recently-created squares are highlighted with red.
In the first test, Olya can apply splitting operations in the following order:
The condition of Olya's happiness will be met, since there is a path of squares of the same size from the lower left square to the upper right one:
The length of the sides of the squares on the path is $$$1$$$. $$$log_2(1) = 0$$$.
In the second test, Olya can apply splitting operations in the following order:
The condition of Olya's happiness will be met, since there is a path of squares of the same size from the lower left square to the upper right one:
The length of the sides of the squares on the path is $$$2$$$. $$$log_2(2) = 1$$$.
In the third test, it takes $$$5$$$ operations for Olya to make the square look like this:
Since it requires her to perform $$$7$$$ splitting operations, and it is impossible to perform them on squares with side equal to $$$1$$$, then Olya cannot do anything more and the answer is "NO".
Sonya had a birthday recently. She was presented with the matrix of size $$$n\times m$$$ and consist of lowercase Latin letters. We assume that the rows are numbered by integers from $$$1$$$ to $$$n$$$ from bottom to top, and the columns are numbered from $$$1$$$ to $$$m$$$ from left to right.
Let's call a submatrix $$$(i_1, j_1, i_2, j_2)$$$ $$$(1\leq i_1\leq i_2\leq n; 1\leq j_1\leq j_2\leq m)$$$ elements $$$a_{ij}$$$ of this matrix, such that $$$i_1\leq i\leq i_2$$$ and $$$j_1\leq j\leq j_2$$$. Sonya states that a submatrix is beautiful if we can independently reorder the characters in each row (not in column) so that all rows and columns of this submatrix form palidroms.
Let's recall that a string is called palindrome if it reads the same from left to right and from right to left. For example, strings $$$abacaba, bcaacb, a$$$ are palindromes while strings $$$abca, acbba, ab$$$ are not.
Help Sonya to find the number of beautiful submatrixes. Submatrixes are different if there is an element that belongs to only one submatrix.
The first line contains two integers $$$n$$$ and $$$m$$$ $$$(1\leq n, m\leq 250)$$$ — the matrix dimensions.
Each of the next $$$n$$$ lines contains $$$m$$$ lowercase Latin letters.
Print one integer — the number of beautiful submatrixes.
1 3 aba
4
2 3 aca aac
11
3 5 accac aaaba cccaa
43
In the first example, the following submatrixes are beautiful: $$$((1, 1), (1, 1)); ((1, 2), (1, 2));$$$ $$$((1, 3), (1, 3)); ((1, 1), (1, 3))$$$.
In the second example, all submatrixes that consist of one element and the following are beautiful: $$$((1, 1), (2, 1));$$$ $$$((1, 1), (1, 3)); ((2, 1), (2, 3)); ((1, 1), (2, 3)); ((2, 1), (2, 2))$$$.
Some of the beautiful submatrixes are: $$$((1, 1), (1, 5)); ((1, 2), (3, 4));$$$ $$$((1, 1), (3, 5))$$$.
The submatrix $$$((1, 1), (3, 5))$$$ is beautiful since it can be reordered as:
accca
aabaa
accca
In such a matrix every row and every column form palindromes.
It is a very important day for Katya. She has a test in a programming class. As always, she was given an interesting problem that she solved very fast. Can you solve that problem?
You are given $$$n$$$ ordered segments sets. Each segment can be represented as a pair of two integers $$$[l, r]$$$ where $$$l\leq r$$$. Each set can contain an arbitrary number of segments (even $$$0$$$). It is possible that some segments are equal.
You are also given $$$m$$$ queries, each of them can be represented as four numbers: $$$a, b, x, y$$$. For each segment, find out whether it is true that each set $$$p$$$ ($$$a\leq p\leq b$$$) contains at least one segment $$$[l, r]$$$ that lies entirely on the segment $$$[x, y]$$$, that is $$$x\leq l\leq r\leq y$$$.
Find out the answer to each query.
Note that you need to solve this problem online. That is, you will get a new query only after you print the answer for the previous query.
The first line contains three integers $$$n$$$, $$$m$$$, and $$$k$$$ $$$(1\leq n,m\leq 10^5, 1\leq k\leq 3\cdot10^5)$$$ — the number of sets, queries, and segments respectively.
Each of the next $$$k$$$ lines contains three integers $$$l$$$, $$$r$$$, and $$$p$$$ $$$(1\leq l\leq r\leq 10^9, 1\leq p\leq n)$$$ — the limits of the segment and the index of a set, to which this segment belongs.
Each of the next $$$m$$$ lines contains four integers $$$a, b, x, y$$$ $$$(1\leq a\leq b\leq n, 1\leq x\leq y\leq 10^9)$$$ — the description of the query.
For each query, print "yes" or "no" in a new line.
After printing a query, do not forget to output end of line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use:
5 5 9 3 6 3 1 3 1 2 4 2 1 2 3 4 6 5 2 5 3 7 9 4 2 3 1 4 10 4 1 2 2 3 1 2 2 4 1 3 1 5 2 3 3 6 2 4 2 9
no yes yes no yes
For the first query, the answer is negative since the second set does not contain a segment that lies on the segment $$$[2, 3]$$$.
In the second query, the first set contains $$$[2, 3]$$$, and the second set contains $$$[2, 4]$$$.
In the third query, the first set contains $$$[2, 3]$$$, the second set contains $$$[2, 4]$$$, and the third set contains $$$[2, 5]$$$.
In the fourth query, the second set does not contain a segment that lies on the segment $$$[3, 6]$$$.
In the fifth query, the second set contains $$$[2, 4]$$$, the third set contains $$$[2, 5]$$$, and the fourth contains $$$[7, 9]$$$.