0%

Max. Score:75

A Shikaari (hunter) once went on a Code hunt and came across an array A. Being a Shikaari, he wanted to hunt for all possible pairs of indices L and R, such that A[L] and A[R] are equal. He writes down all such pairs of indices L and R, on a piece of paper and then for every such pair, he calculates the sum of elements between these 2 indices(both Exclusive). But, Shikaaris always look for as much hunt as possible, so he wanted to find the maximum sum that he would have obtained after calculating the sum for all possible pairs he listed on the paper. Help him find the Maximum Sum.

**Input:**

The first line of input contains number of testcases T. The 1st line of each testcase, contains a single integer N denoting the number of elements in the array A. The 2nd line of each testcase, contains N space separated integers denoting the elements of the array A

**Output:**

For each testcase you need to print the Maximum sum that the Shikaari would be able to get.

**Constraints:**

1 <= T <= 10

1 <= N <= 105

0 <= A[i] <= 105

**Example :**

**Input :**

1

6

1 3 4 1 3 8

**Output :**

7

**Explanation:**

The Shikaari writes down the following pair of numbers,

1) 0, 3; Here A[0] = A[3] = 1 and the sum of the array from 0 to 3(Both Exclusive) is 3 + 4 = 7

2) 1, 4; Here A[1] = A[4] = 3 and the sum of the array from 0 to 3(Both Exclusive) is 4 + 1 = 5

Thus the maximum sum is 7.

Login to report an issue on this page.