MOD = 10 ** 9 + 7 def solve(n, A, B): def f(A): A = A[:] A.sort() ret = 0 for i, a in enumerate(A): ret += i * a ret -= (n - 1 - i) * a ret %= MOD return ret big = 1 << 30 C = [(a + b) * big for a, b in zip(A, B)] D = [(a - b) * big for a, b in zip(A, B)] tot = (f(C) + f(D)) % MOD Ca = [c - a for (a, c) in zip(A, C)] Da = [d - a for (a, d) in zip(A, D)] a = (tot - (f(Ca) + f(Da))) % MOD Cb = [c - b for (b, c) in zip(B, C)] Db = [d + b for (b, d) in zip(B, D)] b = (tot - (f(Cb) + f(Db))) % MOD return a, b n = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) def stupid(n, A, B): ansa = 0 ansb = 0 for i in range(n): for j in range(n): a = abs(A[i] - A[j]) b = abs(B[i] - B[j]) if a > b: ansa += a ansa %= MOD elif a < b: ansb += b ansb %= MOD return ansa, ansb print(*solve(n, A, B)) exit() import random random.seed(0) for _ in range(1000): n = random.randrange(2, 8) A = random.choices(range(1, 21), k=n) B = random.choices(range(1, 21), k=n) assert solve(n, A, B) == stupid(n, A, B), (solve(n, A, B), stupid(n, A, B), n, A, B)