n*(n*n + 1) / 2 where n is the size of squares. So,
for 3x3, n = 3, and therefore 3*(3*3 + 1) / 2 = 30 / 2 = 15.
For 4x4, n = 4, and therefore 4*(4*4 + 1) / 2 = 68 / 2 = 34.