import qualified Data.Set as S import Data.Array import Data.List main = do n <- readLn a <- map read . words <$> getLine :: IO [Int] let g = accumArray (flip (:)) [] (0, n) $ zip a [1..] dfs s i x = foldl' (\y j -> dfs (S.insert j s) j y) (S.findIndex i s + x) (g ! i) print $ dfs (S.singleton 0) 0 0