Company: UBS_VIT_Vellore
Difficulty: hard
UBS — AI Intern · VIT Vellore (On-campus) OA: 10 July 2026, 10 AM | Package: 14 LPA | CGPA cutoff: 7.5 | MTech eligible: No Eligibility: Only CSE – AI specialization You are given nums , an array of positive integers of size 2 * n . You must perform n operations on this array. In the i-th operation (1-indexed), you: Choose two elements, x and y . Receive a score of i * gcd(x, y) . Remove x and y from nums . Return the maximum score you can receive after performing n operations. The function gcd(x, y) is the greatest common divisor of x and y. Input Format The first line contains an integer M (= 2n), the size of the array. The second line contains M space-separated integers, the elements of nums . Output Format A single integer — the maximum score. Constraints 1 ≤ n ≤ 7 nums.length == 2 * n 1 ≤ nums[i] ≤ 10 6 Examples Input: 2 1 2 Output: 1 The only operation: 1 * gcd(1, 2) = 1. Input: 4 3 4 6 8 Output: