|
<p> |
|
What day is it today? Wasn't there something you were supposed to remember? Eh, it was probably nothing... |
|
</p> |
|
|
|
<p> |
|
... |
|
</p> |
|
|
|
<p> |
|
Wait! Oh no! It's your anniversary today! And you don't have a gift for your spouse! |
|
</p> |
|
|
|
<p> |
|
Only one thing can save you now: online shopping. Logging onto your favourite shopping site, the top automated suggestion looks perfect (or at least passable) — a graph. |
|
Your spouse probably loves graphs, right? More importantly, it can be delivered directly to your house within half an hour. |
|
</p> |
|
|
|
<p> |
|
The graph comes with <strong>N</strong> nodes, the <em>i</em>th of which is labelled with a non-zero integer <strong>L<sub>i</sub></strong>. |
|
Unfortunately, no edges are included by default — you have to pay extra for those. You'd better purchase one or more edges so that it looks like you put extensive thought into your gift. |
|
Purchasing an undirected edge between two different nodes <em>i</em> and <em>j</em> costs <strong>L<sub>i</sub></strong> * <strong>L<sub>j</sub></strong> dollars |
|
(note that this cost may be negative, in which case you actually receive money for "purchasing" that edge). |
|
You won't purchase more than one edge between any unordered pair of nodes, and you won't purchase any self-loops (edges connecting a node directly to itself). |
|
</p> |
|
|
|
<p> |
|
In order to make the graph appealing to your spouse, you've decided that it should have the following two properties: |
|
</p> |
|
|
|
<ol> |
|
<li> Each node should be adjacent to at least one other node. </li> |
|
<li> Each node with a positive label should be adjacent to at most one node with a negative label. </li> |
|
</ol> |
|
|
|
<p> |
|
Any such graph should make a fine gift, so... you might as well go with the cheapest option, right? |
|
You'd like to determine the minimum possible total cost of edges to purchase which result in a graph with both properties described above. Note that this total "cost" may be negative. |
|
</p> |
|
|
|
|
|
<h3>Input</h3> |
|
|
|
<p> |
|
Input begins with an integer <strong>T</strong>, the number of test cases. |
|
For each test case, there is first a line containing the integer <strong>N</strong>. |
|
Then one more line follows containing the <strong>N</strong> space-separated integers <strong>L<sub>1</sub></strong> through <strong>L<sub>N</sub></strong>. |
|
</p> |
|
|
|
|
|
<h3>Output</h3> |
|
|
|
<p> |
|
For the <em>i</em>th test case, output a line containing "Case #<em>i</em>: " followed by the minimum cost (in dollars) required to complete the graph gift. |
|
</p> |
|
|
|
|
|
<h3>Constraints</h3> |
|
|
|
<p> |
|
1 ≤ <strong>T</strong> ≤ 40 <br /> |
|
2 ≤ <strong>N</strong> ≤ 30,000 <br /> |
|
-10,000,000 ≤ <strong>L<sub>i</sub></strong> ≤ 10,000,000 <br /> |
|
<strong>L<sub>i</sub></strong> ≠ 0 <br /> |
|
</p> |
|
|
|
|
|
<h3>Explanation of Sample</h3> |
|
|
|
<p> |
|
In the first case, you should purchase an edge between the two nodes for a cost of (-1)*(-1) = 1. |
|
</p> |
|
|
|
<p> |
|
In the second case, you should purchase an edge from the third node to each of the other nodes, for a cost of (-3)*(-1) + (-3)*2 + (-3)*4 = -15. |
|
</p> |
|
|
|
|