a = gets.split.map(&:to_i) coin = [500, 100, 50, 10, 5, 1] s = a[6] 6.times do |i| while s >= coin[i] && a[i] > 0 s -= coin[i] a[i] -= 1 end end if s == 0 puts "YES" else puts "NO" end