question
large_stringlengths 265
13.2k
|
|---|
Solve the programming task below in a Python markdown code block.
Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places.
Munhattan consists of n streets and m avenues. There is exactly one restaurant on the intersection of each street and avenue. The streets are numbered with integers from 1 to n and the avenues are numbered with integers from 1 to m. The cost of dinner in the restaurant at the intersection of the i-th street and the j-th avenue is c_{ij}.
Jack and Emma decide to choose the restaurant in the following way. Firstly Emma chooses the street to dinner and then Jack chooses the avenue. Emma and Jack makes their choice optimally: Emma wants to maximize the cost of the dinner, Jack wants to minimize it. Emma takes into account that Jack wants to minimize the cost of the dinner. Find the cost of the dinner for the couple in love.
-----Input-----
The first line contains two integers n, m (1 ≤ n, m ≤ 100) — the number of streets and avenues in Munhattan.
Each of the next n lines contains m integers c_{ij} (1 ≤ c_{ij} ≤ 10^9) — the cost of the dinner in the restaurant on the intersection of the i-th street and the j-th avenue.
-----Output-----
Print the only integer a — the cost of the dinner for Jack and Emma.
-----Examples-----
Input
3 4
4 1 3 5
2 2 2 2
5 4 5 1
Output
2
Input
3 3
1 2 3
2 3 1
3 1 2
Output
1
-----Note-----
In the first example if Emma chooses the first or the third streets Jack can choose an avenue with the cost of the dinner 1. So she chooses the second street and Jack chooses any avenue. The cost of the dinner is 2.
In the second example regardless of Emma's choice Jack can choose a restaurant with the cost of the dinner 1.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
You are going to be given an array of integers. Your job is to take that array and find an index N where the sum of the integers to the left of N is equal to the sum of the integers to the right of N. If there is no index that would make this happen, return `-1`.
__For example:__
Let's say you are given the array `{1,2,3,4,3,2,1}`:
Your function will return the index `3`, because at the 3rd position of the array, the sum of left side of the index (`{1,2,3}`) and the sum of the right side of the index (`{3,2,1}`) both equal `6`.
Let's look at another one.
You are given the array `{1,100,50,-51,1,1}`:
Your function will return the index `1`, because at the 1st position of the array, the sum of left side of the index (`{1}`) and the sum of the right side of the index (`{50,-51,1,1}`) both equal `1`.
Last one:
You are given the array `{20,10,-80,10,10,15,35}`
At index 0 the left side is `{}`
The right side is `{10,-80,10,10,15,35}`
They both are equal to `0` when added. (Empty arrays are equal to 0 in this problem)
Index 0 is the place where the left side and right side are equal.
Note: Please remember that in most programming/scripting languages the index of an array starts at 0.
__Input:__
An integer array of length `0 < arr < 1000`. The numbers in the array can be any integer positive or negative.
__Output:__
The lowest index `N` where the side to the left of `N` is equal to the side to the right of `N`. If you do not find an index that fits these rules, then you will return `-1`.
__Note:__
If you are given an array with multiple answers, return the lowest correct index.
Write your solution by modifying this code:
```python
def find_even_index(arr):
```
Your solution should implemented in the function "find_even_index". The i
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
Dr. Jimbo, an applied mathematician, needs to calculate matrices all day for solving his own problems. In his laboratory, he uses an excellent application program for manipulating matrix expressions, however, he cannot use it outside his laboratory because the software consumes much of resources. He wants to manipulate matrices outside, so he needs a small program similar to the excellent application for his handheld computer.
Your job is to provide him a program that computes expressions of matrices.
Expressions of matrices are described in a simple language. Its syntax is shown in Table J.1. Note that even a space and a newline have meaningful roles in the syntax.
<image>
The start symbol of this syntax is program that is defined as a sequence of assignments in Table J.1. Each assignment has a variable on the left hand side of an equal symbol ("=") and an expression of matrices on the right hand side followed by a period and a newline (NL). It denotes an assignment of the value of the expression to the variable. The variable (var in Table J.1) is indicated by an uppercase Roman letter. The value of the expression (expr) is a matrix or a scalar, whose elements are integers. Here, a scalar integer and a 1 × 1 matrix whose only element is the same integer can be used interchangeably.
An expression is one or more terms connected by "+" or "-" symbols. A term is one or more factors connected by "*" symbol. These operators ("+", "-", "*") are left associative.
A factor is either a primary expression (primary) or a "-" symbol followed by a factor. This unary operator "-" is right associative.
The meaning of operators are the same as those in the ordinary arithmetic on matrices: Denoting matrices by A and B, A + B, A - B, A * B, and -A are defined as the matrix sum, difference, product, and negation. The sizes of A and B should be the same for addition and subtraction. The number of columns of A and the number of rows of B should be the same for multiplication.
Note that all the operators +, -, * and unary - represent computations of addition, subtraction, multiplication and negation modulo M = 215 = 32768, respectively. Thus all the values are nonnegative integers between 0 and 32767, inclusive. For example, the result of an expression 2 - 3 should be 32767, instead of -1.
inum is a non-negative decimal integer less than M.
var represents the matrix that is assigned to the variable var in the most recent preceding assignment statement of the same variable.
matrix represents a mathematical matrix similar to a 2-dimensional array whose elements are integers. It is denoted by a row-seq with a pair of enclosing square brackets. row-seq represents a sequence of rows, adjacent two of which are separated by a semicolon. row represents a sequence of expressions, adjacent two of which are separated by a space character.
For example, [1 2 3;4 5 6] represents a matrix <image>. The first row has three integers separated by two space characters, i.e. "1 2 3". The second row has three integers, i.e. "4 5 6". Here, the row-seq consists of the two rows separated by a semicolon. The matrix is denoted by the row-seq with a pair of square brackets.
Note that elements of a row may be matrices again. Thus the nested representation of a matrix may appear. The number of rows of the value of each expression of a row should be the same, and the number of columns of the value of each row of a row-seq should be the same.
For example, a matrix represented by
[[1 2 3;4 5 6] [7 8;9 10] [11;12];13 14 15 16 17 18]
is <image> The sizes of matrices should be consistent, as mentioned above, in order to form a well-formed matrix as the result. For example, [[1 2;3 4] [5;6;7];6 7 8] is not consistent since the first row "[1 2;3 4] [5;6;7]" has two matrices (2 × 2 and 3 × 1) whose numbers of rows are different. [1 2;3 4 5] is not consistent since the number of columns of two rows are different.
The multiplication of 1 × 1 matrix and m × n matrix is well-defined for arbitrary m > 0 and n > 0, since a 1 × 1 matrices can be regarded as a scalar integer. For example, 2*[1 2;3 4] and [1 2;3 4]*3 represent the products of a scalar and a matrix <image> and <image>. [2]*[1 2;3 4] and [1 2;3 4]*[3] are also well-defined similarly.
An indexed-primary is a primary expression followed by two expressions as indices. The first index is 1 × k integer matrix denoted by (i1 i2 ... ik), and the second index is 1 × l integer matrix denoted by (j1 j2 ... jl). The two indices specify the submatrix extracted from the matrix which is the value of the preceding primary expression. The size of the submatrix is k × l and whose (a, b)-element is the (ia, jb)-element of the value of the preceding primary expression. The way of indexing is one-origin, i.e., the first element is indexed by 1.
For example, the value of ([1 2;3 4]+[3 0;0 2])([1],[2]) is equal to 2, since the value of its primary expression is a matrix [4 2;3 6], and the first index [1] and the second [2] indicate the (1, 2)-element of the matrix. The same integer may appear twice or more in an index matrix, e.g., the first index matrix of an expression [1 2;3 4]([2 1 1],[2 1]) is [2 1 1], which has two 1's. Its value is <image>.
A transposed-primary is a primary expression followed by a single quote symbol ("'"), which indicates the transpose operation. The transposed matrix of an m × n matrix A = (aij) (i = 1, ..., m and j = 1, ... , n) is the n × m matrix B = (bij) (i = 1, ... , n and j = 1, ... , m), where bij = aji. For example, the value of [1 2;3 4]' is <image>.
Input
The input consists of multiple datasets, followed by a line containing a zero. Each dataset has the following format.
n
program
n is a positive integer, which is followed by a program that is a sequence of single or multiple lines each of which is an assignment statement whose syntax is defined in Table J.1. n indicates the number of the assignment statements in the program. All the values of vars are undefined at the beginning of a program.
You can assume the following:
* 1 ≤ n ≤ 10,
* the number of characters in a line does not exceed 80 (excluding a newline),
* there are no syntax errors and semantic errors (e.g., reference of undefined var),
* the number of rows of matrices appearing in the computations does not exceed 100, and
* the number of columns of matrices appearing in the computations does not exceed 100.
Output
For each dataset, the value of the expression of each assignment statement of the program should be printed in the same order. All the values should be printed as non-negative integers less than M.
When the value is an m × n matrix A = (aij) (i = 1, ... ,m and j = 1, ... , n), m lines should be printed. In the k-th line (1 ≤ k ≤ m), integers of the k-th row, i.e., ak1, ... , akn, should be printed separated by a space.
After the last value of a dataset is printed, a line containing five minus symbols '-----' should be printed for human readability.
The output should not contain any other extra characters.
Example
Input
1
A=[1 2 3;4 5 6].
1
A=[[1 2 3;4 5 6] [7 8;9 10] [11;12];13 14 15 16 17 18].
3
B=[3 -2 1;-9 8 7].
C=([1 2 3;4 5 6]+B)(2,3).
D=([1 2 3;4 5 6]+B)([1 2],[2 3]).
5
A=2*[1 2;-3 4]'.
B=A([2 1 2],[2 1]).
A=[1 2;3 4]*3.
A=[2]*[1 2;3 4].
A=[1 2;3 4]*[3].
2
A=[11 12 13;0 22 23;0 0 33].
A=[A A';--A''' A].
2
A=[1 -1 1;1 1 -1;-1 1 1]*3.
A=[A -A+-A;-A'([3 2 1],[3 2 1]) -A'].
1
A=1([1 1 1],[1 1 1 1]).
3
A=[1 2 -3;4 -5 6;-7 8 9].
B=A([3 1 2],[2 1 3]).
C=A*B-B*A+-A*-B-B*-A.
3
A=[1 2 3 4 5].
B=A'*A.
C=B([1 5],[5 1]).
3
A=[-11 12 13;21 -22 23;31 32 -33].
B=[1 0 0;0 1 0;0 0 1].
C=[(A-B) (A+B)*B (A+B)*(B-A)([1 1 1],[3 2 1]) [1 2 3;2 1 1;-1 2 1]*(A-B)].
3
A=[11 12 13;0 22 23;0 0 33].
B=[1 2].
C=------A((((B))),B)(B,B)''''''.
2
A=1+[2]+[[3]]+[[[4]]]+2*[[[[5]]]]*3.
B=[(-[([(-A)]+-A)])].
8
A=[1 2;3 4].
B=[A A+[1 1;0 1]*4;A+[1 1;0 1]'*8 A+[1 1;0 1]''*12].
C=B([1],[1]).
C=B([1],[1 2 3 4]).
C=B([1 2 3 4],[1]).
C=B([2 3],[2 3]).
A=[1 2;1 2].
D=(A*-A+-A)'(A'(1,[1 2]),A'(2,[1 2])).
0
Output
1 2 3
4 5 6
-----
1 2 3 7 8 11
4 5 6 9 10 12
13 14 15 16 17 18
-----
3 32766 1
32759 8 7
13
0 4
13 13
-----
2 32762
4 8
8 4
32762 2
8 4
3 6
9 12
2 4
6 8
3 6
9 12
-----
11 12 13
0 22 23
0 0 33
11 12 13 11 0 0
0 22 23 12 22 0
0 0 33 13 23 33
11 0 0 11 12 13
12 22 0 0 22 23
13 23 33 0 0 33
-----
3 32765 3
3 3 32765
32765 3 3
3 32765 3 32762 6 32762
3 3 32765 32762 32762 6
32765 3 3 6 32762 32762
32765 3 32765 32765 32765 3
32765 32765 3 3 32765 32765
3 32765 32765 32765 3 32765
-----
1 1 1 1
1 1 1 1
1 1 1 1
-----
1 2 32765
4 32763 6
32761 8 9
8 32761 9
2 1 32765
32763 4 6
54 32734 32738
32752 32750 174
32598 186 32702
-----
1 2 3 4 5
1 2 3 4 5
2 4 6 8 10
3 6 9 12 15
4 8 12 16 20
5 10 15 20 25
5 1
25 5
-----
32757 12 13
21 32746 23
31 32 32735
1 0 0
0 1 0
0 0 1
32756 12 13 32758 12 13 32573 32588 180 123 62 32725
21 32745 23 21 32747 23 32469 32492 276 28 33 15
31 32 32734 31 32 32736 32365 32396 372 85 32742 32767
-----
11 12 13
0 22 23
0 0 33
1 2
11 12
0 22
-----
40
80
-----
1 2
3 4
1 2 5 6
3 4 3 8
9 2 13 14
11 12 3 16
1
1 2 5 6
1
3
9
11
4 3
2 13
1 2
1 2
32764 32764
32764 32764
-----
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
Today there is going to be an unusual performance at the circus — hamsters and tigers will perform together! All of them stand in circle along the arena edge and now the trainer faces a difficult task: he wants to swap the animals' positions so that all the hamsters stood together and all the tigers also stood together. The trainer swaps the animals in pairs not to create a mess. He orders two animals to step out of the circle and swap places. As hamsters feel highly uncomfortable when tigers are nearby as well as tigers get nervous when there's so much potential prey around (consisting not only of hamsters but also of yummier spectators), the trainer wants to spend as little time as possible moving the animals, i.e. he wants to achieve it with the minimal number of swaps. Your task is to help him.
Input
The first line contains number n (2 ≤ n ≤ 1000) which indicates the total number of animals in the arena. The second line contains the description of the animals' positions. The line consists of n symbols "H" and "T". The "H"s correspond to hamsters and the "T"s correspond to tigers. It is guaranteed that at least one hamster and one tiger are present on the arena. The animals are given in the order in which they are located circle-wise, in addition, the last animal stands near the first one.
Output
Print the single number which is the minimal number of swaps that let the trainer to achieve his goal.
Examples
Input
3
HTH
Output
0
Input
9
HTHTHTHHT
Output
2
Note
In the first example we shouldn't move anybody because the animals of each species already stand apart from the other species. In the second example you may swap, for example, the tiger in position 2 with the hamster in position 5 and then — the tiger in position 9 with the hamster in position 7.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
You need to find if a number can be expressed as sum of two perfect powers. That is, given x find if there exists non negative integers a, b, m, n such that a^m + b^n = x.
Input
First line of the input contains number of test cases T. It is followed by T lines, each line contains a sinle number x.
Output
For each test case, print "Yes" (without quotes) if the number can be expressed as sum of two perfect powers. Otherwise print "No" (without quotes).
Constraints
1 ≤ T ≤ 1000
1 ≤ x ≤ 1000000
m > 1, n > 1
SAMPLE INPUT
5
5
15
9
77
100
SAMPLE OUTPUT
Yes
No
Yes
No
Yes
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt.
Create a program that reads the list of participant numbers and the number of fish caught and outputs the number of winners and the number of fish caught. If there are multiple winners, output the one with the lowest participant number.
input
The input is given in the following format.
n
a1 v1
a2 v2
::
an vn
n (1 ≤ n ≤ 20) represents the number of participants and ai represents the participant number. Participant numbers are different integers between 1 and n. vi (0 ≤ vi ≤ 100) is the number of animals acquired by the participant ai.
output
Output the winner's participant number and the number of fish caught on one line separated by blanks.
Example
Input
6
1 14
2 25
3 42
4 11
5 40
6 37
Output
3 42
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
You have a garden consisting entirely of grass and weeds. Your garden is described by an n × m grid, with rows numbered 1 to n from top to bottom, and columns 1 to m from left to right. Each cell is identified by a pair (r, c) which means that the cell is located at row r and column c. Each cell may contain either grass or weeds. For example, a 4 × 5 garden may look as follows (empty cells denote grass):
<image>
You have a land-mower with you to mow all the weeds. Initially, you are standing with your lawnmower at the top-left corner of the garden. That is, at cell (1, 1). At any moment of time you are facing a certain direction — either left or right. And initially, you face right.
In one move you can do either one of these:
1) Move one cell in the direction that you are facing.
* if you are facing right: move from cell (r, c) to cell (r, c + 1)
<image>
* if you are facing left: move from cell (r, c) to cell (r, c - 1)
<image>
2) Move one cell down (that is, from cell (r, c) to cell (r + 1, c)), and change your direction to the opposite one.
* if you were facing right previously, you will face left
<image>
* if you were facing left previously, you will face right
<image>
You are not allowed to leave the garden. Weeds will be mowed if you and your lawnmower are standing at the cell containing the weeds (your direction doesn't matter). This action isn't counted as a move.
What is the minimum number of moves required to mow all the weeds?
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 150) — the number of rows and columns respectively. Then follow n lines containing m characters each — the content of the grid. "G" means that this cell contains grass. "W" means that this cell contains weeds.
It is guaranteed that the top-left corner of the grid will contain grass.
Output
Print a single number — the minimum number of moves required to mow all the weeds.
Examples
Input
4 5
GWGGW
GGWGG
GWGGG
WGGGG
Output
11
Input
3 3
GWW
WWW
WWG
Output
7
Input
1 1
G
Output
0
Note
For the first example, this is the picture of the initial state of the grid:
<image>
A possible solution is by mowing the weeds as illustrated below:
<image>
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:$f(l, r) = \sum_{i = l}^{r - 1}|a [ i ] - a [ i + 1 ]|\cdot(- 1)^{i - l}$
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 10^5) — the size of the array a.
The second line contains n integers a_1, a_2, ..., a_{n} (-10^9 ≤ a_{i} ≤ 10^9) — the array elements.
-----Output-----
Print the only integer — the maximum value of f.
-----Examples-----
Input
5
1 4 2 3 1
Output
3
Input
4
1 5 4 7
Output
6
-----Note-----
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
A little weird green frog speaks in a very strange variation of English: it reverses sentence, omitting all puntuation marks `, ; ( ) - ` except the final exclamation, question or period. We urgently need help with building a proper translator.
To simplify the task, we always use lower-case letters. Apostrophes are forbidden as well.
Translator should be able to process multiple sentences in one go. Sentences are separated by arbitrary amount of spaces.
**Examples**
`you should use python.` -> `python use should you.`
`look, a fly!` -> `fly a look!`
`multisentence is good. is not it?` -> `good is multisentence. it not is?`
Write your solution by modifying this code:
```python
def frogify(s):
```
Your solution should implemented in the function "frogify". The i
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
Your task is to calculate the distance between two $n$ dimensional vectors $x = \\{x_1, x_2, ..., x_n\\}$ and $y = \\{y_1, y_2, ..., y_n\\}$.
The Minkowski's distance defined below is a metric which is a generalization of both the Manhattan distance and the Euclidean distance.
\\[ D_{xy} = (\sum_{i=1}^n |x_i - y_i|^p)^{\frac{1}{p}} \\]
It can be the Manhattan distance
\\[ D_{xy} = |x_1 - y_1| + |x_2 - y_2| + ... + |x_n - y_n| \\]
where $p = 1 $.
It can be the Euclidean distance
\\[ D_{xy} = \sqrt{(|x_1 - y_1|)^{2} + (|x_2 - y_2|)^{2} + ... + (|x_n - y_n|)^{2}} \\]
where $p = 2 $.
Also, it can be the Chebyshev distance
\\[ D_{xy} = max_{i=1}^n (|x_i - y_i|) \\]
where $p = \infty$
Write a program which reads two $n$ dimensional vectors $x$ and $y$, and calculates Minkowski's distance where $p = 1, 2, 3, \infty$ respectively.
Constraints
* $1 \leq n \leq 100$
* $0 \leq x_i, y_i \leq 1000$
Input
In the first line, an integer $n$ is given. In the second and third line, $x = \\{x_1, x_2, ... x_n\\}$ and $y = \\{y_1, y_2, ... y_n\\}$ are given respectively. The elements in $x$ and $y$ are given in integers.
Output
Print the distance where $p = 1, 2, 3$ and $\infty$ in a line respectively. The output should not contain an absolute error greater than 10-5.
Example
Input
3
1 2 3
2 0 4
Output
4.000000
2.449490
2.154435
2.000000
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
Let's consider a simplified version of order book of some stock. The order book is a list of orders (offers) from people that want to buy or sell one unit of the stock, each order is described by direction (BUY or SELL) and price.
At every moment of time, every SELL offer has higher price than every BUY offer.
In this problem no two ever existed orders will have the same price.
The lowest-price SELL order and the highest-price BUY order are called the best offers, marked with black frames on the picture below. [Image] The presented order book says that someone wants to sell the product at price $12$ and it's the best SELL offer because the other two have higher prices. The best BUY offer has price $10$.
There are two possible actions in this orderbook: Somebody adds a new order of some direction with some price. Somebody accepts the best possible SELL or BUY offer (makes a deal). It's impossible to accept not the best SELL or BUY offer (to make a deal at worse price). After someone accepts the offer, it is removed from the orderbook forever.
It is allowed to add new BUY order only with prices less than the best SELL offer (if you want to buy stock for higher price, then instead of adding an order you should accept the best SELL offer). Similarly, one couldn't add a new SELL order with price less or equal to the best BUY offer. For example, you can't add a new offer "SELL $20$" if there is already an offer "BUY $20$" or "BUY $25$" — in this case you just accept the best BUY offer.
You have a damaged order book log (in the beginning the are no orders in book). Every action has one of the two types: "ADD $p$" denotes adding a new order with price $p$ and unknown direction. The order must not contradict with orders still not removed from the order book. "ACCEPT $p$" denotes accepting an existing best offer with price $p$ and unknown direction.
The directions of all actions are lost. Information from the log isn't always enough to determine these directions. Count the number of ways to correctly restore all ADD action directions so that all the described conditions are satisfied at any moment. Since the answer could be large, output it modulo $10^9 + 7$. If it is impossible to correctly restore directions, then output $0$.
-----Input-----
The first line contains an integer $n$ ($1 \le n \le 363\,304$) — the number of actions in the log.
Each of the next $n$ lines contains a string "ACCEPT" or "ADD" and an integer $p$ ($1 \le p \le 308\,983\,066$), describing an action type and price.
All ADD actions have different prices. For ACCEPT action it is guaranteed that the order with the same price has already been added but has not been accepted yet.
-----Output-----
Output the number of ways to restore directions of ADD actions modulo $10^9 + 7$.
-----Examples-----
Input
6
ADD 1
ACCEPT 1
ADD 2
ACCEPT 2
ADD 3
ACCEPT 3
Output
8
Input
4
ADD 1
ADD 2
ADD 3
ACCEPT 2
Output
2
Input
7
ADD 1
ADD 2
ADD 3
ADD 4
ADD 5
ACCEPT 3
ACCEPT 5
Output
0
-----Note-----
In the first example each of orders may be BUY or SELL.
In the second example the order with price $1$ has to be BUY order, the order with the price $3$ has to be SELL order.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
The cat Snuke wants to play a popular Japanese game called ÅtCoder, so Iroha has decided to teach him Japanese.
When counting pencils in Japanese, the counter word "本" follows the number. The pronunciation of this word varies depending on the number. Specifically, the pronunciation of "本" in the phrase "N 本" for a positive integer N not exceeding 999 is as follows:
- hon when the digit in the one's place of N is 2, 4, 5, 7, or 9;
- pon when the digit in the one's place of N is 0, 1, 6 or 8;
- bon when the digit in the one's place of N is 3.
Given N, print the pronunciation of "本" in the phrase "N 本".
-----Constraints-----
- N is a positive integer not exceeding 999.
-----Input-----
Input is given from Standard Input in the following format:
N
-----Output-----
Print the answer.
-----Sample Input-----
16
-----Sample Output-----
pon
The digit in the one's place of 16 is 6, so the "本" in "16 本" is pronounced pon.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
Given a standard english sentence passed in as a string, write a method that will return a sentence made up of the same words, but sorted by their first letter. However, the method of sorting has a twist to it:
* All words that begin with a lower case letter should be at the beginning of the sorted sentence, and sorted in ascending order.
* All words that begin with an upper case letter should come after that, and should be sorted in descending order.
If a word appears multiple times in the sentence, it should be returned multiple times in the sorted sentence. Any punctuation must be discarded.
## Example
For example, given the input string `"Land of the Old Thirteen! Massachusetts land! land of Vermont and Connecticut!"`, your method should return `"and land land of of the Vermont Thirteen Old Massachusetts Land Connecticut"`. Lower case letters are sorted `a -> l -> l -> o -> o -> t` and upper case letters are sorted `V -> T -> O -> M -> L -> C`.
Write your solution by modifying this code:
```python
def pseudo_sort(st):
```
Your solution should implemented in the function "pseudo_sort". The i
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
You are given a sequence $a$ consisting of $n$ integers $a_1, a_2, \dots, a_n$, and an integer $x$. Your task is to make the sequence $a$ sorted (it is considered sorted if the condition $a_1 \le a_2 \le a_3 \le \dots \le a_n$ holds).
To make the sequence sorted, you may perform the following operation any number of times you want (possibly zero): choose an integer $i$ such that $1 \le i \le n$ and $a_i > x$, and swap the values of $a_i$ and $x$.
For example, if $a = [0, 2, 3, 5, 4]$, $x = 1$, the following sequence of operations is possible:
choose $i = 2$ (it is possible since $a_2 > x$), then $a = [0, 1, 3, 5, 4]$, $x = 2$;
choose $i = 3$ (it is possible since $a_3 > x$), then $a = [0, 1, 2, 5, 4]$, $x = 3$;
choose $i = 4$ (it is possible since $a_4 > x$), then $a = [0, 1, 2, 3, 4]$, $x = 5$.
Calculate the minimum number of operations you have to perform so that $a$ becomes sorted, or report that it is impossible.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 500$) — the number of test cases.
Each test case consists of two lines. The first line contains two integers $n$ and $x$ ($1 \le n \le 500$, $0 \le x \le 500$) — the number of elements in the sequence and the initial value of $x$.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($0 \le a_i \le 500$).
The sum of values of $n$ over all test cases in the input does not exceed $500$.
-----Output-----
For each test case, print one integer — the minimum number of operations you have to perform to make $a$ sorted, or $-1$, if it is impossible.
-----Examples-----
Input
6
4 1
2 3 5 4
5 6
1 1 3 4 4
1 10
2
2 10
11 9
2 10
12 11
5 18
81 324 218 413 324
Output
3
0
0
-1
1
3
-----Note-----
None
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
You are given a secret message you need to decipher. Here are the things you need to know to decipher it:
For each word:
- the second and the last letter is switched (e.g. `Hello` becomes `Holle`)
- the first letter is replaced by its character code (e.g. `H` becomes `72`)
Note: there are no special characters used, only letters and spaces
Examples
```
decipherThis('72olle 103doo 100ya'); // 'Hello good day'
decipherThis('82yade 115te 103o'); // 'Ready set go'
```
Write your solution by modifying this code:
```python
def decipher_this(string):
```
Your solution should implemented in the function "decipher_this". The i
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
Consider the following numbers (where `n!` is `factorial(n)`):
```
u1 = (1 / 1!) * (1!)
u2 = (1 / 2!) * (1! + 2!)
u3 = (1 / 3!) * (1! + 2! + 3!)
...
un = (1 / n!) * (1! + 2! + 3! + ... + n!)
```
Which will win: `1 / n!` or `(1! + 2! + 3! + ... + n!)`?
Are these numbers going to `0` because of `1/n!` or to infinity due
to the sum of factorials or to another number?
## Task
Calculate `(1 / n!) * (1! + 2! + 3! + ... + n!)`
for a given `n`, where `n` is an integer greater or equal to `1`.
To avoid discussions about rounding, return the result **truncated** to 6 decimal places, for example:
```
1.0000989217538616 will be truncated to 1.000098
1.2125000000000001 will be truncated to 1.2125
```
## Remark
Keep in mind that factorials grow rather rapidly, and you need to handle large inputs.
## Hint
You could try to simplify the expression.
Write your solution by modifying this code:
```python
def going(n):
```
Your solution should implemented in the function "going". The i
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
[Image]
It's the end of July – the time when a festive evening is held at Jelly Castle! Guests from all over the kingdom gather here to discuss new trends in the world of confectionery. Yet some of the things discussed here are not supposed to be disclosed to the general public: the information can cause discord in the kingdom of Sweetland in case it turns out to reach the wrong hands. So it's a necessity to not let any uninvited guests in.
There are 26 entrances in Jelly Castle, enumerated with uppercase English letters from A to Z. Because of security measures, each guest is known to be assigned an entrance he should enter the castle through. The door of each entrance is opened right before the first guest's arrival and closed right after the arrival of the last guest that should enter the castle through this entrance. No two guests can enter the castle simultaneously.
For an entrance to be protected from possible intrusion, a candy guard should be assigned to it. There are k such guards in the castle, so if there are more than k opened doors, one of them is going to be left unguarded! Notice that a guard can't leave his post until the door he is assigned to is closed.
Slastyona had a suspicion that there could be uninvited guests at the evening. She knows the order in which the invited guests entered the castle, and wants you to help her check whether there was a moment when more than k doors were opened.
-----Input-----
Two integers are given in the first string: the number of guests n and the number of guards k (1 ≤ n ≤ 10^6, 1 ≤ k ≤ 26).
In the second string, n uppercase English letters s_1s_2... s_{n} are given, where s_{i} is the entrance used by the i-th guest.
-----Output-----
Output «YES» if at least one door was unguarded during some time, and «NO» otherwise.
You can output each letter in arbitrary case (upper or lower).
-----Examples-----
Input
5 1
AABBB
Output
NO
Input
5 1
ABABB
Output
YES
-----Note-----
In the first sample case, the door A is opened right before the first guest's arrival and closed when the second guest enters the castle. The door B is opened right before the arrival of the third guest, and closed after the fifth one arrives. One guard can handle both doors, as the first one is closed before the second one is opened.
In the second sample case, the door B is opened before the second guest's arrival, but the only guard can't leave the door A unattended, as there is still one more guest that should enter the castle through this door.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
To get money for a new aeonic blaster, ranger Qwerty decided to engage in trade for a while. He wants to buy some number of items (or probably not to buy anything at all) on one of the planets, and then sell the bought items on another planet. Note that this operation is not repeated, that is, the buying and the selling are made only once. To carry out his plan, Qwerty is going to take a bank loan that covers all expenses and to return the loaned money at the end of the operation (the money is returned without the interest). At the same time, Querty wants to get as much profit as possible.
The system has n planets in total. On each of them Qwerty can buy or sell items of m types (such as food, medicine, weapons, alcohol, and so on). For each planet i and each type of items j Qwerty knows the following:
* aij — the cost of buying an item;
* bij — the cost of selling an item;
* cij — the number of remaining items.
It is not allowed to buy more than cij items of type j on planet i, but it is allowed to sell any number of items of any kind.
Knowing that the hold of Qwerty's ship has room for no more than k items, determine the maximum profit which Qwerty can get.
Input
The first line contains three space-separated integers n, m and k (2 ≤ n ≤ 10, 1 ≤ m, k ≤ 100) — the number of planets, the number of question types and the capacity of Qwerty's ship hold, correspondingly.
Then follow n blocks describing each planet.
The first line of the i-th block has the planet's name as a string with length from 1 to 10 Latin letters. The first letter of the name is uppercase, the rest are lowercase. Then in the i-th block follow m lines, the j-th of them contains three integers aij, bij and cij (1 ≤ bij < aij ≤ 1000, 0 ≤ cij ≤ 100) — the numbers that describe money operations with the j-th item on the i-th planet. The numbers in the lines are separated by spaces.
It is guaranteed that the names of all planets are different.
Output
Print a single number — the maximum profit Qwerty can get.
Examples
Input
3 3 10
Venus
6 5 3
7 6 5
8 6 10
Earth
10 9 0
8 6 4
10 9 3
Mars
4 3 0
8 4 12
7 2 5
Output
16
Note
In the first test case you should fly to planet Venus, take a loan on 74 units of money and buy three items of the first type and 7 items of the third type (3·6 + 7·8 = 74). Then the ranger should fly to planet Earth and sell there all the items he has bought. He gets 3·9 + 7·9 = 90 units of money for the items, he should give 74 of them for the loan. The resulting profit equals 16 units of money. We cannot get more profit in this case.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
Mrs Jefferson is a great teacher. One of her strategies that helped her to reach astonishing results in the learning process is to have some fun with her students. At school, she wants to make an arrangement of her class to play a certain game with her pupils. For that, she needs to create the arrangement with **the minimum amount of groups that have consecutive sizes**.
Let's see. She has ```14``` students. After trying a bit she could do the needed arrangement:
```[5, 4, 3, 2]```
- one group of ```5``` students
- another group of ```4``` students
- then, another one of ```3```
- and finally, the smallest group of ```2``` students.
As the game was a success, she was asked to help to the other classes to teach and show the game. That's why she desperately needs some help to make this required arrangements that make her spend a lot of time.
To make things worse, she found out that there are some classes with some special number of students that is impossible to get that arrangement.
Please, help this teacher!
Your code will receive the number of students of the class. It should output the arrangement as an array with the consecutive sizes of the groups in decreasing order.
For the special case that no arrangement of the required feature is possible the code should output ```[-1] ```
The value of n is unknown and may be pretty high because some classes joined to to have fun with the game.
You may see more example tests in the Example Tests Cases Box.
Write your solution by modifying this code:
```python
def shortest_arrang(n):
```
Your solution should implemented in the function "shortest_arrang". The i
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
You are given a table consisting of n rows and m columns.
Numbers in each row form a permutation of integers from 1 to m.
You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than once you are allowed to pick two columns and swap them. Thus, you are allowed to perform from 0 to n + 1 actions in total. Operations can be performed in any order.
You have to check whether it's possible to obtain the identity permutation 1, 2, ..., m in each row. In other words, check if one can perform some of the operation following the given rules and make each row sorted in increasing order.
-----Input-----
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 20) — the number of rows and the number of columns in the given table.
Each of next n lines contains m integers — elements of the table. It's guaranteed that numbers in each line form a permutation of integers from 1 to m.
-----Output-----
If there is a way to obtain the identity permutation in each row by following the given rules, print "YES" (without quotes) in the only line of the output. Otherwise, print "NO" (without quotes).
-----Examples-----
Input
2 4
1 3 2 4
1 3 4 2
Output
YES
Input
4 4
1 2 3 4
2 3 4 1
3 4 1 2
4 1 2 3
Output
NO
Input
3 6
2 1 3 4 5 6
1 2 4 3 5 6
1 2 3 4 6 5
Output
YES
-----Note-----
In the first sample, one can act in the following way: Swap second and third columns. Now the table is 1 2 3 4 1 4 3 2 In the second row, swap the second and the fourth elements. Now the table is 1 2 3 4 1 2 3 4
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
Write a function that returns the number of '2's in the factorization of a number.
For example,
```python
two_count(24)
```
should return 3, since the factorization of 24 is 2^3 x 3
```python
two_count(17280)
```
should return 7, since the factorization of 17280 is 2^7 x 5 x 3^3
The number passed to two_count (twoCount) will always be a positive integer greater than or equal to 1.
Write your solution by modifying this code:
```python
def two_count(n):
```
Your solution should implemented in the function "two_count". The i
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
You have an array $a_1, a_2, \dots, a_n$.
Let's call some subarray $a_l, a_{l + 1}, \dots , a_r$ of this array a subpermutation if it contains all integers from $1$ to $r-l+1$ exactly once. For example, array $a = [2, 2, 1, 3, 2, 3, 1]$ contains $6$ subarrays which are subpermutations: $[a_2 \dots a_3]$, $[a_2 \dots a_4]$, $[a_3 \dots a_3]$, $[a_3 \dots a_5]$, $[a_5 \dots a_7]$, $[a_7 \dots a_7]$.
You are asked to calculate the number of subpermutations.
-----Input-----
The first line contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$).
The second line contains $n$ integers $a_1, a_2, \dots , a_n$ ($1 \le a_i \le n$).
This array can contain the same integers.
-----Output-----
Print the number of subpermutations of the array $a$.
-----Examples-----
Input
8
2 4 1 3 4 2 1 2
Output
7
Input
5
1 1 2 1 2
Output
6
-----Note-----
There are $7$ subpermutations in the first test case. Their segments of indices are $[1, 4]$, $[3, 3]$, $[3, 6]$, $[4, 7]$, $[6, 7]$, $[7, 7]$ and $[7, 8]$.
In the second test case $6$ subpermutations exist: $[1, 1]$, $[2, 2]$, $[2, 3]$, $[3, 4]$, $[4, 4]$ and $[4, 5]$.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
Jzzhu is the president of country A. There are n cities numbered from 1 to n in his country. City 1 is the capital of A. Also there are m roads connecting the cities. One can go from city ui to vi (and vise versa) using the i-th road, the length of this road is xi. Finally, there are k train routes in the country. One can use the i-th train route to go from capital of the country to city si (and vise versa), the length of this route is yi.
Jzzhu doesn't want to waste the money of the country, so he is going to close some of the train routes. Please tell Jzzhu the maximum number of the train routes which can be closed under the following condition: the length of the shortest path from every city to the capital mustn't change.
Input
The first line contains three integers n, m, k (2 ≤ n ≤ 105; 1 ≤ m ≤ 3·105; 1 ≤ k ≤ 105).
Each of the next m lines contains three integers ui, vi, xi (1 ≤ ui, vi ≤ n; ui ≠ vi; 1 ≤ xi ≤ 109).
Each of the next k lines contains two integers si and yi (2 ≤ si ≤ n; 1 ≤ yi ≤ 109).
It is guaranteed that there is at least one way from every city to the capital. Note, that there can be multiple roads between two cities. Also, there can be multiple routes going to the same city from the capital.
Output
Output a single integer representing the maximum number of the train routes which can be closed.
Examples
Input
5 5 3
1 2 1
2 3 2
1 3 3
3 4 4
1 5 5
3 5
4 5
5 5
Output
2
Input
2 2 3
1 2 2
2 1 3
2 1
2 2
2 3
Output
2
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
Given a set of $N$ axis-aligned rectangular seals, find the number of overlapped seals on the region which has the maximum number of overlapped seals.
Constraints
* $ 1 \leq N \leq 100000 $
* $ 0 \leq x1_i < x2_i \leq 1000 $
* $ 0 \leq y1_i < y2_i \leq 1000 $
* $ x1_i, y1_i, x2_i, y2_i$ are given in integers
Input
The input is given in the following format.
$N$
$x1_1$ $y1_1$ $x2_1$ $y2_1$
$x1_2$ $y1_2$ $x2_2$ $y2_2$
:
$x1_N$ $y1_N$ $x2_N$ $y2_N$
($x1_i, y1_i$) and ($x2_i, y2_i$) are the coordinates of the top-left and the bottom-right corner of the $i$-th seal respectively.
Output
Print the maximum number of overlapped seals in a line.
Examples
Input
2
0 0 3 2
2 1 4 3
Output
2
Input
2
0 0 2 2
2 0 4 2
Output
1
Input
3
0 0 2 2
0 0 2 2
0 0 2 2
Output
3
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
You are given an array of integers $a_1, a_2, \ldots, a_n$ and an integer $x$.
You need to select the maximum number of elements in the array, such that for every subsegment $a_l, a_{l + 1}, \ldots, a_r$ containing strictly more than one element $(l < r)$, either:
At least one element on this subsegment is not selected, or
$a_l + a_{l+1} + \ldots + a_r \geq x \cdot (r - l + 1)$.
-----Input-----
The first line of input contains one integer $t$ ($1 \leq t \leq 10$): the number of test cases.
The descriptions of $t$ test cases follow, three lines per test case.
In the first line you are given one integer $n$ ($1 \leq n \leq 50000$): the number of integers in the array.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-100000 \leq a_i \leq 100000$).
The third line contains one integer $x$ ($-100000 \leq x \leq 100000$).
-----Output-----
For each test case, print one integer: the maximum number of elements that you can select.
-----Examples-----
Input
4
5
1 2 3 4 5
2
10
2 4 2 4 2 4 2 4 2 4
3
3
-10 -5 -10
-8
3
9 9 -3
5
Output
4
8
2
2
-----Note-----
In the first example, one valid way to select the elements is $[\underline{1}, 2, \underline{3}, \underline{4}, \underline{5}]$. All subsegments satisfy at least one of the criteria. For example, for the subsegment $l = 1$, $r = 2$ we have that the element $2$ is not selected, satisfying the first criterion. For the subsegment $l = 3$, $r = 5$ we have $3 + 4 + 5 = 12 \ge 2 \cdot 3$, satisfying the second criterion.
We can't select all elements, because in this case for $l = 1$, $r = 2$ all elements are selected and we have $a_1 + a_2 = 3 < 2 \cdot 2$. Thus, the maximum number of selected elements is $4$.
In the second example, one valid solution is $[\underline{2}, \underline{4}, 2, \underline{4}, \underline{2}, \underline{4}, 2, \underline{4}, \underline{2}, \underline{4}]$.
In the third example, one valid solution is $[\underline{-10}, -5, \underline{-10}]$.
In the fourth example, one valid solution is $[\underline{9}, \underline{9}, -3]$.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
It is 2050 and romance has long gone, relationships exist solely for practicality.
MatchMyHusband is a website that matches busy working women with perfect house husbands. You have been employed by MatchMyHusband to write a function that determines who matches!!
The rules are... a match occurs providing the husband's "usefulness" rating is greater than or equal to the woman's "needs".
The husband's "usefulness" is the SUM of his cooking, cleaning and childcare abilities and takes the form of an array .
usefulness example --> [15, 26, 19] (15 + 26 + 19) = 60
Every woman that signs up, begins with a "needs" rating of 100. However, it's realised that the longer women wait for their husbands, the more dissatisfied they become with our service. They also become less picky, therefore their needs are subject to exponential decay of 15% per month. https://en.wikipedia.org/wiki/Exponential_decay
Given the number of months since sign up, write a function that returns "Match!" if the husband is useful enough, or "No match!" if he's not.
Write your solution by modifying this code:
```python
def match(usefulness, months):
```
Your solution should implemented in the function "match". The i
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
Polycarpus works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consists of some number of words (that don't contain WUB). To make the dubstep remix of this song, Polycarpus inserts a certain number of words "WUB" before the first word of the song (the number may be zero), after the last word (the number may be zero), and between words (at least one between any pair of neighbouring words), and then the boy glues together all the words, including "WUB", in one string and plays the song at the club.
For example, a song with words "I AM X" can transform into a dubstep remix as "WUBWUBIWUBAMWUBWUBX" and cannot transform into "WUBWUBIAMWUBX".
Recently, Jonny has heard Polycarpus's new dubstep track, but since he isn't into modern music, he decided to find out what was the initial song that Polycarpus remixed. Help Jonny restore the original song.
## Input
The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters
## Output
Return the words of the initial song that Polycarpus used to make a dubsteb remix. Separate the words with a space.
## Examples
```python
song_decoder("WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB")
# => WE ARE THE CHAMPIONS MY FRIEND
```
Write your solution by modifying this code:
```python
def song_decoder(song):
```
Your solution should implemented in the function "song_decoder". The i
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
Consider an infinite triangle made up of layers. Let's number the layers, starting from one, from the top of the triangle (from top to bottom). The $k$-th layer of the triangle contains $k$ points, numbered from left to right. Each point of an infinite triangle is described by a pair of numbers $(r, c)$ ($1 \le c \le r$), where $r$ is the number of the layer, and $c$ is the number of the point in the layer. From each point $(r, c)$ there are two directed edges to the points $(r+1, c)$ and $(r+1, c+1)$, but only one of the edges is activated. If $r + c$ is even, then the edge to the point $(r+1, c)$ is activated, otherwise the edge to the point $(r+1, c+1)$ is activated. Look at the picture for a better understanding.
Activated edges are colored in black. Non-activated edges are colored in gray.
From the point $(r_1, c_1)$ it is possible to reach the point $(r_2, c_2)$, if there is a path between them only from activated edges. For example, in the picture above, there is a path from $(1, 1)$ to $(3, 2)$, but there is no path from $(2, 1)$ to $(1, 1)$.
Initially, you are at the point $(1, 1)$. For each turn, you can:
Replace activated edge for point $(r, c)$. That is if the edge to the point $(r+1, c)$ is activated, then instead of it, the edge to the point $(r+1, c+1)$ becomes activated, otherwise if the edge to the point $(r+1, c+1)$, then instead if it, the edge to the point $(r+1, c)$ becomes activated. This action increases the cost of the path by $1$;
Move from the current point to another by following the activated edge. This action does not increase the cost of the path.
You are given a sequence of $n$ points of an infinite triangle $(r_1, c_1), (r_2, c_2), \ldots, (r_n, c_n)$. Find the minimum cost path from $(1, 1)$, passing through all $n$ points in arbitrary order.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) is the number of test cases. Then $t$ test cases follow.
Each test case begins with a line containing one integer $n$ ($1 \le n \le 2 \cdot 10^5$) is the number of points to visit.
The second line contains $n$ numbers $r_1, r_2, \ldots, r_n$ ($1 \le r_i \le 10^9$), where $r_i$ is the number of the layer in which $i$-th point is located.
The third line contains $n$ numbers $c_1, c_2, \ldots, c_n$ ($1 \le c_i \le r_i$), where $c_i$ is the number of the $i$-th point in the $r_i$ layer.
It is guaranteed that all $n$ points are distinct.
It is guaranteed that there is always at least one way to traverse all $n$ points.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, output the minimum cost of a path passing through all points in the corresponding test case.
-----Examples-----
Input
4
3
1 4 2
1 3 1
2
2 4
2 3
2
1 1000000000
1 1000000000
4
3 10 5 8
2 5 2 4
Output
0
1
999999999
2
-----Note-----
None
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
Takahashi Lake has a perimeter of L. On the circumference of the lake, there is a residence of the lake's owner, Takahashi. Each point on the circumference of the lake has a coordinate between 0 and L (including 0 but not L), which is the distance from the Takahashi's residence, measured counter-clockwise.
There are N trees around the lake; the coordinate of the i-th tree is X_i. There is no tree at coordinate 0, the location of Takahashi's residence.
Starting at his residence, Takahashi will repeat the following action:
* If all trees are burnt, terminate the process.
* Specify a direction: clockwise or counter-clockwise.
* Walk around the lake in the specified direction, until the coordinate of a tree that is not yet burnt is reached for the first time.
* When the coordinate with the tree is reached, burn that tree, stay at the position and go back to the first step.
Find the longest possible total distance Takahashi walks during the process.
Constraints
* 2 \leq L \leq 10^9
* 1 \leq N \leq 2\times 10^5
* 1 \leq X_1 < ... < X_N \leq L-1
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
L N
X_1
:
X_N
Output
Print the longest possible total distance Takahashi walks during the process.
Examples
Input
10 3
2
7
9
Output
15
Input
10 6
1
2
3
6
7
9
Output
27
Input
314159265 7
21662711
77271666
89022761
156626166
160332356
166902656
298992265
Output
1204124749
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
Recently Vasya learned that, given two points with different x coordinates, you can draw through them exactly one parabola with equation of type y = x^2 + bx + c, where b and c are reals. Let's call such a parabola an U-shaped one.
Vasya drew several distinct points with integer coordinates on a plane and then drew an U-shaped parabola through each pair of the points that have different x coordinates. The picture became somewhat messy, but Vasya still wants to count how many of the parabolas drawn don't have any drawn point inside their internal area. Help Vasya.
The internal area of an U-shaped parabola is the part of the plane that lies strictly above the parabola when the y axis is directed upwards.
Input
The first line contains a single integer n (1 ≤ n ≤ 100 000) — the number of points.
The next n lines describe the points, the i-th of them contains two integers x_i and y_i — the coordinates of the i-th point. It is guaranteed that all points are distinct and that the coordinates do not exceed 10^6 by absolute value.
Output
In the only line print a single integer — the number of U-shaped parabolas that pass through at least two of the given points and do not contain any of the given points inside their internal area (excluding the parabola itself).
Examples
Input
3
-1 0
0 2
1 0
Output
2
Input
5
1 0
1 -1
0 -1
-1 0
-1 -1
Output
1
Note
On the pictures below all U-shaped parabolas that pass through at least two given points are drawn for each of the examples. The U-shaped parabolas that do not have any given point inside their internal area are drawn in red.
<image> The first example. <image> The second example.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
# Valid HK Phone Number
## Overview
In Hong Kong, a valid phone number has the format ```xxxx xxxx``` where ```x``` is a decimal digit (0-9). For example:
## Task
Define two functions, ```isValidHKPhoneNumber``` and ```hasValidHKPhoneNumber```, that ```return```s whether a given string is a valid HK phone number and contains a valid HK phone number respectively (i.e. ```true/false``` values).
If in doubt please refer to the example tests.
Write your solution by modifying this code:
```python
def is_valid_HK_phone_number(number):
```
Your solution should implemented in the function "is_valid_HK_phone_number". The i
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
```if-not:sql
Create a function (or write a script in Shell) that takes an integer as an argument and returns "Even" for even numbers or "Odd" for odd numbers.
```
```if:sql
## SQL Notes:
You will be given a table, `numbers`, with one column `number`.
Return a table with a column `is_even` containing "Even" or "Odd" depending on `number` column values.
### numbers table schema
* number INT
### output table schema
* is_even STRING
```
Write your solution by modifying this code:
```python
def even_or_odd(number):
```
Your solution should implemented in the function "even_or_odd". The i
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
Takahashi received otoshidama (New Year's money gifts) from N of his relatives.
You are given N values x_1, x_2, ..., x_N and N strings u_1, u_2, ..., u_N as input. Each string u_i is either JPY or BTC, and x_i and u_i represent the content of the otoshidama from the i-th relative.
For example, if x_1 = 10000 and u_1 = JPY, the otoshidama from the first relative is 10000 Japanese yen; if x_2 = 0.10000000 and u_2 = BTC, the otoshidama from the second relative is 0.1 bitcoins.
If we convert the bitcoins into yen at the rate of 380000.0 JPY per 1.0 BTC, how much are the gifts worth in total?
-----Constraints-----
- 2 \leq N \leq 10
- u_i = JPY or BTC.
- If u_i = JPY, x_i is an integer such that 1 \leq x_i \leq 10^8.
- If u_i = BTC, x_i is a decimal with 8 decimal digits, such that 0.00000001 \leq x_i \leq 100.00000000.
-----Input-----
Input is given from Standard Input in the following format:
N
x_1 u_1
x_2 u_2
:
x_N u_N
-----Output-----
If the gifts are worth Y yen in total, print the value Y (not necessarily an integer).
Output will be judged correct when the absolute or relative error from the judge's output is at most 10^{-5}.
-----Sample Input-----
2
10000 JPY
0.10000000 BTC
-----Sample Output-----
48000.0
The otoshidama from the first relative is 10000 yen. The otoshidama from the second relative is 0.1 bitcoins, which is worth 38000.0 yen if converted at the rate of 380000.0 JPY per 1.0 BTC. The sum of these is 48000.0 yen.
Outputs such as 48000 and 48000.1 will also be judged correct.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
In this Kata, you will be given a multi-dimensional array containing `2 or more` sub-arrays of integers. Your task is to find the maximum product that can be formed by taking any one element from each sub-array.
```
Examples:
solve( [[1, 2],[3, 4]] ) = 8. The max product is given by 2 * 4
solve( [[10,-15],[-1,-3]] ) = 45, given by (-15) * (-3)
solve( [[1,-1],[2,3],[10,-100]] ) = 300, given by (-1) * 3 * (-100)
```
More examples in test cases. Good luck!
Write your solution by modifying this code:
```python
def solve(arr):
```
Your solution should implemented in the function "solve". The i
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
Write a program which reads the two dices constructed in the same way as Dice I, and determines whether these two dices are identical. You can roll a dice in the same way as Dice I, and if all integers observed from the six directions are the same as that of another dice, these dices can be considered as identical.
Constraints
* $0 \leq $ the integer assigned to a face $ \leq 100$
Input
In the first line, six integers assigned to faces of a dice are given in ascending order of their corresponding labels.
In the second line, six integers assigned to faces of another dice are given in ascending order of their corresponding labels.
Output
Print "Yes" if two dices are identical, otherwise "No" in a line.
Examples
Input
1 2 3 4 5 6
6 2 4 3 5 1
Output
Yes
Input
1 2 3 4 5 6
6 5 4 3 2 1
Output
No
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
Little Artyom decided to study probability theory. He found a book with a lot of nice exercises and now wants you to help him with one of them.
Consider two dices. When thrown each dice shows some integer from 1 to n inclusive. For each dice the probability of each outcome is given (of course, their sum is 1), and different dices may have different probability distributions.
We throw both dices simultaneously and then calculate values max(a, b) and min(a, b), where a is equal to the outcome of the first dice, while b is equal to the outcome of the second dice. You don't know the probability distributions for particular values on each dice, but you know the probability distributions for max(a, b) and min(a, b). That is, for each x from 1 to n you know the probability that max(a, b) would be equal to x and the probability that min(a, b) would be equal to x. Find any valid probability distribution for values on the dices. It's guaranteed that the input data is consistent, that is, at least one solution exists.
-----Input-----
First line contains the integer n (1 ≤ n ≤ 100 000) — the number of different values for both dices.
Second line contains an array consisting of n real values with up to 8 digits after the decimal point — probability distribution for max(a, b), the i-th of these values equals to the probability that max(a, b) = i. It's guaranteed that the sum of these values for one dice is 1. The third line contains the description of the distribution min(a, b) in the same format.
-----Output-----
Output two descriptions of the probability distribution for a on the first line and for b on the second line.
The answer will be considered correct if each value of max(a, b) and min(a, b) probability distribution values does not differ by more than 10^{ - 6} from ones given in input. Also, probabilities should be non-negative and their sums should differ from 1 by no more than 10^{ - 6}.
-----Examples-----
Input
2
0.25 0.75
0.75 0.25
Output
0.5 0.5
0.5 0.5
Input
3
0.125 0.25 0.625
0.625 0.25 0.125
Output
0.25 0.25 0.5
0.5 0.25 0.25
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
Polycarp has a checkered sheet of paper of size n × m. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square.
You are to determine the minimum possible number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. The square's side should have positive length.
-----Input-----
The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the sizes of the sheet.
The next n lines contain m letters 'B' or 'W' each — the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white.
-----Output-----
Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1.
-----Examples-----
Input
5 4
WWWW
WWWB
WWWB
WWBB
WWWW
Output
5
Input
1 2
BB
Output
-1
Input
3 3
WWW
WWW
WWW
Output
1
-----Note-----
In the first example it is needed to paint 5 cells — (2, 2), (2, 3), (3, 2), (3, 3) and (4, 2). Then there will be a square with side equal to three, and the upper left corner in (2, 2).
In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square.
In the third example all cells are colored white, so it's sufficient to color any cell black.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
You are playing a computer card game called Splay the Sire. Currently you are struggling to defeat the final boss of the game.
The boss battle consists of $n$ turns. During each turn, you will get several cards. Each card has two parameters: its cost $c_i$ and damage $d_i$. You may play some of your cards during each turn in some sequence (you choose the cards and the exact order they are played), as long as the total cost of the cards you play during the turn does not exceed $3$. After playing some (possibly zero) cards, you end your turn, and all cards you didn't play are discarded. Note that you can use each card at most once.
Your character has also found an artifact that boosts the damage of some of your actions: every $10$-th card you play deals double damage.
What is the maximum possible damage you can deal during $n$ turns?
-----Input-----
The first line contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of turns.
Then $n$ blocks of input follow, the $i$-th block representing the cards you get during the $i$-th turn.
Each block begins with a line containing one integer $k_i$ ($1 \le k_i \le 2 \cdot 10^5$) — the number of cards you get during $i$-th turn. Then $k_i$ lines follow, each containing two integers $c_j$ and $d_j$ ($1 \le c_j \le 3$, $1 \le d_j \le 10^9$) — the parameters of the corresponding card.
It is guaranteed that $\sum \limits_{i = 1}^{n} k_i \le 2 \cdot 10^5$.
-----Output-----
Print one integer — the maximum damage you may deal.
-----Example-----
Input
5
3
1 6
1 7
1 5
2
1 4
1 3
3
1 10
3 5
2 3
3
1 15
2 4
1 10
1
1 100
Output
263
-----Note-----
In the example test the best course of action is as follows:
During the first turn, play all three cards in any order and deal $18$ damage.
During the second turn, play both cards and deal $7$ damage.
During the third turn, play the first and the third card and deal $13$ damage.
During the fourth turn, play the first and the third card and deal $25$ damage.
During the fifth turn, play the only card, which will deal double damage ($200$).
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
Given a triangle of consecutive odd numbers:
```
1
3 5
7 9 11
13 15 17 19
21 23 25 27 29
...
```
find the triangle's row knowing its index (the rows are 1-indexed), e.g.:
```
odd_row(1) == [1]
odd_row(2) == [3, 5]
odd_row(3) == [7, 9, 11]
```
**Note**: your code should be optimized to handle big inputs.
___
The idea for this kata was taken from this kata: [Sum of odd numbers](https://www.codewars.com/kata/sum-of-odd-numbers)
Write your solution by modifying this code:
```python
def odd_row(n):
```
Your solution should implemented in the function "odd_row". The i
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
Sereja is a coder and he likes to take part in Codesorfes rounds. However, Uzhland doesn't have good internet connection, so Sereja sometimes skips rounds.
Codesorfes has rounds of two types: Div1 (for advanced coders) and Div2 (for beginner coders). Two rounds, Div1 and Div2, can go simultaneously, (Div1 round cannot be held without Div2) in all other cases the rounds don't overlap in time. Each round has a unique identifier — a positive integer. The rounds are sequentially (without gaps) numbered with identifiers by the starting time of the round. The identifiers of rounds that are run simultaneously are different by one, also the identifier of the Div1 round is always greater.
Sereja is a beginner coder, so he can take part only in rounds of Div2 type. At the moment he is taking part in a Div2 round, its identifier equals to x. Sereja remembers very well that he has taken part in exactly k rounds before this round. Also, he remembers all identifiers of the rounds he has taken part in and all identifiers of the rounds that went simultaneously with them. Sereja doesn't remember anything about the rounds he missed.
Sereja is wondering: what minimum and what maximum number of Div2 rounds could he have missed? Help him find these two numbers.
-----Input-----
The first line contains two integers: x (1 ≤ x ≤ 4000) — the round Sereja is taking part in today, and k (0 ≤ k < 4000) — the number of rounds he took part in.
Next k lines contain the descriptions of the rounds that Sereja took part in before. If Sereja took part in one of two simultaneous rounds, the corresponding line looks like: "1 num_2 num_1" (where num_2 is the identifier of this Div2 round, num_1 is the identifier of the Div1 round). It is guaranteed that num_1 - num_2 = 1. If Sereja took part in a usual Div2 round, then the corresponding line looks like: "2 num" (where num is the identifier of this Div2 round). It is guaranteed that the identifiers of all given rounds are less than x.
-----Output-----
Print in a single line two integers — the minimum and the maximum number of rounds that Sereja could have missed.
-----Examples-----
Input
3 2
2 1
2 2
Output
0 0
Input
9 3
1 2 3
2 8
1 4 5
Output
2 3
Input
10 0
Output
5 9
-----Note-----
In the second sample we have unused identifiers of rounds 1, 6, 7. The minimum number of rounds Sereja could have missed equals to 2. In this case, the round with the identifier 1 will be a usual Div2 round and the round with identifier 6 will be synchronous with the Div1 round.
The maximum number of rounds equals 3. In this case all unused identifiers belong to usual Div2 rounds.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
This problem is different from the hard version. In this version Ujan makes exactly one exchange. You can hack this problem only if you solve both problems.
After struggling and failing many times, Ujan decided to try to clean up his house again. He decided to get his strings in order first.
Ujan has two distinct strings $s$ and $t$ of length $n$ consisting of only of lowercase English characters. He wants to make them equal. Since Ujan is lazy, he will perform the following operation exactly once: he takes two positions $i$ and $j$ ($1 \le i,j \le n$, the values $i$ and $j$ can be equal or different), and swaps the characters $s_i$ and $t_j$. Can he succeed?
Note that he has to perform this operation exactly once. He has to perform this operation.
-----Input-----
The first line contains a single integer $k$ ($1 \leq k \leq 10$), the number of test cases.
For each of the test cases, the first line contains a single integer $n$ ($2 \leq n \leq 10^4$), the length of the strings $s$ and $t$.
Each of the next two lines contains the strings $s$ and $t$, each having length exactly $n$. The strings consist only of lowercase English letters. It is guaranteed that strings are different.
-----Output-----
For each test case, output "Yes" if Ujan can make the two strings equal and "No" otherwise.
You can print each letter in any case (upper or lower).
-----Example-----
Input
4
5
souse
houhe
3
cat
dog
2
aa
az
3
abc
bca
Output
Yes
No
No
No
-----Note-----
In the first test case, Ujan can swap characters $s_1$ and $t_4$, obtaining the word "house".
In the second test case, it is not possible to make the strings equal using exactly one swap of $s_i$ and $t_j$.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
You are given a permutation $p_1, p_2, \ldots, p_n$ of integers from $1$ to $n$ and an integer $k$, such that $1 \leq k \leq n$. A permutation means that every number from $1$ to $n$ is contained in $p$ exactly once.
Let's consider all partitions of this permutation into $k$ disjoint segments. Formally, a partition is a set of segments $\{[l_1, r_1], [l_2, r_2], \ldots, [l_k, r_k]\}$, such that:
$1 \leq l_i \leq r_i \leq n$ for all $1 \leq i \leq k$; For all $1 \leq j \leq n$ there exists exactly one segment $[l_i, r_i]$, such that $l_i \leq j \leq r_i$.
Two partitions are different if there exists a segment that lies in one partition but not the other.
Let's calculate the partition value, defined as $\sum\limits_{i=1}^{k} {\max\limits_{l_i \leq j \leq r_i} {p_j}}$, for all possible partitions of the permutation into $k$ disjoint segments. Find the maximum possible partition value over all such partitions, and the number of partitions with this value. As the second value can be very large, you should find its remainder when divided by $998\,244\,353$.
-----Input-----
The first line contains two integers, $n$ and $k$ ($1 \leq k \leq n \leq 200\,000$) — the size of the given permutation and the number of segments in a partition.
The second line contains $n$ different integers $p_1, p_2, \ldots, p_n$ ($1 \leq p_i \leq n$) — the given permutation.
-----Output-----
Print two integers — the maximum possible partition value over all partitions of the permutation into $k$ disjoint segments and the number of such partitions for which the partition value is equal to the maximum possible value, modulo $998\,244\,353$.
Please note that you should only find the second value modulo $998\,244\,353$.
-----Examples-----
Input
3 2
2 1 3
Output
5 2
Input
5 5
2 1 5 3 4
Output
15 1
Input
7 3
2 7 3 1 5 4 6
Output
18 6
-----Note-----
In the first test, for $k = 2$, there exists only two valid partitions: $\{[1, 1], [2, 3]\}$ and $\{[1, 2], [3, 3]\}$. For each partition, the partition value is equal to $2 + 3 = 5$. So, the maximum possible value is $5$ and the number of partitions is $2$.
In the third test, for $k = 3$, the partitions with the maximum possible partition value are $\{[1, 2], [3, 5], [6, 7]\}$, $\{[1, 3], [4, 5], [6, 7]\}$, $\{[1, 4], [5, 5], [6, 7]\}$, $\{[1, 2], [3, 6], [7, 7]\}$, $\{[1, 3], [4, 6], [7, 7]\}$, $\{[1, 4], [5, 6], [7, 7]\}$. For all of them, the partition value is equal to $7 + 5 + 6 = 18$.
The partition $\{[1, 2], [3, 4], [5, 7]\}$, however, has the partition value $7 + 3 + 6 = 16$. This is not the maximum possible value, so we don't count it.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework.
The teacher gave Seryozha the coordinates of n distinct points on the abscissa axis and asked to consecutively connect them by semi-circus in a certain order: first connect the first point with the second one, then connect the second point with the third one, then the third one with the fourth one and so on to the n-th point. Two points with coordinates (x_1, 0) and (x_2, 0) should be connected by a semi-circle that passes above the abscissa axis with the diameter that coincides with the segment between points. Seryozha needs to find out if the line on the picture intersects itself. For clarifications, see the picture Seryozha showed to Dima (the left picture has self-intersections, the right picture doesn't have any). [Image]
Seryozha is not a small boy, so the coordinates of the points can be rather large. Help Dima cope with the problem.
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 10^3). The second line contains n distinct integers x_1, x_2, ..., x_{n} ( - 10^6 ≤ x_{i} ≤ 10^6) — the i-th point has coordinates (x_{i}, 0). The points are not necessarily sorted by their x coordinate.
-----Output-----
In the single line print "yes" (without the quotes), if the line has self-intersections. Otherwise, print "no" (without the quotes).
-----Examples-----
Input
4
0 10 5 15
Output
yes
Input
4
0 15 5 10
Output
no
-----Note-----
The first test from the statement is on the picture to the left, the second test is on the picture to the right.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
You are given an array a consisting of n positive integers. You pick two integer numbers l and r from 1 to n, inclusive (numbers are picked randomly, equiprobably and independently). If l > r, then you swap values of l and r. You have to calculate the expected value of the number of unique elements in segment of the array from index l to index r, inclusive (1-indexed).
-----Input-----
The first line contains one integer number n (1 ≤ n ≤ 10^6). The second line contains n integer numbers a_1, a_2, ... a_{n} (1 ≤ a_{i} ≤ 10^6) — elements of the array.
-----Output-----
Print one number — the expected number of unique elements in chosen segment.
Your answer will be considered correct if its absolute or relative error doesn't exceed 10^{ - 4} — formally, the answer is correct if $\operatorname{min}(|x - y|, \frac{|x - y|}{x}) \leq 10^{-4}$, where x is jury's answer, and y is your answer.
-----Examples-----
Input
2
1 2
Output
1.500000
Input
2
2 2
Output
1.000000
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
Natasha's favourite numbers are $n$ and $1$, and Sasha's favourite numbers are $m$ and $-1$. One day Natasha and Sasha met and wrote down every possible array of length $n+m$ such that some $n$ of its elements are equal to $1$ and another $m$ elements are equal to $-1$. For each such array they counted its maximal prefix sum, probably an empty one which is equal to $0$ (in another words, if every nonempty prefix sum is less to zero, then it is considered equal to zero). Formally, denote as $f(a)$ the maximal prefix sum of an array $a_{1, \ldots ,l}$ of length $l \geq 0$. Then:
$$f(a) = \max (0, \smash{\displaystyle\max_{1 \leq i \leq l}} \sum_{j=1}^{i} a_j )$$
Now they want to count the sum of maximal prefix sums for each such an array and they are asking you to help. As this sum can be very large, output it modulo $998\: 244\: 853$.
-----Input-----
The only line contains two integers $n$ and $m$ ($0 \le n,m \le 2\,000$).
-----Output-----
Output the answer to the problem modulo $998\: 244\: 853$.
-----Examples-----
Input
0 2
Output
0
Input
2 0
Output
2
Input
2 2
Output
5
Input
2000 2000
Output
674532367
-----Note-----
In the first example the only possible array is [-1,-1], its maximal prefix sum is equal to $0$.
In the second example the only possible array is [1,1], its maximal prefix sum is equal to $2$.
There are $6$ possible arrays in the third example:
[1,1,-1,-1], f([1,1,-1,-1]) = 2
[1,-1,1,-1], f([1,-1,1,-1]) = 1
[1,-1,-1,1], f([1,-1,-1,1]) = 1
[-1,1,1,-1], f([-1,1,1,-1]) = 1
[-1,1,-1,1], f([-1,1,-1,1]) = 0
[-1,-1,1,1], f([-1,-1,1,1]) = 0
So the answer for the third example is $2+1+1+1+0+0 = 5$.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
You should write a simple function that takes string as input and checks if it is a valid Russian postal code, returning `true` or `false`.
A valid postcode should be 6 digits with no white spaces, letters or other symbols. Empty string should also return false.
Please also keep in mind that a valid post code **cannot start with** `0, 5, 7, 8 or 9`
## Examples
Valid postcodes:
* 198328
* 310003
* 424000
Invalid postcodes:
* 056879
* 12A483
* 1@63
* 111
Write your solution by modifying this code:
```python
def zipvalidate(postcode):
```
Your solution should implemented in the function "zipvalidate". The i
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
Welcome to Innopolis city. Throughout the whole year, Innopolis citizens suffer from everlasting city construction.
From the window in your room, you see the sequence of n hills, where i-th of them has height a_{i}. The Innopolis administration wants to build some houses on the hills. However, for the sake of city appearance, a house can be only built on the hill, which is strictly higher than neighbouring hills (if they are present). For example, if the sequence of heights is 5, 4, 6, 2, then houses could be built on hills with heights 5 and 6 only.
The Innopolis administration has an excavator, that can decrease the height of an arbitrary hill by one in one hour. The excavator can only work on one hill at a time. It is allowed to decrease hills up to zero height, or even to negative values. Increasing height of any hill is impossible. The city administration wants to build k houses, so there must be at least k hills that satisfy the condition above. What is the minimum time required to adjust the hills to achieve the administration's plan?
However, the exact value of k is not yet determined, so could you please calculate answers for all k in range $1 \leq k \leq \lceil \frac{n}{2} \rceil$? Here $\lceil \frac{n}{2} \rceil$ denotes n divided by two, rounded up.
-----Input-----
The first line of input contains the only integer n (1 ≤ n ≤ 5000)—the number of the hills in the sequence.
Second line contains n integers a_{i} (1 ≤ a_{i} ≤ 100 000)—the heights of the hills in the sequence.
-----Output-----
Print exactly $\lceil \frac{n}{2} \rceil$ numbers separated by spaces. The i-th printed number should be equal to the minimum number of hours required to level hills so it becomes possible to build i houses.
-----Examples-----
Input
5
1 1 1 1 1
Output
1 2 2
Input
3
1 2 3
Output
0 2
Input
5
1 2 3 2 2
Output
0 1 3
-----Note-----
In the first example, to get at least one hill suitable for construction, one can decrease the second hill by one in one hour, then the sequence of heights becomes 1, 0, 1, 1, 1 and the first hill becomes suitable for construction.
In the first example, to get at least two or at least three suitable hills, one can decrease the second and the fourth hills, then the sequence of heights becomes 1, 0, 1, 0, 1, and hills 1, 3, 5 become suitable for construction.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
# Introduction and Warm-up (Highly recommended)
# [Playing With Lists/Arrays Series](https://www.codewars.com/collections/playing-with-lists-slash-arrays)
___
# Task
**_Given_** an *array/list [] of integers* , **_Find_** *the Nth smallest element in this array of integers*
___
# Notes
* **_Array/list_** size is *at least 3* .
* **_Array/list's numbers_** *could be a **_mixture_** of positives , negatives and zeros* .
* **_Repetition_** *in array/list's numbers could occur* , so **_don't Remove Duplications_** .
___
# Input >> Output Examples
```
nthSmallest({3,1,2} ,2) ==> return (2)
```
## **_Explanation_**:
Since the passed number is **_2_** , Then * **_the second smallest_** element in this array/list is **_2_***
___
```
nthSmallest({15,20,7,10,4,3} ,3) ==> return (7)
```
## **_Explanation_**:
Since the passed number is **_3_** , Then * **_the third smallest_** element in this array/list is **_7_***
___
```
nthSmallest({2,169,13,-5,0,-1} ,4) ==> return (2)
```
## **_Explanation_**:
Since the passed number is **_4_** , Then * **_the fourth smallest_** element in this array/list is **_2_***
___
```
nthSmallest({177,225,243,-169,-12,-5,2,92} ,5) ==> return (92)
```
## **_Explanation_**:
Since the passed number is **_5_** , Then * **_the fifth smallest_** element in this array/list is **_92_***
___
___
___
# [Playing with Numbers Series](https://www.codewars.com/collections/playing-with-numbers)
# [Playing With Lists/Arrays Series](https://www.codewars.com/collections/playing-with-lists-slash-arrays)
# [For More Enjoyable Katas](http://www.codewars.com/users/MrZizoScream/authored)
___
## ALL translations are welcomed
## Enjoy Learning !!
# Zizou
Write your solution by modifying this code:
```python
def nth_smallest(arr, pos):
```
Your solution should implemented in the function "nth_smallest". The i
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
Mad scientist Mike is busy carrying out experiments in chemistry. Today he will attempt to join three atoms into one molecule.
A molecule consists of atoms, with some pairs of atoms connected by atomic bonds. Each atom has a valence number — the number of bonds the atom must form with other atoms. An atom can form one or multiple bonds with any other atom, but it cannot form a bond with itself. The number of bonds of an atom in the molecule must be equal to its valence number. [Image]
Mike knows valence numbers of the three atoms. Find a molecule that can be built from these atoms according to the stated rules, or determine that it is impossible.
-----Input-----
The single line of the input contains three space-separated integers a, b and c (1 ≤ a, b, c ≤ 10^6) — the valence numbers of the given atoms.
-----Output-----
If such a molecule can be built, print three space-separated integers — the number of bonds between the 1-st and the 2-nd, the 2-nd and the 3-rd, the 3-rd and the 1-st atoms, correspondingly. If there are multiple solutions, output any of them. If there is no solution, print "Impossible" (without the quotes).
-----Examples-----
Input
1 1 2
Output
0 1 1
Input
3 4 5
Output
1 3 2
Input
4 1 1
Output
Impossible
-----Note-----
The first sample corresponds to the first figure. There are no bonds between atoms 1 and 2 in this case.
The second sample corresponds to the second figure. There is one or more bonds between each pair of atoms.
The third sample corresponds to the third figure. There is no solution, because an atom cannot form bonds with itself.
The configuration in the fourth figure is impossible as each atom must have at least one atomic bond.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
A remote island chain contains n islands, labeled 1 through n. Bidirectional bridges connect the islands to form a simple cycle — a bridge connects islands 1 and 2, islands 2 and 3, and so on, and additionally a bridge connects islands n and 1. The center of each island contains an identical pedestal, and all but one of the islands has a fragile, uniquely colored statue currently held on the pedestal. The remaining island holds only an empty pedestal.
The islanders want to rearrange the statues in a new order. To do this, they repeat the following process: First, they choose an island directly adjacent to the island containing an empty pedestal. Then, they painstakingly carry the statue on this island across the adjoining bridge and place it on the empty pedestal.
Determine if it is possible for the islanders to arrange the statues in the desired order.
-----Input-----
The first line contains a single integer n (2 ≤ n ≤ 200 000) — the total number of islands.
The second line contains n space-separated integers a_{i} (0 ≤ a_{i} ≤ n - 1) — the statue currently placed on the i-th island. If a_{i} = 0, then the island has no statue. It is guaranteed that the a_{i} are distinct.
The third line contains n space-separated integers b_{i} (0 ≤ b_{i} ≤ n - 1) — the desired statues of the ith island. Once again, b_{i} = 0 indicates the island desires no statue. It is guaranteed that the b_{i} are distinct.
-----Output-----
Print "YES" (without quotes) if the rearrangement can be done in the existing network, and "NO" otherwise.
-----Examples-----
Input
3
1 0 2
2 0 1
Output
YES
Input
2
1 0
0 1
Output
YES
Input
4
1 2 3 0
0 3 2 1
Output
NO
-----Note-----
In the first sample, the islanders can first move statue 1 from island 1 to island 2, then move statue 2 from island 3 to island 1, and finally move statue 1 from island 2 to island 3.
In the second sample, the islanders can simply move statue 1 from island 1 to island 2.
In the third sample, no sequence of movements results in the desired position.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
One day Polycarpus got hold of two non-empty strings s and t, consisting of lowercase Latin letters. Polycarpus is quite good with strings, so he immediately wondered, how many different pairs of "x y" are there, such that x is a substring of string s, y is a subsequence of string t, and the content of x and y is the same. Two pairs are considered different, if they contain different substrings of string s or different subsequences of string t. Read the whole statement to understand the definition of different substrings and subsequences.
The length of string s is the number of characters in it. If we denote the length of the string s as |s|, we can write the string as s = s1s2... s|s|.
A substring of s is a non-empty string x = s[a... b] = sasa + 1... sb (1 ≤ a ≤ b ≤ |s|). For example, "code" and "force" are substrings or "codeforces", while "coders" is not. Two substrings s[a... b] and s[c... d] are considered to be different if a ≠ c or b ≠ d. For example, if s="codeforces", s[2...2] and s[6...6] are different, though their content is the same.
A subsequence of s is a non-empty string y = s[p1p2... p|y|] = sp1sp2... sp|y| (1 ≤ p1 < p2 < ... < p|y| ≤ |s|). For example, "coders" is a subsequence of "codeforces". Two subsequences u = s[p1p2... p|u|] and v = s[q1q2... q|v|] are considered different if the sequences p and q are different.
Input
The input consists of two lines. The first of them contains s (1 ≤ |s| ≤ 5000), and the second one contains t (1 ≤ |t| ≤ 5000). Both strings consist of lowercase Latin letters.
Output
Print a single number — the number of different pairs "x y" such that x is a substring of string s, y is a subsequence of string t, and the content of x and y is the same. As the answer can be rather large, print it modulo 1000000007 (109 + 7).
Examples
Input
aa
aa
Output
5
Input
codeforces
forceofcode
Output
60
Note
Let's write down all pairs "x y" that form the answer in the first sample: "s[1...1] t[1]", "s[2...2] t[1]", "s[1...1] t[2]","s[2...2] t[2]", "s[1...2] t[1 2]".
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
There are $n$ candy boxes in front of Tania. The boxes are arranged in a row from left to right, numbered from $1$ to $n$. The $i$-th box contains $r_i$ candies, candies have the color $c_i$ (the color can take one of three values — red, green, or blue). All candies inside a single box have the same color (and it is equal to $c_i$).
Initially, Tanya is next to the box number $s$. Tanya can move to the neighbor box (that is, with a number that differs by one) or eat candies in the current box. Tanya eats candies instantly, but the movement takes one second.
If Tanya eats candies from the box, then the box itself remains in place, but there is no more candies in it. In other words, Tanya always eats all the candies from the box and candies in the boxes are not refilled.
It is known that Tanya cannot eat candies of the same color one after another (that is, the colors of candies in two consecutive boxes from which she eats candies are always different). In addition, Tanya's appetite is constantly growing, so in each next box from which she eats candies, there should be strictly more candies than in the previous one.
Note that for the first box from which Tanya will eat candies, there are no restrictions on the color and number of candies.
Tanya wants to eat at least $k$ candies. What is the minimum number of seconds she will need? Remember that she eats candies instantly, and time is spent only on movements.
-----Input-----
The first line contains three integers $n$, $s$ and $k$ ($1 \le n \le 50$, $1 \le s \le n$, $1 \le k \le 2000$) — number of the boxes, initial position of Tanya and lower bound on number of candies to eat. The following line contains $n$ integers $r_i$ ($1 \le r_i \le 50$) — numbers of candies in the boxes. The third line contains sequence of $n$ letters 'R', 'G' and 'B', meaning the colors of candies in the correspondent boxes ('R' for red, 'G' for green, 'B' for blue). Recall that each box contains candies of only one color. The third line contains no spaces.
-----Output-----
Print minimal number of seconds to eat at least $k$ candies. If solution doesn't exist, print "-1".
-----Examples-----
Input
5 3 10
1 2 3 4 5
RGBRR
Output
4
Input
2 1 15
5 6
RG
Output
-1
-----Note-----
The sequence of actions of Tanya for the first example:
move from the box $3$ to the box $2$; eat candies from the box $2$; move from the box $2$ to the box $3$; eat candy from the box $3$; move from the box $3$ to the box $4$; move from the box $4$ to the box $5$; eat candies from the box $5$.
Since Tanya eats candy instantly, the required time is four seconds.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
If you visit Aizu Akabeko shrine, you will find a unique paper fortune on which a number with more than one digit is written.
Each digit ranges from 1 to 9 (zero is avoided because it is considered a bad omen in this shrine). Using this string of numeric values, you can predict how many years it will take before your dream comes true. Cut up the string into more than one segment and compare their values. The difference between the largest and smallest value will give you the number of years before your wish will be fulfilled. Therefore, the result varies depending on the way you cut up the string. For example, if you are given a string 11121314 and divide it into segments, say, as 1,11,21,3,14, then the difference between the largest and smallest is 21 - 1 = 20. Another division 11,12,13,14 produces 3 (i.e. 14 - 11) years. Any random division produces a game of luck. However, you can search the minimum number of years using a program.
Given a string of numerical characters, write a program to search the minimum years before your wish will be fulfilled.
Input
The input is given in the following format.
n
An integer n is given. Its number of digits is from 2 to 100,000, and each digit ranges from 1 to 9.
Output
Output the minimum number of years before your wish will be fulfilled.
Examples
Input
11121314
Output
3
Input
123125129
Output
6
Input
119138
Output
5
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
An **anagram** is the result of rearranging the letters of a word to produce a new word.
**Note:** anagrams are case insensitive
Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise.
## Examples
* `"foefet"` is an anagram of `"toffee"`
* `"Buckethead"` is an anagram of `"DeathCubeK"`
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
Arkady decides to observe a river for n consecutive days. The river's water level on each day is equal to some real value.
Arkady goes to the riverside each day and makes a mark on the side of the channel at the height of the water level, but if it coincides with a mark made before, no new mark is created. The water does not wash the marks away. Arkady writes down the number of marks strictly above the water level each day, on the i-th day this value is equal to mi.
Define di as the number of marks strictly under the water level on the i-th day. You are to find out the minimum possible sum of di over all days. There are no marks on the channel before the first day.
Input
The first line contains a single positive integer n (1 ≤ n ≤ 105) — the number of days.
The second line contains n space-separated integers m1, m2, ..., mn (0 ≤ mi < i) — the number of marks strictly above the water on each day.
Output
Output one single integer — the minimum possible sum of the number of marks strictly below the water level among all days.
Examples
Input
6
0 1 0 3 0 2
Output
6
Input
5
0 1 2 1 2
Output
1
Input
5
0 1 1 2 2
Output
0
Note
In the first example, the following figure shows an optimal case.
<image>
Note that on day 3, a new mark should be created because if not, there cannot be 3 marks above water on day 4. The total number of marks underwater is 0 + 0 + 2 + 0 + 3 + 1 = 6.
In the second example, the following figure shows an optimal case.
<image>
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
You are given an array $a_1, a_2, \dots, a_n$. You can perform the following operation any number of times: Choose a pair of two neighboring equal elements $a_i = a_{i + 1}$ (if there is at least one such pair). Replace them by one element with value $a_i + 1$.
After each such operation, the length of the array will decrease by one (and elements are renumerated accordingly). What is the minimum possible length of the array $a$ you can get?
-----Input-----
The first line contains the single integer $n$ ($1 \le n \le 500$) — the initial length of the array $a$.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 1000$) — the initial array $a$.
-----Output-----
Print the only integer — the minimum possible length you can get after performing the operation described above any number of times.
-----Examples-----
Input
5
4 3 2 2 3
Output
2
Input
7
3 3 4 4 4 3 3
Output
2
Input
3
1 3 5
Output
3
Input
1
1000
Output
1
-----Note-----
In the first test, this is one of the optimal sequences of operations: $4$ $3$ $2$ $2$ $3$ $\rightarrow$ $4$ $3$ $3$ $3$ $\rightarrow$ $4$ $4$ $3$ $\rightarrow$ $5$ $3$.
In the second test, this is one of the optimal sequences of operations: $3$ $3$ $4$ $4$ $4$ $3$ $3$ $\rightarrow$ $4$ $4$ $4$ $4$ $3$ $3$ $\rightarrow$ $4$ $4$ $4$ $4$ $4$ $\rightarrow$ $5$ $4$ $4$ $4$ $\rightarrow$ $5$ $5$ $4$ $\rightarrow$ $6$ $4$.
In the third and fourth tests, you can't perform the operation at all.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
There are X+Y+Z people, conveniently numbered 1 through X+Y+Z. Person i has A_i gold coins, B_i silver coins and C_i bronze coins.
Snuke is thinking of getting gold coins from X of those people, silver coins from Y of the people and bronze coins from Z of the people. It is not possible to get two or more different colors of coins from a single person. On the other hand, a person will give all of his/her coins of the color specified by Snuke.
Snuke would like to maximize the total number of coins of all colors he gets. Find the maximum possible number of coins.
Constraints
* 1 \leq X
* 1 \leq Y
* 1 \leq Z
* X+Y+Z \leq 10^5
* 1 \leq A_i \leq 10^9
* 1 \leq B_i \leq 10^9
* 1 \leq C_i \leq 10^9
Input
Input is given from Standard Input in the following format:
X Y Z
A_1 B_1 C_1
A_2 B_2 C_2
:
A_{X+Y+Z} B_{X+Y+Z} C_{X+Y+Z}
Output
Print the maximum possible total number of coins of all colors he gets.
Examples
Input
1 2 1
2 4 4
3 2 1
7 6 7
5 2 3
Output
18
Input
3 3 2
16 17 1
2 7 5
2 16 12
17 7 7
13 2 10
12 18 3
16 15 19
5 6 2
Output
110
Input
6 2 4
33189 87907 277349742
71616 46764 575306520
8801 53151 327161251
58589 4337 796697686
66854 17565 289910583
50598 35195 478112689
13919 88414 103962455
7953 69657 699253752
44255 98144 468443709
2332 42580 752437097
39752 19060 845062869
60126 74101 382963164
Output
3093929975
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
Implement a function called makeAcronym that returns the first letters of each word in a passed in string.
Make sure the letters returned are uppercase.
If the value passed in is not a string return 'Not a string'.
If the value passed in is a string which contains characters other than spaces and alphabet letters, return 'Not letters'.
If the string is empty, just return the string itself: "".
**EXAMPLES:**
```
'Hello codewarrior' -> 'HC'
'a42' -> 'Not letters'
42 -> 'Not a string'
[2,12] -> 'Not a string'
{name: 'Abraham'} -> 'Not a string'
```
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
When little Petya grew up and entered the university, he started to take part in АСМ contests. Later he realized that he doesn't like how the АСМ contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members efficiently), so he decided to organize his own contests PFAST Inc. — Petr and Friends Are Solving Tasks Corporation. PFAST Inc. rules allow a team to have unlimited number of members.
To make this format of contests popular he organised his own tournament. To create the team he will prepare for the contest organised by the PFAST Inc. rules, he chose several volunteers (up to 16 people) and decided to compile a team from them. Petya understands perfectly that if a team has two people that don't get on well, then the team will perform poorly. Put together a team with as many players as possible given that all players should get on well with each other.
Input
The first line contains two integer numbers n (1 ≤ n ≤ 16) — the number of volunteers, and m (<image>) — the number of pairs that do not get on. Next n lines contain the volunteers' names (each name is a non-empty string consisting of no more than 10 uppercase and/or lowercase Latin letters). Next m lines contain two names — the names of the volunteers who do not get on. The names in pair are separated with a single space. Each pair of volunteers who do not get on occurs exactly once. The strings are case-sensitive. All n names are distinct.
Output
The first output line should contain the single number k — the number of people in the sought team. Next k lines should contain the names of the sought team's participants in the lexicographical order. If there are several variants to solve the problem, print any of them. Petya might not be a member of the sought team.
Examples
Input
3 1
Petya
Vasya
Masha
Petya Vasya
Output
2
Masha
Petya
Input
3 0
Pasha
Lesha
Vanya
Output
3
Lesha
Pasha
Vanya
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
# Solve For X
You will be given an equation as a string and you will need to [solve for X](https://www.mathplacementreview.com/algebra/basic-algebra.php#solve-for-a-variable) and return x's value. For example:
```python
solve_for_x('x - 5 = 20') # should return 25
solve_for_x('20 = 5 * x - 5') # should return 5
solve_for_x('5 * x = x + 8') # should return 2
solve_for_x('(5 - 3) * x = x + 2') # should return 2
```
NOTES:
* All numbers will be whole numbers
* Don't forget about the [order of operations](https://www.mathplacementreview.com/algebra/basic-algebra.php#order-of-operations).
* If the random tests don't pass the first time, just run them again.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
Write a function that takes an array/list of numbers and returns a number such that
Explanation
total([1,2,3,4,5]) => 48
1+2=3--\ 3+5 => 8 \
2+3=5--/ \ == 8+12=>20\
==>5+7=> 12 / \ 20+28 => 48
3+4=7--\ / == 12+16=>28/
4+5=9--/ 7+9 => 16 /
if total([1,2,3]) => 8 then
first+second => 3 \
then 3+5 => 8
second+third => 5 /
### Examples
```python
total([-1,-1,-1]) => -4
total([1,2,3,4]) => 20
```
**Note:** each array/list will have at least an element and all elements will be valid numbers.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
Consider sequences \{A_1,...,A_N\} of length N consisting of integers between 1 and K (inclusive).
There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them.
Since this sum can be enormous, print the value modulo (10^9+7).
Here \gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1, ..., A_N.
-----Constraints-----
- 2 \leq N \leq 10^5
- 1 \leq K \leq 10^5
- All values in input are integers.
-----Input-----
Input is given from Standard Input in the following format:
N K
-----Output-----
Print the sum of \gcd(A_1, ..., A_N) over all K^N sequences, modulo (10^9+7).
-----Sample Input-----
3 2
-----Sample Output-----
9
\gcd(1,1,1)+\gcd(1,1,2)+\gcd(1,2,1)+\gcd(1,2,2)+\gcd(2,1,1)+\gcd(2,1,2)+\gcd(2,2,1)+\gcd(2,2,2)=1+1+1+1+1+1+1+2=9
Thus, the answer is 9.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
We have a tree with N vertices numbered 1 to N. The i-th edge in this tree connects Vertex a_i and b_i.
For each k=1, ..., N, solve the problem below:
- Consider writing a number on each vertex in the tree in the following manner:
- First, write 1 on Vertex k.
- Then, for each of the numbers 2, ..., N in this order, write the number on the vertex chosen as follows:
- Choose a vertex that still does not have a number written on it and is adjacent to a vertex with a number already written on it. If there are multiple such vertices, choose one of them at random.
- Find the number of ways in which we can write the numbers on the vertices, modulo (10^9+7).
-----Constraints-----
- 2 \leq N \leq 2 \times 10^5
- 1 \leq a_i,b_i \leq N
- The given graph is a tree.
-----Input-----
Input is given from Standard Input in the following format:
N
a_1 b_1
:
a_{N-1} b_{N-1}
-----Output-----
For each k=1, 2, ..., N in this order, print a line containing the answer to the problem.
-----Sample Input-----
3
1 2
1 3
-----Sample Output-----
2
1
1
The graph in this input is as follows:
For k=1, there are two ways in which we can write the numbers on the vertices, as follows:
- Writing 1, 2, 3 on Vertex 1, 2, 3, respectively
- Writing 1, 3, 2 on Vertex 1, 2, 3, respectively
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
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.
-----Input-----
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 a_{i} (0 ≤ a_{i} ≤ 15) — Vitya's records.
It's guaranteed that the input data is consistent.
-----Output-----
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.
-----Examples-----
Input
5
3 4 5 6 7
Output
UP
Input
7
12 13 14 15 14 13 12
Output
DOWN
Input
1
8
Output
-1
-----Note-----
In 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.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an elephant or a bear from those sticks. They can make an animal from sticks in the following way:
* Four sticks represent the animal's legs, these sticks should have the same length.
* Two remaining sticks represent the animal's head and body. The bear's head stick must be shorter than the body stick. The elephant, however, has a long trunk, so his head stick must be as long as the body stick. Note that there are no limits on the relations between the leg sticks and the head and body sticks.
Your task is to find out which animal can be made from the given stick set. The zoo keeper wants the sticks back after the game, so they must never be broken, even bears understand it.
Input
The single line contains six space-separated integers li (1 ≤ li ≤ 9) — the lengths of the six sticks. It is guaranteed that the input is such that you cannot make both animals from the sticks.
Output
If you can make a bear from the given set, print string "Bear" (without the quotes). If you can make an elephant, print string "Elephant" (wıthout the quotes). If you can make neither a bear nor an elephant, print string "Alien" (without the quotes).
Examples
Input
4 2 5 4 4 4
Output
Bear
Input
4 4 5 4 4 5
Output
Elephant
Input
1 2 3 4 5 6
Output
Alien
Note
If you're out of creative ideas, see instructions below which show how to make a bear and an elephant in the first two samples. The stick of length 2 is in red, the sticks of length 4 are in green, the sticks of length 5 are in blue.
<image>
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
The Cybermen and the Daleks have long been the Doctor's main enemies. Everyone knows that both these species enjoy destroying everything they encounter. However, a little-known fact about them is that they both also love taking Turing tests!
Heidi designed a series of increasingly difficult tasks for them to spend their time on, which would allow the Doctor enough time to save innocent lives!
The funny part is that these tasks would be very easy for a human to solve.
The first task is as follows. There are some points on the plane. All but one of them are on the boundary of an axis-aligned square (its sides are parallel to the axes). Identify that point.
-----Input-----
The first line contains an integer $n$ ($2 \le n \le 10$).
Each of the following $4n + 1$ lines contains two integers $x_i, y_i$ ($0 \leq x_i, y_i \leq 50$), describing the coordinates of the next point.
It is guaranteed that there are at least $n$ points on each side of the square and all $4n + 1$ points are distinct.
-----Output-----
Print two integers — the coordinates of the point that is not on the boundary of the square.
-----Examples-----
Input
2
0 0
0 1
0 2
1 0
1 1
1 2
2 0
2 1
2 2
Output
1 1
Input
2
0 0
0 1
0 2
0 3
1 0
1 2
2 0
2 1
2 2
Output
0 3
-----Note-----
In both examples, the square has four sides $x=0$, $x=2$, $y=0$, $y=2$.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
Jerry is a little mouse. He is trying to survive from the cat Tom. Jerry is carrying a parallelepiped-like piece of cheese of size A × B × C. It is necessary to trail this cheese to the Jerry's house. There are several entrances in the Jerry's house. Each entrance is a rounded hole having its own radius R. Could you help Jerry to find suitable holes to be survive?
Your task is to create a program which estimates whether Jerry can trail the cheese via each hole. The program should print "OK" if Jerry can trail the cheese via the corresponding hole (without touching it). Otherwise the program should print "NA".
You may assume that the number of holes is less than 10000.
Input
The input is a sequence of datasets. The end of input is indicated by a line containing three zeros. Each dataset is formatted as follows:
A B C
n
R1
R2
.
.
Rn
n indicates the number of holes (entrances) and Ri indicates the radius of i-th hole.
Output
For each datasets, the output should have n lines. Each line points the result of estimation of the corresponding hole.
Example
Input
10 6 8
5
4
8
6
2
5
0 0 0
Output
NA
OK
OK
NA
NA
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
Casimir has a string $s$ which consists of capital Latin letters 'A', 'B', and 'C' only. Each turn he can choose to do one of the two following actions:
he can either erase exactly one letter 'A' and exactly one letter 'B' from arbitrary places of the string (these letters don't have to be adjacent);
or he can erase exactly one letter 'B' and exactly one letter 'C' from arbitrary places in the string (these letters don't have to be adjacent).
Therefore, each turn the length of the string is decreased exactly by $2$. All turns are independent so for each turn, Casimir can choose any of two possible actions.
For example, with $s$ $=$ "ABCABC" he can obtain a string $s$ $=$ "ACBC" in one turn (by erasing the first occurrence of 'B' and the second occurrence of 'A'). There are also many other options for a turn aside from this particular example.
For a given string $s$ determine whether there is a sequence of actions leading to an empty string. In other words, Casimir's goal is to erase all letters from the string. Is there a way to do this?
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Each test case is described by one string $s$, for which you need to determine if it can be fully erased by some sequence of turns. The string $s$ consists of capital letters 'A', 'B', 'C' and has a length from $1$ to $50$ letters, inclusive.
-----Output-----
Print $t$ lines, each line containing the answer to the corresponding test case. The answer to a test case should be YES if there is a way to fully erase the corresponding string and NO otherwise.
You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes, and YES will all be recognized as positive answers).
-----Examples-----
Input
6
ABACAB
ABBA
AC
ABC
CABCBB
BCBCBCBCBCBCBCBC
Output
NO
YES
NO
NO
YES
YES
-----Note-----
None
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
Snuke found a random number generator. It generates an integer between 0 and 2^N-1 (inclusive). An integer sequence A_0, A_1, \cdots, A_{2^N-1} represents the probability that each of these integers is generated. The integer i (0 \leq i \leq 2^N-1) is generated with probability A_i / S, where S = \sum_{i=0}^{2^N-1} A_i. The process of generating an integer is done independently each time the generator is executed.
Snuke has an integer X, which is now 0. He can perform the following operation any number of times:
* Generate an integer v with the generator and replace X with X \oplus v, where \oplus denotes the bitwise XOR.
For each integer i (0 \leq i \leq 2^N-1), find the expected number of operations until X becomes i, and print it modulo 998244353. More formally, represent the expected number of operations as an irreducible fraction P/Q. Then, there exists a unique integer R such that R \times Q \equiv P \mod 998244353,\ 0 \leq R < 998244353, so print this R.
We can prove that, for every i, the expected number of operations until X becomes i is a finite rational number, and its integer representation modulo 998244353 can be defined.
Constraints
* 1 \leq N \leq 18
* 1 \leq A_i \leq 1000
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_0 A_1 \cdots A_{2^N-1}
Output
Print 2^N lines. The (i+1)-th line (0 \leq i \leq 2^N-1) should contain the expected number of operations until X becomes i, modulo 998244353.
Examples
Input
2
1 1 1 1
Output
0
4
4
4
Input
2
1 2 1 2
Output
0
499122180
4
499122180
Input
4
337 780 799 10 796 875 331 223 941 67 148 483 390 565 116 355
Output
0
468683018
635850749
96019779
657074071
24757563
745107950
665159588
551278361
143136064
557841197
185790407
988018173
247117461
129098626
789682908
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
Mole is hungry again. He found one ant colony, consisting of n ants, ordered in a row. Each ant i (1 ≤ i ≤ n) has a strength si.
In order to make his dinner more interesting, Mole organizes a version of «Hunger Games» for the ants. He chooses two numbers l and r (1 ≤ l ≤ r ≤ n) and each pair of ants with indices between l and r (inclusively) will fight. When two ants i and j fight, ant i gets one battle point only if si divides sj (also, ant j gets one battle point only if sj divides si).
After all fights have been finished, Mole makes the ranking. An ant i, with vi battle points obtained, is going to be freed only if vi = r - l, or in other words only if it took a point in every fight it participated. After that, Mole eats the rest of the ants. Note that there can be many ants freed or even none.
In order to choose the best sequence, Mole gives you t segments [li, ri] and asks for each of them how many ants is he going to eat if those ants fight.
Input
The first line contains one integer n (1 ≤ n ≤ 105), the size of the ant colony.
The second line contains n integers s1, s2, ..., sn (1 ≤ si ≤ 109), the strengths of the ants.
The third line contains one integer t (1 ≤ t ≤ 105), the number of test cases.
Each of the next t lines contains two integers li and ri (1 ≤ li ≤ ri ≤ n), describing one query.
Output
Print to the standard output t lines. The i-th line contains number of ants that Mole eats from the segment [li, ri].
Examples
Input
5
1 3 2 4 2
4
1 5
2 5
3 5
4 5
Output
4
4
1
1
Note
In the first test battle points for each ant are v = [4, 0, 2, 0, 2], so ant number 1 is freed. Mole eats the ants 2, 3, 4, 5.
In the second test case battle points are v = [0, 2, 0, 2], so no ant is freed and all of them are eaten by Mole.
In the third test case battle points are v = [2, 0, 2], so ants number 3 and 5 are freed. Mole eats only the ant 4.
In the fourth test case battle points are v = [0, 1], so ant number 5 is freed. Mole eats the ant 4.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
Little Elephant is playing a game with arrays. He is given an array A0, A1, ..., AN−1 of N integers. And then Q queries are given, each containing an integer K. He has to tell how many subarrays satisfy the condition: the function foo returns K when it is applied to the subarray.
In this problem, a subarray is defined as a sequence of continuous elements Ai, Ai+1, ..., Aj where 0 ≤ i ≤ j ≤ N−1. The function foo, when applied to an array, returns the minimum of all the elements in the array.
For example, foo returns 5 when it is applied to the array [7, 5, 10, 7, 5, 8]. Please note that the subarrays Ai, Ai+1, ..., Aj and Ak, Ak+1, ..., Al are different if and only if i ≠ k or j ≠ l in this problem.
-----Input-----
The first line of input contains N, denoting the size of the array. The next line contains N space separated integers A0, A1, ..., AN−1, denoting the array. Then the next line contains Q, denoting the number of queries. Each query consists of one integer per line, denoting K.
-----Output-----
For each query, print the required number of subarrays.
-----Constraints-----
- 1 ≤ N ≤ 50
- 1 ≤ Ai ≤ 1000000 (106)
- 1 ≤ Q ≤ 10
- 1 ≤ K ≤ 1000000 (106)
-----Example-----
Input:
5
4 1 2 3 4
4
3
4
6
1
Output:
2
2
0
8
-----Explanation-----
Query 1. Only the two subarrays [3, 4] and [3] satisfy.
Query 2. Again only the two subarrays [4] and [4] satisfy. Please note that these subarrays (A0 and A4) are considered different.
Query 3. No subarray satisfies.
Query 4. The eight subarrays [4, 1], [4, 1, 2], [4, 1, 2, 3], [4, 1, 2, 3, 4], [1], [1, 2], [1, 2, 3] and [1, 2, 3, 4] satisfy.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
Silver Fox is fighting with N monsters.
The monsters are standing in a row, and we can assume them to be standing on a number line. The i-th monster, standing at the coordinate X_i, has the health of H_i.
Silver Fox can use bombs to attack the monsters.
Using a bomb at the coordinate x decreases the healths of all monsters between the coordinates x-D and x+D (inclusive) by A.
There is no way other than bombs to decrease the monster's health.
Silver Fox wins when all the monsters' healths become 0 or below.
Find the minimum number of bombs needed to win.
-----Constraints-----
- 1 \leq N \leq 2 \times 10^5
- 0 \leq D \leq 10^9
- 1 \leq A \leq 10^9
- 0 \leq X_i \leq 10^9
- 1 \leq H_i \leq 10^9
- X_i are distinct.
- All values in input are integers.
-----Input-----
Input is given from Standard Input in the following format:
N D A
X_1 H_1
:
X_N H_N
-----Output-----
Print the minimum number of bombs needed to win.
-----Sample Input-----
3 3 2
1 2
5 4
9 2
-----Sample Output-----
2
First, let us use a bomb at the coordinate 4 to decrease the first and second monsters' health by 2.
Then, use a bomb at the coordinate 6 to decrease the second and third monsters' health by 2.
Now, all the monsters' healths are 0.
We cannot make all the monsters' health drop to 0 or below with just one bomb.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
Nauuo is a girl who loves drawing circles.
One day she has drawn a circle and wanted to draw a tree on it.
The tree is a connected undirected graph consisting of n nodes and n-1 edges. The nodes are numbered from 1 to n.
Nauuo wants to draw a tree on the circle, the nodes of the tree should be in n distinct points on the circle, and the edges should be straight without crossing each other.
"Without crossing each other" means that every two edges have no common point or the only common point is an endpoint of both edges.
Nauuo wants to draw the tree using a permutation of n elements. A permutation of n elements is a sequence of integers p_1,p_2,…,p_n in which every integer from 1 to n appears exactly once.
After a permutation is chosen Nauuo draws the i-th node in the p_i-th point on the circle, then draws the edges connecting the nodes.
The tree is given, Nauuo wants to know how many permutations are there so that the tree drawn satisfies the rule (the edges are straight without crossing each other). She only wants to know the answer modulo 998244353, can you help her?
It is obvious that whether a permutation is valid or not does not depend on which n points on the circle are chosen.
Input
The first line contains a single integer n (2≤ n≤ 2⋅ 10^5) — the number of nodes in the tree.
Each of the next n-1 lines contains two integers u and v (1≤ u,v≤ n), denoting there is an edge between u and v.
It is guaranteed that the given edges form a tree.
Output
The output contains a single integer — the number of permutations suitable to draw the given tree on a circle satisfying the rule, modulo 998244353.
Examples
Input
4
1 2
1 3
2 4
Output
16
Input
4
1 2
1 3
1 4
Output
24
Note
Example 1
All valid permutations and their spanning trees are as follows.
<image>
Here is an example of invalid permutation: the edges (1,3) and (2,4) are crossed.
<image>
Example 2
Every permutation leads to a valid tree, so the answer is 4! = 24.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
Vasya’s elder brother Petya loves playing computer games. In one of his favourite computer games Petya reached the final level where a fight with the boss take place.
While playing the game Petya found spell scrolls and now he is about to use them. Let’s describe the way fighting goes on this level:
1) The boss has two parameters: max — the initial amount of health and reg — regeneration rate per second.
2) Every scroll also has two parameters: powi — spell power measured in percents — the maximal amount of health counted off the initial one, which allows to use the scroll (i.e. if the boss has more than powi percent of health the scroll cannot be used); and dmgi the damage per second inflicted upon the boss if the scroll is used. As soon as a scroll is used it disappears and another spell is cast upon the boss that inflicts dmgi of damage per second upon him until the end of the game.
During the battle the actions per second are performed in the following order: first the boss gets the damage from all the spells cast upon him, then he regenerates reg of health (at the same time he can’t have more than max of health), then the player may use another scroll (no more than one per second).
The boss is considered to be defeated if at the end of a second he has nonpositive ( ≤ 0) amount of health.
Help Petya to determine whether he can win with the set of scrolls available to him and if he can, determine the minimal number of seconds he needs to do it.
Input
The first line contains three integers N, max and reg (1 ≤ N, max, reg ≤ 1000) –– the amount of scrolls and the parameters of the boss. The next N lines contain two integers powi and dmgi each — the parameters of the i-th scroll (0 ≤ powi ≤ 100, 1 ≤ dmgi ≤ 2000).
Output
In case Petya can’t complete this level, output in the single line NO.
Otherwise, output on the first line YES. On the second line output the minimal time after which the boss can be defeated and the number of used scrolls. In the next lines for each used scroll output space-separated number of seconds passed from the start of the battle to the moment the scroll was used and the number of the scroll. Scrolls are numbered starting from 1 in the input order. The first scroll is considered to be available to be used after 0 seconds.
Output scrolls in the order they were used. It is not allowed to use scrolls after the boss is defeated.
Examples
Input
2 10 3
100 3
99 1
Output
NO
Input
2 100 10
100 11
90 9
Output
YES
19 2
0 1
10 2
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
$n$ students attended the first meeting of the Berland SU programming course ($n$ is even). All students will be divided into two groups. Each group will be attending exactly one lesson each week during one of the five working days (Monday, Tuesday, Wednesday, Thursday and Friday), and the days chosen for the groups must be different. Furthermore, both groups should contain the same number of students.
Each student has filled a survey in which they told which days of the week are convenient for them to attend a lesson, and which are not.
Your task is to determine if it is possible to choose two different week days to schedule the lessons for the group (the first group will attend the lesson on the first chosen day, the second group will attend the lesson on the second chosen day), and divide the students into two groups, so the groups have equal sizes, and for each student, the chosen lesson day for their group is convenient.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases.
Then the descriptions of $t$ testcases follow.
The first line of each testcase contains one integer $n$ ($2 \le n \le 1000$) — the number of students.
The $i$-th of the next $n$ lines contains $5$ integers, each of them is $0$ or $1$. If the $j$-th integer is $1$, then the $i$-th student can attend the lessons on the $j$-th day of the week. If the $j$-th integer is $0$, then the $i$-th student cannot attend the lessons on the $j$-th day of the week.
Additional constraints on the input: for each student, at least one of the days of the week is convenient, the total number of students over all testcases doesn't exceed $10^5$.
-----Output-----
For each testcase print an answer. If it's possible to divide the students into two groups of equal sizes and choose different days for the groups so each student can attend the lesson in the chosen day of their group, print "YES" (without quotes). Otherwise, print "NO" (without quotes).
-----Examples-----
Input
2
4
1 0 0 1 0
0 1 0 0 1
0 0 0 1 0
0 1 0 1 0
2
0 0 0 1 0
0 0 0 1 0
Output
YES
NO
-----Note-----
In the first testcase, there is a way to meet all the constraints. For example, the first group can consist of the first and the third students, they will attend the lessons on Thursday (the fourth day); the second group can consist of the second and the fourth students, and they will attend the lessons on Tuesday (the second day).
In the second testcase, it is impossible to divide the students into groups so they attend the lessons on different days.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
Let s(x) be sum of digits in decimal representation of positive integer x. Given two integers n and m, find some positive integers a and b such that
* s(a) ≥ n,
* s(b) ≥ n,
* s(a + b) ≤ m.
Input
The only line of input contain two integers n and m (1 ≤ n, m ≤ 1129).
Output
Print two lines, one for decimal representation of a and one for decimal representation of b. Both numbers must not contain leading zeros and must have length no more than 2230.
Examples
Input
6 5
Output
6
7
Input
8 16
Output
35
53
Note
In the first sample, we have n = 6 and m = 5. One valid solution is a = 6, b = 7. Indeed, we have s(a) = 6 ≥ n and s(b) = 7 ≥ n, and also s(a + b) = s(13) = 4 ≤ m.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
The greatest common divisor is an indispensable element in mathematics handled on a computer. Using the greatest common divisor can make a big difference in the efficiency of the calculation. One of the algorithms to find the greatest common divisor is "Euclidean algorithm". The flow of the process is shown below.
<image>
For example, for 1071 and 1029, substitute 1071 for X and 1029 for Y,
The remainder of 1071 ÷ 1029 is 42, and 42 is substituted for X to replace X and Y. (1 step)
The remainder of 1029 ÷ 42 is 21, and 21 is substituted for X to replace X and Y. (2 steps)
The remainder of 42 ÷ 21 is 0, and 0 is substituted for X to replace X and Y. (3 steps)
Since Y has become 0, X at this time is the greatest common divisor. Therefore, the greatest common divisor is 21.
In this way, we were able to find the greatest common divisor of 1071 and 1029 in just three steps. The Euclidean algorithm produces results overwhelmingly faster than the method of comparing divisors.
Create a program that takes two integers as inputs, finds the greatest common divisor using the Euclidean algorithm, and outputs the greatest common divisor and the number of steps required for the calculation.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Two integers a, b (2 ≤ a, b ≤ 231-1) are given on one line for each dataset.
The number of datasets does not exceed 1000.
Output
For each data set, the greatest common divisor of the two input integers and the number of steps of the Euclidean algorithm for calculation are output on one line separated by blanks.
Example
Input
1071 1029
5 5
0 0
Output
21 3
5 1
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
## Task
Implement a function which finds the numbers less than `2`, and the indices of numbers greater than `1` in the given sequence, and returns them as a pair of sequences.
Return a nested array or a tuple depending on the language:
* The first sequence being only the `1`s and `0`s from the original sequence.
* The second sequence being the indexes of the elements greater than `1` in the original sequence.
## Examples
```python
[ 0, 1, 2, 1, 5, 6, 2, 1, 1, 0 ] => ( [ 0, 1, 1, 1, 1, 0 ], [ 2, 4, 5, 6 ] )
```
Please upvote and enjoy!
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
You are on the island which can be represented as a $n \times m$ table. The rows are numbered from $1$ to $n$ and the columns are numbered from $1$ to $m$. There are $k$ treasures on the island, the $i$-th of them is located at the position $(r_i, c_i)$.
Initially you stand at the lower left corner of the island, at the position $(1, 1)$. If at any moment you are at the cell with a treasure, you can pick it up without any extra time. In one move you can move up (from $(r, c)$ to $(r+1, c)$), left (from $(r, c)$ to $(r, c-1)$), or right (from position $(r, c)$ to $(r, c+1)$). Because of the traps, you can't move down.
However, moving up is also risky. You can move up only if you are in a safe column. There are $q$ safe columns: $b_1, b_2, \ldots, b_q$. You want to collect all the treasures as fast as possible. Count the minimum number of moves required to collect all the treasures.
-----Input-----
The first line contains integers $n$, $m$, $k$ and $q$ ($2 \le n, \, m, \, k, \, q \le 2 \cdot 10^5$, $q \le m$) — the number of rows, the number of columns, the number of treasures in the island and the number of safe columns.
Each of the next $k$ lines contains two integers $r_i, c_i$, ($1 \le r_i \le n$, $1 \le c_i \le m$) — the coordinates of the cell with a treasure. All treasures are located in distinct cells.
The last line contains $q$ distinct integers $b_1, b_2, \ldots, b_q$ ($1 \le b_i \le m$) — the indices of safe columns.
-----Output-----
Print the minimum number of moves required to collect all the treasures.
-----Examples-----
Input
3 3 3 2
1 1
2 1
3 1
2 3
Output
6
Input
3 5 3 2
1 2
2 3
3 1
1 5
Output
8
Input
3 6 3 2
1 6
2 2
3 4
1 6
Output
15
-----Note-----
In the first example you should use the second column to go up, collecting in each row treasures from the first column. [Image]
In the second example, it is optimal to use the first column to go up. [Image]
In the third example, it is optimal to collect the treasure at cell $(1;6)$, go up to row $2$ at column $6$, then collect the treasure at cell $(2;2)$, go up to the top row at column $1$ and collect the last treasure at cell $(3;4)$. That's a total of $15$ moves. [Image]
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward as forward. Examples of numerical palindromes are:
2332
110011
54322345
For a given number `num`, write a function to test if it's a numerical palindrome or not and return a boolean (true if it is and false if not).
```if-not:haskell
Return "Not valid" if the input is not an integer or less than `0`.
```
```if:haskell
Return `Nothing` if the input is less than `0` and `Just True` or `Just False` otherwise.
```
Other Kata in this Series:
Numerical Palindrome #1
Numerical Palindrome #1.5
Numerical Palindrome #2
Numerical Palindrome #3
Numerical Palindrome #3.5
Numerical Palindrome #4
Numerical Palindrome #5
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
International Abbreviation Olympiad takes place annually starting from 1989. Each year the competition receives an abbreviation of form IAO'y, where y stands for some number of consequent last digits of the current year. Organizers always pick an abbreviation with non-empty string y that has never been used before. Among all such valid abbreviations they choose the shortest one and announce it to be the abbreviation of this year's competition.
For example, the first three Olympiads (years 1989, 1990 and 1991, respectively) received the abbreviations IAO'9, IAO'0 and IAO'1, while the competition in 2015 received an abbreviation IAO'15, as IAO'5 has been already used in 1995.
You are given a list of abbreviations. For each of them determine the year it stands for.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the number of abbreviations to process.
Then n lines follow, each containing a single abbreviation. It's guaranteed that each abbreviation contains at most nine digits.
Output
For each abbreviation given in the input, find the year of the corresponding Olympiad.
Examples
Input
5
IAO'15
IAO'2015
IAO'1
IAO'9
IAO'0
Output
2015
12015
1991
1989
1990
Input
4
IAO'9
IAO'99
IAO'999
IAO'9999
Output
1989
1999
2999
9999
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
Let's write all the positive integer numbers one after another from $1$ without any delimiters (i.e. as a single string). It will be the infinite sequence starting with 123456789101112131415161718192021222324252627282930313233343536...
Your task is to print the $k$-th digit of this sequence.
-----Input-----
The first and only line contains integer $k$ ($1 \le k \le 10000$) — the position to process ($1$-based index).
-----Output-----
Print the $k$-th digit of the resulting infinite sequence.
-----Examples-----
Input
7
Output
7
Input
21
Output
5
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
You got a job as a marketer in a pet shop, and your current task is to boost sales of cat food. One of the strategies is to sell cans of food in packs with discounts.
Suppose you decided to sell packs with $a$ cans in a pack with a discount and some customer wants to buy $x$ cans of cat food. Then he follows a greedy strategy: he buys $\left\lfloor \frac{x}{a} \right\rfloor$ packs with a discount; then he wants to buy the remaining $(x \bmod a)$ cans one by one.
$\left\lfloor \frac{x}{a} \right\rfloor$ is $x$ divided by $a$ rounded down, $x \bmod a$ is the remainer of $x$ divided by $a$.
But customers are greedy in general, so if the customer wants to buy $(x \bmod a)$ cans one by one and it happens that $(x \bmod a) \ge \frac{a}{2}$ he decides to buy the whole pack of $a$ cans (instead of buying $(x \bmod a)$ cans). It makes you, as a marketer, happy since the customer bought more than he wanted initially.
You know that each of the customers that come to your shop can buy any number of cans from $l$ to $r$ inclusive. Can you choose such size of pack $a$ that each customer buys more cans than they wanted initially?
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
The first and only line of each test case contains two integers $l$ and $r$ ($1 \le l \le r \le 10^9$) — the range of the number of cans customers can buy.
-----Output-----
For each test case, print YES if you can choose such size of pack $a$ that each customer buys more cans than they wanted initially. Otherwise, print NO.
You can print each character in any case.
-----Example-----
Input
3
3 4
1 2
120 150
Output
YES
NO
YES
-----Note-----
In the first test case, you can take, for example, $a = 5$ as the size of the pack. Then if a customer wants to buy $3$ cans, he'll buy $5$ instead ($3 \bmod 5 = 3$, $\frac{5}{2} = 2.5$). The one who wants $4$ cans will also buy $5$ cans.
In the second test case, there is no way to choose $a$.
In the third test case, you can take, for example, $a = 80$.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
You are given an array $a$ consisting of $n$ non-negative integers. It is guaranteed that $a$ is sorted from small to large.
For each operation, we generate a new array $b_i=a_{i+1}-a_{i}$ for $1 \le i < n$. Then we sort $b$ from small to large, replace $a$ with $b$, and decrease $n$ by $1$.
After performing $n-1$ operations, $n$ becomes $1$. You need to output the only integer in array $a$ (that is to say, you need to output $a_1$).
-----Input-----
The input consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. The description of the test cases follows.
The first line of each test case contains one integer $n$ ($2\le n\le 10^5$) — the length of the array $a$.
The second line contains $n$ integers $a_1,a_2,\dots,a_n$ ($0\le a_1\le \ldots\le a_n \le 5\cdot 10^5$) — the array $a$.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2.5\cdot 10^5$, and the sum of $a_n$ over all test cases does not exceed $5\cdot 10^5$.
-----Output-----
For each test case, output the answer on a new line.
-----Examples-----
Input
5
3
1 10 100
4
4 8 9 13
5
0 0 0 8 13
6
2 4 8 16 32 64
7
0 0 0 0 0 0 0
Output
81
3
1
2
0
-----Note-----
To simplify the notes, let $\operatorname{sort}(a)$ denote the array you get by sorting $a$ from small to large.
In the first test case, $a=[1,10,100]$ at first. After the first operation, $a=\operatorname{sort}([10-1,100-10])=[9,90]$. After the second operation, $a=\operatorname{sort}([90-9])=[81]$.
In the second test case, $a=[4,8,9,13]$ at first. After the first operation, $a=\operatorname{sort}([8-4,9-8,13-9])=[1,4,4]$. After the second operation, $a=\operatorname{sort}([4-1,4-4])=[0,3]$. After the last operation, $a=\operatorname{sort}([3-0])=[3]$.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
Turtle Shi-ta and turtle Be-ko decided to divide a chocolate. The shape of the chocolate is rectangle. The corners of the chocolate are put on (0,0), (w,0), (w,h) and (0,h). The chocolate has lines for cutting. They cut the chocolate only along some of these lines.
The lines are expressed as follows. There are m points on the line connected between (0,0) and (0,h), and between (w,0) and (w,h). Each i-th point, ordered by y value (i = 0 then y =0), is connected as cutting line. These lines do not share any point where 0 < x < w . They can share points where x = 0 or x = w . However, (0, li ) = (0,lj ) and (w,ri ) = (w,rj ) implies i = j . The following figure shows the example of the chocolate.
<image>
There are n special almonds, so delicious but high in calories on the chocolate. Almonds are circle but their radius is too small. You can ignore radius of almonds. The position of almond is expressed as (x,y) coordinate.
Two turtles are so selfish. Both of them have requirement for cutting.
Shi-ta's requirement is that the piece for her is continuous. It is possible for her that she cannot get any chocolate. Assume that the minimum index of the piece is i and the maximum is k . She must have all pieces between i and k . For example, chocolate piece 1,2,3 is continuous but 1,3 or 0,2,4 is not continuous.
Be-ko requires that the area of her chocolate is at least S . She is worry about her weight. So she wants the number of almond on her chocolate is as few as possible.
They doesn't want to make remainder of the chocolate because the chocolate is expensive.
Your task is to compute the minumum number of Beko's almonds if both of their requirment are satisfied.
Input
Input consists of multiple test cases.
Each dataset is given in the following format.
n m w h S
l0 r0
...
lm-1 rm-1
x0 y0
...
xn-1 yn-1
The last line contains five 0s. n is the number of almonds. m is the number of lines. w is the width of the chocolate. h is the height of the chocolate. S is the area that Be-ko wants to eat. Input is integer except xi yi.
Input satisfies following constraints.
1 ≤ n ≤ 30000
1 ≤ m ≤ 30000
1 ≤ w ≤ 200
1 ≤ h ≤ 1000000
0 ≤ S ≤ w*h
If i < j then li ≤ lj and ri ≤ rj and then i -th lines and j -th lines share at most 1 point. It is assured that lm-1 and rm-1 are h. xi yi is floating point number with ten digits. It is assured that they are inside of the chocolate. It is assured that the distance between points and any lines is at least 0.00001.
Output
You should output the minumum number of almonds for Be-ko.
Example
Input
2 3 10 10 50
3 3
6 6
10 10
4.0000000000 4.0000000000
7.0000000000 7.0000000000
2 3 10 10 70
3 3
6 6
10 10
4.0000000000 4.0000000000
7.0000000000 7.0000000000
2 3 10 10 30
3 3
6 6
10 10
4.0000000000 4.0000000000
7.0000000000 7.0000000000
2 3 10 10 40
3 3
6 6
10 10
4.0000000000 4.0000000000
7.0000000000 7.0000000000
2 3 10 10 100
3 3
6 6
10 10
4.0000000000 4.0000000000
7.0000000000 7.0000000000
0 0 0 0 0
Output
1
1
0
1
2
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
On the planet Mars a year lasts exactly n days (there are no leap years on Mars). But Martians have the same weeks as earthlings — 5 work days and then 2 days off. Your task is to determine the minimum possible and the maximum possible number of days off per year on Mars.
-----Input-----
The first line of the input contains a positive integer n (1 ≤ n ≤ 1 000 000) — the number of days in a year on Mars.
-----Output-----
Print two integers — the minimum possible and the maximum possible number of days off per year on Mars.
-----Examples-----
Input
14
Output
4 4
Input
2
Output
0 2
-----Note-----
In the first sample there are 14 days in a year on Mars, and therefore independently of the day a year starts with there will be exactly 4 days off .
In the second sample there are only 2 days in a year on Mars, and they can both be either work days or days off.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
Edogawa Conan got tired of solving cases, and invited his friend, Professor Agasa, over. They decided to play a game of cards. Conan has n cards, and the i-th card has a number a_{i} written on it.
They take turns playing, starting with Conan. In each turn, the player chooses a card and removes it. Also, he removes all cards having a number strictly lesser than the number on the chosen card. Formally, if the player chooses the i-th card, he removes that card and removes the j-th card for all j such that a_{j} < a_{i}.
A player loses if he cannot make a move on his turn, that is, he loses if there are no cards left. Predict the outcome of the game, assuming both players play optimally.
-----Input-----
The first line contains an integer n (1 ≤ n ≤ 10^5) — the number of cards Conan has.
The next line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5), where a_{i} is the number on the i-th card.
-----Output-----
If Conan wins, print "Conan" (without quotes), otherwise print "Agasa" (without quotes).
-----Examples-----
Input
3
4 5 7
Output
Conan
Input
2
1 1
Output
Agasa
-----Note-----
In the first example, Conan can just choose the card having number 7 on it and hence remove all the cards. After that, there are no cards left on Agasa's turn.
In the second example, no matter which card Conan chooses, there will be one one card left, which Agasa can choose. After that, there are no cards left when it becomes Conan's turn again.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
International Center for Picassonian Cubism is a Spanish national museum of cubist artworks, dedicated to Pablo Picasso. The center held a competition for an artwork that will be displayed in front of the facade of the museum building. The artwork is a collection of cubes that are piled up on the ground and is intended to amuse visitors, who will be curious how the shape of the collection of cubes changes when it is seen from the front and the sides.
The artwork is a collection of cubes with edges of one foot long and is built on a flat ground that is divided into a grid of one foot by one foot squares. Due to some technical reasons, cubes of the artwork must be either put on the ground, fitting into a unit square in the grid, or put on another cube in the way that the bottom face of the upper cube exactly meets the top face of the lower cube. No other way of putting cubes is possible.
You are a member of the judging committee responsible for selecting one out of a plenty of artwork proposals submitted to the competition. The decision is made primarily based on artistic quality but the cost for installing the artwork is another important factor. Your task is to investigate the installation cost for each proposal. The cost is proportional to the number of cubes, so you have to figure out the minimum number of cubes needed for installation.
Each design proposal of an artwork consists of the front view and the side view (the view seen from the right-hand side), as shown in Figure 1.
<image>
Figure 1: An example of an artwork proposal
The front view (resp., the side view) indicates the maximum heights of piles of cubes for each column line (resp., row line) of the grid.
There are several ways to install this proposal of artwork, such as the following figures.
<image>
In these figures, the dotted lines on the ground indicate the grid lines. The left figure makes use of 16 cubes, which is not optimal. That is, the artwork can be installed with a fewer number of cubes. Actually, the right one is optimal and only uses 13 cubes. Note that, a single pile of height three in the right figure plays the roles of two such piles in the left one.
Notice that swapping columns of cubes does not change the side view. Similarly, swapping rows does not change the front view. Thus, such swaps do not change the costs of building the artworks.
For example, consider the artwork proposal given in Figure 2.
<image>
Figure 2: Another example of artwork proposal
An optimal installation of this proposal of artwork can be achieved with 13 cubes, as shown in the following figure, which can be obtained by exchanging the rightmost two columns of the optimal installation of the artwork of Figure 1.
<image>
Input
The input is a sequence of datasets. The end of the input is indicated by a line containing two zeros separated by a space. Each dataset is formatted as follows.
w d
h1 h2 ... hw
h'1 h'2 ... h'd
The integers w and d separated by a space are the numbers of columns and rows of the grid, respectively. You may assume 1 ≤ w ≤ 10 and 1 ≤ d ≤ 10. The integers separated by a space in the second and third lines specify the shape of the artwork. The integers hi (1 ≤ hi ≤ 20, 1 ≤ i ≤ w) in the second line give the front view, i.e., the maximum heights of cubes per each column line, ordered from left to right (seen from the front). The integers hi (1 ≤ hi ≤ 20, 1 ≤ i ≤ d) in the third line give the side view, i.e., the maximum heights of cubes per each row line, ordered from left to right (seen from the right-hand side).
Output
For each dataset, output a line containing the minimum number of cubes. The output should not contain any other extra characters.
You can assume that, for each dataset, there is at least one way to install the artwork.
Example
Input
5 5
1 2 3 4 5
1 2 3 4 5
5 5
2 5 4 1 3
4 1 5 3 2
5 5
1 2 3 4 5
3 3 3 4 5
3 3
7 7 7
7 7 7
3 3
4 4 4
4 3 4
4 3
4 2 2 4
4 2 1
4 4
2 8 8 8
2 3 8 3
10 10
9 9 9 9 9 9 9 9 9 9
9 9 9 9 9 9 9 9 9 9
10 9
20 1 20 20 20 20 20 18 20 20
20 20 20 20 7 20 20 20 20
0 0
Output
15
15
21
21
15
13
32
90
186
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even.
Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits.
Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket.
If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally.
-----Input-----
The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ — the number of digits in the ticket.
The second line contains a string of $n$ digits and "?" characters — the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even.
-----Output-----
If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes).
-----Examples-----
Input
4
0523
Output
Bicarp
Input
2
??
Output
Bicarp
Input
8
?054??0?
Output
Bicarp
Input
6
???00?
Output
Monocarp
-----Note-----
Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp.
In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
Problem
Yamano Mifune Gakuen's 1st grade G group is a class where female students carrying misfortune gather. They face various challenges every day with the goal of being happy.
In their class, they can take practical happiness courses as part of the test of happiness.
From Monday to Friday, there are classes from 1st to Nth, and there are M courses that can be taken.
Subject i starts from the ai period of the day of the week di (di = 0, 1, 2, 3, 4 corresponds to Monday, Tuesday, Wednesday, Thursday, and Friday, respectively), and is performed in consecutive ki frames. The degree of happiness obtained when taking the course is ti.
Each student is free to choose up to L subjects so that they do not overlap each other. How do you choose the subject to get the highest level of happiness? Please find the maximum value of happiness that can be obtained from the information of the given subject.
Constraints
* 2 ≤ N ≤ 8
* 0 ≤ M ≤ 300
* 0 ≤ L ≤ min (N × 5, M)
* 0 ≤ di ≤ 4
* 1 ≤ ai ≤ N
* 1 ≤ ki
* ai + ki --1 ≤ N
* 1 ≤ ti ≤ 100
Input
The input is given in the following format.
N M L
d1 a1 k1 t1
d2 a2 k2 t2
...
dM aM kM tM
The first line is given three integers N, M, L separated by blanks.
The four integers di, ai, ki, and ti are given on the 2nd to M + 1th lines, separated by blanks.
Output
Output the maximum value of the sum of happiness on one line.
Examples
Input
3 7 3
0 1 1 1
0 1 1 2
1 1 3 4
1 1 1 1
1 2 1 2
2 1 1 3
2 2 2 1
Output
9
Input
5 10 5
0 1 1 2
0 2 1 2
0 1 2 3
1 2 1 2
1 4 2 3
2 1 1 1
2 1 1 2
3 3 2 3
4 1 1 2
4 2 1 2
Output
13
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment $0$ and turn power off at moment $M$. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, some program is already installed into the lamp.
The lamp allows only good programs. Good program can be represented as a non-empty array $a$, where $0 < a_1 < a_2 < \dots < a_{|a|} < M$. All $a_i$ must be integers. Of course, preinstalled program is a good program.
The lamp follows program $a$ in next manner: at moment $0$ turns power and light on. Then at moment $a_i$ the lamp flips its state to opposite (if it was lit, it turns off, and vice versa). The state of the lamp flips instantly: for example, if you turn the light off at moment $1$ and then do nothing, the total time when the lamp is lit will be $1$. Finally, at moment $M$ the lamp is turning its power off regardless of its state.
Since you are not among those people who read instructions, and you don't understand the language it's written in, you realize (after some testing) the only possible way to alter the preinstalled program. You can insert at most one element into the program $a$, so it still should be a good program after alteration. Insertion can be done between any pair of consecutive elements of $a$, or even at the begining or at the end of $a$.
Find such a way to alter the program that the total time when the lamp is lit is maximum possible. Maybe you should leave program untouched. If the lamp is lit from $x$ till moment $y$, then its lit for $y - x$ units of time. Segments of time when the lamp is lit are summed up.
-----Input-----
First line contains two space separated integers $n$ and $M$ ($1 \le n \le 10^5$, $2 \le M \le 10^9$) — the length of program $a$ and the moment when power turns off.
Second line contains $n$ space separated integers $a_1, a_2, \dots, a_n$ ($0 < a_1 < a_2 < \dots < a_n < M$) — initially installed program $a$.
-----Output-----
Print the only integer — maximum possible total time when the lamp is lit.
-----Examples-----
Input
3 10
4 6 7
Output
8
Input
2 12
1 10
Output
9
Input
2 7
3 4
Output
6
-----Note-----
In the first example, one of possible optimal solutions is to insert value $x = 3$ before $a_1$, so program will be $[3, 4, 6, 7]$ and time of lamp being lit equals $(3 - 0) + (6 - 4) + (10 - 7) = 8$. Other possible solution is to insert $x = 5$ in appropriate place.
In the second example, there is only one optimal solution: to insert $x = 2$ between $a_1$ and $a_2$. Program will become $[1, 2, 10]$, and answer will be $(1 - 0) + (10 - 2) = 9$.
In the third example, optimal answer is to leave program untouched, so answer will be $(3 - 0) + (7 - 4) = 6$.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
This is the easy version of the problem. The difference between the versions is that the easy version does not require you to output the numbers of the rods to be removed. You can make hacks only if all versions of the problem are solved.
Stitch likes experimenting with different machines with his friend Sparky. Today they built another machine.
The main element of this machine are $n$ rods arranged along one straight line and numbered from $1$ to $n$ inclusive. Each of these rods must carry an electric charge quantitatively equal to either $1$ or $-1$ (otherwise the machine will not work). Another condition for this machine to work is that the sign-variable sum of the charge on all rods must be zero.
More formally, the rods can be represented as an array of $n$ numbers characterizing the charge: either $1$ or $-1$. Then the condition must hold: $a_1 - a_2 + a_3 - a_4 + \ldots = 0$, or $\sum\limits_{i=1}^n (-1)^{i-1} \cdot a_i = 0$.
Sparky charged all $n$ rods with an electric current, but unfortunately it happened that the rods were not charged correctly (the sign-variable sum of the charge is not zero). The friends decided to leave only some of the rods in the machine. Sparky has $q$ questions. In the $i$th question Sparky asks: if the machine consisted only of rods with numbers $l_i$ to $r_i$ inclusive, what minimal number of rods could be removed from the machine so that the sign-variable sum of charges on the remaining ones would be zero? Perhaps the friends got something wrong, and the sign-variable sum is already zero. In that case, you don't have to remove the rods at all.
If the number of rods is zero, we will assume that the sign-variable sum of charges is zero, that is, we can always remove all rods.
Help your friends and answer all of Sparky's questions!
-----Input-----
Each test contains multiple test cases.
The first line contains one positive integer $t$ ($1 \le t \le 10^3$), denoting the number of test cases. Description of the test cases follows.
The first line of each test case contains two positive integers $n$ and $q$ ($1 \le n, q \le 3 \cdot 10^5$) — the number of rods and the number of questions.
The second line of each test case contains a non-empty string $s$ of length $n$, where the charge of the $i$-th rod is $1$ if $s_i$ is the "+" symbol, or $-1$ if $s_i$ is the "-" symbol.
Each next line from the next $q$ lines contains two positive integers $l_i$ ans $r_i$ ($1 \le l_i \le r_i \le n$) — numbers, describing Sparky's questions.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$, and the sum of $q$ over all test cases does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case, print a single integer — the minimal number of rods that can be removed.
-----Examples-----
Input
3
14 1
+--++---++-++-
1 14
14 3
+--++---+++---
1 14
6 12
3 10
4 10
+-+-
1 1
1 2
1 3
1 4
2 2
2 3
2 4
3 3
3 4
4 4
Output
2
2
1
0
1
2
1
2
1
2
1
1
2
1
-----Note-----
In the first test case for the first query you can remove the rods numbered $5$ and $8$, then the following set of rods will remain: +--+--++-++-. It is easy to see that here the sign-variable sum is zero.
In the second test case:
For the first query, we can remove the rods numbered $1$ and $11$, then the following set of rods will remain: --++---++---. It is easy to see that here the sign-variable sum is zero.
For the second query we can remove the rod numbered $9$, then the following set of rods will remain: ---++-. It is easy to see that here the variable sum is zero.
For the third query we can not remove the rods at all.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
Alice and Bob play a game. There is a paper strip which is divided into n + 1 cells numbered from left to right starting from 0. There is a chip placed in the n-th cell (the last one).
Players take turns, Alice is first. Each player during his or her turn has to move the chip 1, 2 or k cells to the left (so, if the chip is currently in the cell i, the player can move it into cell i - 1, i - 2 or i - k). The chip should not leave the borders of the paper strip: it is impossible, for example, to move it k cells to the left if the current cell has number i < k. The player who can't make a move loses the game.
Who wins if both participants play optimally?
Alice and Bob would like to play several games, so you should determine the winner in each game.
-----Input-----
The first line contains the single integer T (1 ≤ T ≤ 100) — the number of games. Next T lines contain one game per line. All games are independent.
Each of the next T lines contains two integers n and k (0 ≤ n ≤ 10^9, 3 ≤ k ≤ 10^9) — the length of the strip and the constant denoting the third move, respectively.
-----Output-----
For each game, print Alice if Alice wins this game and Bob otherwise.
-----Example-----
Input
4
0 3
3 3
3 4
4 4
Output
Bob
Alice
Bob
Alice
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
You went to the store, selling $n$ types of chocolates. There are $a_i$ chocolates of type $i$ in stock.
You have unlimited amount of cash (so you are not restricted by any prices) and want to buy as many chocolates as possible. However if you buy $x_i$ chocolates of type $i$ (clearly, $0 \le x_i \le a_i$), then for all $1 \le j < i$ at least one of the following must hold: $x_j = 0$ (you bought zero chocolates of type $j$) $x_j < x_i$ (you bought less chocolates of type $j$ than of type $i$)
For example, the array $x = [0, 0, 1, 2, 10]$ satisfies the requirement above (assuming that all $a_i \ge x_i$), while arrays $x = [0, 1, 0]$, $x = [5, 5]$ and $x = [3, 2]$ don't.
Calculate the maximum number of chocolates you can buy.
-----Input-----
The first line contains an integer $n$ ($1 \le n \le 2 \cdot 10^5$), denoting the number of types of chocolate.
The next line contains $n$ integers $a_i$ ($1 \le a_i \le 10^9$), denoting the number of chocolates of each type.
-----Output-----
Print the maximum number of chocolates you can buy.
-----Examples-----
Input
5
1 2 1 3 6
Output
10
Input
5
3 2 5 4 10
Output
20
Input
4
1 1 1 1
Output
1
-----Note-----
In the first example, it is optimal to buy: $0 + 0 + 1 + 3 + 6$ chocolates.
In the second example, it is optimal to buy: $1 + 2 + 3 + 4 + 10$ chocolates.
In the third example, it is optimal to buy: $0 + 0 + 0 + 1$ chocolates.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
This is the easier version of the problem. In this version $1 \le n, m \le 100$. You can hack this problem only if you solve and lock both problems.
You are given a sequence of integers $a=[a_1,a_2,\dots,a_n]$ of length $n$. Its subsequence is obtained by removing zero or more elements from the sequence $a$ (they do not necessarily go consecutively). For example, for the sequence $a=[11,20,11,33,11,20,11]$:
$[11,20,11,33,11,20,11]$, $[11,20,11,33,11,20]$, $[11,11,11,11]$, $[20]$, $[33,20]$ are subsequences (these are just some of the long list); $[40]$, $[33,33]$, $[33,20,20]$, $[20,20,11,11]$ are not subsequences.
Suppose that an additional non-negative integer $k$ ($1 \le k \le n$) is given, then the subsequence is called optimal if:
it has a length of $k$ and the sum of its elements is the maximum possible among all subsequences of length $k$; and among all subsequences of length $k$ that satisfy the previous item, it is lexicographically minimal.
Recall that the sequence $b=[b_1, b_2, \dots, b_k]$ is lexicographically smaller than the sequence $c=[c_1, c_2, \dots, c_k]$ if the first element (from the left) in which they differ less in the sequence $b$ than in $c$. Formally: there exists $t$ ($1 \le t \le k$) such that $b_1=c_1$, $b_2=c_2$, ..., $b_{t-1}=c_{t-1}$ and at the same time $b_t<c_t$. For example:
$[10, 20, 20]$ lexicographically less than $[10, 21, 1]$, $[7, 99, 99]$ is lexicographically less than $[10, 21, 1]$, $[10, 21, 0]$ is lexicographically less than $[10, 21, 1]$.
You are given a sequence of $a=[a_1,a_2,\dots,a_n]$ and $m$ requests, each consisting of two numbers $k_j$ and $pos_j$ ($1 \le k \le n$, $1 \le pos_j \le k_j$). For each query, print the value that is in the index $pos_j$ of the optimal subsequence of the given sequence $a$ for $k=k_j$.
For example, if $n=4$, $a=[10,20,30,20]$, $k_j=2$, then the optimal subsequence is $[20,30]$ — it is the minimum lexicographically among all subsequences of length $2$ with the maximum total sum of items. Thus, the answer to the request $k_j=2$, $pos_j=1$ is the number $20$, and the answer to the request $k_j=2$, $pos_j=2$ is the number $30$.
-----Input-----
The first line contains an integer $n$ ($1 \le n \le 100$) — the length of the sequence $a$.
The second line contains elements of the sequence $a$: integer numbers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$).
The third line contains an integer $m$ ($1 \le m \le 100$) — the number of requests.
The following $m$ lines contain pairs of integers $k_j$ and $pos_j$ ($1 \le k \le n$, $1 \le pos_j \le k_j$) — the requests.
-----Output-----
Print $m$ integers $r_1, r_2, \dots, r_m$ ($1 \le r_j \le 10^9$) one per line: answers to the requests in the order they appear in the input. The value of $r_j$ should be equal to the value contained in the position $pos_j$ of the optimal subsequence for $k=k_j$.
-----Examples-----
Input
3
10 20 10
6
1 1
2 1
2 2
3 1
3 2
3 3
Output
20
10
20
10
20
10
Input
7
1 2 1 3 1 2 1
9
2 1
2 2
3 1
3 2
3 3
1 1
7 1
7 7
7 4
Output
2
3
2
3
2
3
1
1
3
-----Note-----
In the first example, for $a=[10,20,10]$ the optimal subsequences are: for $k=1$: $[20]$, for $k=2$: $[10,20]$, for $k=3$: $[10,20,10]$.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
One day you wanted to read something, so you went to your bookshelf to grab some book. But when you saw how messy the bookshelf was you decided to clean it up first.
There are $n$ books standing in a row on the shelf, the $i$-th book has color $a_i$.
You'd like to rearrange the books to make the shelf look beautiful. The shelf is considered beautiful if all books of the same color are next to each other.
In one operation you can take one book from any position on the shelf and move it to the right end of the shelf.
What is the minimum number of operations you need to make the shelf beautiful?
-----Input-----
The first line contains one integer $n$ ($1 \le n \le 5 \cdot 10^5$) — the number of books.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) — the book colors.
-----Output-----
Output the minimum number of operations to make the shelf beautiful.
-----Examples-----
Input
5
1 2 2 1 3
Output
2
Input
5
1 2 2 1 1
Output
1
-----Note-----
In the first example, we have the bookshelf $[1, 2, 2, 1, 3]$ and can, for example:
take a book on position $4$ and move to the right end: we'll get $[1, 2, 2, 3, 1]$;
take a book on position $1$ and move to the right end: we'll get $[2, 2, 3, 1, 1]$.
In the second example, we can move the first book to the end of the bookshelf and get $[2,2,1,1,1]$.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
Efim just received his grade for the last test. He studies in a special school and his grade can be equal to any positive decimal fraction. First he got disappointed, as he expected a way more pleasant result. Then, he developed a tricky plan. Each second, he can ask his teacher to round the grade at any place after the decimal point (also, he can ask to round to the nearest integer).
There are t seconds left till the end of the break, so Efim has to act fast. Help him find what is the maximum grade he can get in no more than t seconds. Note, that he can choose to not use all t seconds. Moreover, he can even choose to not round the grade at all.
In this problem, classic rounding rules are used: while rounding number to the n-th digit one has to take a look at the digit n + 1. If it is less than 5 than the n-th digit remain unchanged while all subsequent digits are replaced with 0. Otherwise, if the n + 1 digit is greater or equal to 5, the digit at the position n is increased by 1 (this might also change some other digits, if this one was equal to 9) and all subsequent digits are replaced with 0. At the end, all trailing zeroes are thrown away.
For example, if the number 1.14 is rounded to the first decimal place, the result is 1.1, while if we round 1.5 to the nearest integer, the result is 2. Rounding number 1.299996121 in the fifth decimal place will result in number 1.3.
-----Input-----
The first line of the input contains two integers n and t (1 ≤ n ≤ 200 000, 1 ≤ t ≤ 10^9) — the length of Efim's grade and the number of seconds till the end of the break respectively.
The second line contains the grade itself. It's guaranteed that the grade is a positive number, containing at least one digit after the decimal points, and it's representation doesn't finish with 0.
-----Output-----
Print the maximum grade that Efim can get in t seconds. Do not print trailing zeroes.
-----Examples-----
Input
6 1
10.245
Output
10.25
Input
6 2
10.245
Output
10.3
Input
3 100
9.2
Output
9.2
-----Note-----
In the first two samples Efim initially has grade 10.245.
During the first second Efim can obtain grade 10.25, and then 10.3 during the next second. Note, that the answer 10.30 will be considered incorrect.
In the third sample the optimal strategy is to not perform any rounding at all.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
KISS stands for Keep It Simple Stupid.
It is a design principle for keeping things simple rather than complex.
You are the boss of Joe.
Joe is submitting words to you to publish to a blog. He likes to complicate things.
Define a function that determines if Joe's work is simple or complex.
Input will be non emtpy strings with no punctuation.
It is simple if:
``` the length of each word does not exceed the amount of words in the string ```
(See example test cases)
Otherwise it is complex.
If complex:
```python
return "Keep It Simple Stupid"
```
or if it was kept simple:
```python
return "Good work Joe!"
```
Note: Random test are random and nonsensical. Here is a silly example of a random test:
```python
"jump always mostly is touchy dancing choice is pineapples mostly"
```
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
There is an array with some numbers. All numbers are equal except for one. Try to find it!
```python
find_uniq([ 1, 1, 1, 2, 1, 1 ]) == 2
find_uniq([ 0, 0, 0.55, 0, 0 ]) == 0.55
```
It’s guaranteed that array contains at least 3 numbers.
The tests contain some very huge arrays, so think about performance.
This is the first kata in series:
1. Find the unique number (this kata)
2. [Find the unique string](https://www.codewars.com/kata/585d8c8a28bc7403ea0000c3)
3. [Find The Unique](https://www.codewars.com/kata/5862e0db4f7ab47bed0000e5)
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Solve the programming task below in a Python markdown code block.
You are given $a$ uppercase Latin letters 'A' and $b$ letters 'B'.
The period of the string is the smallest such positive integer $k$ that $s_i = s_{i~mod~k}$ ($0$-indexed) for each $i$. Note that this implies that $k$ won't always divide $a+b = |s|$.
For example, the period of string "ABAABAA" is $3$, the period of "AAAA" is $1$, and the period of "AABBB" is $5$.
Find the number of different periods over all possible strings with $a$ letters 'A' and $b$ letters 'B'.
-----Input-----
The first line contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$) — the number of letters 'A' and 'B', respectively.
-----Output-----
Print the number of different periods over all possible strings with $a$ letters 'A' and $b$ letters 'B'.
-----Examples-----
Input
2 4
Output
4
Input
5 3
Output
5
-----Note-----
All the possible periods for the first example: $3$ "BBABBA" $4$ "BBAABB" $5$ "BBBAAB" $6$ "AABBBB"
All the possible periods for the second example: $3$ "BAABAABA" $5$ "BAABABAA" $6$ "BABAAABA" $7$ "BAABAAAB" $8$ "AAAAABBB"
Note that these are not the only possible strings for the given periods.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.