Lengths of lines in a Square Grid on an A4 page

d = 1 (slider from 0 to 5, step 0.01)
n = 15 (slider from 0 to 40, step 1)
m = 10 (slider from 0 to 40, step 1)
pSumBlue = Sequence(Sum[Sequence[Segment[(i * d, j * d), (d * (i + 1), d * j)], i, 0, m - 1]], j, 0, n)
SumBlue = Sum(pSumBlue)
pSumRed = Sequence(Sum[Sequence[Segment[(i * d, j * d), (i * d, (j + 1) * d)], i, 0, m]], j, 0, n - 1)
SumRed = Sum(pSumRed)
TotalLineLength: SumBlue + SumRed
list1 = Sequence(Sequence[(d * i, d * j), i, 0, m], j, 0, n)
list2 = Sequence(Sequence[Segment[(i * d, j * d), (d * (i + 1), d * j)], i, 0, m - 1], j, 0, n)
list3 = Sequence(Sequence[Segment[(i * d, j * d), (i * d, (j + 1) * d)], i, 0, m], j, 0, n - 1)
A = Intersect(a, e)
B = Intersect(b, e)
C = Intersect(b, c)
D = Intersect(a, c)
poly1, a_1, b_1, c_1, d_1 = Polygon(A, B, C, D)
text1: "Length of lines = " + TotalLineLength + ""