say {+$^c div($_=$^a-1+$^b)*$a+min $c%$_,+$a}(|get.words)