Official algorithmic problem description and constraints.
Polycarp was given an array π of π integers. He really likes triples of numbers, so for each π (1β€πβ€πβ2) he wrote down a triple of elements [ππ,ππ+1,ππ+2].
Polycarp considers a pair of triples π and π beautiful if they differ in exactly one position, that is, one of the following conditions is satisfied:
Find the number of beautiful pairs of triples among the written triples [ππ,ππ+1,ππ+2].
Detailed video explanations, mathematical intuition, and clean C++ implementation code.