program main implicit none character*10000::S character::c integer*8::i,j,len integer*8::left(5),right(5) data left/5*0/,right/5*0/ read *,S len = LEN_TRIM(S) do i=1,len c = S(i:i) if(c.eq.'(') then left(1) = left(1) + 1 right(1) = right(1) + 1 else if(c.eq.'^') then left(3) = left(3) + left(2) left(2) = left(1) left(1) = 0 right(4) = right(4) + right(3) right(3) = right(2) right(2) = 0 else if(c.eq.'*') then left(4) = left(4) + left(3) left(3) = 0 right(2) = right(2) + right(1) right(1) = 0 else if(c.eq.')') then left(5) = left(5) + left(4) right(5) = right(5) + right(4) end if end do print '(i0," ",i0)',left(5), right(5) end program main