Wall Street posts gains for fourth week; ends flat for day