solved 27
solved 28
solved 29

improved algorithm of 28