#P10589. Totem Counting in Ancient Wall Painting
Totem Counting in Ancient Wall Painting
Totem Counting in Ancient Wall Painting
The ancient wall painting in Loulan City shows N distinct points with coordinates (1, y1), (2, y2), ..., (N, yN). The vertical coordinates y1, y2, ..., yN form a permutation of the numbers from 1 to N. Two tribes worship different totems represented by specific patterns in any triple of points:
- A V-totem is defined for a triple with indices \(1 \le i < j y_j \quad \text{and} \quad y_j < y_k \]
- An \(\wedge\)-totem is defined for a triple with indices \(1 \le i < j < k \le N\) such that \[ y_i y_k \]
Your task is to count how many V-totems and \(\wedge\)-totems exist among the N points.
inputFormat
The input consists of two lines:
- The first line contains a single integer N, the number of points.
- The second line contains N space-separated integers representing the permutation \(y_1, y_2, \dots, y_N\).
outputFormat
Print two space-separated integers. The first is the count of V-totems and the second is the count of \(\wedge\)-totems.
sample
5
1 5 3 2 4
3 4
</p>