Ben had macarons and Bryan had cookies. Both gave half of what they had to each other. Ben sold 9 macarons and Bryan sold 36 cookies. In the end, the ratios of macarons to cookies for Ben and Bryan were 1 : 6 and 1 : 4 respectively. How many macarons did Ben have at first?