#include #include #include #include using namespace std; #define RREP(i,s,e) for (int i = e-1; i >= s; i--) #define rrep(i,n) RREP(i,0,n) #define REP(i,s,e) for (int i = s; i < e; i++) #define rep(i,n) REP(i,0,n) map,int> comb; long long combination(int n, int k) { int ret; pair p {n,k}; if (comb.count(p)) return comb[p]; if (n < k) return 0; else if (n == k || k == 0) return 1; else { comb[p] = (combination(n-1,k) + combination(n-1,k-1)) % 1000000007; return comb[p]; } } int main() { int n; cin >> n; map a; rep(i,n) { int x; cin >> x; a[x]++; } long long ans = combination(n,3); for (auto p : a) ans = (ans - (combination(p.second,2)*(n-p.second) + combination(p.second,3)) % 1000000007 + 1000000007) % 1000000007; cout << ans << endl; return 0; }