Awesome Strings Question - Compressed Bracket Sequence

I need your help in understand the line paragraph of the editorial of Problem - 1556C - Codeforces

The next observation is that if we fix the number of opening brackets taken from 𝑐𝑙cl, then we can count the number of brackets that we should take from π‘π‘Ÿcr. Using these observations we can calculate the answer for π‘™β€¦π‘Ÿl…r using the following formula: π‘šπ‘–π‘›(𝑐𝑙,π‘π‘Ÿβˆ’π‘π‘Žπ‘™π‘Žπ‘›π‘π‘’)βˆ’π‘šπ‘Žπ‘₯(1,π‘šπ‘–π‘›π΅π‘Žπ‘™π‘Žπ‘›π‘π‘’)+1min(cl,crβˆ’balance)βˆ’max(1,minBalance)+1.

Could someone elaborate this formula possibly provide an example to understand it better?
AC Solution: Status - Codeforces

In the solution, please explain the left and right equations i.e; what exactly they are calculating

static long solve(int []c, int n){
    long ans=0;
    for(int l=0;l<n;l+=2){
      long min_balance=c[l];
      long balance=c[l];
      for(int r=l+1;r<n;r++){
        if(r%2==0){
          // adding the open brackets to cur
          balance+=c[r];
        }else{
          // 
          long left=Math.max(0, balance-c[r]);
          long right=Math.min(min_balance, Math.min(balance-1, c[l]-1));

          if(left<=right){
            ans+=right-left+1;
          }
          // removing closed brackets from open
          balance-=c[r];
          min_balance=Math.min(min_balance, balance);
        }
      }
    }
    return ans;
  }