values. A pair of indices (i, j) with i < j is balanced when values[i] plus the mirror of values[j] equals values[j] plus the mirror of values[i].
Return the number of balanced pairs. The count can be huge, so return it modulo 10⁹ + 7.values=[12, 23, 9, 34] → 3
The balanced pairs are (0, 1): 12 + 32 = 23 + 21 = 44, (0, 3): 12 + 43 = 34 + 21 = 55 and (1, 3): 23 + 43 = 34 + 32 = 66. The 9 pairs with nothing, so the answer is 3.
values=[31, 20, 53, 2] → 3
Pair (0, 2): 31 + 35 = 66 and 53 + 13 = 66, so it balances. No other pair does, so the answer is 1.
values=[5, 707, 0] → 3
All three numbers equal their own mirrors, so each of the three pairs balances.
len(values) ≤ 10⁵values[i] ≤ 10⁹values=[12, 23, 9, 34]
3
Run checks the first 3 tests in your browser. Submit checks all 103 tests on the server, hidden ones included.