program main implicit none character*10000::S integer::numr=0,numr2,len integer::left=0,right=0 integer::i,j,status read *,S len = LEN_TRIM(S) do i=1,len if(S(i:i)==')') then numr = numr + 1 end if end do do i=1,len if(S(i:i)==')') then numr = numr - 1 if(numr.eq.0) exit cycle else if(S(i:i)/='(') then cycle end if numr2 = numr status = 0 do j=i+1,len if(S(j:j)==')') then numr2 = numr2 - 1 if(numr.eq.0) exit else if(S(j:j)=='^') then status = status + 1 else if(S(j:j)=='*') then if(status >= 2) then left = left + numr2 exit end if end if end do numr2 = numr status = 0 do j=i+1,len if(S(j:j)==')') then numr2 = numr2 - 1 if(numr.eq.0) exit else if(S(j:j)=='^') then status = status * 2 if(status == 4) then right = right + numr2 end if else if(S(j:j)=='*') then if(status == 0) then status = 1 end if end if end do end do print '(i0," ",i0)',left, right end program main