Gold ends at a more than 3-week high as U.S. equities, dollar weaken