f=open("in20_2.txt",'r') out=open("out_32_20_2.txt",'w') n=int(f.readline()) for i in range(1,4): exp1=f.readline() exp=[] for i in range(0,len(exp1)): if str(exp1[i])=='\n': tt=0 else: exp.append(exp1[i]) stack=[] stack.append(exp[0]) #print stack while( len(stack) != 0 ): for i in range(1,len(exp)): if ( str(exp[i]) != ')'): stack.append(exp[i]) else: inn=len(stack)-1 str1=stack[inn-2]+stack[inn]+stack[inn-1] stack.pop() stack.pop() stack.pop() stack.pop() stack.append(str1) if(len(stack)==1): break out.write(str(stack)+"\n") f.close() out.close()