# Awesome Strings Question - Compressed Bracket Sequence

I need your help in understand the line paragraph of the editorial of https://codeforces.com/problemset/problem/1556/C

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: https://codeforces.com/problemset/status?my=on

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;
}
``````