use integer;sub f{map{push@{-$_},"$a[--$|] $'"for@a=/\d+ /g}<>;my$r=1;$r+=$t=!$c[$_]++&&&f,$%+=$t*($N-$t)*/ /*$'*2for@{-$_};$r}f for$N=<>;print$%