You are given an array $$$a$$$ of $$$n$$$ integers, where all elements except for at most one are equal to $$$-1$$$ or $$$1$$$. The remaining element $$$x$$$ satisfies $$$-10^9 \le x \le 10^9$$$.
Find all possible sums of subarrays of $$$a$$$, including the empty subarray, whose sum is defined as $$$0$$$. In other words, find all integers $$$x$$$ such that the array $$$a$$$ has at least one subarray (possibly empty) with sum equal to $$$x$$$. A subarray is a contiguous subsegment of an array.
Output these sums in ascending order. Each sum should be printed only once, even if it is achieved by multiple subarrays.
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then, $$$t$$$ test cases follow.
Each test case consists of two lines:
Additional constraint on the input: the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
For each test case, output two lines:
Each sum should be printed only once, even if it is produced by multiple subarrays.
551 -1 10 1 15-1 -1 -1 -1 -12-1 227 131 4 -1
8 -1 0 1 2 9 10 11 12 6 -5 -4 -3 -2 -1 0 4 -1 0 1 2 4 0 1 7 8 6 -1 0 1 3 4 5
Let's define $$$a[i,j]$$$ as the subarray of $$$a$$$ from position $$$i$$$ to position $$$j$$$.
Consider the first test case of the example:
Name |
---|