map{$_=reverse;y/()/)(/;for(/./g){$a+=/\(/;$e+=$d*/\)/;$b+=$a,$a=0if/\*/;$d+=$c,$c=$b,$b=0if/\^/}$a=$b=$c=$d=$e=!print"$e "}(<>)x2