Problem with logic of this pattern problem

join shbcf.ru