from collections import deque
n = int(input())
a = list(map(int, input().split()))
check = [-1] * len(a)
q = deque()
q.append(0)
check[0] = 0
while q:
x = q.popleft()
for i in range(1, a[x] + 1):
y = x + i
if y >= len(a):
continue
if check[y] == -1:
q.append(y)
check[y] = check[x] + 1
print(check[-1])
bfs 로 풀 수 있다
n = int(input())
a = list(map(int, input().split()))
check = [-1] * n
check[0] = 0
for i in range(n):
if check[i] == -1:
continue
for j in range(1, a[i] + 1):
if i + j >= n:
break
if check[i + j] == -1 or check[i] + 1 < check[i + j]:
check[i + j] = check[i] + 1
print(check[-1])
dp..