def distribute(N,nmax):
	"""
	Distribute N things into cells as equally as possible such that 
	no cell has more than nmax things.
	"""
	actual_max = int(2.*(nmax+1)/3.)
	numcells = int(round(N*1./actual_max))
	each_cell = [actual_max]*(numcells-1)
	rem = N-sum(each_cell)
	if rem>0: each_cell.append(rem)
	assert sum(each_cell)==N
	return each_cell