import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Main main = new Main();
        main.solve();
    }
    public void solve() throws Exception {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        long[] a_o = new long[N + 1];
        long[] a_f = new long[N + 1];
        long[] a_b = new long[N + 1];
        for (int i = 0; i < N + 1; i++) {
            a_f[i] = scan.nextLong();
            a_b[i] = a_f[i];
            a_o[i] = a_f[i];
        }
        long[] b_f = new long[N + 1];
        long[] b_b = new long[N + 1];
        for (int i = 0; i < N; i++) {
            b_f[i] = scan.nextLong();
            b_b[i] = b_f[i];
        }
        long answer = front(N, a_o, a_f, b_f);
        answer = Math.max(answer,back(N, a_o, a_f, b_f));
        System.out.println(answer);
    }
    private long front(int N, long[] o, long[] a, long[] b) {
        for (int i = 0; i < N; i++) {
            if (0 < b[i]) {
                if (b[i] < a[i]) {
                    a[i] -= b[i];
                    b[i] = 0;
                    continue;
                } else {
                    b[i] -= a[i];
                    a[i] = 0;
                }
            }
            if (b[i] < a[i+1]) {
                a[i+1] -= b[i];
                b[i] = 0;
            } else {
                b[i] -= a[i+1];
                a[i+1] = 0;
            }
        }
        long answer = 0;
        for (int i = 0; i < N + 1; i++) {
            answer += o[i] - a[i];
        }
        return answer;
    }
    private long back(int N, long[] o, long[] a, long[] b) {
        for (int i = N-1; 0 <= i; i--) {
            if (0 < b[i+1]) {
                if (b[i] < a[i+1]) {
                    a[i+1] -= b[i];
                    b[i] = 0;
                    continue;
                } else {
                    b[i] -= a[i+1];
                    a[i+1] = 0;
                }
            }
            if (b[i] < a[i]) {
                a[i] -= b[i];
                b[i] = 0;
            } else {
                b[i] -= a[i];
                a[i] = 0;
            }
        }
        long answer = 0;
        for (int i = 0; i < N + 1; i++) {
            answer += o[i] - a[i];
        }
        return answer;
    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) throws Exception {
        Main main = new Main();
        main.solve();
    }
    public void solve() throws Exception {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        long[] a_o = new long[N + 1];
        long[] a_f = new long[N + 1];
        long[] a_b = new long[N + 1];
        for (int i = 0; i < N + 1; i++) {
            a_f[i] = scan.nextLong();
            a_b[i] = a_f[i];
            a_o[i] = a_f[i];
        }
        long[] b_f = new long[N + 1];
        long[] b_b = new long[N + 1];
        for (int i = 0; i < N; i++) {
            b_f[i] = scan.nextLong();
            b_b[i] = b_f[i];
        }
        long answer = front(N, a_o, a_f, b_f);
        answer = Math.max(answer,back(N, a_o, a_f, b_f));
        System.out.println(answer);
    }
    private long front(int N, long[] o, long[] a, long[] b) {
        for (int i = 0; i < N; i++) {
            if (0 < b[i]) {
                if (b[i] < a[i]) {
                    a[i] -= b[i];
                    b[i] = 0;
                    continue;
                } else {
                    b[i] -= a[i];
                    a[i] = 0;
                }
            }
            if (b[i] < a[i+1]) {
                a[i+1] -= b[i];
                b[i] = 0;
            } else {
                b[i] -= a[i+1];
                a[i+1] = 0;
            }
        }
        long answer = 0;
        for (int i = 0; i < N + 1; i++) {
            answer += o[i] - a[i];
        }
        return answer;
    }
    private long back(int N, long[] o, long[] a, long[] b) {
        for (int i = N-1; 0 <= i; i--) {
            if (0 < b[i+1]) {
                if (b[i] < a[i+1]) {
                    a[i+1] -= b[i];
                    b[i] = 0;
                    continue;
                } else {
                    b[i] -= a[i+1];
                    a[i+1] = 0;
                }
            }
            if (b[i] < a[i]) {
                a[i] -= b[i];
                b[i] = 0;
            } else {
                b[i] -= a[i];
                a[i] = 0;
            }
        }
        long answer = 0;
        for (int i = 0; i < N + 1; i++) {
            answer += o[i] - a[i];
        }
        return answer;
    }
} Main public static void main(String[] args) throws Exception {
        Main main = new Main();
        main.solve();
    } main {
        Main main = new Main();
        main.solve();
    } Main main = new Main(); main new Main() main.solve() main.solve main String[] args args public void solve() throws Exception {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        long[] a_o = new long[N + 1];
        long[] a_f = new long[N + 1];
        long[] a_b = new long[N + 1];
        for (int i = 0; i < N + 1; i++) {
            a_f[i] = scan.nextLong();
            a_b[i] = a_f[i];
            a_o[i] = a_f[i];
        }
        long[] b_f = new long[N + 1];
        long[] b_b = new long[N + 1];
        for (int i = 0; i < N; i++) {
            b_f[i] = scan.nextLong();
            b_b[i] = b_f[i];
        }
        long answer = front(N, a_o, a_f, b_f);
        answer = Math.max(answer,back(N, a_o, a_f, b_f));
        System.out.println(answer);
    } solve {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        long[] a_o = new long[N + 1];
        long[] a_f = new long[N + 1];
        long[] a_b = new long[N + 1];
        for (int i = 0; i < N + 1; i++) {
            a_f[i] = scan.nextLong();
            a_b[i] = a_f[i];
            a_o[i] = a_f[i];
        }
        long[] b_f = new long[N + 1];
        long[] b_b = new long[N + 1];
        for (int i = 0; i < N; i++) {
            b_f[i] = scan.nextLong();
            b_b[i] = b_f[i];
        }
        long answer = front(N, a_o, a_f, b_f);
        answer = Math.max(answer,back(N, a_o, a_f, b_f));
        System.out.println(answer);
    } Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in))); scan new Scanner(new BufferedReader(new InputStreamReader(System.in))) int N = scan.nextInt(); N scan.nextInt() scan.nextInt scan long[] a_o = new long[N + 1]; a_o new long[N + 1] N + 1 N 1 long[] a_f = new long[N + 1]; a_f new long[N + 1] N + 1 N 1 long[] a_b = new long[N + 1]; a_b new long[N + 1] N + 1 N 1 for (int i = 0; i < N + 1; i++) {
            a_f[i] = scan.nextLong();
            a_b[i] = a_f[i];
            a_o[i] = a_f[i];
        } int i = 0; int i = 0; i 0 i < N + 1 i N + 1 N 1 i++ i++ i {
            a_f[i] = scan.nextLong();
            a_b[i] = a_f[i];
            a_o[i] = a_f[i];
        } {
            a_f[i] = scan.nextLong();
            a_b[i] = a_f[i];
            a_o[i] = a_f[i];
        } a_f[i] = scan.nextLong() a_f[i] a_f i scan.nextLong() scan.nextLong scan a_b[i] = a_f[i] a_b[i] a_b i a_f[i] a_f i a_o[i] = a_f[i] a_o[i] a_o i a_f[i] a_f i long[] b_f = new long[N + 1]; b_f new long[N + 1] N + 1 N 1 long[] b_b = new long[N + 1]; b_b new long[N + 1] N + 1 N 1 for (int i = 0; i < N; i++) {
            b_f[i] = scan.nextLong();
            b_b[i] = b_f[i];
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            b_f[i] = scan.nextLong();
            b_b[i] = b_f[i];
        } {
            b_f[i] = scan.nextLong();
            b_b[i] = b_f[i];
        } b_f[i] = scan.nextLong() b_f[i] b_f i scan.nextLong() scan.nextLong scan b_b[i] = b_f[i] b_b[i] b_b i b_f[i] b_f i long answer = front(N, a_o, a_f, b_f); answer front(N, a_o, a_f, b_f) front N a_o a_f b_f answer = Math.max(answer,back(N, a_o, a_f, b_f)) answer Math.max(answer,back(N, a_o, a_f, b_f)) Math.max Math answer back(N, a_o, a_f, b_f) back N a_o a_f b_f System.out.println(answer) System.out.println System.out System System.out answer private long front(int N, long[] o, long[] a, long[] b) {
        for (int i = 0; i < N; i++) {
            if (0 < b[i]) {
                if (b[i] < a[i]) {
                    a[i] -= b[i];
                    b[i] = 0;
                    continue;
                } else {
                    b[i] -= a[i];
                    a[i] = 0;
                }
            }
            if (b[i] < a[i+1]) {
                a[i+1] -= b[i];
                b[i] = 0;
            } else {
                b[i] -= a[i+1];
                a[i+1] = 0;
            }
        }
        long answer = 0;
        for (int i = 0; i < N + 1; i++) {
            answer += o[i] - a[i];
        }
        return answer;
    } front {
        for (int i = 0; i < N; i++) {
            if (0 < b[i]) {
                if (b[i] < a[i]) {
                    a[i] -= b[i];
                    b[i] = 0;
                    continue;
                } else {
                    b[i] -= a[i];
                    a[i] = 0;
                }
            }
            if (b[i] < a[i+1]) {
                a[i+1] -= b[i];
                b[i] = 0;
            } else {
                b[i] -= a[i+1];
                a[i+1] = 0;
            }
        }
        long answer = 0;
        for (int i = 0; i < N + 1; i++) {
            answer += o[i] - a[i];
        }
        return answer;
    } for (int i = 0; i < N; i++) {
            if (0 < b[i]) {
                if (b[i] < a[i]) {
                    a[i] -= b[i];
                    b[i] = 0;
                    continue;
                } else {
                    b[i] -= a[i];
                    a[i] = 0;
                }
            }
            if (b[i] < a[i+1]) {
                a[i+1] -= b[i];
                b[i] = 0;
            } else {
                b[i] -= a[i+1];
                a[i+1] = 0;
            }
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            if (0 < b[i]) {
                if (b[i] < a[i]) {
                    a[i] -= b[i];
                    b[i] = 0;
                    continue;
                } else {
                    b[i] -= a[i];
                    a[i] = 0;
                }
            }
            if (b[i] < a[i+1]) {
                a[i+1] -= b[i];
                b[i] = 0;
            } else {
                b[i] -= a[i+1];
                a[i+1] = 0;
            }
        } {
            if (0 < b[i]) {
                if (b[i] < a[i]) {
                    a[i] -= b[i];
                    b[i] = 0;
                    continue;
                } else {
                    b[i] -= a[i];
                    a[i] = 0;
                }
            }
            if (b[i] < a[i+1]) {
                a[i+1] -= b[i];
                b[i] = 0;
            } else {
                b[i] -= a[i+1];
                a[i+1] = 0;
            }
        } if (0 < b[i]) {
                if (b[i] < a[i]) {
                    a[i] -= b[i];
                    b[i] = 0;
                    continue;
                } else {
                    b[i] -= a[i];
                    a[i] = 0;
                }
            } 0 < b[i] 0 b[i] b i {
                if (b[i] < a[i]) {
                    a[i] -= b[i];
                    b[i] = 0;
                    continue;
                } else {
                    b[i] -= a[i];
                    a[i] = 0;
                }
            } if (b[i] < a[i]) {
                    a[i] -= b[i];
                    b[i] = 0;
                    continue;
                } else {
                    b[i] -= a[i];
                    a[i] = 0;
                } b[i] < a[i] b[i] b i a[i] a i {
                    a[i] -= b[i];
                    b[i] = 0;
                    continue;
                } a[i] -= b[i] a[i] a i b[i] b i b[i] = 0 b[i] b i 0 continue; {
                    b[i] -= a[i];
                    a[i] = 0;
                } b[i] -= a[i] b[i] b i a[i] a i a[i] = 0 a[i] a i 0 if (b[i] < a[i+1]) {
                a[i+1] -= b[i];
                b[i] = 0;
            } else {
                b[i] -= a[i+1];
                a[i+1] = 0;
            } b[i] < a[i+1] b[i] b i a[i+1] a i+1 i 1 {
                a[i+1] -= b[i];
                b[i] = 0;
            } a[i+1] -= b[i] a[i+1] a i+1 i 1 b[i] b i b[i] = 0 b[i] b i 0 {
                b[i] -= a[i+1];
                a[i+1] = 0;
            } b[i] -= a[i+1] b[i] b i a[i+1] a i+1 i 1 a[i+1] = 0 a[i+1] a i+1 i 1 0 long answer = 0; answer 0 for (int i = 0; i < N + 1; i++) {
            answer += o[i] - a[i];
        } int i = 0; int i = 0; i 0 i < N + 1 i N + 1 N 1 i++ i++ i {
            answer += o[i] - a[i];
        } {
            answer += o[i] - a[i];
        } answer += o[i] - a[i] answer o[i] - a[i] o[i] o i a[i] a i return answer; answer int N N long[] o o long[] a a long[] b b private long back(int N, long[] o, long[] a, long[] b) {
        for (int i = N-1; 0 <= i; i--) {
            if (0 < b[i+1]) {
                if (b[i] < a[i+1]) {
                    a[i+1] -= b[i];
                    b[i] = 0;
                    continue;
                } else {
                    b[i] -= a[i+1];
                    a[i+1] = 0;
                }
            }
            if (b[i] < a[i]) {
                a[i] -= b[i];
                b[i] = 0;
            } else {
                b[i] -= a[i];
                a[i] = 0;
            }
        }
        long answer = 0;
        for (int i = 0; i < N + 1; i++) {
            answer += o[i] - a[i];
        }
        return answer;
    } back {
        for (int i = N-1; 0 <= i; i--) {
            if (0 < b[i+1]) {
                if (b[i] < a[i+1]) {
                    a[i+1] -= b[i];
                    b[i] = 0;
                    continue;
                } else {
                    b[i] -= a[i+1];
                    a[i+1] = 0;
                }
            }
            if (b[i] < a[i]) {
                a[i] -= b[i];
                b[i] = 0;
            } else {
                b[i] -= a[i];
                a[i] = 0;
            }
        }
        long answer = 0;
        for (int i = 0; i < N + 1; i++) {
            answer += o[i] - a[i];
        }
        return answer;
    } for (int i = N-1; 0 <= i; i--) {
            if (0 < b[i+1]) {
                if (b[i] < a[i+1]) {
                    a[i+1] -= b[i];
                    b[i] = 0;
                    continue;
                } else {
                    b[i] -= a[i+1];
                    a[i+1] = 0;
                }
            }
            if (b[i] < a[i]) {
                a[i] -= b[i];
                b[i] = 0;
            } else {
                b[i] -= a[i];
                a[i] = 0;
            }
        } int i = N-1; int i = N-1; i N-1 N 1 0 <= i 0 i i-- i-- i {
            if (0 < b[i+1]) {
                if (b[i] < a[i+1]) {
                    a[i+1] -= b[i];
                    b[i] = 0;
                    continue;
                } else {
                    b[i] -= a[i+1];
                    a[i+1] = 0;
                }
            }
            if (b[i] < a[i]) {
                a[i] -= b[i];
                b[i] = 0;
            } else {
                b[i] -= a[i];
                a[i] = 0;
            }
        } {
            if (0 < b[i+1]) {
                if (b[i] < a[i+1]) {
                    a[i+1] -= b[i];
                    b[i] = 0;
                    continue;
                } else {
                    b[i] -= a[i+1];
                    a[i+1] = 0;
                }
            }
            if (b[i] < a[i]) {
                a[i] -= b[i];
                b[i] = 0;
            } else {
                b[i] -= a[i];
                a[i] = 0;
            }
        } if (0 < b[i+1]) {
                if (b[i] < a[i+1]) {
                    a[i+1] -= b[i];
                    b[i] = 0;
                    continue;
                } else {
                    b[i] -= a[i+1];
                    a[i+1] = 0;
                }
            } 0 < b[i+1] 0 b[i+1] b i+1 i 1 {
                if (b[i] < a[i+1]) {
                    a[i+1] -= b[i];
                    b[i] = 0;
                    continue;
                } else {
                    b[i] -= a[i+1];
                    a[i+1] = 0;
                }
            } if (b[i] < a[i+1]) {
                    a[i+1] -= b[i];
                    b[i] = 0;
                    continue;
                } else {
                    b[i] -= a[i+1];
                    a[i+1] = 0;
                } b[i] < a[i+1] b[i] b i a[i+1] a i+1 i 1 {
                    a[i+1] -= b[i];
                    b[i] = 0;
                    continue;
                } a[i+1] -= b[i] a[i+1] a i+1 i 1 b[i] b i b[i] = 0 b[i] b i 0 continue; {
                    b[i] -= a[i+1];
                    a[i+1] = 0;
                } b[i] -= a[i+1] b[i] b i a[i+1] a i+1 i 1 a[i+1] = 0 a[i+1] a i+1 i 1 0 if (b[i] < a[i]) {
                a[i] -= b[i];
                b[i] = 0;
            } else {
                b[i] -= a[i];
                a[i] = 0;
            } b[i] < a[i] b[i] b i a[i] a i {
                a[i] -= b[i];
                b[i] = 0;
            } a[i] -= b[i] a[i] a i b[i] b i b[i] = 0 b[i] b i 0 {
                b[i] -= a[i];
                a[i] = 0;
            } b[i] -= a[i] b[i] b i a[i] a i a[i] = 0 a[i] a i 0 long answer = 0; answer 0 for (int i = 0; i < N + 1; i++) {
            answer += o[i] - a[i];
        } int i = 0; int i = 0; i 0 i < N + 1 i N + 1 N 1 i++ i++ i {
            answer += o[i] - a[i];
        } {
            answer += o[i] - a[i];
        } answer += o[i] - a[i] answer o[i] - a[i] o[i] o i a[i] a i return answer; answer int N N long[] o o long[] a a long[] b b public class Main {
    public static void main(String[] args) throws Exception {
        Main main = new Main();
        main.solve();
    }
    public void solve() throws Exception {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        long[] a_o = new long[N + 1];
        long[] a_f = new long[N + 1];
        long[] a_b = new long[N + 1];
        for (int i = 0; i < N + 1; i++) {
            a_f[i] = scan.nextLong();
            a_b[i] = a_f[i];
            a_o[i] = a_f[i];
        }
        long[] b_f = new long[N + 1];
        long[] b_b = new long[N + 1];
        for (int i = 0; i < N; i++) {
            b_f[i] = scan.nextLong();
            b_b[i] = b_f[i];
        }
        long answer = front(N, a_o, a_f, b_f);
        answer = Math.max(answer,back(N, a_o, a_f, b_f));
        System.out.println(answer);
    }
    private long front(int N, long[] o, long[] a, long[] b) {
        for (int i = 0; i < N; i++) {
            if (0 < b[i]) {
                if (b[i] < a[i]) {
                    a[i] -= b[i];
                    b[i] = 0;
                    continue;
                } else {
                    b[i] -= a[i];
                    a[i] = 0;
                }
            }
            if (b[i] < a[i+1]) {
                a[i+1] -= b[i];
                b[i] = 0;
            } else {
                b[i] -= a[i+1];
                a[i+1] = 0;
            }
        }
        long answer = 0;
        for (int i = 0; i < N + 1; i++) {
            answer += o[i] - a[i];
        }
        return answer;
    }
    private long back(int N, long[] o, long[] a, long[] b) {
        for (int i = N-1; 0 <= i; i--) {
            if (0 < b[i+1]) {
                if (b[i] < a[i+1]) {
                    a[i+1] -= b[i];
                    b[i] = 0;
                    continue;
                } else {
                    b[i] -= a[i+1];
                    a[i+1] = 0;
                }
            }
            if (b[i] < a[i]) {
                a[i] -= b[i];
                b[i] = 0;
            } else {
                b[i] -= a[i];
                a[i] = 0;
            }
        }
        long answer = 0;
        for (int i = 0; i < N + 1; i++) {
            answer += o[i] - a[i];
        }
        return answer;
    }
} public class Main {
    public static void main(String[] args) throws Exception {
        Main main = new Main();
        main.solve();
    }
    public void solve() throws Exception {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        long[] a_o = new long[N + 1];
        long[] a_f = new long[N + 1];
        long[] a_b = new long[N + 1];
        for (int i = 0; i < N + 1; i++) {
            a_f[i] = scan.nextLong();
            a_b[i] = a_f[i];
            a_o[i] = a_f[i];
        }
        long[] b_f = new long[N + 1];
        long[] b_b = new long[N + 1];
        for (int i = 0; i < N; i++) {
            b_f[i] = scan.nextLong();
            b_b[i] = b_f[i];
        }
        long answer = front(N, a_o, a_f, b_f);
        answer = Math.max(answer,back(N, a_o, a_f, b_f));
        System.out.println(answer);
    }
    private long front(int N, long[] o, long[] a, long[] b) {
        for (int i = 0; i < N; i++) {
            if (0 < b[i]) {
                if (b[i] < a[i]) {
                    a[i] -= b[i];
                    b[i] = 0;
                    continue;
                } else {
                    b[i] -= a[i];
                    a[i] = 0;
                }
            }
            if (b[i] < a[i+1]) {
                a[i+1] -= b[i];
                b[i] = 0;
            } else {
                b[i] -= a[i+1];
                a[i+1] = 0;
            }
        }
        long answer = 0;
        for (int i = 0; i < N + 1; i++) {
            answer += o[i] - a[i];
        }
        return answer;
    }
    private long back(int N, long[] o, long[] a, long[] b) {
        for (int i = N-1; 0 <= i; i--) {
            if (0 < b[i+1]) {
                if (b[i] < a[i+1]) {
                    a[i+1] -= b[i];
                    b[i] = 0;
                    continue;
                } else {
                    b[i] -= a[i+1];
                    a[i+1] = 0;
                }
            }
            if (b[i] < a[i]) {
                a[i] -= b[i];
                b[i] = 0;
            } else {
                b[i] -= a[i];
                a[i] = 0;
            }
        }
        long answer = 0;
        for (int i = 0; i < N + 1; i++) {
            answer += o[i] - a[i];
        }
        return answer;
    }
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Main main = new Main();
        main.solve();
    }
    public void solve() throws Exception {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        long[] a_o = new long[N + 1];
        long[] a_f = new long[N + 1];
        long[] a_b = new long[N + 1];
        for (int i = 0; i < N + 1; i++) {
            a_f[i] = scan.nextLong();
            a_b[i] = a_f[i];
            a_o[i] = a_f[i];
        }
        long[] b_f = new long[N + 1];
        long[] b_b = new long[N + 1];
        for (int i = 0; i < N; i++) {
            b_f[i] = scan.nextLong();
            b_b[i] = b_f[i];
        }
        long answer = front(N, a_o, a_f, b_f);
        answer = Math.max(answer,back(N, a_o, a_f, b_f));
        System.out.println(answer);
    }
    private long front(int N, long[] o, long[] a, long[] b) {
        for (int i = 0; i < N; i++) {
            if (0 < b[i]) {
                if (b[i] < a[i]) {
                    a[i] -= b[i];
                    b[i] = 0;
                    continue;
                } else {
                    b[i] -= a[i];
                    a[i] = 0;
                }
            }
            if (b[i] < a[i+1]) {
                a[i+1] -= b[i];
                b[i] = 0;
            } else {
                b[i] -= a[i+1];
                a[i+1] = 0;
            }
        }
        long answer = 0;
        for (int i = 0; i < N + 1; i++) {
            answer += o[i] - a[i];
        }
        return answer;
    }
    private long back(int N, long[] o, long[] a, long[] b) {
        for (int i = N-1; 0 <= i; i--) {
            if (0 < b[i+1]) {
                if (b[i] < a[i+1]) {
                    a[i+1] -= b[i];
                    b[i] = 0;
                    continue;
                } else {
                    b[i] -= a[i+1];
                    a[i+1] = 0;
                }
            }
            if (b[i] < a[i]) {
                a[i] -= b[i];
                b[i] = 0;
            } else {
                b[i] -= a[i];
                a[i] = 0;
            }
        }
        long answer = 0;
        for (int i = 0; i < N + 1; i++) {
            answer += o[i] - a[i];
        }
        return answer;
    }
}
