#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define pb push_back
using i64 = long long;
template<typename T>
using vec = vector<T>;
using pi = pair<int,int>;
template<typename T,size_t n>
using arr = array<T,n>;
int n;
vec<int> x,y;
int32_t main(){
ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
cin >> n;
int sum = 0;
x.assign(n,0);
y.assign(n,0);
for (int i = 0; i < n; i++) cin >> x[i];
for (int i = 0; i < n; i++){
cin >> y[i];
sum += y[i];
}
int i = n-1,j = n-1;
int total = 0,up = 0,notr = 0;
for (int i = n-1; i > -1; i--){
int mn = min(total,x[i]);
up += mn;
total -= mn;
x[i] -= mn;
mn = min(notr,x[i]);
up += mn;
notr -= mn;
x[i] -= mn;
int mn2 = min(x[i],y[i]);
notr += mn2;
y[i] -= mn2;
total += y[i];
}
// cout << up << " " << notr << " " << sum << '\n';
cout << 2 * up + notr - sum << '\n';
return 0;
}