You are given a binary string$$$^\dagger$$$ $$$s$$$ of length $$$n$$$ and an integer $$$k$$$.
You are allowed to do the following operation on $$$s$$$ :
What are the maximum number of $$$1$$$'s in $$$s$$$ after performing the above operation infinitely many times (possibly zero)?
$$$^\dagger$$$ A binary string is a string which only contains $$$0$$$'s and $$$1$$$'s.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). The description of the test cases follows.
The first line of each testcase contains two integers $$$n,k$$$ ($$$2 \le n \le 10^3$$$, $$$1 \le k \le ⌊\frac{n}{2}⌋$$$), the length of binary string and an integer.
The second line of each testcase contains a binary string $$$s$$$ of length $$$n$$$.
For each test case, print a single integer — the maximum number of $$$1$$$'s in $$$s$$$ after performing the above operation infinitely many times(possibly zero).
62 1002 1013 11013 11114 211004 11010
1 1 2 3 2 3
In the $$$6$$$-th test case, $$$s = 1010$$$ and $$$k = 1$$$
Let choose $$$i = 2$$$, now $$$s_2$$$ becomes $$$1$$$ and $$$s_3$$$ becomes $$$0$$$. So $$$s = 1100$$$.
Let choose $$$i = 3$$$, now $$$s_3$$$ becomes $$$1$$$ and $$$s_4$$$ becomes $$$0$$$. So $$$s = 1110$$$.
Hence, maximum number of $$$1$$$'s in $$$s = 1110$$$ is $$$3$$$.
You are given a binary string$$$^\dagger$$$ $$$s$$$ of length $$$n$$$ and an integer $$$k$$$.
You are allowed to do the following operation on $$$s$$$ :
For every $$$k(1 \le k \le ⌊\frac{n}{2}⌋)$$$, find the minimum number of above operations required to do on $$$s$$$ to get maximum number of $$$1$$$'s in $$$s$$$.
$$$^\dagger$$$ A binary string is a string which only contains $$$0$$$'s and $$$1$$$'s.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). The description of the test cases follows.
The first line of each testcase contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the length of the binary string.
The second line of each testcase contains a binary string $$$s$$$ of length $$$n$$$.
It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.
For each test case, print $$$⌊\frac{n}{2}⌋$$$ integers — minimum number of above operations required to do on $$$s$$$ to get maximum number of $$$1$$$'s in $$$s$$$.
521031004011051010071010010
0 1 3 0 3 1 5 2 1
Alice and Bob decided to play the following game on $$$n$$$ piles of stones where the $$$i$$$-th$$$(1 \le i \le n)$$$ pile contains $$$p_i$$$ stones with Alice starting first :
The player who cannot make a move loses. Note that both Alice and Bob are intelligent, so they always play optimally.
Now your task is to construct any permutation$$$^\dagger$$$ $$$p$$$ of length $$$n$$$ such that the number of pairs ($$$l, r$$$)($$$1 \le l \le r \le n$$$), where Alice will win if both players play the game on piles $$$l, l+1, ..., r-1, r$$$, is maximum possible.
$$$^\dagger$$$ A permutation is an array of length $$$n$$$, where each number from $$$1$$$ to $$$n$$$ appears exactly once.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10000$$$). The description of the test cases follows.
The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$) — the number of piles.
It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
For each test case, print $$$n$$$ integers — the required permutation $$$p$$$.
If there are multiple answers, output any.
3147
1 2 3 1 4 3 4 7 1 6 5 2
Alice and Bob decided to play the following game on $$$n$$$ piles of stones where the $$$i^{th}(1 \le i \le n)$$$ pile contains $$$p_i$$$ stones, with Alice starting first :
The player who cannot make a move loses. Note that both Alice and Bob are intelligent, so they always play optimally.
Now your task is to count the number of permutations$$$^\dagger$$$ $$$p$$$ of length $$$n$$$ such that the number of pairs ($$$l, r$$$)($$$1 \le l \le r \le n$$$), where Alice will win if both players play the game on piles $$$l, l+1, ..., r-1, r$$$, is maximum possible.
$$$^\dagger$$$ A permutation is an array of length $$$n$$$, where each number from $$$1$$$ to $$$n$$$ appears exactly once.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10000$$$). The description of the test cases follows.
The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$) — the number of piles.
It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
For each test case, print a single integer — the required answer modulo $$$10^9 + 7$$$.
3147
1 12 1440
Scientists from the NewEra got a string $$$s$$$ of length $$$n$$$ which contains lowercase English letters from far away space.
They have a machine which is capable of doing exactly one of the following operations in one second with an empty string $$$t$$$:
Scientists got information that within $$$m$$$ seconds the machine will die, so they decided to generate a copy of $$$s$$$ in $$$m$$$ seconds, i.e., they want to make $$$t = s$$$ by using the machine for exactly $$$m$$$ seconds.
Now the scientists are wondering in how many different ways they can make $$$t = s$$$ modulo $$$10^9 + 7$$$.
Each test contains multiple test cases. The first line contains the number of test cases $$$tc$$$ ($$$1 \le tc \le 1000$$$). The description of the test cases follows.
The first line of each testcase contains two integers $$$n,m$$$ ($$$1 \le n,m \le 8000$$$), the length of the string and the deadline of the machine.
The second line of each testcase contains a string $$$s$$$ of length $$$n$$$ which contains lowercase English letters.
It is guaranteed that the sum of $$$n$$$ and the sum of $$$m$$$ over all test cases doesn't exceed $$$8000$$$.
For each test case, print a single integer — the number of different ways to make $$$t = s$$$ modulo $$$10^9+7$$$.
53 4abc1 3d5 3asdfg7 10wuhudsm9 11yugandhar
1 53 0 235 261
In a class, a test has happened and $$$n$$$ students participated in it. In this test, there is only one question and the answer to the question is an integer $$$x$$$. All the students gave their answers as integers, i.e., $$$a_i$$$ is the answer of the $$$i$$$-th$$$(1 \le i \le n)$$$ student. Student $$$i$$$ will pass the exam if |$$$x-a_i$$$| is the minimum possible among all the students who attended the exam.
Now your task is to answer $$$q$$$ queries of two types :
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). The description of the test cases follows.
The first line of each test case contains two integers $$$n,q$$$ ($$$1 \le n,q \le 2 \cdot 10^5$$$) — the number of students and the number of queries.
The second line of each test case contains $$$n$$$ space separated integers $$$a_{i}$$$ ($$$-10^9 \le a_{i} \le 10^9$$$) — the answer from the $$$i$$$-th student.
The next $$$q$$$ lines contain one of the two forms:
It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$2 \cdot 10^5$$$.
It is guaranteed that the sum of $$$q$$$ over all test cases doesn't exceed $$$2 \cdot 10^5$$$.
For each test case — print the required answer for the $$$1$$$-st type query.
23 51 -2 31 1 3 02 3 -21 2 3 12 1 -41 1 1 -107 81 2 4 2 4 6 71 3 5 51 1 7 52 1 62 4 41 1 7 51 1 3 22 7 11 1 7 -1
1 2 1 2 3 5 1 1
You are given a tree containing $$$n$$$ nodes where each node is either red node or blue node and the value of the node $$$i$$$ is $$$a_i(1 \le i \le n)$$$.
Let $$$R$$$ be the number of red nodes and $$$B$$$ be the number of blue nodes, then beauty of the tree is defined as ($$$\sum_{i = 1}^R a_i - \sum_{i = 1}^B a_i$$$), i.e., difference between sum of values of all red nodes and sum of values of all blue nodes.
A tree will be called "Perfect Tree" if it satisfies the following conditions :
A Forest will be called "Perfect Forest" if atleast one of it's tree is a Perfect tree. Otherwise it will be a "Non-Perfect Forest".
Find the minimum number of edges to remove from the given tree to make the forest "Non-Perfect Forest".
The first line of each test contains single integer $$$n$$$ $$$(1 \le n \le 8000)$$$ — the size of the tree.
The next line contains $$$n$$$ space-seperated integers $$$a_i$$$ $$$(1 \le a_i \le 10^9)$$$ — the value of the $$$i^{th}$$$ node.
The next line contains a binary string $$$S$$$ of length $$$n$$$, where $$$S_i = 0$$$ indicates that $$$i^{th}$$$ node is red node, $$$S_i = 1$$$ indicates that $$$i^{th}$$$ node is blue node.
The next $$$n-1$$$ lines contain two integers $$$x,y$$$ $$$(1 \le x,y \le n, x≠y)$$$ — there is an edge between $$$x$$$ and $$$y$$$.
For each test, print single integer — the minimum number of edges to remove from the given tree to make the forest "Non-Perfect Forest"
62 4 3 6 5 10110015 43 16 51 52 3
1
79 10 11 5 2 3 600101103 16 41 23 54 74 1
2
In the first test, The beauty of the tree is $$$(2+6+5) - (4+3+1) = 5$$$, i.e., beauty $$$\ge 0$$$ and $$$(R = 3 \gt 0)$$$ and $$$(B = 3 \gt 0)$$$. So the given tree is "Perfect tree" and the forest is "Perfect Forest".
After removing the edge between nodes $$$4$$$ and $$$5$$$.
The Beauty of the tree containing nodes {$$$1,2,3,5,6$$$} is $$$(2+5) - (3+4+1) = -1$$$ i.e., beauty $$$ \lt 0$$$. So this tree is "Non-Perfect Tree".
The Beauty of the tree containing nodes {$$$4$$$} is $$$(6) - () = 6$$$ i.e., beauty $$$\ge 0$$$ but $$$(B = 0)$$$. So this tree is "Non-Perfect Tree".
As both trees are "Non-Perfect Tree". The resultant forest is "Non-Perfect Forest". Hence minimum number of edges to remove from the given tree to make the forest "Non-Perfect Forest" is $$$1$$$.