Farmer John's N cows (3≤N≤1000) stand in a row on the number line, and no two of them stand at the same position. They are practicing throws with a baseball before an important game against the cows on the neighboring farm.
While Farmer John watches, three cows (X,Y,Z) complete two successful throws. Cow X throws the ball to cow Y, who stands to the right of X, and then cow Y throws the ball to cow Z, who stands to the right of Y. The second throw travels at least as far as the first one and no more than twice as far. Count the triples (X,Y,Z) that Farmer John could have been watching.
In the first example five cows stand at positions 3, 1, 10, 7, 4. The four triples that work are the cows at positions (1,3,7), (1,4,7), (4,7,10), (1,4,10).