Brian had 3 times as much money as Rahim. Brian spent $158 of his money to buy a birthday gift for his grandma while Rahim was awarded $42 for winning a competition. In the end, they had the same amount of money. How much did they have altogether at first?