A winter cloth distribution campaign will be held in the city of BugBlossoms. There are two orphanages separated by a river, and each orphanage has $$$n$$$ rooms numbered from $$$1$$$ to $$$n$$$ from left to right. Crossing the river takes $$$k$$$ units of time. Each room is either empty or occupied by a single child (represented by each character 1 in the input strings).
As Ad-Duha is managing the campaign alone, she has decided to keep all the winter clothing packages in a single room — that is, in exactly one of the $$$2n$$$ rooms across both orphanages — due to a lack of volunteers. The children from every occupied room in both orphanages must come to that chosen room to collect their winter clothes.
If the packages are located in room $$$i$$$ of an orphanage and a child is in room $$$j$$$:
Ad-Duha wants to choose the room so as to minimize the maximum time any child spends reaching the room containing the packages.
Once this room is chosen, the children are split into two groups:
Ad-Duha felt sad that the children in Group B had to cross the river to receive their winter clothes, so she decided to give them books, flowers and chocolates as well. She has $$$m$$$ gift boxes in total. Each child in Group A gets exactly $$$x$$$ boxes, and each child in Group B gets exactly $$$y$$$ boxes, where:
The total $$$a \cdot x + b \cdot y$$$ must not be more than $$$m$$$. Ad-Duha wants to give away as many boxes as possible. Find the minimum number of boxes that remain ungifted.
The first line contains an integer $$$T$$$ — the number of test cases.
Each test case is described as follows:
It is guaranteed that each of the two strings contains at least two 1s, so whichever orphanage is chosen, $$$a \ge 1$$$ and $$$b \ge 2$$$.
It is also guaranteed that $$$a + 2b \le m$$$ for whichever orphanage is chosen. That is, both $$$c_1 + 2c_2 \le m$$$ and $$$c_2 + 2c_1 \le m$$$, where $$$c_1$$$ and $$$c_2$$$ are the numbers of 1s in the first and second string.
Constraints:
For each test case, print the following three lines:
If the minimum time can be reached by placing the packages in orphanage 1 and also by placing them in orphanage 2, you may take either orphanage as the one with the packages when you compute $$$a$$$ and $$$b$$$. Any of the resulting answers for the third line is accepted.
Every test case must print exactly three lines. If you cannot compute some part, print -1 in its place:
| Subtask | Points | $$$T$$$ | $$$n$$$ | Additional Constraints |
| 0 | 0 | - | - | The examples |
| 1 | 30 | $$$\le 10$$$ | $$$\le 10^3$$$ | No additional constraints. |
| 2 | 30 | - | $$$\le 10^3$$$ | No additional constraints. |
| 3 | 40 | - | - | No additional constraints. |
All other constraints are the same as in the Input section.
Each test case in a file is scored separately, and the score of the file is the average over its test cases. For one test case:
If the first line is wrong, the whole test case scores $$$0$$$.
55 3 2010100001016 10 411000010100104 1 15111000114 2 11110101103 1 8111110
7 2 1 0 16 1 1 1 5 2 1 1 6 1 1 0 4 1 1 1
Test 1: The first orphanage has children in rooms $$$1$$$ and $$$3$$$, and the second in rooms $$$3$$$ and $$$5$$$.
Placing the packages in room $$$1$$$ of the second orphanage:
Test 2: Placing the packages in room $$$1$$$ of the first orphanage:
"This town ain't big enough for the two of us."
Arthur Morgan has been challenged to a game of Russian Roulette. However, this isn't normal Russian Roulette — it is played on an $$$N \times M$$$ grid where each cell $$$(r, c)$$$ has an integer value $$$A_{r,c}$$$.
Before the game starts, Arthur chooses a positive integer $$$X$$$:
Connected safe cells (sharing an edge up, down, left, or right) form a safe zone. The size of a safe zone is the total number of cells in it.
Arthur starts at $$$(1, 1)$$$ and can move up, down, left, or right. To win the game, he must reach any cell in a safe zone of size at least $$$S$$$, while stepping on at most $$$K$$$ unsafe cells along his path (including $$$(1, 1)$$$ if it is unsafe).
Find the maximum integer $$$X$$$ Arthur can choose to win the game, or output 0 if it is impossible.
Rows are numbered from top to bottom and columns from left to right, so $$$(1, 1)$$$ is the top-left cell.
Constraints:
Print a single integer — the maximum valid $$$X$$$, or 0 if Arthur cannot win.
| Subtask | Points | $$$N$$$ | $$$M$$$ | $$$K$$$ | $$$S$$$ | $$$A_{r,c}$$$ | Additional Constraints |
| 0 | 0 | - | - | - | - | - | The examples |
| 1 | 20 | $$$\le 40$$$ | $$$\le 40$$$ | - | - | $$$\le 50$$$ | No additional constraints. |
| 2 | 20 | - | - | - | $$$= 1$$$ | $$$\in \{1, 2\}$$$ | An optimal path only moves Down and Right. |
| 3 | 25 | - | - | $$$= N \times M$$$ | - | - | No additional constraints. |
| 4 | 35 | - | - | - | - | - | No additional constraints. |
All other constraints are the same as in the Input section.
3 4 1 39 2 8 81 1 2 94 4 1 7
8
The grid is:
9 2 8 8
1 1 2 9
4 4 1 7
Choose $$$X = 8$$$. The safe cells are $$$(1,1)$$$, $$$(1,3)$$$, $$$(1,4)$$$ and $$$(2,4)$$$.
Choose $$$X = 9$$$. Only $$$(1,1)$$$ and $$$(2,4)$$$ are safe, and each forms a zone of size $$$1 \lt S$$$, so Arthur cannot win. Therefore the maximum valid $$$X$$$ is $$$8$$$.
Anya has sat for her mid-term exam in her school, Eden Academy. She must achieve all the stella stars to keep her family together and save world peace. Otherwise, Loid's "Operation Strix" will fail. The students next to her are struggling to answer the questions, so she can't take any worthy help from her telepathy ability. Help her to find the answers.
She is given an array $$$A$$$ with $$$N$$$ integers. Let's denote: $$$$$$\pi(x) = \text{the number of prime numbers from } 1 \text{ to } x.$$$$$$
There are $$$Q$$$ questions (queries) to answer, of two types:
Help Anya cook in her exam and make Damian fall for her, making Operation Strix succeed.
Constraints:
For every query of type $$$1$$$, print one integer: $$$\sum_{i=l}^{r} \pi(A_i)$$$, where $$$\pi(A_i)$$$ is the number of prime numbers from $$$1$$$ to $$$A_i$$$.
Print the answers in the order the queries are given.
| Subtask | Points | $$$N$$$ | $$$Q$$$ | $$$A_i$$$ | $$$v$$$ | Additional Constraints |
| 0 | 0 | - | - | - | - | The examples |
| 1 | 10 | $$$\le 1000$$$ | $$$\le 1000$$$ | $$$\le 10^4$$$ | $$$\le 10^4$$$ | No additional constraints. |
| 2 | 15 | $$$\le 5000$$$ | $$$\le 5000$$$ | $$$\le 10^6$$$ | $$$\le 10^6$$$ | No additional constraints. |
| 3 | 20 | - | - | $$$\le 10^7$$$ | - | There are no type $$$2$$$ queries. |
| 4 | 25 | - | - | $$$\le 10^7$$$ | $$$\le 10^7$$$ | No additional constraints. |
| 5 | 30 | - | - | $$$\le 10^8$$$ | $$$\le 10^8$$$ | No additional constraints. |
104 3 0 50 49 1 3 4 4 381 5 61 4 41 9 92 7 501 2 81 8 92 1 32 9 3
15 15 2 49 4
The initial array is $$$A = [4, 3, 0, 50, 49, 1, 3, 4, 4, 3]$$$. Useful values: $$$\pi(0) = \pi(1) = 0$$$, $$$\pi(3) = \pi(4) = 2$$$, $$$\pi(49) = \pi(50) = 15$$$.