


Let 'ARR' = [1,0,0] then the possible subarrays of 'ARR' will be: {1}, {0}, {0}, {1,0}, {0,0}, {1,0,0}.
If the given array 'ARR' = [1,0,0,0,1,1,0,1]
Then the number of 1’s subarrays will be 5. [{1},{1},{1},{1,1},{1}]
And the number of 0’s subarrays will be 7. [{0},{0},{0},{0,0},{0,0},{0,0,0},{0}]
So our answer will be 5 + 7 = 12.
The first line of input contains an integer ‘T’ denoting the number of test cases to run. Then the test case follows.
The first line of each test case contains an integer ‘N’ representing the array’s size.
The second line of each test case contains N space-separated integers representing the array’s elements.
For each test case print, the sum of the number of 1’s subarrays and the number of 0’s subarrays.
For each test case print output in a separate line.
You don’t have to take any input or print anything; it already has been taken care of. Just implement the function.
1 <= T <= 100
1 <= N <= 5000
0 <= ARR[i] <= 1
Where ARR[i] denotes the elements of the array.
Time Limit: 1 sec
We will do the same for 0 also, by taking variables ‘COUNT0’ = 0, and ‘SUM0’ = 0.
After that, we will return ‘SUM1’ + ‘SUM0’.
Algorithm: