#K50742. Unique Prefix Sum Evaluation

    ID: 28932 Type: Default 1000ms 256MiB

Unique Prefix Sum Evaluation

Unique Prefix Sum Evaluation

You are given multiple test cases. In each test case, you are given an array (A) of (N) integers. The prefix sum array (P) is defined as follows: (P[0] = A[0]) and for (i \ge 1), (P[i] = P[i-1] + A[i]). Your task is to compute the prefix sum array for each test case, extract all unique values from it, and then output the sum of these unique values.

For example, if (A = [1, 2, 3, 4, 5]), then the prefix sum array is (P = [1, 3, 6, 10, 15]). Since all values in (P) are unique, the answer is (1 + 3 + 6 + 10 + 15 = 35).

inputFormat

The input begins with an integer (T) (the number of test cases).

Each test case consists of two lines:
1. The first line contains an integer (N), the number of elements in the array.
2. The second line contains (N) space-separated integers, representing the array (A).

outputFormat

For each test case, output a single line containing the sum of all unique values from the prefix sum array.## sample

2
5
1 2 3 4 5
4
1 1 1 1
35

10

</p>