def min(a,b); a < b ? a : b; end N = gets.to_i X = gets.split.map(&:to_i) Y = gets.split.map(&:to_i) L = N.times.inject(Float::INFINITY) do |d,i| min(d, X[i] + Y[i]) end P = Array.new(N + 2, 0) P[0] = 0 P[N + 1] = L N.times do |i| P[i + 1] = min(L, X[i]) end puts L puts P