Maximum run between identical elements
Haskell, 62 bytes

f takes a list of integers and returns an integer.



f l=maximum[x+sum m-sum n|x:m&lt;-t l,y:n&lt;-t m,x==y]
t=scanr(:)[]


Try it online!

How it works


t is the standard "get all suffixes of a list without importing Data.List.tails" function.
In f l, the list comprehension iterates through all the non-empty suffixes of the argument list l, with first element x and remainder m.
For each, it does the same for all nonempty suffixes of m, selecting first element y and remainder n.
If x and y are equal, the list comprehension includes the sum of the elements between them. This sublist is the same as x:m with its suffix n stripped off, so the sum can be calculated as x+sum m-sum n.