■ middle j■ lower than middle■ higher than middle
rising = lowerLeft × higherRight, falling = higherLeft × lowerRight
teams = 0
teams added with each soldier as the middle
Every team has a middle soldier j. Fix j, count who is smaller or bigger on each side, and multiply: that counts all teams through j without listing them.