import static java.lang.System.err; import static java.lang.System.out; import java.util.Arrays; import java.util.Comparator; public class Main { public static void main(String[] args) { new Main(); out.flush(); err.flush(); } public static class Pair implements Comparable{ int A, B; Pair(int A, int B) { this.A = A; this.B = B; } @Override public int compareTo(Pair o) { return Long.compare(A + (long)B * o.A, o.A + (long)o.B * A); } } public Main() { try (java.util.Scanner sc = new java.util.Scanner(System.in)) { int N = sc.nextInt(); int[] A = new int[N], B = new int[N]; for (int i = 0;i < N;++ i) A[i] = sc.nextInt(); for (int i = 0;i < N;++ i) B[i] = sc.nextInt(); Pair[] p = new Pair[N]; for (int i = 0;i < N;++ i) p[i] = new Pair(A[i], B[i]); Arrays.sort(p, Comparator.reverseOrder()); final int MOD = 1_000_000_007; long level = 1; long ans = 0; for (Pair i : p) { ans = (ans + level * i.A) % MOD; level = level * i.B % MOD; } out.println(ans); } } }