ary = gets.split.map(&:to_i) price = [500, 100, 50, 10, 5, 1] g = ary[6] dp = Array.new(g + 1, -1) dp[0] = 0 6.times do |i| (g + 1).times do |j| if dp[j] >= 0 dp[j] = ary[i] elsif j < price[i] || dp[j - price[i]] <= 0 dp[j] = -1 else dp[j] = dp[j - price[i]] - 1 end end end if dp[g] >= 0 puts "YES" else puts "NO" end