Let D be the total distance to the library.

Let d be the distance covered running *to* the library.

This means D - d is the distance covered walking *to* the library.

From the problem you know d/(12 km/h) + (D-d)/(8 km/h) = 20 min

The distance covered running *from* the library is 2d.

This means D - 2d is the distance covered walking *from* the library.

From the problem you know 2d/(12 km/h) + (D - 2d)/(8 km/h) = 17.5 min

Solve for D