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