Karan, who owns a shop at an exhibition, is planning to launch a promotion where customers receive free items with the purchase of specific items. He has chosen a few items for this special offer, which he's called the "Buzz Day Sale." Additionally, there are unlimited quantities available for each item type.
He assigned a unique ID to each item basis it's worth and put up a board that reads, "For every purchase of an item with ID K, all other items with IDs that are factors of K, will be free."
Veda visited Karan's shop on Buzz Day with the aim of acquiring as many items as possible while carrying a limited amount of money, A. If there are several ways to maximize the number of free items, she will strive to maximize the total worth of the items she receives freely.
Given the IDs of all the items offered in the sale and their costs, determine the maximum number of items Veda can receive for free and the maximum total worth of those items.