= 2 && $steps <= 1000000) { foreach ($topography as $step) { if ($step == 'U') { $cnt++; } elseif ($step == 'D') { $cnt--; } if ($cnt < 0) { if ($prevcnt >= 0) { $valley++; } } $prevcnt = $cnt; } echo $valley; } ?>