Second-best matrix chain multiplication optimization