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 C (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_DIM_CNT		2										// 次元数
#define D_LINE_CNT		100000									// 最大線数
#define D_MOD			1000000007								// 除数

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpT, *szpFpA;
#endif

// ソート関数 - int昇順
int
fSortFnc(
	const void *pzpVal1			// <I> 値１
	, const void *pzpVal2		// <I> 値２
)
{
	int *lipVal1 = (int *)pzpVal1;
	int *lipVal2 = (int *)pzpVal2;

	// 昇順
	if (*lipVal1 >  *lipVal2) {
		return(1);
	}
	else if (*lipVal1 < *lipVal2) {
		return(-1);
	}

	return 0;
}

// 同一値の削除
int
fDelSame(
	int *pipArray				// <I/O> 配列
	, int *pipACnt				// <I/O> 配列数
)
{
	int i;

	// 配列更新
	int liTNo = 1;
	for (i = 1; i < *pipACnt; i++) {
		if (pipArray[i] != pipArray[i - 1]) {
			pipArray[liTNo] = pipArray[i];
			liTNo++;
		}
	}

	// 配列数更新
	*pipACnt = liTNo;

	return 0;
}

// 実行メイン
int
fMain(
	int piTNo					// <I> テスト番号 1～
)
{
	int i, j;
	char lc1Buf[1024], lc1Out[1024];

	// テストファイルオープン
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", piTNo);
	szpFpT = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", piTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#endif

	// 本数取得
	int li1Cnt[D_DIM_CNT];
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpT);
#else
	fgets(lc1Buf, sizeof(lc1Buf), stdin);
#endif
	sscanf(lc1Buf, "%d%d", &li1Cnt[0], &li1Cnt[1]);

	long long ll1Len[D_DIM_CNT];
	for (i = 0; i < D_DIM_CNT; i++) {

		// 長さ合計 - 初期化
		ll1Len[i] = 0;

		// 直線位置 - 取得
		int li1Pos[D_LINE_CNT];
		for (j = 0; j < li1Cnt[i]; j++) {
#ifdef D_TEST
			fscanf(szpFpT, "%d", &li1Pos[j]);
#else
			fscanf(stdin, "%d", &li1Pos[j]);
#endif
		}

		// 直線位置 - ソート
		qsort(li1Pos, li1Cnt[i], sizeof(int), fSortFnc);

		// 直線位置 - 同一値の削除
		fDelSame(li1Pos, &li1Cnt[i]);

		// 長さ合計 - 取得
		for (j = 0; j < li1Cnt[i]; j++) {

			// 右側(上側)
			ll1Len[i] += (long long)li1Pos[j] * (long long)j % D_MOD;
			ll1Len[i] %= D_MOD;

			// 左側(下側)
			ll1Len[i] -= (long long)li1Pos[j] * (long long)(li1Cnt[i] - j - 1) % D_MOD;
			ll1Len[i] %= D_MOD;
		}
	}

	// 合計面積
	long long llArea = ll1Len[0] * ll1Len[1] % D_MOD;

	// 結果セット
	sprintf(lc1Out, "%lld\n", llArea);

	// 結果表示
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, lc1Out)) {
		siRes = -1;
	}
#else
	printf("%s", lc1Out);
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpT);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", piTNo);
	}
	else {
		printf("NG %d\n", piTNo);
	}
#endif

	return 0;
}

int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		fMain(i);
	}
#else
	fMain(0);
#endif

	return 0;
}