<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def backtracking(a, L, bestsofar):
 """ Start with the heaviest weight and emit index """

    w, j = max(L.items())
    while j != -1:
        yield j
        w, j = bestsofar[j]