import java.math.*;
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    BigInteger A[] = new BigInteger[N+1];
    BigInteger B[] = new BigInteger[N];
    BigInteger out = new BigInteger("0");
    for (int i=0; i<N+1; i++) {
      A[i] = sc.nextBigInteger();
    }
    for (int i=0; i<N; i++) {
      B[i] = sc.nextBigInteger();
    }
    for (int i=0; i<N; i++) {
      //if(A[i] > B[i]){
      if(A[i].compareTo(B[i]) == 1){
        out = out.add(B[i]);
        A[i] = A[i].subtract(B[i]);
        B[i] = B[i].subtract(B[i]);
      } else {
        out = out.add(A[i]);
        B[i] = B[i].subtract(A[i]);
        A[i] = A[i].subtract(A[i]);
      }
      if(A[i+1].compareTo(B[i]) == 1){
        out = out.add(B[i]);
        A[i+1] = A[i+1].subtract(B[i]);
        B[i] = B[i].subtract(B[i]);
      } else {
        out = out.add(A[i+1]);
        B[i] = B[i].subtract(A[i+1]);
        A[i+1] = A[i+1].subtract(A[i+1]);
      }
    }
    System.out.println(out);
  }
} import java.math.*; math.* java import java.util.*; util.* java public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    BigInteger A[] = new BigInteger[N+1];
    BigInteger B[] = new BigInteger[N];
    BigInteger out = new BigInteger("0");
    for (int i=0; i<N+1; i++) {
      A[i] = sc.nextBigInteger();
    }
    for (int i=0; i<N; i++) {
      B[i] = sc.nextBigInteger();
    }
    for (int i=0; i<N; i++) {
      //if(A[i] > B[i]){
      if(A[i].compareTo(B[i]) == 1){
        out = out.add(B[i]);
        A[i] = A[i].subtract(B[i]);
        B[i] = B[i].subtract(B[i]);
      } else {
        out = out.add(A[i]);
        B[i] = B[i].subtract(A[i]);
        A[i] = A[i].subtract(A[i]);
      }
      if(A[i+1].compareTo(B[i]) == 1){
        out = out.add(B[i]);
        A[i+1] = A[i+1].subtract(B[i]);
        B[i] = B[i].subtract(B[i]);
      } else {
        out = out.add(A[i+1]);
        B[i] = B[i].subtract(A[i+1]);
        A[i+1] = A[i+1].subtract(A[i+1]);
      }
    }
    System.out.println(out);
  }
} Main public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    BigInteger A[] = new BigInteger[N+1];
    BigInteger B[] = new BigInteger[N];
    BigInteger out = new BigInteger("0");
    for (int i=0; i<N+1; i++) {
      A[i] = sc.nextBigInteger();
    }
    for (int i=0; i<N; i++) {
      B[i] = sc.nextBigInteger();
    }
    for (int i=0; i<N; i++) {
      //if(A[i] > B[i]){
      if(A[i].compareTo(B[i]) == 1){
        out = out.add(B[i]);
        A[i] = A[i].subtract(B[i]);
        B[i] = B[i].subtract(B[i]);
      } else {
        out = out.add(A[i]);
        B[i] = B[i].subtract(A[i]);
        A[i] = A[i].subtract(A[i]);
      }
      if(A[i+1].compareTo(B[i]) == 1){
        out = out.add(B[i]);
        A[i+1] = A[i+1].subtract(B[i]);
        B[i] = B[i].subtract(B[i]);
      } else {
        out = out.add(A[i+1]);
        B[i] = B[i].subtract(A[i+1]);
        A[i+1] = A[i+1].subtract(A[i+1]);
      }
    }
    System.out.println(out);
  } main {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    BigInteger A[] = new BigInteger[N+1];
    BigInteger B[] = new BigInteger[N];
    BigInteger out = new BigInteger("0");
    for (int i=0; i<N+1; i++) {
      A[i] = sc.nextBigInteger();
    }
    for (int i=0; i<N; i++) {
      B[i] = sc.nextBigInteger();
    }
    for (int i=0; i<N; i++) {
      //if(A[i] > B[i]){
      if(A[i].compareTo(B[i]) == 1){
        out = out.add(B[i]);
        A[i] = A[i].subtract(B[i]);
        B[i] = B[i].subtract(B[i]);
      } else {
        out = out.add(A[i]);
        B[i] = B[i].subtract(A[i]);
        A[i] = A[i].subtract(A[i]);
      }
      if(A[i+1].compareTo(B[i]) == 1){
        out = out.add(B[i]);
        A[i+1] = A[i+1].subtract(B[i]);
        B[i] = B[i].subtract(B[i]);
      } else {
        out = out.add(A[i+1]);
        B[i] = B[i].subtract(A[i+1]);
        A[i+1] = A[i+1].subtract(A[i+1]);
      }
    }
    System.out.println(out);
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc BigInteger A[] = new BigInteger[N+1]; A new BigInteger[N+1] N+1 N 1 BigInteger B[] = new BigInteger[N]; B new BigInteger[N] N BigInteger out = new BigInteger("0"); out new BigInteger("0") for (int i=0; i<N+1; i++) {
      A[i] = sc.nextBigInteger();
    } int i=0; int i=0; i 0 i<N+1 i N+1 N 1 i++ i++ i {
      A[i] = sc.nextBigInteger();
    } {
      A[i] = sc.nextBigInteger();
    } A[i] = sc.nextBigInteger() A[i] A i sc.nextBigInteger() sc.nextBigInteger sc for (int i=0; i<N; i++) {
      B[i] = sc.nextBigInteger();
    } int i=0; int i=0; i 0 i<N i N i++ i++ i {
      B[i] = sc.nextBigInteger();
    } {
      B[i] = sc.nextBigInteger();
    } B[i] = sc.nextBigInteger() B[i] B i sc.nextBigInteger() sc.nextBigInteger sc for (int i=0; i<N; i++) {
      //if(A[i] > B[i]){
      if(A[i].compareTo(B[i]) == 1){
        out = out.add(B[i]);
        A[i] = A[i].subtract(B[i]);
        B[i] = B[i].subtract(B[i]);
      } else {
        out = out.add(A[i]);
        B[i] = B[i].subtract(A[i]);
        A[i] = A[i].subtract(A[i]);
      }
      if(A[i+1].compareTo(B[i]) == 1){
        out = out.add(B[i]);
        A[i+1] = A[i+1].subtract(B[i]);
        B[i] = B[i].subtract(B[i]);
      } else {
        out = out.add(A[i+1]);
        B[i] = B[i].subtract(A[i+1]);
        A[i+1] = A[i+1].subtract(A[i+1]);
      }
    } int i=0; int i=0; i 0 i<N i N i++ i++ i {
      //if(A[i] > B[i]){
      if(A[i].compareTo(B[i]) == 1){
        out = out.add(B[i]);
        A[i] = A[i].subtract(B[i]);
        B[i] = B[i].subtract(B[i]);
      } else {
        out = out.add(A[i]);
        B[i] = B[i].subtract(A[i]);
        A[i] = A[i].subtract(A[i]);
      }
      if(A[i+1].compareTo(B[i]) == 1){
        out = out.add(B[i]);
        A[i+1] = A[i+1].subtract(B[i]);
        B[i] = B[i].subtract(B[i]);
      } else {
        out = out.add(A[i+1]);
        B[i] = B[i].subtract(A[i+1]);
        A[i+1] = A[i+1].subtract(A[i+1]);
      }
    } {
      //if(A[i] > B[i]){
      if(A[i].compareTo(B[i]) == 1){
        out = out.add(B[i]);
        A[i] = A[i].subtract(B[i]);
        B[i] = B[i].subtract(B[i]);
      } else {
        out = out.add(A[i]);
        B[i] = B[i].subtract(A[i]);
        A[i] = A[i].subtract(A[i]);
      }
      if(A[i+1].compareTo(B[i]) == 1){
        out = out.add(B[i]);
        A[i+1] = A[i+1].subtract(B[i]);
        B[i] = B[i].subtract(B[i]);
      } else {
        out = out.add(A[i+1]);
        B[i] = B[i].subtract(A[i+1]);
        A[i+1] = A[i+1].subtract(A[i+1]);
      }
    } if(A[i].compareTo(B[i]) == 1){
        out = out.add(B[i]);
        A[i] = A[i].subtract(B[i]);
        B[i] = B[i].subtract(B[i]);
      } else {
        out = out.add(A[i]);
        B[i] = B[i].subtract(A[i]);
        A[i] = A[i].subtract(A[i]);
      } A[i].compareTo(B[i]) == 1 A[i].compareTo(B[i]) A[i].compareTo A[i] A i B[i] B i 1 {
        out = out.add(B[i]);
        A[i] = A[i].subtract(B[i]);
        B[i] = B[i].subtract(B[i]);
      } out = out.add(B[i]) out out.add(B[i]) out.add out B[i] B i A[i] = A[i].subtract(B[i]) A[i] A i A[i].subtract(B[i]) A[i].subtract A[i] A i B[i] B i B[i] = B[i].subtract(B[i]) B[i] B i B[i].subtract(B[i]) B[i].subtract B[i] B i B[i] B i {
        out = out.add(A[i]);
        B[i] = B[i].subtract(A[i]);
        A[i] = A[i].subtract(A[i]);
      } out = out.add(A[i]) out out.add(A[i]) out.add out A[i] A i B[i] = B[i].subtract(A[i]) B[i] B i B[i].subtract(A[i]) B[i].subtract B[i] B i A[i] A i A[i] = A[i].subtract(A[i]) A[i] A i A[i].subtract(A[i]) A[i].subtract A[i] A i A[i] A i if(A[i+1].compareTo(B[i]) == 1){
        out = out.add(B[i]);
        A[i+1] = A[i+1].subtract(B[i]);
        B[i] = B[i].subtract(B[i]);
      } else {
        out = out.add(A[i+1]);
        B[i] = B[i].subtract(A[i+1]);
        A[i+1] = A[i+1].subtract(A[i+1]);
      } A[i+1].compareTo(B[i]) == 1 A[i+1].compareTo(B[i]) A[i+1].compareTo A[i+1] A i+1 i 1 B[i] B i 1 {
        out = out.add(B[i]);
        A[i+1] = A[i+1].subtract(B[i]);
        B[i] = B[i].subtract(B[i]);
      } out = out.add(B[i]) out out.add(B[i]) out.add out B[i] B i A[i+1] = A[i+1].subtract(B[i]) A[i+1] A i+1 i 1 A[i+1].subtract(B[i]) A[i+1].subtract A[i+1] A i+1 i 1 B[i] B i B[i] = B[i].subtract(B[i]) B[i] B i B[i].subtract(B[i]) B[i].subtract B[i] B i B[i] B i {
        out = out.add(A[i+1]);
        B[i] = B[i].subtract(A[i+1]);
        A[i+1] = A[i+1].subtract(A[i+1]);
      } out = out.add(A[i+1]) out out.add(A[i+1]) out.add out A[i+1] A i+1 i 1 B[i] = B[i].subtract(A[i+1]) B[i] B i B[i].subtract(A[i+1]) B[i].subtract B[i] B i A[i+1] A i+1 i 1 A[i+1] = A[i+1].subtract(A[i+1]) A[i+1] A i+1 i 1 A[i+1].subtract(A[i+1]) A[i+1].subtract A[i+1] A i+1 i 1 A[i+1] A i+1 i 1 System.out.println(out) System.out.println System.out System System.out out String[] args args public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    BigInteger A[] = new BigInteger[N+1];
    BigInteger B[] = new BigInteger[N];
    BigInteger out = new BigInteger("0");
    for (int i=0; i<N+1; i++) {
      A[i] = sc.nextBigInteger();
    }
    for (int i=0; i<N; i++) {
      B[i] = sc.nextBigInteger();
    }
    for (int i=0; i<N; i++) {
      //if(A[i] > B[i]){
      if(A[i].compareTo(B[i]) == 1){
        out = out.add(B[i]);
        A[i] = A[i].subtract(B[i]);
        B[i] = B[i].subtract(B[i]);
      } else {
        out = out.add(A[i]);
        B[i] = B[i].subtract(A[i]);
        A[i] = A[i].subtract(A[i]);
      }
      if(A[i+1].compareTo(B[i]) == 1){
        out = out.add(B[i]);
        A[i+1] = A[i+1].subtract(B[i]);
        B[i] = B[i].subtract(B[i]);
      } else {
        out = out.add(A[i+1]);
        B[i] = B[i].subtract(A[i+1]);
        A[i+1] = A[i+1].subtract(A[i+1]);
      }
    }
    System.out.println(out);
  }
} public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    BigInteger A[] = new BigInteger[N+1];
    BigInteger B[] = new BigInteger[N];
    BigInteger out = new BigInteger("0");
    for (int i=0; i<N+1; i++) {
      A[i] = sc.nextBigInteger();
    }
    for (int i=0; i<N; i++) {
      B[i] = sc.nextBigInteger();
    }
    for (int i=0; i<N; i++) {
      //if(A[i] > B[i]){
      if(A[i].compareTo(B[i]) == 1){
        out = out.add(B[i]);
        A[i] = A[i].subtract(B[i]);
        B[i] = B[i].subtract(B[i]);
      } else {
        out = out.add(A[i]);
        B[i] = B[i].subtract(A[i]);
        A[i] = A[i].subtract(A[i]);
      }
      if(A[i+1].compareTo(B[i]) == 1){
        out = out.add(B[i]);
        A[i+1] = A[i+1].subtract(B[i]);
        B[i] = B[i].subtract(B[i]);
      } else {
        out = out.add(A[i+1]);
        B[i] = B[i].subtract(A[i+1]);
        A[i+1] = A[i+1].subtract(A[i+1]);
      }
    }
    System.out.println(out);
  }
} Main
import java.math.*;
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    BigInteger A[] = new BigInteger[N+1];
    BigInteger B[] = new BigInteger[N];
    BigInteger out = new BigInteger("0");
    for (int i=0; i<N+1; i++) {
      A[i] = sc.nextBigInteger();
    }
    for (int i=0; i<N; i++) {
      B[i] = sc.nextBigInteger();
    }
    for (int i=0; i<N; i++) {
      //if(A[i] > B[i]){
      if(A[i].compareTo(B[i]) == 1){
        out = out.add(B[i]);
        A[i] = A[i].subtract(B[i]);
        B[i] = B[i].subtract(B[i]);
      } else {
        out = out.add(A[i]);
        B[i] = B[i].subtract(A[i]);
        A[i] = A[i].subtract(A[i]);
      }
      if(A[i+1].compareTo(B[i]) == 1){
        out = out.add(B[i]);
        A[i+1] = A[i+1].subtract(B[i]);
        B[i] = B[i].subtract(B[i]);
      } else {
        out = out.add(A[i+1]);
        B[i] = B[i].subtract(A[i+1]);
        A[i+1] = A[i+1].subtract(A[i+1]);
      }
    }
    System.out.println(out);
  }
}
