Optimal variable length codes