program main implicit none integer*8::N,w,nw,i,comb,total character*100000::S read *,S nw = -1 comb = 0 total = 0 do i=LEN_TRIM(S),1,-1 if(S(i:i).eq.'w') then nw = nw + 1 comb = comb + nw else if(S(i:i).eq.'c') then total = total + comb end if end do print '(i0)', total end program main