you give array integer stones stonesi weight ith stoneWe playing game stone on turn choose heavy stone smash suppose heavy stone weight x y x y the result smash isIf x y stone destroy andIf x y stone weight x destroy stone weight y new weight y xAt end game stone leftReturn weight remain stone if stone leave return 0 example 1input stone 274181output 1explanation we combine 7 8 1 array convert 24111 thenwe combine 2 4 2 array convert 2111 thenwe combine 2 1 1 array convert 111 thenwe combine 1 1 0 array convert 1 that s value stoneexample 2input stone 1output 1 Constraints1 stoneslength 301 stonesi 1000