Alice Bob turn play game Alice start firstThere n stone arrange row on player turn number stone followingchoose integer x 1 remove leftmost x stone rowadd sum remove stone value player scoreplace new stone value equal sum leave rowthe game stop stone leave rowthe score difference Alice Bob Alices score Bobs score Alices goal maximize score difference Bobs goal minimize score differencegiven integer array stone length n stonesi represent value ith stone leave return score difference Alice Bob play optimally example 1input stone 12345output 5explanation Alice remove 4 stone add 1 2 3 4 2 score place stone value 2 leave stone 25 Bob remove 2 stone add 2 5 3 score place stone value 3 leave stone 3the difference score 2 3 5example 2input stone 76510526output 13explanation Alice remove stone add 7 6 5 10 5 2 6 13 score place stone value 13 leave stone 13the difference score 13 0 13example 3input stone 1012output 22explanation Alice remove stone she add 10 12 22 score place stone value 22 leave stone 22the difference score 22 0 22 Constraintsn stoneslength2 n 105104 stonesi 104