n = gets.to_i
a = gets.strip.split.map(&:to_i)
b = gets.strip.split.map(&:to_i)

sum = 0
i = 0
s = b[0]
while i<n-1 do
  if a[i]>=s
    sum += s
    s = b[i+1]
  else
    sum += a[i]
    s = b[i+1]+(s-a[i])
  end
  i += 1
end
sum += [s,a[n-1]+a[n]].min

c = a.reverse
d = b.reverse
tum = 0
i = 0
s = d[0]
while i<n-1 do
  if c[i]>=s
    tum += s
    s = d[i+1]
  else
    tum += c[i]
    s = d[i+1]+(s-c[i])
  end
  i += 1
end
tum += [s,c[n-1]+c[n]].min

puts [sum,tum].min

