An unsuccessful attempt to make solution for 1029 faster.