values. The variety of a non-empty window (a run of consecutive elements) is the number of distinct values it contains.
Square the variety of every window of the array and add the results up. The total can be huge, so return it modulo 10⁹ + 7.values=[3, 3, 5] → 12
The windows [3], [3], [5] and [3, 3] hold one distinct value each, while [3, 5] and [3, 3, 5] hold two: 1 + 1 + 1 + 1 + 4 + 4 = 12.
values=[1, 2, 3] → 20
Three windows of length 1 give 1 each, two of length 2 give 4 each, and the whole array gives 9: 20 in total.
len(values) ≤ 10⁵values[i] ≤ 10⁵values=[3, 3, 5]
12
Run checks the first 3 tests in your browser. Submit checks all 115 tests on the server, hidden ones included.