#include "bits/stdc++.h" using namespace std; int main() { int N; cin >> N; vector A(N); map m1; for (int i = 0; i < N; i++) { cin >> A[i]; m1[A[i]]++; } map m2; for (auto i : m1){ m2[i.second]++; } long long mod = (long long)1e9 + 7; long long ans = 0; for (auto i: m2) { for (auto j : m2) { if (i.first <= j.first) continue; for (auto k : m2) { if (i.first <= k.first) continue; if (j.first <= k.first) continue; ans += (long long)i.first * j.first % mod * k.first % mod * i.second % mod * j.second % mod * k.second % mod; ans %= mod; } } } for (auto i : m2) { for (auto j : m2) { if (i == j) continue; ans += (long long)i.first * i.first % mod * j.first % mod * ((long long)i.second * (i.second - 1) / 2) % mod * j.second % mod; ans %= mod; } } for (auto i : m2) { ans += (long long)i.first * i.first % mod * i.first % mod * (((long long)(i.second) * (i.second - 1) * (i.second - 2) / 6) % mod) % mod; ans %= mod; } cout << ans << endl; }