Answer:
The gambler came with $31.
Explanation:
Let x be the initial amount.
At the end of the first race at the track he had doubled his money, that is 2x.
He bet $31 on the second race and tripled the money he came with.
Means 3x.
He bet $51 on the third race and quadrupled his original bankroll that is 4x.
He bet $84 on the fourth race and lost it, but still had $40 left.
Summing all the values, we get;

=>

=>

=> x = 31
Hence, the gambler came with $31.