You are given an integer $$$n$$$.
Construct a permutation $$$p$$$ of length $$$n$$$ such that for each $$$i$$$ $$$(1 \le i \le n-2)$$$, $$$(a_i+a_{i+1}) \mod 2 \neq (a_{i+1} + a_{i+2}) \mod 2$$$.
It is guaranteed that the answer always exists.
The first line contains a single integer $$$tc \: (1 \le tc \lt 1000)$$$ — the number of testcases.
The only line of each testcase contains a single integer $$$n \: (1 \le n \le 5\cdot 10^5)$$$.
It is guaranteed that the sum of $$$n$$$ over all the testcases doesn't exceed $$$5 \cdot 10^5$$$.
For each testcase, print a permutation $$$p$$$.
If there are multiple answers, print any.
512456
1 1 2 1 2 4 3 1 2 4 3 5 1 6 2 3 5 4
You are given two arrays $$$a$$$ and $$$b$$$, each of size $$$n$$$.
Count the number of good subarrays $$$[l,r]$$$.
A subarray $$$[l,r]$$$ is considered good if the following two conditions hold:
The first line of the input contains one single integer $$$tc$$$ $$$(1 \le tc \le 10^5)$$$ — the number of test cases.
The first line of each test case contains one single integer $$$n$$$ $$$(1 \le n \le 5 \cdot 10^5)$$$ — the length of the array.
The second line contains $$$n$$$ integers $$$a_i$$$ $$$(1 \le a_i \le 10^9)$$$ — the array $$$a$$$.
The third line contains $$$n$$$ integers $$$b_i$$$ $$$(1 \le b_i \le 10^9)$$$ — the array $$$b$$$.
It is guaranteed that the sum of $$$n$$$ over all testcases doesn't exceed $$$5 \cdot 10^5$$$.
For each test case print the number of good subarrays.
231 3 22 1 351 2 3 4 55 4 3 2 1
2 3
DGeneral Hamilton has $$$n^3$$$ small cubes of dimensions $$$1 \times 1 \times 1$$$. Each small cube has six faces numbered with the integers from $$$1$$$ to $$$6$$$, with each number appearing exactly once. The arrangement of these numbers on the faces is the same for all cubes (the small cubes are identical).
DGeneral Hamilton wants to build a large cube of dimensions $$$n \times n \times n$$$ using these small cubes. The large cube will also have $$$6$$$ faces, numbered from $$$1$$$ to $$$6$$$, with each number appearing exactly once. Each face will consist of $$$n \times n$$$ visible squares, where each visible square shows the number on the corresponding face of the small cube placed there.
DGeneral Hamilton wants to know, how many different large cubes can he form?
Two large cubes are considered different if there is at least one face and at least one visible square on that face where the number on that square is different between the two cubes. Remember that the faces are numbered.
Print the answer modulo $$$10^9 + 7$$$.
The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases.
Each of the next $$$t$$$ lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the dimension of the large cube DGeneral Hamilton wants to build. He has exactly $$$n^3$$$ small cubes.
For each test case, print a single integer — the number of different large cubes that can be formed modulo $$$10^9 + 7$$$.
212
24 75313406
You are given an array $$$a$$$ of $$$n$$$ integers, you can do this operation at most once:
Print the minimum size of a subset you can choose such that after performing the operation, the GCD (Greatest Common Divisor) of all elements of the array is greater than one. If the GCD is already greater than one without performing the operation, print $$$0$$$.
The first line of the input contains a single integer $$$n \: ( 1 \le n \le 10^6)$$$ — the size of the array $$$a$$$.
The second line contains $$$n$$$ integers $$$a_i (1 \le a_i \le 10^9)$$$ — the elements of the array $$$a$$$.
Print a single integer — the minimum size of the chosen subset or $$$0$$$ if the GCD is already greater than one.
51 2 3 4 5
3
We define the score of a permutation $$$p$$$ of length $$$n$$$ as following : $$$$$$ \sum_{i=2} ^n p_i \oplus p_{i-1} $$$$$$
Given $$$n$$$, find the expected value of the score of a random permutation of length $$$n$$$, modulo $$$10^9+7$$$.
Formally, let $$$M=10^9+7$$$. It can be shown that the answer can be expressed as an irreducible fraction $$$\frac{p}{q}$$$, where $$$p$$$ and $$$q$$$ are integers and $$$q\not\equiv 0(mod M)$$$. Output the integer equal to $$$p \cdot q^{-1} mod M$$$. In other words, output such an integer $$$x$$$ that $$$0 \leq x \lt M$$$ and $$$x \cdot q \equiv p (mod M)$$$.
The first line contains a single integer $$$tc :\ (1 \le tc \le 10^5)$$$ — the number of testcases.
The only line of each testcase contains a single integer $$$n \: (1 \le n \le 10^{9})$$$.
For each testcase, print the expected value of the score of a random permutation of length $$$n$$$, modulo $$$10^9+7$$$.
4124882
0312476632137
Ahmad is always tired.
He is so tired that he cannot make his small array beautiful :(
And by beautiful we mean that for $$$(2\le i\le n)$$$ $$$a_i \oplus a_{i-1}=X$$$ for some constant $$$X$$$.
By $$$\oplus$$$ we mean the well known xor operation.
You will be given Ahmad's array, what is the minimum number of bits you need to change so that Ahmad's array is beautiful?
The first line contains a single integer $$$tc \: (1\le tc \le 1000)$$$ — the number of testcases.
The first line of each test case contains a single integer $$$n \: (3\le n\le 1000)$$$.
The next line contains $$$n$$$ integers $$$a_i \: (1\le a_i \le 1000) $$$.
For each test case print one integer, the answer to the problem.
551 2 3 4 531 2 131 1 14100 200 300 4003100 1 1
4 0 0 7 4
in the first test case we change $$$4$$$ bits and the array becomes [$$$1,2,1,2,1$$$] and xor of any two adjacent numbers is $$$3$$$.
You are given $$$n$$$ squares, where the side length of the $$$i$$$-th square is $$$a_i$$$.
Your task is to count the number of triples $$$(i, j, k)$$$ where ($$$1 \le i \lt j \lt k \le n$$$) such that the three squares at indices $$$i, j,$$$ and $$$k$$$ can be arranged to form a rectangle without any gaps or overlaps.
A square is considered a special case of a rectangle.
The first line contains an integer $$$t$$$ ($$$1 \le t \le 2\cdot 10^5$$$) — the number of test cases.
The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 2\cdot 10^5$$$) — the number of squares.
The second line contains $$$n$$$ space-separated integers $$$a_i$$$ ($$$1 \le a_i \le 10^9$$$) — the side length of each square.
It is guaranteed that the sum of $$$n$$$ over all test cases will not exceed $$$2 \cdot 10^5$$$.
For each test case, print a single integer — the number of triples of squares that can form a rectangle.
253 3 3 3 541 2 3 4
4 0
In the first test case, the possible triples are: $$$(1, 2, 3)$$$, $$$(1, 2, 4)$$$, $$$(1, 3, 4)$$$, $$$(2, 3, 4)$$$.
Given a string $$$s$$$ of length $$$n$$$ consisting of lowercase English letters.
The concatenation of a sequence of strings is the string that results from writing down these strings in the order they appear in the sequence. For example, the concatenation of the sequence ["code"$$$,$$$ "force"$$$,$$$ "s"] is the string "codeforces".
A partition of the string $$$s$$$ is a sequence $$$a$$$ of strings such that if we concatenate the strings in the sequence, the result will be the string $$$s$$$. Note that there may exists more than one possible partition of the string.
We call a partition of the string $$$s$$$ good if the following holds:
The size of the partition is defined as the number of strings in that partition. Your task is to find the minimum size of a good partition.
The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — representing the number of testcases.
Each line of the next $$$t$$$ lines contains a string $$$s$$$ of length $$$|s|$$$ ($$$1 \le |s| \le 10^5$$$) — representing the string that is required to partition.
It's guaranteed that the sum of $$$|s|$$$ over all testcases doesn't exceed $$$10^5$$$.
For each testcase, print a new line containing a single integer representing the minimum size of a good partition.
3codeforcesacpcaywwaaaaa
2 2 6
You are given an array $$$a$$$ of $$$n$$$ integers, and a binary string $$$b$$$ of length $$$n$$$.
For each $$$i$$$ from $$$1$$$ to $$$n$$$ (in order), you will perform one of the following actions:
The first line of the input contains a single integer $$$tc$$$ $$$(1 \le tc \le 10^5)$$$ — the number of testcases.
The first line of each test case contains a single integer $$$n$$$ $$$(1 \le n \le 5 \cdot 10^5)$$$ — the length of the array.
The second line of each test case contains $$$n$$$ integers $$$a_i$$$ $$$(1 \le a_i \le n)$$$ — the array $$$a$$$.
The third line of each test case contains a binary string $$$b$$$ of length $$$n$$$.
It is guaranteed that the sum of $$$n$$$ over all testcases doesn't exceed $$$5 \cdot 10^5$$$.
For each test case, print the final array after performing all the operations.
231 2 311154 5 1 1 201101
3 1 2 2 1 5 4 1
Ahmad is very tired, so he decided to play Minecraft with his friend Apraham.
As soon as he entered the game, a guy named Steve gave him $$$2$$$ fully grown rabbits and disappeared.
Apraham, curious about how rabbits live in this world, made some observations:
Ahmad and Apraham now want to crash the server with these super cute rabbits UWU HeHe..
Today Ahmad has $$$2$$$ fully grown rabbits and he is so curious about how many rabbits will he have after n days.
As i said Ahmad is STILL tired so this mission is yours obviously :)
Since the final answer could be astronomically large, please output the result modulo $$$10^9+7$$$ .
Will you go down the rabbit hole?
The only line contains three integers $$$n,X,Y \: (1 \le n\le 10^{18})$$$ $$$(1\le X,Y\le 1000)$$$
Print a single integer , the number of rabbits Ahmad has after $$$n$$$ days mod $$$10^9+7$$$
2 2 3
10
20 2 3
8018
1000 4 5
641939610
in the first test case:
after two days Ahmad will get extra 8 rabbits so 2+8=10
You are given a tree of $$$n$$$ nodes. Each node $$$i$$$ has a value $$$a_i$$$. Count the number of simple paths where the LCM of the values of the nodes on the path equals $$$X$$$. In other words, count the number of pairs of nodes $$$u,v$$$ $$$(1 \le u \le v \le n)$$$ where the LCM(Least Common Multiple) of the values $$$a_i$$$ of the nodes on the simple path between $$$u$$$ and $$$v$$$ is equal to $$$X$$$.
The first line contains two integers $$$n,X \: (1 \le n \le 10^5)(1 \le X \le 10^6)$$$.
The second line contains $$$n$$$ integers $$$a_i \: (1 \le a_i \le 10^6)$$$ — the values of the nodes.
Each of the following $$$n-1$$$ lines contains two integers $$$u,v \: (1 \le u,v \le n)(u \neq v)$$$ — the edges of the tree.
It is guaranteed that the edges form a tree.
Print a single integer — the number of paths with LCM equal to $$$X$$$.
7 121 5 2 12 4 3 61 25 11 34 27 36 3
3
Given an array $$$a$$$ of length $$$n$$$ consisting of positive integers.
The average of a sequence $$$b$$$ of length $$$m$$$ is equal to $$$\frac{b_1 \text{ } + \text{ } b_2 \text{ } + \text{ } \dots \text{ } + \text{ } b_m}{m}$$$. Note that the average is not necessarily an integer.
A sequence $$$c$$$ is considered a subsequence of $$$a$$$ if we can obtain $$$c$$$ by removing some elements (possibly zero) from $$$a$$$ (not necessarily adjacent elements). For example, [$$$1$$$], [$$$1$$$, $$$3$$$] and [$$$1$$$, $$$2$$$, $$$4$$$, $$$6$$$, $$$1$$$, $$$3$$$] are all subsequences of [$$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$, $$$5$$$, $$$6$$$, $$$9$$$, $$$1$$$, $$$3$$$].
Your task is to find if there exists any subsequence of $$$a$$$ consisting of at least 2 elements, such that the average of this subsequnce is an integer.
The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^3$$$) — representing the number of testcases.
The first line of each testcase contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — representing the size of the array.
The second line of each testcase contains $$$n$$$ space-separated integers $$$a_1, a_2, ..., a_n$$$ ($$$1 \le a_i \le 10^9$$$) — representing the elements of the array.
It's guaranteed the sum of $$$n$$$ over all testcases doesn't exceed $$$10^5$$$.
For each testcase, print a new line containing a single word — YES if the answer exists and NO otherwise. The checker is not case-sensitive, meaning that responses like Yes, yES and yes will be considered positive responses and responses like No, nO and no will be treated as negative responses.
226 5710 9 8 7 6 5 4
NOYES
You are given an array of integers $$$m$$$ of length $$$n$$$.
You have to construct a rooted tree of $$$n$$$ nodes, such that for each node $$$x$$$, $$$m_x$$$ is equal to the mex of the nodes in the subtree of $$$x$$$. In other words, if we take the set of nodes in the subtree of node $$$x$$$, the mex(minimum excluded value) of this set should be equal to $$$m_x$$$.
Note that the tree should be $$$0$$$-indexed, the nodes should be numbered from $$$0$$$ to $$$n-1$$$.
The first line contains a single integer $$$tc \: (1 \le tc \le 10^5)$$$— the number of testcases.
The first line of each testcase contains a single integer $$$n \: (1 \le n \le 10^5)$$$.
The second line of each testcase consists of $$$n$$$ integers $$$m_i \: (0 \le m_i \le n)$$$.
It is guaranteed that there exists at least one solution for each tesctase.
It is guaranteed that the sum of $$$n$$$ overall testcases doesn't exceed $$$10^5$$$.
For each testcase, print $$$n$$$ lines.
On the first line print a single integer $$$root \: (0 \le root \le n-1)$$$ — the root of the tree.
On each of the next $$$n-1$$$ lines, print two integers $$$u,v \: (0 \le u,v \le n-1)$$$ — the edges of the tree.
If there are many answers, print any.
242 0 4 041 4 0 0
2 0 1 0 3 2 0 1 0 1 1 3 3 2