Sort the three values as . The sum of differences equals . Thus an odd gives zero triples. If , all values must be equal, giving triples.
Otherwise, let . If , the answer is zero. For , the minimum has choices, and the maximum is . There are strictly intermediate values, each giving six permutations. If the middle value equals either endpoint, each of the two choices gives three permutations. Hence each minimum contributes triples, and the answer is .
Subtask 1: enumerate every ordered triple in time and extra space. Subtask 2: evaluate the formula in time and extra space.
The maximum answer is . All required arithmetic fits in signed 64-bit integers. Avoid 32-bit multiplication and floating-point arithmetic.
Solution written by GPT