diff = Array.new
ans = Array.new
chenge = Array.new
loop do
  num = gets.chomp!.to_i
  if num == 0
    break
  else
  end
  pi = gets.chomp!.split(/\s/)
  pi.size.times do |i|
    pi[i] = pi[i].to_i
  end
  jo = gets.chomp!.split(/\s/)
  jo.size.times do |j|
    jo[j] = jo[j].to_i
  end
  pi.size.times do |k|
    chenge[k] = 0
  end
  (pi.size - 1).times do |l|
    diff[l] = jo[l] - (pi[l] + pi[l + 1])
  end
  renge = 0
  (pi.size - 1).times do |m|
    if (pi[m] + pi[m + 1]) < jo[m] && chenge[m] == 0
      if m == (pi.size - 2)
        ans[renge] = (pi[m] + pi[m + 1] + jo[m])
        chenge[m + 1] = 1
        renge = renge + 1
      else
        if diff[m] >= diff[m + 1]
          ans[renge] = pi[m] + pi[m + 1] + jo[m]
          chenge[m + 1] = 1
          renge = renge + 1
        else
        end
      end
    else
      if chenge[m] == 1
      else
        ans[renge] = pi[m]
        renge = renge + 1
      end
    end
  end
  if chenge[pi.size - 1] == 0
    ans[renge] = pi[pi.size - 1]
  else
  end
  print ans
  sum = 0
  ans.each do |n|
    sum = sum + n
  end
  fin = ans.size * sum
  puts fin
end      