Editorial for Count the squares

plz someone provide the Editorial for this problem