#include #include #include #include #include #include #include #include #include using namespace std; #define FOR(x,y) for(int x = 0;x < y;x++) #define LLI long long int template class UF { public: vector par,rank,cnt; UF() {par=rank=vector(um,0); cnt=vector(um,1); for(int i=0;irank[y]) return par[x]=y; rank[x]+=rank[x]==rank[y]; return par[y]=x; } }; LLI combination(int n){ return (LLI)n*(n-1)*(n-2)/6; } LLI combination2(int n){ return (LLI)n*(n-1)/2; } LLI calculate(int n,int m){ if(m==2)return n-2; else{ return combination2(m)*(n-m)+combination(m); } } int main() { int n; cin >> n; map data; vector buffer; FOR(i, n) { int value; cin >> value; if(data.find(value) == data.end()) { data[value] = 1; buffer.push_back(value); } else { data[value]++; } } const LLI mod = 1000000007; LLI count = combination(n); LLI remove = 0; for(auto iterator = data.begin(); iterator != data.end();iterator++) { remove += calculate(n, iterator->second); } LLI result = (count - remove) % mod; cout << result << endl; return 0; }