The array nums contains 2*n positive integers. Perform exactly n operations, numbered from 1 through n. On operation i, choose two remaining elements x and y, add i * gcd(x,y) to your score, and remove both elements. Here gcd is the greatest common divisor. Return the largest total score possible. Equal values at different indices are separate elements, and the order in which you remove pairs affects the score.
Example 1:
Input: nums = [2,4]
Output: 2Explanation: There is one operation. The greatest common divisor of 2 and 4 is 2, so the total is 1 × 2=2.
Example 2:
Input: nums = [2,2,3,3]
Output: 8Explanation: Remove the two 2s first for 1 × 2 points, then the two 3s for 2 × 3 points. The total is 8. Pairing a 2 with a 3 instead gives smaller greatest common divisors.
Example 3:
Input: nums = [5,5,5,5]
Output: 15Explanation: Every pair has greatest common divisor 5. The two operations contribute 1 × 5 and 2 × 5, for a total of 15.
Constraints:
nums.length == 2*n, where1 <= n <= 7.1 <= nums[i] <= 1000000.