values. Consider every way to pick exactly 5 of its elements while keeping their order (subsequences of length 5; picks with different index sets are different even if the numbers match).
A pick is good when its middle, third element is the **unique mode**: that value occurs among the five strictly more often than any other value.
Count the good picks. The count can be large, so return it modulo 10⁹ + 7.values=[5, 5, 1, 5, 5, 5] → 3
Six elements give six picks of five, each dropping one element. Dropping index 0, 1 or 2 leaves a 5 in the middle, and 5 is the most frequent value. Dropping index 3, 4 or 5 puts the 1 in the middle, which appears once and is not the mode. That makes 3.
values=[1, 2, 3, 2, 1] → 0
The only pick is the whole array. The middle value 3 appears once, while 1 and 2 appear twice each.
values=[6, 4, 6, 8, 6] → 1
The middle value 6 appears three times, every other value once.
len(values) ≤ 1000values[i] ≤ 10⁹values=[5, 5, 1, 5, 5, 5]
3
Run checks the first 3 tests in your browser. Submit checks all 136 tests on the server, hidden ones included.