A farmer has 242 goats and sheep in total. He sells half of the goats and buys 28 more sheep. In the end he has three times as many sheep as goats. How many sheep did he have to start with?

A farmer has 242 goats and sheep in total. He sells half of the goats and buys 28 more sheep. In the end he has three times as many sheep as goats. How many sheep did he have to start with?