#C4683. Maximum Distinct Snippet Sum

    ID: 48248 Type: Default 1000ms 256MiB

Maximum Distinct Snippet Sum

Maximum Distinct Snippet Sum

Given an array of \(n\) integers, a snippet is defined as any contiguous subarray. The value of a snippet is the sum of its distinct elements. In other words, if a snippet spans indices \(i\) to \(j\), its value is given by:

$$\sum_{x \in S} x$$

where \(S\) is the set of distinct elements in the subarray \(a_i, a_{i+1}, \ldots, a_j\). Your task is to compute the maximum snippet value over all possible snippets of the array.

inputFormat

The first line of input contains a single integer (n), the number of elements in the array. The second line contains (n) space-separated integers representing the array elements.

outputFormat

Output a single integer denoting the maximum snippet value.## sample

6
1 2 1 3 4 2
10

</p>