program mixing_experiment
  implicit none
  integer :: n, ma, mb, a, b, c, dp(0:400,0:400)
  integer :: i, ia, ib, m
  integer, parameter :: infty = 10000000
  dp = infty
  read(*,*) n, ma, mb
  dp(0,0) = 0
  do i = 1, n
    read(*,*) a, b, c
    do ia = 400, a, -1
      do ib = 400, b, -1
        dp(ia,ib) = min(dp(ia,ib),dp(ia-a,ib-b)+c)
      end do
    end do
  end do
  m = infty
  do i = 1, 400/ma
    ia = i*ma
    ib = i*mb
    if (ib.gt.400) exit
    m = min(dp(ia,ib),m)
  end do
  if (m.eq.infty) then
    write(*,'(i0)') -1
  else
    write(*,'(i0)') m
  end if
  stop
end program mixing_experiment