S&P 500 hits record, posts third weekly gain