def boggle_neighbors(n2, cache={}):
if cache.get(n2):<EOL><INDENT>return cache.get(n2)<EOL><DEDENT>n = exact_sqrt(n2)<EOL>neighbors = [None] * n2<EOL>for i in range(n2):<EOL><INDENT>neighbors[i] = []<EOL>on_top = i < n<EOL>on_bottom = i >= n2 - n<EOL>on_left = i % n == <NUM_LIT:0><EOL>on_right = (i+<NUM_LIT:1>) % n == <NUM_LIT:0><EOL>if not on_top:<EOL><INDENT>neighbors[i].append(i - n)<EOL>if not on_left:  neighbors[i].append(i - n - <NUM_LIT:1>)<EOL>if not on_right: neighbors[i].append(i - n + <NUM_LIT:1>)<EOL><DEDENT>if not on_bottom:<EOL><INDENT>neighbors[i].append(i + n)<EOL>if not on_left:  neighbors[i].append(i + n - <NUM_LIT:1>)<EOL>if not on_right: neighbors[i].append(i + n + <NUM_LIT:1>)<EOL><DEDENT>if not on_left: neighbors[i].append(i - <NUM_LIT:1>)<EOL>if not on_right: neighbors[i].append(i + <NUM_LIT:1>)<EOL><DEDENT>cache[n2] = neighbors<EOL>return neighbors<EOL>
Return a list of lists, where the i-th element is the list of indexes
    for the neighbors of square i.