Unnamed Trick 1
Prerequisite Task 1: You are given two array $A$ and $B$ of length $n$.
For each $j$ ($0\le j \le n-1$) print $\sum_{i=0}^{j-1}{[A_{i}=B_{j}]}$
In other words, for each $j$($0\le j \le n-1$) print number of index $i$(i<j) where $B_j=A_i$
Constraints click to hide $1\le n \le 10^{5}$
$-10^{9} \le A_{i},B_{i} \le 10^{9}$
cpp map<int, int> cnt; for (int j = 0; j < n; j++) { cout << cnt[B[j]] << '\n'; cnt[A[j]]++; } Prerequisite Task 2: Same as task 1, just find $\sum_{j=0}^{n-1}{\sum_{i=0}^{j-1}{[A_{i}=B_{j}]}}$