Minimum steps to reach a point

A robot is designed to move forward by A steps and B steps backward alternatively.
It takes t seconds to move one step.Also there is two ditches Forward ditch and Backward Ditch.I need to find the minimum number of steps to reach any of forward or backward ditch.
input format:A B t Distance to backward ditch Distance to forward ditch
9 4 3 13 10
9 7 1 11 13
4 4 3 8 12
63 F (F :forward ditch)
25 F
No Ditch
Any hint please?

Oops. Its from a live contest I think ! Patience !!!