mod = 998244353 N = gets.to_i A = Array.new(3) B = Array.new(3) (0..2).each do |i| A[i], B[i] = gets.split.map(&:to_i) end N2 = A[0]*A[1]*A[2]*3 ans = [B[0]*A[1]*A[2],A[0]*B[1]*A[2],A[0]*A[1]*B[2]].max * 3 * N.div(N2) % mod dp = Array.new(N2+1, 0) (0..N2).each do |i| (0..2).each do |j| dp[i+A[j]] = [dp[i+A[j]], dp[i]+B[j]].max if i+A[j] <= N2 end end puts (ans+dp[N%N2])%mod