# coins: [int; 6] = [500, 100, 50, 10, 5, 1] # 0 1 2 3 4 5 $rates = [5, 2, 5, 2, 5] $values = [500, 100, 50, 10, 5] def normalize coins 5.times {|i| coins[4 - i] += coins[5 - i] / $rates[4 - i] coins[5 - i] %= $rates[4 - i] } coins end def is_possible coins, target 5.times {|i| return false if coins[i] < target / $values[i] target %= $values[i] } return false if coins[5] < target 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"