def get_grid_power(left_x, top_y, power_sums, size):
    """
    Given the top x and y values and the size of the grid to compute, this function uses the
    power sum grid to return the grid power in constant time.
    """
    # Get the far ends
    right_x = min(left_x + size - 1, 299)
    bottom_y = min(top_y + size - 1, 299)

    #print(left_x, top_y)
    return (
        power_sums[right_x][bottom_y]
        - (power_sums[left_x-1][bottom_y] if left_x != 0 else 0)
        - (power_sums[right_x][top_y-1] if top_y != 0 else 0)
        + (power_sums[left_x-1][top_y-1] if left_x != 0 and top_y != 0 else 0)
    )
    #power = 0
    #for x in range(left_x, left_x+size):
        #for y in range(top_y, top_y+size):
            #try:
                #power += grid[x][y]
            #except IndexError:
                #pass

    #return power