def f(seq, num):
arr = [0]*1000
arr[0] = 1
index = 0
for count, n in zip(range(2,num), seq):
back = index-n
forw = index+n
if back >= 0 and arr[back]==0:
arr[back]=count
index=back
elif arr[forw]==0:
arr[forw]=count
index=forw
else:
print(f"Stuck at {n}: {index}.")
return arr