The problem of two trains

(author unknown)
It is believed that if you can solve this problem, you have a mentality of a programmer. But this is not necessary true :) Do you want to try?