You are given an array $$$a$$$ with $$$n$$$ integers. You can perform the following operation at most $$$k$$$ times:
After performing all operations, you have to select $$$k$$$ consecutive elements, and the sum of the $$$k$$$ elements becomes your score. Find the maximum score you can get.
Here $$$x \bmod y$$$ denotes the remainder from dividing $$$x$$$ by $$$y$$$.
The first line contains one integer $$$t$$$ ($$$1 \le t \le 600$$$) — the number of test cases.
Each test case consists of two lines.
The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 100$$$) — the length of the array and the number in the statement above.
The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) — the array itself.
For each test case, print the maximum score you can get, one per line.
53 25 6 01 175 37 0 4 0 44 22 7 3 43 31000000000 1000000000 999999997
11 7 15 10 2999999997
In the first test case, we can get a score of $$$11$$$ if we select $$$a_1, a_2$$$ without performing any operations.
In the third test case, we can get a score of $$$15$$$ if we first swap $$$a_1$$$ with $$$a_4$$$ and then select $$$a_3, a_4, a_5$$$.
There is a badminton championship in which $$$n$$$ players take part. The players are numbered from $$$1$$$ to $$$n$$$.
The championship proceeds as follows: player $$$1$$$ and player $$$2$$$ play a game, then the winner and player $$$3$$$ play a game, and then the winner and player $$$4$$$ play a game, and so on. So, $$$n-1$$$ games are played, and the winner of the last game becomes the champion. There are no draws in the games.
You want to find out the result of championship. Currently, you only know the following information:
Given $$$n$$$, $$$x$$$, and $$$y$$$, find out if there is a result that matches this information.
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases.
The only line of each test case contains three integers $$$n$$$, $$$x$$$, $$$y$$$ ($$$2 \le n \le 10^5$$$, $$$0 \le x, y \lt n$$$).
It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$2 \cdot 10^5$$$.
Print the answer for each test case, one per line. If there is no result that matches the given information about $$$n$$$, $$$x$$$, $$$y$$$, print $$$-1$$$. Otherwise, print $$$n-1$$$ space separated integers, where the $$$i$$$-th integer is the player number of the winner of the $$$i$$$-th game.
If there are multiple valid results, print any.
55 2 08 1 23 0 02 0 16 3 0
1 1 4 4 -1 -1 2 -1
In the first test case, player $$$1$$$ and player $$$4$$$ won $$$x$$$ times, player $$$2$$$ and player $$$3$$$ won $$$y$$$ times.
In the second, third, and fifth test cases, no valid result exists.
You are given an array $$$a$$$ with $$$n$$$ non-negative integers. You can apply the following operation on it.
Find any sequence of at most $$$n$$$ operations that makes $$$a$$$ non-decreasing. It can be proven that it is always possible. Note that you do not have to minimize the number of operations.
An array $$$a_1, a_2, \ldots, a_n$$$ is non-decreasing if and only if $$$a_1 \le a_2 \le \ldots \le a_n$$$.
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases.
Each test case consists of two lines. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the length of the array.
The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) — the array itself.
It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.
For each test case, print one integer $$$m$$$ ($$$0 \le m \le n$$$), the number of operations, in the first line.
Then print $$$m$$$ lines. Each line must contain two integers $$$l_i, r_i$$$, which are the indices you chose in the $$$i$$$-th operation ($$$1 \le l_i \lt r_i \le n$$$).
If there are multiple solutions, print any of them.
327 851 1000000000 3 0 510
0 2 3 4 1 2 0
In the second test case, $$$a$$$ changes like this:
In the first and third test cases, $$$a$$$ is already non-decreasing.
This is the easy version of the problem. In this version, $$$n \le 3000$$$, $$$x \ge y$$$ holds. You can make hacks only if both versions of the problem are solved.
You are given two binary strings $$$a$$$ and $$$b$$$, both of length $$$n$$$. You can do the following operation any number of times (possibly zero).
You have to find the minimum cost needed to make $$$a$$$ equal to $$$b$$$ or say there is no way to do so.
The first line contains one integer $$$t$$$ ($$$1 \le t \le 600$$$) — the number of test cases.
Each test case consists of three lines. The first line of each test case contains three integers $$$n$$$, $$$x$$$, and $$$y$$$ ($$$5 \le n \le 3000$$$, $$$1 \le y \le x \le 10^9$$$) — the length of the strings, and the costs per operation.
The second line of each test case contains the string $$$a$$$ of length $$$n$$$. The string only consists of digits $$$0$$$ and $$$1$$$.
The third line of each test case contains the string $$$b$$$ of length $$$n$$$. The string only consists of digits $$$0$$$ and $$$1$$$.
It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3000$$$.
For each test case, if there is no way to make $$$a$$$ equal to $$$b$$$, print $$$-1$$$. Otherwise, print the minimum cost needed to make $$$a$$$ equal to $$$b$$$.
45 8 701001001015 7 201000110117 8 3011100101000015 10 10110001100
8 -1 6 0
In the first test case, selecting indices $$$2$$$ and $$$3$$$ costs $$$8$$$, which is the minimum possible cost.
In the second test case, we cannot make $$$a$$$ equal to $$$b$$$ using any number of operations.
In the third test case, we can perform the following operations:
The total cost is $$$6$$$.
In the fourth test case, we don't have to perform any operations.
This is the hard version of this problem. In this version, $$$n \le 5000$$$ holds, and this version has no restriction between $$$x$$$ and $$$y$$$. You can make hacks only if both versions of the problem are solved.
You are given two binary strings $$$a$$$ and $$$b$$$, both of length $$$n$$$. You can do the following operation any number of times (possibly zero).
You have to find the minimum cost needed to make $$$a$$$ equal to $$$b$$$ or say there is no way to do so.
The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases.
Each test case consists of three lines. The first line of each test case contains three integers $$$n$$$, $$$x$$$, and $$$y$$$ ($$$5 \le n \le 5000$$$, $$$1 \le x, y \le 10^9$$$) — the length of the strings, and the costs per operation.
The second line of each test case contains the string $$$a$$$ of length $$$n$$$. The string only consists of digits $$$0$$$ and $$$1$$$.
The third line of each test case contains the string $$$b$$$ of length $$$n$$$. The string only consists of digits $$$0$$$ and $$$1$$$.
It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$5000$$$.
For each test case, if there is no way to make $$$a$$$ equal to $$$b$$$, print $$$-1$$$. Otherwise, print the minimum cost needed to make $$$a$$$ equal to $$$b$$$.
65 8 901001001016 2 110000011000005 7 201000110117 8 3011100101000016 3 40100011010005 10 10110001100
8 10 -1 6 7 0
In the first test case, selecting indices $$$2$$$ and $$$3$$$ costs $$$8$$$, which is the minimum.
In the second test case, we can perform the following operations.
The total cost is $$$10$$$.
In the third test case, we cannot make $$$a$$$ equal to $$$b$$$ using any number of operations.
In the fourth test case, we can perform the following operations.
The total cost is $$$6$$$.
In the fifth test case, we can perform the following operations.
The total cost is $$$7$$$.
In the sixth test case, we don't have to perform any operation.
There is a conveyor with $$$120$$$ rows and $$$120$$$ columns. Each row and column is numbered from $$$0$$$ to $$$119$$$, and the cell in $$$i$$$-th row and $$$j$$$-th column is denoted as $$$(i, j)$$$. The top leftmost cell is $$$(0, 0)$$$. Each cell has a belt, and all belts are initially facing to the right.
Initially, a slime ball is on the belt of $$$(0, 0)$$$, and other belts are empty. Every second, the state of the conveyor changes as follows:
There are $$$q$$$ queries, each being three integers $$$t$$$, $$$x$$$, and $$$y$$$. You have to find out if there is a slime at the cell $$$(x, y)$$$ after $$$t$$$ seconds from the start. Can you do it?
The first line contains one integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of queries.
The only line of each query contains three integers $$$t$$$, $$$x$$$, and $$$y$$$ ($$$0 \le t \le 10^{18}$$$, $$$0 \le x, y \lt 120$$$).
Print the answer for each test case, one per line. If there is a slime ball in the cell $$$(x, y)$$$ after $$$t$$$ seconds from the initial state, print "YES". Otherwise, print "NO".
61 1 05 1 30 0 02 4 52 0 21547748756 100 111
NO YES YES NO YES YES
The state of conveyor with $$$t = 0$$$. Red arrow represents the direction of each belt, and blue figure represents slime.

The state of conveyor with $$$t = 1$$$.

The state of conveyor with $$$t = 2$$$.
