Robi and Aritro are good friends and math enthusiasts who frequently debate over who has the ultimate mathematical rizz and aura. To settle the debate and prove that he is the absolute goat, Aritro challenges Robi with a problem that targets his weakness in numbers. If Robi loses, Aritro pulls all the huzz; if Robi wins, his rizz is unmatched.
Aritro gives him an array $$$a$$$ of $$$n$$$ distinct integers greater than 1. Using normal numbers is lowkey mid for Aritro. Instead, he uses prime powers! Each element $$$a_i$$$ is a prime power, meaning that $$$a_i = p^q$$$ for some prime $$$p$$$ and integer $$$q \ge 1$$$.
Aritro challenges Robi to choose $$$k$$$ indices, where $$$1 \le k \le n$$$, satisfying $$$i_1 \lt i_2 \lt \dots \lt i_k$$$ such that the corresponding array values form a strictly increasing subsequence. More formally, the chosen elements must satisfy:
$$$$$$a_{i_1} \lt a_{i_2} \lt \dots \lt a_{i_k}$$$$$$
Let $$$f(a_i) = q$$$ denote the exponent of $$$a_i$$$. Robi must choose a subsequence whose total exponent sum is as large as possible. More formally, output:
$$$$$$\sum_{j=1}^{k} f(a_{i_j})$$$$$$
Output the maximum possible value of this sum.
Constraints
Subtasks
| Subtask | Points | Add. constraints |
| $$$1$$$ | $$$5$$$ | $$$n = 1$$$, $$$a[i] \le 10^6$$$ |
| $$$2$$$ | $$$8$$$ | $$$n \le 16$$$, $$$q = 1$$$ |
| $$$3$$$ | $$$7$$$ | $$$n \le 16$$$, $$$a[i] \le 10^6$$$ |
| $$$4$$$ | $$$15$$$ | $$$n = 1$$$ |
| $$$5$$$ | $$$10$$$ | $$$ n \le 16$$$ |
| $$$6$$$ | $$$15$$$ | $$$q=1$$$ |
| $$$7$$$ | $$$40$$$ | No additional constraints |
4 16 27 3 2
7
In the first example, the prime power representations of the elements are:
The optimal strictly increasing subsequence is $$$[16, 27]$$$, obtained by choosing $$$i_1 = 1$$$ and $$$i_2 = 2$$$. The maximum possible sum of the exponents is $$$f(16) + f(27) = 4 + 3 = 7$$$.
Robi is the greatest technician who ever lived. He came to visit his friend Aritro's house, where Aritro was proudly showing off his new Wi-Fi connection. Robi also wanted to test it, but asking Aritro for the Wi-Fi password would be far too ordinary for a technician of his caliber. Using his special software, Robi found the password; however, he still had to solve the puzzle given by the system to access it.
Robi has discovered two arrays of $$$n$$$ integers, $$$A$$$ and $$$B$$$. You can perform the following operation at most once:
For two arrays $$$A$$$ and $$$B$$$ of the same length, define
$$$$$$F(A, B) = \min|\text{MEX}(A) - \text{MEX}(B)|$$$$$$
where the minimum is taken over all possible ways of performing the operation above, including not performing any swap. In other words, $$$F(A, B)$$$ is the smallest possible gap between the two $$$\text{MEX}$$$ values that you can achieve by performing at most one swap.
Robi must compute, for every prefix length from $$$1$$$ to $$$n$$$, the value $$$F$$$ for that prefix. That is, for each $$$k$$$ ($$$1 \le k \le n$$$), he needs to do the following:
$$$$$$F\big(A[0 \dots k-1],\; B[0 \dots k-1]\big).$$$$$$
In other words, he must compute the function for every prefix of the arrays. For each prefix, the difference between the two $$$\text{MEX}$$$ values must be minimized.
Each prefix is evaluated independently; a swap performed for one prefix does not affect any other prefix.
Help Robi solve the puzzle!
Constraints
Subtasks
| Subtask | Points | Add. constraints |
| $$$1$$$ | $$$5$$$ | $$$n=10, A[i]=B[i]$$$ |
| $$$2$$$ | $$$15$$$ | $$$A[i]$$$ is even |
| $$$3$$$ | $$$15$$$ | $$$ n \le 1000$$$ |
| $$$4$$$ | $$$20$$$ | $$$ n \le 5000$$$ |
| $$$5$$$ | $$$45$$$ | No additional constraints |
5 0 1 2 3 4 0 1 1 2 3
0 0 1 1 1
4 0 4 2 2 1 1 0 2
1 1 1 0
$$$\text{MEX}(A)$$$ is defined as the smallest non-negative integer that is not present in the array. For example, $$$\text{MEX}([1,2,0,5])$$$ is $$$3$$$, and $$$\text{MEX}([1,2,4,9])$$$ is $$$0$$$.
In the second example, for every index $$$i$$$, we compute as follows:
Ibor bought $$$n$$$ boxes of candies, and each box contains exactly $$$n$$$ candies.There is exactly one special box among them. All candies in this special box have a taste value of $$$v$$$, while all candies in the other $$$n - 1$$$ normal boxes have a taste value of $$$w$$$. It is guaranteed that the special candies taste better than the normal ones ($$$v \gt w$$$).
You are given the number of boxes, $$$n$$$. You need to figure out the normal taste $$$w$$$, the special taste $$$v$$$, and the 1-based index of the special candy box. To do this, you can ask Ibor to do the following procedure :
Implementation Details
You should implement the following procedure:
std::vector< long long > find_candy(int n,int q)
The above procedure can make calls to the following procedure:
long long taste_candy(std::vector< long long > a)
Your code must not scan anything from the standard input (i.e. use scanf or cin) or print anything to the standard output (i.e. use printf or cout). However, you can print debugging information to stderr. For communication, use the functions described above. The grader is not adaptive. Meaning the value of $$$w$$$ $$$v$$$ $$$idx$$$ is fixed before a call to find_candy is made.
Constraints
Input format:
Output format:
Here, $$$A$$$ is the output of find_candy, $$$B$$$ is the original solution,$$$X$$$ is the number of all calls to taste_candy.
Note that the grader used for actual evaluation is different from the sample grader.
| Subtask | Points | Add. constraints |
| $$$1$$$ | $$$40$$$ | $$$v=w+1, q=2$$$ |
| $$$2$$$ | $$$60$$$ | No additional constraints |
For the last subtask, your score is determined using a formula. Let's assume you asked Ibor total $$$X$$$ number of times. Your final score will be calculated using the following table:
| X | Score |
| $$$X \gt 10^4$$$ | $$$0$$$ |
| $$$10 \lt X \le 10^4 $$$ | $$$40 \times \left( 1.15 - \left(\dfrac{\log_{10} X}{4}\right)^2 \right)$$$ |
| $$$X \le 10$$$ | 60 |
10 2 6 7 6
Returned: {6, 7, 6}
Expected: {6, 7, 6}
Queries: 2
Let's consider the following case.
$$$$$$n = 4,\quad q = 10000,\quad w = 6,\quad v = 7,\quad idx = 3$$$$$$
The following call will be made.
find_candy(4, 10000)
This procedure may call taste_candy as follows:
taste_candy({1, 1, 1, 1})
Suppose the query is made using the array $$$a$$$: $$$$$$a = [1, 1, 1, 1]$$$$$$
Since box 3 is special, taste_candy(a) returns:
$$$$$$ (1 \times 6) + (1 \times 6) + (1 \times 7) + (1 \times 6) = 25. $$$$$$
Using the returned values from the queries, you must determine $$$w$$$, $$$v$$$, and $$$idx$$$.