Two pirates were playing with golden coins. During game, the first pirate lost half of his coins to the second pirate, then the second pirate lost half of his coins to the first pirate, then again the first lost half of his coins to the second. At the end of the game, the first pirate had 21 coins, and the second had 45 coins. How many coins did the first pirate have initially?