<>;map$'?$@[$_+$']+=$-=$@[$_]+$`-$@[$_+$']:(${(a..c)[$@[$_]<=>$`]}=$_),reverse!/ | /..@@for<>;print$a||1,$/,$b?$b-1:inf