def collapse(d,k1,k2,k3):
	"""
	For keys k1, k2 that cancel down to k3.
	"""

	if d[k1] > d[k2]:
		d[k3] += d[k2]
		d[k1] = d[k1] - d[k2]
		d[k2] = 0
	else:
		d[k3] += d[k1]
		d[k2] = d[k2] - d[k1]
		d[k1] = 0

	return d