N = gets.to_i A, B, C = gets.split.map(&:to_i) dp = Array.new(N+1, 0) (0..N-3).each do |i| dp[i+3] = [dp[i+3], dp[i]+A].max if i+3 <= N dp[i+5] = [dp[i+5], dp[i]+B].max if i+5 <= N dp[i+10] = [dp[i+10], dp[i]+C].max if i+10 <= N end puts dp.max