The brackets groups act like cells, and the bigger cell “eats” the smaller one. Understanding this, we can write a simple Python script which parses the expression, finds the answer and eventually prints the flag. The code is this:
defsize(s): m=0 count=0 for i in range(len(s)): if s[i]=='(': count+=1 elif s[i]==')': m=max(m,count) count-=1 return m
defanswer(arr,s1): for i in range(len(arr)-1): if size(s1)>size(arr[i+1]): s1=s1[:-1]+arr[i+1]+')' elif size(s1)==size(arr[i+1]): s1=s1+arr[i+1] else: s1='('+s1+arr[i+1][1:] return s1