Codeforces Global Round 19
D
Yet Another Minimization Problem
Codeforces
1800
原题
← CE →
翻译中…

You are given two arrays $a$ and $b$, both of length $n$.

翻译中…

You can perform the following operation any number of times (possibly zero): select an index $i$ ($1 \leq i \leq n$) and swap $a_i$ and $b_i$.

翻译中…

Let's define the cost of the array $a$ as $\sum_{i=1}^{n} \sum_{j=i + 1}^{n} (a_i + a_j)^2$. Similarly, the cost of the array $b$ is $\sum_{i=1}^{n} \sum_{j=i + 1}^{n} (b_i + b_j)^2$.

翻译中…

Your task is to minimize the total cost of two arrays.

翻译中…

Input

翻译中…

Each test case consists of several test cases. The first line contains a single integer $t$ ($1 \leq t \leq 40$) — the number of test cases. The following is a description of the input data sets.

翻译中…

The first line of each test case contains an integer $n$ ($1 \leq n \leq 100$) — the length of both arrays.

翻译中…

The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 100$) — elements of the first array.

翻译中…

The third line of each test case contains $n$ integers $b_1, b_2, \ldots, b_n$ ($1 \leq b_i \leq 100$) — elements of the second array.

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $100$.

翻译中…

Output

翻译中…

For each test case, print the minimum possible total cost.

翻译中…

Note

翻译中…

In the second test case, in one of the optimal answers after all operations $a = [2, 6, 4, 6]$, $b = [3, 7, 6, 1]$.

翻译中…

The cost of the array $a$ equals to $(2 + 6)^2 + (2 + 4)^2 + (2 + 6)^2 + (6 + 4)^2 + (6 + 6)^2 + (4 + 6)^2 = 508$.

翻译中…

The cost of the array $b$ equals to $(3 + 7)^2 + (3 + 6)^2 + (3 + 1)^2 + (7 + 6)^2 + (7 + 1)^2 + (6 + 1)^2 = 479$.

翻译中…

The total cost of two arrays equals to $508 + 479 = 987$.

翻译中…

样例

Input #1
3
1
3
6
4
3 6 6 6
2 7 4 1
4
6 7 2 4
2 5 3 5
Output #1
0
987
914
InputCopy OutputCopy
题目信息
题号
1637D
时间限制
2 s
内存限制
256 MB
标签
动态规划
贪心
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。