Stocks end up as indexes gain on the week