1 2 3 4 5 6 7 8 9 10 11 12
#!/usr/bin/awk -f { xs[++i] = $1 ys[$2]++ } END { for (i in xs) d += xs[i] * ys[xs[i]] print d }