There is a chessboard containing $$$n$$$ rows and $$$m$$$ columns. Cell at the $$$i^{th}$$$ row and $$$j^{th}$$$ column is denoted as $$$(i,j)$$$. Cell $$$(i,j)$$$ is colored white if $$$(i+j)$$$ is even; otherwise, it is colored black.
Your task is to place the maximum kings on white cells such that no two kings attack each other.
Two kings will attack each other if their cells are adjacent by edge or corner.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The description of the test cases follows.
The first line of each testcase contains two space-separated integers $$$n$$$ and $$$m$$$ ($$$1 \le n,m \le 100$$$).
For each test case, print a single integer — the maximum number of kings placed on the given chessboard which satisfies the given condition.
62 36 14 47 86 74 9
2 3 4 16 12 10
Zogbi is playing a video game, in which there is a circle divided into $$$n$$$ equal sectors, and initially each sector has a cone in it. She wins the game if she moves all the cones to any one specific sector in the minimum number of operations.
In one operation, she can select any two distinct cones and must move both of them independently to any one of their adjacent sectors from their current sector.
Note: two sectors are adjacent if they share a side in circular order.
For example, consider the case $$$n = 4$$$, as shown below. In each operation, she moves the two cones shown by red arrows to an adjacent sector. She makes exactly two operations to move all cones to one same sector. And it can be shown that one cannot do it in less than $$$2$$$ operations.
n = 4, operations are shown by red arrows. Find the minimum number of operations. If it is impossible to move all cones to the same sector, output $$$-1$$$ instead.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1\le t \le 2\cdot10^5$$$). The description of the test cases follows.
The first line of each test case contains only one positive integer $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$), representing the number of sectors (so the cones).
Additionally, the sum of n over all the test cases doesn't exceed $$$2\cdot10^5$$$.
For each test case, output a single line containing an integer — the minimum number of operations to move all cones to one same sector. If it is impossible to move all cones to the same sector, then output $$$-1$$$ instead.
712345812
0 -1 1 2 3 8 18
The fourth test case is explained with a figure in the problem statement.
You will be given a tree containing $$$n$$$ nodes. An unordered pair $$$(u,v)$$$ is called a Super Pair if it satisfies the following conditions:
Your task is to calculate the number of Super Pairs.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^{4}$$$). 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 number of nodes in the given tree.
The next $$$n-1$$$ lines contain two integers $$$u,v$$$ $$$(1 \le u,v \le n, u≠v)$$$ — there is an edge connecting $$$u$$$ and $$$v$$$.
It is guaranteed that the sum of $$$n$$$ over all testcases doesn't exceed $$$10^{5}$$$.
For each testcase, print a single integer — the number of Super Pairs.
322 141 23 11 461 21 31 44 55 6
0 3 7
Pritesh had a permutation $$$p$$$ of length $$$n$$$. He took all the prefixes $$$[p_1, p_2, \dots, p_i]$$$ ($$$1\leq i\leq n$$$) of the permutation $$$p$$$ and calculated the $$$\operatorname{MEX}$$$ (minimal excluded element) of each prefix. Unfortunately, he forgot the permutation but remembers the sum $$$S$$$ of all the MEX values. Can you help him find the permutation $$$p$$$?
If there are multiple solutions, print any of them. If there is no solution, print a single integer $$$-1$$$.
The $$$\operatorname{MEX}$$$ of a collection of integers $$$c_1, c_2, \ldots, c_k$$$ is defined as the smallest non-negative integer $$$x$$$ which does not occur in the collection $$$c$$$.
A permutation of length $$$n$$$ is an array consisting of $$$n$$$ distinct integers from $$$0$$$ to $$$n-1$$$ in arbitrary order. For example, $$$[2, 3, 1, 0, 4]$$$ is a permutation, but $$$[0, 1, 1]$$$ is not a permutation ($$$1$$$ appears twice in the array), and $$$[0, 2, 3]$$$ is also not a permutation ($$$n = 3$$$ but there is $$$3$$$ in the array).
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The description of the test cases follows.
The first line of each test case contains two integers $$$n$$$ and $$$S$$$ ($$$1 \le n \le 3 \times 10^5$$$, $$$1 \le S \le 10^9$$$).
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \times 10^5$$$.
For each test case, output the permutation $$$p$$$ of length $$$n$$$ such that the sum of the MEX of all prefixes equals $$$S$$$. If there are multiple solutions, print any of them. If there is no solution, print a single integer $$$-1$$$.
43 52 102 24 3
0 2 1 -1 1 0 -1
For the first test case, $$$\operatorname{MEX}([0]) + \operatorname{MEX}([0, 2]) + \operatorname{MEX}([0, 2, 1]) = 1 + 1 + 3 = 5$$$.
For the second test case, it can be shown that no such permutation exists.
You have $$$n$$$ integers $$$a_1,a_2,...,a_n$$$ written from left to right. For all integers $$$1 \leq i \lt n$$$, you can either put an XOR symbol ($$$\oplus$$$) or an ADD symbol ($$$+$$$) between $$$a_i$$$ and $$$a_{i+1}$$$ to form an expression. The cost of the expression formed is the alternative result of the expression itself. Find the sum of costs from all possible $$$2^{n-1}$$$ expressions. Since the sum of costs might be too large, find the sum modulo $$$998244353$$$.
The alternative result of an expression is the result of the expression if the XOR operation is done before any other operation. For example, the alternative result of $$$5 + 3 \oplus 5$$$ is $$$5 + 6 = 11$$$ since $$$3 \oplus 5 = 6$$$ and the XOR operation has to be done before the ADD operation.
The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^5$$$) — the number of test cases.
The first line for each test case contains an integer $$$n$$$ ($$$2 \leq n \leq 5 \cdot 10^5$$$) — the number of integers inside the expression.
The second line for each test case contains $$$n$$$ integers $$$a_1,a_2,\dots,a_n$$$ ($$$1 \leq a_i \lt 2^{29}$$$).
It is guaranteed that the sum of $$$n$$$ from all test cases does not exceed $$$5 \cdot 10^5$$$.
For each test case, output a single integer — the sum of costs from all possible $$$2^{n-1}$$$ expressions, modulo $$$998244353$$$.
435 3 521012 10123166374059 166374059 1663740595123456789 432101234 123454321 456787654 133769420
38 2024 1 153140146
Let $$$f(X)$$$ be the cost of the expression $$$X$$$.
For the first test case, there are $$$4$$$ expressions, which are $$$\{5 + 3 + 5\}, \{5 + 3 \oplus 5\}, \{5 \oplus 3 + 5\}, \{5 \oplus 3 \oplus 5\}$$$. The sum of costs is $$$f(\{5 + 3 + 5\}) + f(\{5 + 3 \oplus 5\}) + f(\{5 \oplus 3 + 5\}) + f(\{5 \oplus 3 \oplus 5\}) = 13 + 11 + 11 + 3 = 38$$$.
For the second test case, there are $$$2$$$ expressions, which are $$$\{1012 + 1012\}$$$ and $$$\{1012 \oplus 1012\}$$$.
This time Yugandhar came up with two binary strings $$$a$$$ and $$$b$$$ of length $$$n$$$ and is thinking of asking you to construct a binary matrix which has $$$n$$$ rows and $$$n$$$ columns, such that the following condition holds:
But Wuhudsm thinks it is boring to concentrate on a single thing. Hence, he asked you to calculate the number of different binary matrices of size $$$n$$$ rows and $$$n$$$ columns which you can construct to make the above conditions hold.
The number may be large so print it modulo $$$10^{9}+7$$$.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10$$$). The description of the test cases follows.
The first line of each testcase contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$), the length of binary strings $$$a$$$ and $$$b$$$.
The second line of each testcase contains a binary string $$$a$$$ of length $$$n$$$.
The third line of each testcase contains a binary string $$$b$$$ of length $$$n$$$.
For each test case, print a single integer — the number of different binary matrices modulo $$$10^{9}+7$$$.
5200112011130011113010110400000101
2 3 49 0 225
In the first test case, all possible matrices are:
| 0 | 1 |
| 1 | 0 |
| 1 | 0 |
| 0 | 1 |
In the second test case, all possible matrices are:
| 0 | 0 |
| 1 | 1 |
| 0 | 1 |
| 1 | 1 |
| 1 | 0 |
| 1 | 1 |
Alice and Bob play a game on two positive integers $$$x$$$ and $$$y$$$. They take turns alternatively, with Alice making the first move. In a move, a player can subtract a multiple of one number from the other number. After the operation, both should remain non-negative. The first person to make the value of $$$x \cdot y$$$ equal to $$$0$$$ wins.
An example of the game on $$$x = 4$$$, $$$y = 14$$$:
Given two positive integers $$$l$$$ and $$$r\ (l \le r)$$$. Your task is to find the number of ordered pairs $$$(x,y)$$$ such that $$$l \le x \le y \le r$$$ and Alice wins for these pairs.
The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^5$$$).
For each test case, the only line contains two space-separated integers $$$l$$$ and $$$r$$$ ($$$1 \le l \le r \le 10^9$$$).
For each test case output a single number in a new line — the number of ordered pairs for which Alice will win.
41 34 566 9991 1000000
5 2 247645 309017803391
In the first test case, the ordered pairs for which Alice will win are $$$(1,1),(1,2),(1,3),(2,2)$$$ and $$$(3,3)$$$.
In the second test case, the ordered pairs for which Alice will win are $$$(4,4)$$$ and $$$(5,5)$$$.