Problem 3351 · Hard

Sum of Good Subsequences

Track, for each value, how many good subsequences end with it and their total sum, so each new element extends only its neighbours in value.

Open the interactive visualisation