Valen had tarts and Japheth had cookies. Both gave half of what they had to each other. Valen sold 9 tarts and Japheth sold 37 cookies. In the end, the ratios of tarts to cookies for Valen and Japheth were 1 : 7 and 1 : 5 respectively. How many tarts did Valen have at first?