Buggy python submission (verdict: Runtime Error):
import Queue
n = input()
p = []
for i in xrange(n):
    p.append(int(raw_input()))
dist = [10**7] * n
mark = [0]*n
que = Queue.PriorityQueue()
que.put((0, 0))
dist[0] = 0
idx = 0
while not que.empty():
    co, v = que.get()
    if dist[v] < co:
        continue
    for k in xrange(1, 7):
        idx += 1
        go = v+k
        while p[go]:
            go += p[go]
            if mark[go] == idx:
                go = -1
                break
            mark[go] = idx
        if go==-1:
            continue
        if go==n-1:
            print dist[v] + 1
            exit(0)
        if dist[v] + 1 < dist[go]:
            dist[go] = dist[v] + 1
            que.put((dist[go], go))

Fixed submission:
import Queue
INF = 10**9
n = input()
p = [i+int(raw_input()) for i in xrange(n)]

used = [0] * n
idx = 0
for i in xrange(n):
    if p[i]!=i:
        path = []
        go = i
        idx += 1
        while go!=INF and p[go]!=go:
            if used[go]==idx:
                go = INF
                break
            used[go] = idx
            path.append(go)
            go = p[go]
        for e in path:
            p[e] = go

dist = [INF] * n
que = Queue.Queue()
que.put(0)
dist[0] = 0
while not que.empty():
    v = que.get()
    for k in xrange(1, min(7, n-v)):
        go = p[v+k]
        if go==n-1:
            print dist[v]+1
            exit(0)
        if go!=INF and dist[v] + 1 < dist[go]:
            dist[go] = dist[v] + 1
            que.put(go)

Buggy python submission (verdict: Runtime Error):
import Queue
INF = 10**9+7
n = input()
p = []
for i in xrange(n):
    p.append(int(raw_input()))
dist = [10**7] * n
calc = [-1] * n
used = [False] * n
que = Queue.PriorityQueue()
que.put((0, 0))
dist[0] = 0
def dfs(pos, calc, used, f):
    if p[pos]==0:
        return pos
    if calc[pos]!=-1:
        return calc[pos]
    if used[pos]:
        return INF
    used[pos] = True
    calc[pos] = dfs(pos+p[pos], calc, used, p[pos])
    used[pos] = False
    return calc[pos]
while not que.empty():
    co, v = que.get()
    if dist[v] < co:
        continue
    for k in xrange(1, 7):
        go = v+k
        if go>=n:
            break
        if p[go] != 0:
            if calc[go]==-1:
                dfs(go, calc, used, 0)
            if calc[go]==INF:
                continue
            go = calc[go]
        if go==n-1:
            print dist[v]+1
            exit(0)
        if dist[v] + 1 < dist[go]:
            dist[go] = dist[v] + 1
            que.put((dist[go], go))

Fixed submission:
import Queue
INF = 10**9
n = input()
p = [i+int(raw_input()) for i in xrange(n)]

used = [0] * n
idx = 0
for i in xrange(n):
    if p[i]!=i:
        path = []
        go = i
        idx += 1
        while go!=INF and p[go]!=go:
            if used[go]==idx:
                go = INF
                break
            used[go] = idx
            path.append(go)
            go = p[go]
        for e in path:
            p[e] = go

dist = [INF] * n
que = Queue.Queue()
que.put(0)
dist[0] = 0
while not que.empty():
    v = que.get()
    for k in xrange(1, min(7, n-v)):
        go = p[v+k]
        if go==n-1:
            print dist[v]+1
            exit(0)
        if go!=INF and dist[v] + 1 < dist[go]:
            dist[go] = dist[v] + 1
            que.put(go)

Buggy python submission (verdict: Runtime Error):
import Queue, sys
INF = 10**9+7
n = input()
p = []
for i in xrange(n):
    p.append(int(raw_input()))
dist = [10**7] * n
calc = [-1] * n
used = [False] * n
que = Queue.PriorityQueue()
que.put((0, 0))
dist[0] = 0
sys.setrecursionlimit(10**5+7)
def dfs(pos, calc, used, f):
    if p[pos]==0:
        return pos
    if calc[pos]!=-1:
        return calc[pos]
    if used[pos]:
        return INF
    used[pos] = True
    calc[pos] = dfs(pos+p[pos], calc, used, p[pos])
    used[pos] = False
    return calc[pos]
while not que.empty():
    co, v = que.get()
    if dist[v] < co:
        continue
    for k in xrange(1, 7):
        go = v+k
        if go>=n:
            break
        if p[go] != 0:
            if calc[go]==-1:
                dfs(go, calc, used, 0)
            if calc[go]==INF:
                continue
            go = calc[go]
        if go==n-1:
            print dist[v]+1
            exit(0)
        if dist[v] + 1 < dist[go]:
            dist[go] = dist[v] + 1
            que.put((dist[go], go))

Fixed submission:
import Queue
INF = 10**9
n = input()
p = [i+int(raw_input()) for i in xrange(n)]

used = [0] * n
idx = 0
for i in xrange(n):
    if p[i]!=i:
        path = []
        go = i
        idx += 1
        while go!=INF and p[go]!=go:
            if used[go]==idx:
                go = INF
                break
            used[go] = idx
            path.append(go)
            go = p[go]
        for e in path:
            p[e] = go

dist = [INF] * n
que = Queue.Queue()
que.put(0)
dist[0] = 0
while not que.empty():
    v = que.get()
    for k in xrange(1, min(7, n-v)):
        go = p[v+k]
        if go==n-1:
            print dist[v]+1
            exit(0)
        if go!=INF and dist[v] + 1 < dist[go]:
            dist[go] = dist[v] + 1
            que.put(go)