This is a overhaul of this now deleted question by ar kang. If the OP of that question would like to reclaim this question or has a problem with me posting this I'd be happy to accommodate
Given a list of integers as input find the maximum possible sum of a continuous sublist that starts and ends with the same value. The sublists must be of length at least 2. For example for the list
[1, 2, -2, 4, 1, 4]
There are 2 different continuous sublists start and end with the same value
[1,2,-2,4,1] -> 6
[4,1,4] -> 9
The bigger sum is 9 so you output 9.
You may assume every input contains at least 1 duplicate.
This is code-golf so answers will be scored in bytes with fewer bytes being better.
Test cases
[1,2,-2,4,1,4] -> 9
[1,2,1,2] -> 5
[-1,-2,-1,-2] -> -4
[1,1,1,8,-1,8] -> 15
[1,1,1,-1,6,-1] -> 4
[2,8,2,-3,2] -> 12
[1,1,80] -> 2
[2,8,2,3,2] -> 17
[2,8,2,3,2]
be 12 or 17? I presume 17. \$\endgroup\$