You are playing a card game with your friends. Every card is marked with a positive integer. You start the game with 2N cards on your hand, and the game lasts N rounds. In each round, you have to remove 2 cards from your hand.
Your score in each round is gcd(card, card2) * round_number, where card and card2 are the cards that you removed and round_number is the current round. Your total score will be the sum of the scores that you received in each round.
What is the maximum total score that you can get?
Constraints
1 <= n <= 10, n represents the total number of rounds.
1 <= cards[i] <= 10^9, cards represents the array of the cards on your hand, and cards[i] represents the positive integer marked on card i.
The round_number starts from 1.
Example:
Input:
n = 3
cards = [8, 5, 6, 25, 6, 16]
Output:
41
Explanation:
The game can proceed as follow:
round_number 1: remove card = 5, card2 = 25, so gcd(5, 25) * round_number = 5 * 1 = 5.
round_number 2: remove card = 6, card2 = 6, so gcd(6, 6) * round_number = 6 * 2 = 12.
round_number 3: remove card = 8, card2 = 16, so gcd(8, 16) * round_number = 8 * 3 = 24.
The maximum total score is 5 + 12 + 24 = 41.
Copyright © A++ Code Bootcamp 2023