def best_type(dx, da, dc, ufflib, types):
    """Chooses the best UFF type according to neighborhood."""
    mincost = 1000.0
    mintyp = None
    for typ in types:
        xx, aa, cc = ufflib[typ]
        cost_x = (dx - xx) ** 2 / 2.5
        cost_a = (da - aa) ** 2 / 180.0
        cost_c = (dc - cc) ** 2 / 4.0
        cost = cost_x + cost_a + cost_c
        if cost < mincost:
            mintyp = typ
            mincost = cost
    return mintyp
