Stone Game VIII

Alice and Bob take turns removing stones from a row, with Alice going first.

During a player's turn, they must remove at least 2 piles from the left end. The player receives points equal to the sum of all removed piles.

The twist: Each turn, a player chooses to either:

  • Take exactly 2 piles from the left, or
  • Take the same number of piles as the opponent took on the previous turn (must be at least 2).

Alice's first move must be taking exactly 2 piles. Assuming both play optimally, return the maximum score difference (Alice minus Bob).

Examples
Input: [-1,2,-3,4,-5]
Output: 5
Hints

Stone Game VIII

Alice and Bob take turns removing stones from a row, with Alice going first.