Stocks gain, commodities rise on inflation worries