In this two by two grid, the total length of all twelve line segments is twelve units. In a similar forty by forty grid of squares that are the same size, what is the total length of all line segments?

For a forty by forty grid of squares, the total length of all line segments is 3460.