import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
  static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

    public String next() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    int n = sc.nextInt();
    int[] v = sc.nextIntArray(n);
    int[] c = sc.nextIntArray(n);

    int[] values = new int[n];
    for (int i = 0; i < n; i++) values[i] = v[i] - c[i];
    Set<Integer> dp = new HashSet<>();
    Set<Integer> ndp = new HashSet<>();
    dp.add(0);
    for (int i = 0; i < n; i++) {
      ndp.clear();
      for (int val : dp) {
        ndp.add(val);
        ndp.add(val + values[i]);
      }
      dp.clear();
      dp.addAll(ndp);
    }
    int max = Integer.MIN_VALUE;
    for (int val : dp) max = Math.max(max, val);
    System.out.println(max);
  }
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStream; InputStream java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.*; util.* java public class Main {
  static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

    public String next() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    int n = sc.nextInt();
    int[] v = sc.nextIntArray(n);
    int[] c = sc.nextIntArray(n);

    int[] values = new int[n];
    for (int i = 0; i < n; i++) values[i] = v[i] - c[i];
    Set<Integer> dp = new HashSet<>();
    Set<Integer> ndp = new HashSet<>();
    dp.add(0);
    for (int i = 0; i < n; i++) {
      ndp.clear();
      for (int val : dp) {
        ndp.add(val);
        ndp.add(val + values[i]);
      }
      dp.clear();
      dp.addAll(ndp);
    }
    int max = Integer.MIN_VALUE;
    for (int val : dp) max = Math.max(max, val);
    System.out.println(max);
  }
} Main public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    int n = sc.nextInt();
    int[] v = sc.nextIntArray(n);
    int[] c = sc.nextIntArray(n);

    int[] values = new int[n];
    for (int i = 0; i < n; i++) values[i] = v[i] - c[i];
    Set<Integer> dp = new HashSet<>();
    Set<Integer> ndp = new HashSet<>();
    dp.add(0);
    for (int i = 0; i < n; i++) {
      ndp.clear();
      for (int val : dp) {
        ndp.add(val);
        ndp.add(val + values[i]);
      }
      dp.clear();
      dp.addAll(ndp);
    }
    int max = Integer.MIN_VALUE;
    for (int val : dp) max = Math.max(max, val);
    System.out.println(max);
  } main {
    FastScanner sc = new FastScanner(System.in);
    int n = sc.nextInt();
    int[] v = sc.nextIntArray(n);
    int[] c = sc.nextIntArray(n);

    int[] values = new int[n];
    for (int i = 0; i < n; i++) values[i] = v[i] - c[i];
    Set<Integer> dp = new HashSet<>();
    Set<Integer> ndp = new HashSet<>();
    dp.add(0);
    for (int i = 0; i < n; i++) {
      ndp.clear();
      for (int val : dp) {
        ndp.add(val);
        ndp.add(val + values[i]);
      }
      dp.clear();
      dp.addAll(ndp);
    }
    int max = Integer.MIN_VALUE;
    for (int val : dp) max = Math.max(max, val);
    System.out.println(max);
  } FastScanner sc = new FastScanner(System.in); sc new FastScanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] v = sc.nextIntArray(n); v sc.nextIntArray(n) sc.nextIntArray sc n int[] c = sc.nextIntArray(n); c sc.nextIntArray(n) sc.nextIntArray sc n int[] values = new int[n]; values new int[n] n for (int i = 0; i < n; i++) values[i] = v[i] - c[i]; int i = 0; int i = 0; i 0 i < n i n i++ i++ i values[i] = v[i] - c[i]; values[i] = v[i] - c[i] values[i] values i v[i] - c[i] v[i] v i c[i] c i Set<Integer> dp = new HashSet<>(); dp new HashSet<>() Set<Integer> ndp = new HashSet<>(); ndp new HashSet<>() dp.add(0) dp.add dp 0 for (int i = 0; i < n; i++) {
      ndp.clear();
      for (int val : dp) {
        ndp.add(val);
        ndp.add(val + values[i]);
      }
      dp.clear();
      dp.addAll(ndp);
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      ndp.clear();
      for (int val : dp) {
        ndp.add(val);
        ndp.add(val + values[i]);
      }
      dp.clear();
      dp.addAll(ndp);
    } {
      ndp.clear();
      for (int val : dp) {
        ndp.add(val);
        ndp.add(val + values[i]);
      }
      dp.clear();
      dp.addAll(ndp);
    } ndp.clear() ndp.clear ndp for (int val : dp) {
        ndp.add(val);
        ndp.add(val + values[i]);
      } int val dp {
        ndp.add(val);
        ndp.add(val + values[i]);
      } {
        ndp.add(val);
        ndp.add(val + values[i]);
      } ndp.add(val) ndp.add ndp val ndp.add(val + values[i]) ndp.add ndp val + values[i] val values[i] values i dp.clear() dp.clear dp dp.addAll(ndp) dp.addAll dp ndp int max = Integer.MIN_VALUE; max Integer.MIN_VALUE Integer Integer.MIN_VALUE for (int val : dp) max = Math.max(max, val); int val dp max = Math.max(max, val); max = Math.max(max, val) max Math.max(max, val) Math.max Math max val System.out.println(max) System.out.println System.out System System.out max String[] args args static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

    public String next() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  } FastScanner private BufferedReader reader = null; reader null private StringTokenizer tokenizer = null; tokenizer null public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    } FastScanner {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    } reader = new BufferedReader(new InputStreamReader(in)) reader new BufferedReader(new InputStreamReader(in)) tokenizer = null tokenizer null InputStream in in public String next() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    } next {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    } if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      } tokenizer == null || !tokenizer.hasMoreTokens() tokenizer == null tokenizer null !tokenizer.hasMoreTokens() tokenizer.hasMoreTokens() tokenizer.hasMoreTokens tokenizer {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      } try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        } catch (IOException e) {
          throw new RuntimeException(e);
        } IOException e {
          throw new RuntimeException(e);
        } throw new RuntimeException(e); new RuntimeException(e) {
          tokenizer = new StringTokenizer(reader.readLine());
        } tokenizer = new StringTokenizer(reader.readLine()) tokenizer new StringTokenizer(reader.readLine()) return tokenizer.nextToken(); tokenizer.nextToken() tokenizer.nextToken tokenizer public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    } nextLine {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    } if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      } tokenizer == null || !tokenizer.hasMoreTokens() tokenizer == null tokenizer null !tokenizer.hasMoreTokens() tokenizer.hasMoreTokens() tokenizer.hasMoreTokens tokenizer {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      } try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        } catch (IOException e) {
          throw new RuntimeException(e);
        } IOException e {
          throw new RuntimeException(e);
        } throw new RuntimeException(e); new RuntimeException(e) {
          return reader.readLine();
        } return reader.readLine(); reader.readLine() reader.readLine reader return tokenizer.nextToken("\n"); tokenizer.nextToken("\n") tokenizer.nextToken tokenizer "\n" public long nextLong() {
      return Long.parseLong(next());
    } nextLong {
      return Long.parseLong(next());
    } return Long.parseLong(next()); Long.parseLong(next()) Long.parseLong Long next() next public int nextInt() {
      return Integer.parseInt(next());
    } nextInt {
      return Integer.parseInt(next());
    } return Integer.parseInt(next()); Integer.parseInt(next()) Integer.parseInt Integer next() next public double nextDouble() {
      return Double.parseDouble(next());
    } nextDouble {
      return Double.parseDouble(next());
    } return Double.parseDouble(next()); Double.parseDouble(next()) Double.parseDouble Double next() next public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    } nextIntArray {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    } int[] a = new int[n]; a new int[n] n for (int i = 0; i < n; i++)
        a[i] = nextInt(); int i = 0; int i = 0; i 0 i < n i n i++ i++ i a[i] = nextInt(); a[i] = nextInt() a[i] a i nextInt() nextInt return a; a int n n public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    } nextLongArray {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    } long[] a = new long[n]; a new long[n] n for (int i = 0; i < n; i++)
        a[i] = nextLong(); int i = 0; int i = 0; i 0 i < n i n i++ i++ i a[i] = nextLong(); a[i] = nextLong() a[i] a i nextLong() nextLong return a; a int n n public class Main {
  static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

    public String next() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    int n = sc.nextInt();
    int[] v = sc.nextIntArray(n);
    int[] c = sc.nextIntArray(n);

    int[] values = new int[n];
    for (int i = 0; i < n; i++) values[i] = v[i] - c[i];
    Set<Integer> dp = new HashSet<>();
    Set<Integer> ndp = new HashSet<>();
    dp.add(0);
    for (int i = 0; i < n; i++) {
      ndp.clear();
      for (int val : dp) {
        ndp.add(val);
        ndp.add(val + values[i]);
      }
      dp.clear();
      dp.addAll(ndp);
    }
    int max = Integer.MIN_VALUE;
    for (int val : dp) max = Math.max(max, val);
    System.out.println(max);
  }
} public class Main {
  static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

    public String next() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    int n = sc.nextInt();
    int[] v = sc.nextIntArray(n);
    int[] c = sc.nextIntArray(n);

    int[] values = new int[n];
    for (int i = 0; i < n; i++) values[i] = v[i] - c[i];
    Set<Integer> dp = new HashSet<>();
    Set<Integer> ndp = new HashSet<>();
    dp.add(0);
    for (int i = 0; i < n; i++) {
      ndp.clear();
      for (int val : dp) {
        ndp.add(val);
        ndp.add(val + values[i]);
      }
      dp.clear();
      dp.addAll(ndp);
    }
    int max = Integer.MIN_VALUE;
    for (int val : dp) max = Math.max(max, val);
    System.out.println(max);
  }
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
  static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

    public String next() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    int n = sc.nextInt();
    int[] v = sc.nextIntArray(n);
    int[] c = sc.nextIntArray(n);

    int[] values = new int[n];
    for (int i = 0; i < n; i++) values[i] = v[i] - c[i];
    Set<Integer> dp = new HashSet<>();
    Set<Integer> ndp = new HashSet<>();
    dp.add(0);
    for (int i = 0; i < n; i++) {
      ndp.clear();
      for (int val : dp) {
        ndp.add(val);
        ndp.add(val + values[i]);
      }
      dp.clear();
      dp.addAll(ndp);
    }
    int max = Integer.MIN_VALUE;
    for (int val : dp) max = Math.max(max, val);
    System.out.println(max);
  }
}