Maximum Score with Co-Prime Element
Try each index and each final value, pay one change for each neighbour that shares a factor, and keep the best value minus cost.
Try each index and each final value, pay one change for each neighbour that shares a factor, and keep the best value minus cost.