Problem:
Score : 500 points

Problem Statement

On a two-dimensional plane, there are m lines drawn parallel to the x axis, and n lines drawn parallel to the y axis.
Among the lines parallel to the x axis, the i-th from the bottom is represented by y = y_i.
Similarly, among the lines parallel to the y axis, the i-th from the left is represented by x = x_i.

For every rectangle that is formed by these lines, find its area, and print the total area modulo 10^9+7.

That is, for every quadruple (i,j,k,l) satisfying 1\leq i < j\leq n and 1\leq k < l\leq m, find the area of the rectangle formed by the lines x=x_i, x=x_j, y=y_k and y=y_l, and print the sum of these areas modulo 10^9+7.

Constraints

2 \leq n,m \leq 10^5

-10^9 \leq x_1 < ... < x_n \leq 10^9

-10^9 \leq y_1 < ... < y_m \leq 10^9

x_i and y_i are integers.

Input

Input is given from Standard Input in the following format:

n m
x_1 x_2 ... x_n
y_1 y_2 ... y_m

Output

Print the total area of the rectangles, modulo 10^9+7.

Sample Input 1

3 3
1 3 4
1 3 6

Sample Output 1

60

The following figure illustrates this input:

The total area of the nine rectangles A, B, ..., I shown in the following figure, is 60.

Sample Input 2

6 5
-790013317 -192321079 95834122 418379342 586260100 802780784
-253230108 193944314 363756450 712662868 735867677

Sample Output 2

835067060

Solution in Rust (1.15.1) (judge verdict: Wrong Answer)

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

use std::collections::VecDeque;



fn bfs(h: i64, w: i64, s: Vec<Vec<bool>>) -> usize {
    let mut visited = vec![vec![false; w as usize]; h as usize];
    let mut res = 0;
    let next = vec![(0, -1), (-1, 0), (0, 1), (1, 0)];
    let mut q = VecDeque::new();
    for i in 0..h {
        for j in 0..w {
            if visited[i as usize][j as usize] {
                continue;
            }
            if s[i as usize][j as usize] {
                visited[i as usize][j as usize] = true;
                q.push_back(((i, j), true));
            }
            let mut black = 1;
            let mut white = 0;
            while let Some(((height, width), c)) = q.pop_front() {
                for n in 0..4 {
                    let n = next[n];
                    let height = height + n.1;
                    let width = width + n.0;
                    if width < 0 || height < 0 || width >= w || height >= h {
                        continue;
                    }
                    if visited[height as usize][width as usize] {
                        continue;
                    }
                    if c ^ s[height as usize][width as usize] {
                        q.push_back(((height, width), s[height as usize][width as usize]));
                        if s[height as usize][width as usize] {
                            black += 1;
                        } else {
                            white += 1;
                        }
                        visited[height as usize][width as usize] = true;
                    }
                }
            }
            res += black * white;
        }
    }
    res
}

const MOD: i64 = 1000000000 + 7;


fn solve(mut xs: Vec<i64>, mut ys: Vec<i64>) -> i64 {
    xs.sort();
    ys.sort();

    let mut x_total = 0;
    let len = xs.len() as i64;
    for i in 0..len {
        x_total += xs[i as usize] * i - xs[i as usize] * (len - 1 - i);
    }

    let mut y_total = 0;
    let len = ys.len() as i64;
    for i in 0..len {
        y_total += ys[i as usize] * i - ys[i as usize] * (len - 1 - i);
    }
    (x_total % MOD * y_total % MOD) % MOD
}

fn main() {
    input!{
        n: usize,
        m: usize,
        xs: [i64; n],
        ys: [i64; m],
    }
    println!("{}", solve(xs, ys));
}