Alice and Bob decided to play the following game on a pile containing $$$n$$$ 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.
You are the best friend of Alice. So add the minimum number of additional stones to the pile so that Alice will win.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^3$$$). The description of the test cases follows.
The first line of each testcase contain single integer $$$n$$$ ($$$1 \le n \le 10^3$$$) — the number of stones in a pile.
For each test case, print a single integer — minimum number of additional stones added to the pile so that Alice will win.
424610
0 0 1 2
A grid containing $$$n$$$ rows and $$$n$$$ columns is called Beautiful grid if it satisfies the following conditions :
Your task is to construct any Beautiful grid for given $$$n$$$ and $$$k$$$.
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$$$ ($$$1 \le n \le 10^3$$$, $$$1 \le k \le 26$$$).
It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^3$$$.
For each test case, print $$$-1$$$ if there is no Beautiful grid. Otherwise print $$$n$$$ strings each of length $$$n$$$.
If there are multiple answers, output any.
51 12 12 23 23 26
z kk kk -1 www wyw www -1
You are given an integer array $$$a$$$ containing $$$n$$$ elements.
Find the maximum value of $$$^\dagger$$$ $$$gcd(a_1, a_2, a_3, \cdots , a_n)$$$, after applying the following operation exactly once :
$$$^\dagger$$$ $$$gcd(a_1, a_2, a_3, \cdots , a_n)$$$ denotes the greatest common divisor of $$$a_1, a_2, a_3, \cdots , a_n$$$.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^3$$$). The description of the test cases follows.
The first line of each test case contains single integer $$$n$$$ ($$$3 \le n \le 10^5$$$) — the length of the array.
The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1 \le a_{i} \le 10^9$$$).
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
For each test case, print single integer — the maximum value of $$$gcd(a_1, a_2, a_3, \cdots , a_n)$$$.
432 3 244 3 2 164 4 3 3 2 293 6 9 2 3 6 9 3 6
3 2 2 3
In the $$$1$$$-th test case, Choose $$$i = 1$$$ and $$$j = 3$$$ and change $$$a_i$$$ to $$$9$$$ and $$$a_j$$$ to $$$9$$$.
So the final array is $$$9, 3, 9$$$.
Hence, $$$gcd(9, 3, 9) = 3$$$.
An integer array $$$b$$$ containing $$$m$$$ elements is called perfect-prefix array, if it satisfies the following condition :
You can do the following operation on $$$b$$$ any number of times (possibly zero) :
Let $$$f(b)$$$ be the minimum number of operations required to turn $$$b$$$ into perfect-prefix array. If it is not possible to turn $$$b$$$ into perfect-prefix array then $$$f(b) = -1$$$.
You are given an integer array $$$a$$$ containing $$$n$$$ elements where each element is either $$$1$$$ or $$$-1$$$.
Now your task is to answer $$$q$$$ queries of following type :
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 5 \cdot 10^5$$$) — the size of the array and the number of queries.
The second line of each test case contains $$$n$$$ space separated integers $$$a_{i}$$$ ($$$-1 \le a_{i} \le 1$$$ , $$$a_i ≠ 0$$$).
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 $$$5 \cdot 10^5$$$.
It is guaranteed that the sum of $$$q$$$ over all test cases doesn't exceed $$$5 \cdot 10^5$$$.
For each test case, print the required answer for the $$$1$$$-st type query.
25 51 1 -1 1 -11 1 41 2 42 31 1 41 4 511 61 1 1 1 -1 -1 -1 1 1 -1 -11 7 91 1 112 52 61 1 71 7 10
0 1 0 -1 1 0 0 -1
You are given an integer grid $$$a$$$ containing $$$n$$$ rows and $$$n$$$ columns. Let $$$a_{i,j}$$$ denote the value at the $$$i$$$-th row from the top and $$$j$$$-th column from the left.
Now your task is to construct a tree (undirected acyclic graph) containing $$$n$$$ nodes, such that :
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^3$$$). The description of the test cases follows.
The first line of each test case contains single integer $$$n$$$ ($$$2 \le n \le 10^3$$$).
The next $$$n$$$ lines of each test case contains $$$n$$$ integers $$$a_{i,1},a_{i,2},\cdots,a_{i,n}$$$ ($$$1 \le a_{i,j} \le n$$$).
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^3$$$.
For each test case, print $$$-1$$$ if there is no possible tree.
Otherwise, print $$$n-1$$$ lines — the edges of the tree.
If there are multiple answers output any.
541 1 1 11 2 1 11 1 3 31 1 3 451 1 1 1 11 2 1 1 11 1 3 3 31 1 3 4 31 1 3 3 551 1 1 1 23 4 1 1 33 4 1 1 52 3 1 2 31 2 3 4 561 1 1 1 1 11 2 2 1 1 21 2 3 2 3 11 1 2 4 3 21 1 3 3 5 21 2 1 2 2 671 1 1 1 1 1 11 2 1 2 1 1 11 1 3 1 3 3 31 2 1 4 1 1 11 1 3 1 5 5 31 1 3 1 5 6 31 1 3 1 3 3 7
3 4 2 1 1 3 3 5 1 2 4 3 3 1 -1 -1 2 4 3 1 3 6 4 1 7 3 5 6
You are given a rooted tree containing $$$n$$$ nodes and rooted at node $$$1$$$.
Now your task is to count the number of different permutations $$$p$$$ of length $$$n$$$ which satisfies the following condition :
$$$^\dagger$$$ Node $$$a$$$ is an ancestor of node $$$b$$$ if the shortest path from $$$b$$$ to the root passes through $$$a$$$.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^3$$$). The description of the test cases follows.
The first line of each test case contains a single integer $$$n$$$ $$$(3 \le n \le 5000)$$$ — the size of the tree.
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$$$.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$5000$$$.
For each test case, print a single integer — the required count modulo $$$10^9 + 7$$$.
231 31 254 51 43 12 4
2 4
For the first test case, the permutations which satisfies the condition are :
For the second test case, the permutations which satisfies the condition are :
You are given a permutation $$$p$$$ of length $$$n$$$.
You are allowed to do the following operation :
Let $$$f(p)$$$ denotes the minimum number of operations required to sort $$$p$$$ in ascending order.
Find the value of $$$f(p)$$$ and also answer the $$$q$$$ queries :
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^3$$$). The description of the test cases follows.
The first line of each test case contains two integers $$$n,q$$$ $$$(2 \le n,q \le 5 \cdot 10^4)$$$ — the length of the permutation and the number of queries.
The second line of each test case contains $$$n$$$ integers $$$p_1,p_2,\cdots,p_n$$$ ($$$1 \le p_{i} \le n$$$).
The next $$$q$$$ lines of each test case contains two integers $$$x,y$$$ $$$(1 \le x \lt y \le n)$$$.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$5 \cdot 10^4$$$.
It is guaranteed that the sum of $$$q$$$ over all test cases does not exceed $$$5 \cdot 10^4$$$.
For each test case, print $$$q+1$$$ space separated integers — the value of $$$f(p)$$$.
25 33 1 2 5 41 34 51 27 57 3 5 1 2 4 62 31 43 71 54 5
3 2 1 0 5 4 3 4 5 6