$rates = [5, 2, 5, 2, 5] $values = [500, 100, 50, 10, 5] def normalize cs 5.times {|i| cs[4 - i] += cs[5 - i] / $rates[4 - i] cs[5 - i] %= $rates[4 - i] } cs end def is_possible cs, t 5.times {|i| return false if cs[i] < t / $values[i] cs[i] -= t / $values[i] t %= $values[i] } r = $values.zip(cs).collect {|s| s[0] * s[1] }.sum + cs[5] return false if r < t true end a, b, c, d, e, f, g = gets.chomp.split.map &:to_i puts (is_possible(normalize([a, b, c, d, e, f]), g)) ? "YES" : "NO"