($n,$m,$k,$o,@b)=/\S+/gfor<>.<>;--$k;$#{$_}++,($_+=$_&-$_)>$k||redo for@b;map{$-='*'eq$o?$k/$_:$k-$_;0while$r+=@{$-},$--=$-&-$-}<>;print$n*$m-$r