Need Help with the Time Complexity of a DP Solution

Problem: Brackets

I wrote a dynamic programming solution to the above problem but can’t analyze its time complexity. Can someone please help?

In my code, f(l, r) is the maximum sum that can be obtained in the range [l, r].

EDIT: Can someone please confirm if it’s \mathcal{O}(n^3)?