SmallR likes a game called "Deleting Substrings". In the game you are given a sequence of integers
w, you can modify the sequence and get points. The only type of modification you can perform is (unexpected, right?) deleting substrings. More formally, you can choose several contiguous elements of
w and delete them from the sequence. Let's denote the sequence of chosen elements as
wl,wl+1,...,wr. They must meet the conditions:
-
the equality |wi-wi+1|=1 must hold for all i (l≤i<r);
-
the inequality 2·wi-wi+1-wi-1≥0 must hold for all i (l<i<r).
After deleting the chosen substring of
w, you gain
vr-l+1 points. You can perform the described operation again and again while proper substrings exist. Also you can end the game at any time. Your task is to calculate the maximum total score you can get in the game.