import java.io.*; import java.util.*; public class Main { static final int MOD = 1000000007; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); Work[] works = new Work[n]; for (int i = 0; i < n; i++) { works[i] = new Work(sc.nextInt()); } for (int i = 0; i < n; i++) { works[i].b = sc.nextInt(); } Arrays.sort(works); long base = 1; long income = 0; for (Work x : works) { income += x.a * base % MOD; income %= MOD; base *= x.b; base %= MOD; } System.out.println(income); } static class Work implements Comparable { long a; long b; public Work(long a) { this.a = a; } public int compareTo(Work another) { long left = a + b * another.a; long right = another.a + another.b * a; if (left == right) { return 0; } else if (left < right) { return 1; } else { return -1; } } } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }