A store sells hardcover books for $8 and paperback books for $5. You buy 9 books, represented by the equation x+y=9, where x is the number of hardcover books and y is the number of paperback books. The equation 8x+5y=51 represents the total cost. How many of each type of book did you buy?