program main
    implicit none
    integer:: n, rate(2), i,j,k, dj,dk,dc, jj,kk
    integer:: inf = 10000, lowest, mul
    integer, allocatable:: med(:,:), cost(:), dp(:,:), ndp(:,:)

    read*, n, rate(1:2)
    allocate(med(2,n), cost(n), dp(0:n*10,0:n*10), ndp(0:n*10,0:n*10))
    
    do i = 1,n
        read*, med(1:2,i), cost(i)
    end do

    ndp(:,:) = inf
    dp(:,:) = inf

    ndp(0,0) = 0
    dp(0,0) = 0

    do i = 1, n
        dj = med(1,i)
        dk = med(2,i)
        dc = cost(i)
        do j = 0, n*10    
            do k = 0, n*10
                if (j+dj > n*10 .or. k+dk > n*10) cycle
                ndp(j+dj, k+dk) = min(ndp(j+dj,k+dk), dp(j,k)+dc)
            end do
        end do
        dp = ndp       
    end do
    lowest = inf
    mul = 1

    do while(maxval(rate)*mul <= 10*n)
        jj = rate(1)*mul
        kk = rate(2)*mul
        if (dp(jj,kk) < lowest)then
        endif
        lowest = min(lowest, dp(jj, kk))
        mul = mul + 1
    end do

    if(lowest < inf)then
        print'(i0)', lowest
    else
        print'(i0)', -1
    end if
    
end program