def optimize(need, dest, eqs):
    req = need.copy()
    while any((((req[i] > 0) and (i != dest)) for i in req)):
        elt = [i for i in req if ((req[i] > 0) and (i != dest))][0]
        did = False
        others = []
        req = repl(elt, req, eqs[elt])
    return req[dest]
def optimize(need, dest, eqs):
    req = need.copy()
    while any((((req[i] > 0) and (i != dest)) for i in req)):
        elt = [i for i in req if ((req[i] > 0) and (i != dest))][0]
        did = False
        others = []
        req = repl(elt, req, eqs[elt])
    return req[dest]