#!perl -plaF $l=1;$v=M999D499C99L49X9V4I=~$d+$' and$_+=($v<$l?-1:1)*($l=$v)while$d=pop@F