values. Call four indices p < q < r < s a balanced quadruple if:
- values[p] * values[r] == values[q] * values[s];
- every two neighbouring chosen indices have at least one unchosen element between them: q - p ≥ 2, r - q ≥ 2, s - r ≥ 2.
Return the number of balanced quadruples. Two quadruples are different if they differ in at least one index.values=[2, 9, 3, 9, 6, 9, 4] → 1
Indices (0, 2, 4, 6) work: 2 · 6 = 3 · 4 = 12, and there is a gap between neighbouring indices. There are no others.
values=[1, 2, 3, 4, 5, 6, 7] → 0
With length 7 the only possible choice is (0, 2, 4, 6), and 1 · 5 ≠ 3 · 7.
values=[5, 5, 5, 5, 5, 5, 5, 5] → 5
values=[2, 9, 3, 9, 6, 9, 4]
1
Run checks the first 3 tests in your browser. Submit checks all 111 tests on the server, hidden ones included.