Improved solution for 1078. Still WA#2