One day, Vogons wanted to build a new hyperspace highway through a distant system with $$$n$$$ planets. The $$$i$$$-th planet is on the orbit $$$a_i$$$, there could be multiple planets on the same orbit. It's a pity that all the planets are on the way and need to be destructed.
Vogons have two machines to do that.
Vogons can use each machine as many times as they want.
Vogons are very greedy, so they want to destroy all planets with minimum amount of money spent. Can you help them to know the minimum cost of this project?
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then the test cases follow.
Each test case consists of two lines.
The first line contains two integers $$$n$$$ and $$$c$$$ ($$$1 \le n, c \le 100$$$) — the number of planets and the cost of the second machine usage.
The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 100$$$), where $$$a_i$$$ is the orbit of the $$$i$$$-th planet.
For each test case print a single integer — the minimum cost of destroying all planets.
410 12 1 4 5 2 4 5 5 1 25 23 2 1 2 22 21 12 21 2
4 4 2 2
11 1001
1
In the first test case, the cost of using both machines is the same, so you can always use the second one and destroy all planets in orbit $$$1$$$, all planets in orbit $$$2$$$, all planets in orbit $$$4$$$, all planets in orbit $$$5$$$.
In the second test case, it is advantageous to use the second machine for $$$2$$$ Triganic Pus to destroy all the planets in orbit $$$2$$$, then destroy the remaining two planets using the first machine.
In the third test case, you can use the first machine twice or the second machine once.
In the fourth test case, it is advantageous to use the first machine twice.
$$$n$$$ people live on the coordinate line, the $$$i$$$-th one lives at the point $$$x_i$$$ ($$$1 \le i \le n$$$). They want to choose a position $$$x_0$$$ to meet. The $$$i$$$-th person will spend $$$|x_i - x_0|$$$ minutes to get to the meeting place. Also, the $$$i$$$-th person needs $$$t_i$$$ minutes to get dressed, so in total he or she needs $$$t_i + |x_i - x_0|$$$ minutes.
Here $$$|y|$$$ denotes the absolute value of $$$y$$$.
These people ask you to find a position $$$x_0$$$ that minimizes the time in which all $$$n$$$ people can gather at the meeting place.
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^3$$$) — the number of test cases. Then the test cases follow.
Each test case consists of three lines.
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of people.
The second line contains $$$n$$$ integers $$$x_1, x_2, \dots, x_n$$$ ($$$0 \le x_i \le 10^{8}$$$) — the positions of the people.
The third line contains $$$n$$$ integers $$$t_1, t_2, \dots, t_n$$$ ($$$0 \le t_i \le 10^{8}$$$), where $$$t_i$$$ is the time $$$i$$$-th person needs to get dressed.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
For each test case, print a single real number — the optimum position $$$x_0$$$. It can be shown that the optimal position $$$x_0$$$ is unique.
Your answer will be considered correct if its absolute or relative error does not exceed $$$10^{−6}$$$. Formally, let your answer be $$$a$$$, the jury's answer be $$$b$$$. Your answer will be considered correct if $$$\frac{|a−b|}{max(1,|b|)} \le 10^{−6}$$$.
710323 10 021 40 031 2 30 0 031 2 34 1 233 3 35 3 365 4 7 2 10 43 2 5 1 4 6
0 2 2.5 2 1 3 6
You have a string $$$s$$$ consisting of digits from $$$0$$$ to $$$9$$$ inclusive. You can perform the following operation any (possibly zero) number of times:
What is the lexicographically smallest string you can get by performing these operations?
A string $$$a$$$ is lexicographically smaller than a string $$$b$$$ of the same length if and only if the following holds:
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then the test cases follow.
Each test case consists of a single line that contains one string $$$s$$$ ($$$1 \le |s| \le 2 \cdot 10^5$$$) — the string consisting of digits. Please note that $$$s$$$ is just a string consisting of digits, so leading zeros are allowed.
It is guaranteed that the sum of lengths of $$$s$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
Print a single string — the minimum string that is possible to obtain.
404829901314752277691991
02599 9 01 111334567888999
In the first test case:
Nothing needs to be done in the second and third test cases.
You have two strings $$$s_1$$$ and $$$s_2$$$ of length $$$n$$$, consisting of lowercase English letters. You can perform the following operation any (possibly zero) number of times:
Is it possible to make these two strings equal by doing described operations?
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then the test cases follow.
Each test case consists of three lines.
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the length of the strings $$$s_1$$$ and $$$s_2$$$.
The second line contains the string $$$s_1$$$ of length $$$n$$$, consisting of lowercase English letters.
The third line contains the string $$$s_2$$$ of length $$$n$$$, consisting of lowercase English letters.
It is guaranteed that the sum of $$$n$$$ for all test cases does not exceed $$$2 \cdot 10^5$$$.
For each test case, print "YES" if it is possible to make the strings equal, and "NO" otherwise.
73cbcaba5abcaacbabb5abcaacbabz1aa1ab6abadaaadaaba8abcabdaaadabcaba
YES YES NO YES NO NO YES
In the first test case:
In the second test case:
In the third test case, it's impossible to make strings equal.
You are given an array $$$a_1, a_2, \ldots, a_n$$$ of positive integers.
Find the number of pairs of indices $$$(l, r)$$$, where $$$1 \le l \le r \le n$$$, that pass the check. The check is performed in the following manner:
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10$$$) — the number of test cases. Then the test cases follow.
Each test case consists of two lines.
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 5 \cdot 10^5$$$) — the size of the array.
The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^6$$$).
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$5 \cdot 10^5$$$.
For each test case, print a single integer — the number of pairs of indices that pass the check.
61122 422 342 4 7 14716 5 18 7 7 12 14616 14 2 6 16 2
1 3 2 7 10 19
Below $$$x \mid y$$$ denotes that $$$y$$$ is divisible by $$$x$$$.
In the first test case, there is one pair $$$(1, 1)$$$, the maximum for this pair is $$$1$$$, the minimum is also $$$1$$$, $$$1 \mid 1$$$, so the check is passed, and the answer is $$$1$$$.
In the second test case, there are $$$3$$$ segments:
In the third test case, there are $$$3$$$ segments:
You are given a permutation $$$p$$$ of length $$$n$$$ and a positive integer $$$k$$$. Consider a permutation $$$q$$$ of length $$$n$$$ such that for any integers $$$i$$$ and $$$j$$$, where $$$1 \le i \lt j \le n$$$, we have $$$$$$p_{q_i} \le p_{q_j} + k.$$$$$$
Find the minimum possible number of inversions in a permutation $$$q$$$.
A permutation is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).
An inversion in a permutation $$$a$$$ is a pair of indices $$$i$$$ and $$$j$$$ ($$$1 \le i, j \le n$$$) such that $$$i \lt j$$$, but $$$a_i \gt a_j$$$.
The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 5000$$$, $$$1 \le k \le 8$$$).
The second line contains $$$n$$$ distinct integers $$$p_1, p_2, \ldots, p_n$$$ ($$$1 \le p_i \le n$$$).
Print the minimum possible number of inversions in the permutation $$$q$$$.
1 1 1
0
3 1 2 3 1
1
5 2 5 4 3 2 1
6
10 3 5 8 6 10 2 7 4 1 9 3
18
In the first example, the only permutation is $$$q = [1]$$$ ($$$0$$$ inversions). Then $$$p_{q_1} = 1$$$.
In the second example, the only permutation with $$$1$$$ inversion is $$$q = [1, 3, 2]$$$. Then $$$p_{q_1} = 2$$$, $$$p_{q_2} = 1$$$, $$$p_{q_3} = 3$$$.
In the third example, one of the possible permutations with $$$6$$$ inversions is $$$q = [3, 4, 5, 1, 2]$$$. Then $$$p_{q_1} = 3$$$, $$$p_{q_2} = 2$$$, $$$p_{q_3} = 1$$$, $$$p_{q_4} = 5$$$, $$$p_{q_5} = 4$$$.