B4. On a board with 28 rows and 37 columns, a number is written in each square with a red pen: in the top row from left to right the numbers 1 to 37, in the row below from left to right the numbers 38 to 74, and so on.

Then, with a green pen, a number is written again in each square, but now the numbers 1 to 28 go from top to bottom in the leftmost column, in the next column from top to bottom the numbers 29 to 56, and so on.

In the top-left square, the number 1 is now written in both red and green. Add up the red numbers, from all the squares where the red and green numbers are the same. What is the result?
B4. 5185 We number the rows from top to bottom 0 through 27 and the columns from left to right 0 through 36. Consider the cell in row $r$ and column $k$. The red number here is $1+k+37 r$ and the green number is $1+r+28 k$. These two numbers are equal precisely when $36 r=27 k$ or if $4 r=3 k$. The solutions are obtained by taking $r$ to be the multiples of three $0,3, \ldots, 27$ and for $k$ the corresponding multiples of four $0,4, \ldots, 36$. The corresponding colored numbers are $1,1+115,1+2 \cdot 115, \ldots, 1+9 \cdot 115$. Adding these ten numbers gives the answer: $(1+(1+9 \cdot 115)) \cdot 5=5185$.