def METHOD_NAME(costs_x, x):
    for y, w in edges[x]:
        costs_y = costs[side[y]]
        cost_y = costs_y.get(y)
        if cost_y is not None:
            cost_y += 2 * (-w if costs_x is costs_y else w)
            costs_y.insert(y, cost_y, True)