#P10998. Counting Special Quadruplets
Counting Special Quadruplets
Counting Special Quadruplets
You are given m triplets \((u_i, v_i, w_i)\) such that \(1 \le u_i < v_i < w_i \le n\) and all the triplets are pairwise distinct. Count the number of quadruplets \((a, b, c, d)\) satisfying \(1 \le a < b < c < d \le n\) for which the following four triplets exist among the given triplets:
- \((a, b, c)\)
- \((a, b, d)\)
- \((a, c, d)\)
- \((b, c, d)\)
Find and output the number of such quadruplets.
inputFormat
The first line contains two integers \(n\) and \(m\), where \(n\) is the maximum number and \(m\) is the number of given triplets.
Each of the next \(m\) lines contains three integers \(u_i, v_i, w_i\) representing a triplet. It is guaranteed that \(1 \le u_i < v_i < w_i \le n\) and all triplets are pairwise distinct.
outputFormat
Output a single integer, the number of quadruplets \((a,b,c,d)\) satisfying the condition.
sample
4 4
1 2 3
1 2 4
1 3 4
2 3 4
1