Gold ends at highest in nearly 3 weeks; palladium at 16-year high