You are given a multiset (i. e. a set that can contain multiple equal integers) containing $$$2n$$$ integers. Determine if you can split it into exactly $$$n$$$ pairs (i. e. each element should be in exactly one pair) so that the sum of the two elements in each pair is odd (i. e. when divided by $$$2$$$, the remainder is $$$1$$$).
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1\leq t\leq 100$$$) — the number of test cases. The description of the test cases follows.
The first line of each test case contains an integer $$$n$$$ ($$$1\leq n\leq 100$$$).
The second line of each test case contains $$$2n$$$ integers $$$a_1,a_2,\dots, a_{2n}$$$ ($$$0\leq a_i\leq 100$$$) — the numbers in the set.
For each test case, print "Yes" if it can be split into exactly $$$n$$$ pairs so that the sum of the two elements in each pair is odd, and "No" otherwise. You can print each letter in any case.
5 2 2 3 4 5 3 2 3 4 5 5 5 1 2 4 1 2 3 4 1 5 3 2 6 7 3 4
Yes No No Yes No
In the first test case, a possible way of splitting the set is $$$(2,3)$$$, $$$(4,5)$$$.
In the second, third and fifth test case, we can prove that there isn't any possible way.
In the fourth test case, a possible way of splitting the set is $$$(2,3)$$$.
There is an infinite set generated as follows:
For example, when $$$a=3$$$ and $$$b=6$$$, the five smallest elements of the set are:
Given positive integers $$$a$$$, $$$b$$$, $$$n$$$, determine if $$$n$$$ is in this set.
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1\leq t\leq 10^5$$$) — the number of test cases. The description of the test cases follows.
The only line describing each test case contains three integers $$$n$$$, $$$a$$$, $$$b$$$ ($$$1\leq n,a,b\leq 10^9$$$) separated by a single space.
For each test case, print "Yes" if $$$n$$$ is in this set, and "No" otherwise. You can print each letter in any case.
5 24 3 5 10 3 6 2345 1 4 19260817 394 485 19260817 233 264
Yes No Yes No Yes
In the first test case, $$$24$$$ is generated as follows:
Thus we can see $$$24$$$ is in this set.
The five smallest elements of the set in the second test case is described in statements. We can see that $$$10$$$ isn't among them.
Let $$$f(i)$$$ denote the minimum positive integer $$$x$$$ such that $$$x$$$ is not a divisor of $$$i$$$.
Compute $$$\sum_{i=1}^n f(i)$$$ modulo $$$10^9+7$$$. In other words, compute $$$f(1)+f(2)+\dots+f(n)$$$ modulo $$$10^9+7$$$.
The first line contains a single integer $$$t$$$ ($$$1\leq t\leq 10^4$$$), the number of test cases. Then $$$t$$$ cases follow.
The only line of each test case contains a single integer $$$n$$$ ($$$1\leq n\leq 10^{16}$$$).
For each test case, output a single integer $$$ans$$$, where $$$ans=\sum_{i=1}^n f(i)$$$ modulo $$$10^9+7$$$.
6 1 2 3 4 10 10000000000000000
2 5 7 10 26 366580019
In the fourth test case $$$n=4$$$, so $$$ans=f(1)+f(2)+f(3)+f(4)$$$.
Therefore, $$$ans=f(1)+f(2)+f(3)+f(4)=2+3+2+3=10$$$.
You are given a sequence $$$A$$$, where its elements are either in the form + x or -, where $$$x$$$ is an integer.
For such a sequence $$$S$$$ where its elements are either in the form + x or -, define $$$f(S)$$$ as follows:
The sequence $$$b$$$ is a subsequence of the sequence $$$a$$$ if $$$b$$$ can be derived from $$$a$$$ by removing zero or more elements without changing the order of the remaining elements. For all $$$A$$$'s subsequences $$$B$$$, compute the sum of $$$f(B)$$$, modulo $$$998\,244\,353$$$.
The first line contains an integer $$$n$$$ ($$$1\leq n\leq 500$$$) — the length of $$$A$$$.
Each of the next $$$n$$$ lines begins with an operator + or -. If the operator is +, then it's followed by an integer $$$x$$$ ($$$1\le x \lt 998\,244\,353$$$). The $$$i$$$-th line of those $$$n$$$ lines describes the $$$i$$$-th element in $$$A$$$.
Print one integer, which is the answer to the problem, modulo $$$998\,244\,353$$$.
4 - + 1 + 2 -
16
15 + 2432543 - + 4567886 + 65638788 - + 578943 - - + 62356680 - + 711111 - + 998244352 - -
750759115
In the first example, the following are all possible pairs of $$$B$$$ and $$$f(B)$$$:
The sum of these values is $$$16$$$.
This is the easy version of the problem. The only difference between the easy version and the hard version is the constraints on $$$n$$$. You can only make hacks if both versions are solved.
A permutation of $$$1, 2, \ldots, n$$$ is a sequence of $$$n$$$ integers, where each integer from $$$1$$$ to $$$n$$$ appears exactly once. For example, $$$[2,3,1,4]$$$ is a permutation of $$$1, 2, 3, 4$$$, but $$$[1,4,2,2]$$$ isn't because $$$2$$$ appears twice in it.
Recall that the number of inversions in a permutation $$$a_1, a_2, \ldots, a_n$$$ is the number of pairs of indices $$$(i, j)$$$ such that $$$i \lt j$$$ and $$$a_i \gt a_j$$$.
Let $$$p$$$ and $$$q$$$ be two permutations of $$$1, 2, \ldots, n$$$. Find the number of permutation pairs $$$(p,q)$$$ that satisfy the following conditions:
Print the number of such pairs modulo $$$mod$$$. Note that $$$mod$$$ may not be a prime.
The only line contains two integers $$$n$$$ and $$$mod$$$ ($$$1\le n\le 50$$$, $$$1\le mod\le 10^9$$$).
Print one integer, which is the answer modulo $$$mod$$$.
4 403458273
17
The following are all valid pairs $$$(p,q)$$$ when $$$n=4$$$.
This is the hard version of the problem. The only difference between the easy version and the hard version is the constraints on $$$n$$$. You can only make hacks if both versions are solved.
A permutation of $$$1, 2, \ldots, n$$$ is a sequence of $$$n$$$ integers, where each integer from $$$1$$$ to $$$n$$$ appears exactly once. For example, $$$[2,3,1,4]$$$ is a permutation of $$$1, 2, 3, 4$$$, but $$$[1,4,2,2]$$$ isn't because $$$2$$$ appears twice in it.
Recall that the number of inversions in a permutation $$$a_1, a_2, \ldots, a_n$$$ is the number of pairs of indices $$$(i, j)$$$ such that $$$i \lt j$$$ and $$$a_i \gt a_j$$$.
Let $$$p$$$ and $$$q$$$ be two permutations of $$$1, 2, \ldots, n$$$. Find the number of permutation pairs $$$(p,q)$$$ that satisfy the following conditions:
Print the number of such pairs modulo $$$mod$$$. Note that $$$mod$$$ may not be a prime.
The only line contains two integers $$$n$$$ and $$$mod$$$ ($$$1\le n\le 500$$$, $$$1\le mod\le 10^9$$$).
Print one integer, which is the answer modulo $$$mod$$$.
4 403458273
17
The following are all valid pairs $$$(p,q)$$$ when $$$n=4$$$.