#!perl -pl sub f{substr$`,$_*"@_-1"}s//push@a,($_)=grep$a[-$_]-$_<(f gt f-2)&1le f,1.."@-"/ger