Solution for flowers problem