To reach the winning post A will have to cover a distance of (500 - 140)m, i.e., 360 m.
While A covers 3 m, B covers 4 m.
While A covers 360 m, B covers4 / 3x 360 m = 480 m.
Thus, when A reaches the winning post, B covers 480 m and therefore remains 20 m behind.
A wins by 20 m.