# [Perl 5], <s>156</s> 147 bytes

<!-- language-all: lang-perl -->

    $q='$F[$i';map{eval"\$i++while$q]$_"}"<$q+1]",">$q+1]&&$q]>$q+2]&&\$i<\@F"if eval"$q-1]-$q+1]||$q]>$q+1]";$\.=$".sum@F[$p..$i];($p=++$i)<@F&&redo}{

[Try it online!][TIO-jvy6gki7]

[Perl 5]: https://www.perl.org/
[TIO-jvy6gki7]: https://tio.run/##LY3LDoIwEEV/hTSToqltWhM2PAwrVrp0JcSQWOMkIOWhLoBft1bC5s5J5twZo7sqsBbaxIfsAuhHdWlG/S4rkgMy9nlgpaEt4EpmEkPLVEF25LAApW7xx71DZ8d5mhG8e0sbWq4KvnjTtHquG0EuEiCif9Wp@2eEACyiDZiEMcBtnGaUdvrWzKO1Snoq8PYu5ZpKfhszYPPsLT8FQirp5hH7IQzPA1aJu2p5aX4 "Perl 5 – Try It Online"